Put back the simple in simplegfx

This commit is contained in:
plutoo 2018-02-01 22:28:30 +01:00
parent 03144eba8a
commit 227c2f7cea

View File

@ -2,28 +2,20 @@
#include <stdio.h> #include <stdio.h>
#include <switch.h> #include <switch.h>
#include "image_bin.h"//Your own raw RGB888 1280x720 image at "data/image.bin" is required.
//See also libnx gfx.h. //See also libnx gfx.h.
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
u8 *framebuf; u32* framebuf;
u32 *framebuf32;
u32 width=0, height=0;
u32 image_width = 1280, image_height = 720;
u32 tmp_width, tmp_height;
u32 x, y;
u32 j;
u32 pos;
u32 pos2;
u8 *imageptr = (u8*)image_bin;
u32 cnt=0; u32 cnt=0;
//gfxInitResolutionDefault();//Enable max-1080p support. Remove for 720p-only resolution. //Enable max-1080p support. Remove for 720p-only resolution.
//gfxInitResolutionDefault();
gfxInitDefault(); gfxInitDefault();
//gfxConfigureAutoResolutionDefault(true);//Set current resolution automatically depending on current/changed OperationMode. Only use this when using gfxInitResolution*().
//Note that while the above commented code enables 1080p for docked-mode, this example only draws a 720p image, with the rest of the screen being left at white. //Set current resolution automatically depending on current/changed OperationMode. Only use this when using gfxInitResolution*().
//gfxConfigureAutoResolutionDefault(true);
while(appletMainLoop()) while(appletMainLoop())
{ {
@ -32,8 +24,8 @@ int main(int argc, char **argv)
if (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_PLUS) break; if (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_PLUS) break;
framebuf = gfxGetFramebuffer((u32*)&width, (u32*)&height); u32 width, height;
framebuf32 = (u32*)framebuf; framebuf = (u32*) gfxGetFramebuffer((u32*)&width, (u32*)&height);
if(cnt==60) if(cnt==60)
{ {
@ -44,22 +36,12 @@ int main(int argc, char **argv)
cnt++; cnt++;
} }
tmp_width = image_width;
tmp_height = image_height;
if(tmp_width > width) tmp_width = width;
if(tmp_height > height) tmp_height = height;
memset(framebuf, 0xff, gfxGetFramebufferSize());
for(x=0; x<image_width; x+=4)//Every 4 pixels with the below pixel-format is stored consecutively in memory.
{
for(y=0; y<image_height; y++)
{
//Each pixel is 4-bytes due to RGBA8888. //Each pixel is 4-bytes due to RGBA8888.
pos = gfxGetFramebufferDisplayOffset(x, y); //Set framebuf to different shades of grey.
pos2 = (x + (y*image_width)) * 3; u32 x, y;
for(j=0; j<4; j++)framebuf32[pos+j] = RGBA8_MAXALPHA(imageptr[pos2+0+(j*3)]+(cnt*4), imageptr[pos2+1+(j*3)], imageptr[pos2+2+(j*3)]); for (x=0; x<width; x++)
} for (y=0; y<width; y++)
} framebuf[gfxGetFramebufferDisplayOffset(x, y)] = 0x01010101 * cnt * 4;
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
@ -69,4 +51,3 @@ int main(int argc, char **argv)
gfxExit(); gfxExit();
return 0; return 0;
} }