Hello everyone,
Currently the game I’m working on doesn’t redraw everything to the
screen everytime (it could, but doesn’t). On iOS this is fine, but on
Mac OS X (10.6.8 Snow Leopard) most of the time this is OK, but
sometimes it ‘flickers’ - it looks like some runs it has a single buffer
source and other runs it has a double buffer source - but i don’t
understand what has changed…
Anyone got any ideas why? It sort of feels like I’m using the API
wrongly by drawing incrementally per frame … is this ok or not? There
is a iPhoneOS example that does this in ‘rectangles.c’ (although that
does have a SDL_RenderClear() before the main loop … but since I draw
the whole screen … I can’t see that being a problem).
I’m currently building against SDL 1.3 build 5605 (although I have the
repo checked out here that I will test against the tip next).
My code looks like this (with some lines removed for clarity):
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0)
{return 1;}
window = SDL_CreateWindow("Gulpman",
WINDOW_X_START, WINDOW_Y_START,
SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN
);
if (!window) {return 1;}
renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) {return 1;}
SDL_Event event;
while (!done) {
while (SDL_PollEvent(&event))
{
// <<<<normal stuff here>>>
}
// <<<more uninteresting stuff here like moving player,
monsters, etc >>>
render(renderer, graphics);
SDL_Delay(50); // for testing … frame rate control
not in yet
}
// <<>>
void render(SDL_Renderer renderer, MyGraphics graphics)
{
// <<>>>
// things like x, y, fg_colour, bg_colour and colour, vary per frame
if(!bg_transparent) {
SDL_Rect rect = { x, y, GLYPH_SIZE_SCREEN,
GLYPH_SIZE_SCREEN };
SDL_SetRenderDrawColor(renderer, colour.r, colour.g,
colour.b,colour.unused);
SDL_RenderFillRect(renderer, &rect);
}
SDL_Texture* tex = texture[fg_colour];
if(tex)
{
SDL_RenderCopy(renderer, tex, &srcRect, &dstRect);
}
// <<< more lines>>>
/* update screen */
SDL_RenderPresent(renderer);
}
Regards,
Rob