[SDL] Flickering and division by zero in Windows

Andre de Leiradella leiradella at bigfoot.com
Wed Feb 28 19:06:58 PST 2007


Hi Ryan.
> I'm just wondering if SDL_gfx is implicitly calling SDL_Flip() and so 
> are you, causing you to each update a different buffer with some part of 
> the rendering (and hence, flicker).
>   
Now I understand. I had a look at SDL_gfxPrimitives' source code and 
there is no SDL_Flip in there though.
> I'm just guessing, though. Can you post source code that triggers this 
> issue? That would make it much easier to say what's going wrong.
>   
Lua code? Won't help much... but here it goes:

-- set the video mode
local screen = image_lib.set_video(800, 600)
-- load and resize the background
local background = image_lib.load('background.png')
background = background.resize(screen.width, screen.height)
-- evaluates a half-transparent black color
local transparent = image_lib.color(0, 0, 0, 128)
-- loop until the user presses the left mouse button
while true do
    -- query the mouse
    x, y, left = input_lib.mouse()
    -- blit the background to the screen, covering all pixels
    background.blit(screen, 0, 0)
    -- fill a square with the half-transparent black
    screen.filled_rect(10, 10, screen.width - 10, screen.width - 10, 
transparent)
    -- update the screen
    screen.update()
    -- if left mouse button was pressed, break the loop
    if left then
       break
    end
end

. screen is obtained via SDL_SetVideoMode
. background is an 8bpp image loaded via IMG_LoadImage and resized via 
SDL_ResizeXY from Dave Olsen et al.
. the transparent color is obtained combining red, green, blue and alpha 
values into a single Uint32
. input_lib.mouse queries the mouse using SDL_GetMouseState
. background.blit blits the background image over another surface, in 
this a screen, using SDL_BlitSurface
. screen.update() calls either SDL_Flip or SDL_UpdateRect, I tried both 
in my tests

Thanks for the interest!

Andre


More information about the SDL mailing list