Hello,
I want to draw raw RGBA buffer to screen. Until now, I used sf2d, but it seems overkill for this task: I have to create and free textures all the time.
So, I tried do use gfx directly. For my opinion, the code looks much better this way: I save allocating and deallocating memory all over the time.
However, I have the following problem: When I suspend the cia, the top screen turns black. With sf2d this problem did not exist. I've created a minimal example to demonstrate the problem:
What can I do to fix the issue? And notably, is using gfx this way really better to solve my task? I.e., what is the best (i.e. fastest) way to copy a pixel buffer to screen? Should I use citro3d (is there a minimal example)?
I want to draw raw RGBA buffer to screen. Until now, I used sf2d, but it seems overkill for this task: I have to create and free textures all the time.
Code:
sf2d_texture* top_screen = sf2d_create_texture(400, 240, TEXFMT_RGBA8, SF2D_PLACE_RAM);
sf2d_fill_texture_from_RGBA8(top_screen, buffer, 400, 240);
sf2d_texture_tile32(top_screen);
sf2d_start_frame(GFX_TOP, GFX_LEFT);
sf2d_draw_texture(top_screen,0,0);
sf2d_end_frame();
sf2d_swapbuffers();
sf2d_free_texture(top_screen);
So, I tried do use gfx directly. For my opinion, the code looks much better this way: I save allocating and deallocating memory all over the time.
Code:
memcpy(gfxGetFramebuffer(GFX_TOP,GFX_LEFT,0,0), buffer, 4*240*400);
gfxFlushBuffers();
gfxSwapBuffers();
gspWaitForVBlank();
However, I have the following problem: When I suspend the cia, the top screen turns black. With sf2d this problem did not exist. I've created a minimal example to demonstrate the problem:
Code:
#include <3ds.h>
#define WIDTH 240
#define HEIGHT 400
void fill_buffer(u32* buffer, u32 color) {
int x,y;
for (y=0;y<HEIGHT;y++) {
for (x=0;x<WIDTH;x++) {
buffer[x+y*WIDTH] = color;
}
}
}
int main() {
gfxInit(GSP_RGBA8_OES, GSP_RGBA8_OES, false);
gfxSetDoubleBuffering(GFX_TOP,1);
while(aptMainLoop()) {
hidScanInput();
// fill top screen with red
fill_buffer((u32*)gfxGetFramebuffer(GFX_TOP,GFX_LEFT,0,0), 0xFF0000FF);
gfxFlushBuffers();
gfxSwapBuffers();
gspWaitForVBlank();
}
gfxExit();
return 0;
}
What can I do to fix the issue? And notably, is using gfx this way really better to solve my task? I.e., what is the best (i.e. fastest) way to copy a pixel buffer to screen? Should I use citro3d (is there a minimal example)?
Last edited by bayleef,