First i am new to SDL and for a long time I didn’t programm anything…
So, I want to learn some old graphics programming in the claasic 320x200x8 VGA Mode.
I managed to get it working. But with SDL2 it’s much slower than with SDL1.
I was wondering if this is normal or something with my code is wrong?
I use a 8Bit RGBSurface, a 32bit RGBSurface, and texture in streaming mode.
this is how I create the window ect. (shortened)
SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;
SDL_Texture *texture = NULL;
SDL_Surface *helper_surface = NULL;
SDL_Surface *video_buffer = NULL;
window = SDL_CreateWindow(“SDL2 Stars”, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, XRES, YRES, vmodeflag);
renderer = SDL_CreateRenderer(window, -1, 0);
SDL_RenderSetLogicalSize(renderer, XRES, YRES);
video_buffer = SDL_CreateRGBSurface(0, XRES, YRES, 8, 0, 0, 0, 0);
helper_surface = SDL_CreateRGBSurface(0, XRES, YRES, 32, 0, 0, 0, 0);
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, XRES, YRES);
where XRES = 320
YRES = 200
vmodeflag one of SDL_WINDOW_SHOWN, SDL_WINDOW_FULLSCREEN, SDL_WINDOW_FULLSCREEN_DESKTOP
and this is the function that I call to make the pixels I draw to the 8bit Surface visible on screen.
/* blit the 320x200x8 Surface to a 32bit helper /
/ Surface for pixel format conversion (8bit palettized to /
/ 32bit). SDL2 Textures don’t work with 8bit pixels formats. */
SDL_BlitSurface(video_buffer, NULL, helper_surface, NULL);
/* move it to the texture */
SDL_LockTexture(texture, NULL, &pixels, &pitch);
/* maybe slower than SDL_ConvertPixels ?? */ //SDL_UpdateTexture(texture, NULL, helper_surface->pixels, helper_surface->pitch);
/* and make it visible on screen */
SDL_RenderCopy(renderer, texture, NULL, NULL);
In SDL1 it’s just Blitting the surface I draw on, to the screen surface and then call SLD_Flip.
That’s much faster …
Is there anything wrong with my SDL2 code or any way to do it without texture and renderer?