Why does my square remain on the screen after updating window surface?

Another issue that I’m running into is that I am not seeing changes made to my screen surface. I am testing this by drawing a square once, then updating in the loop. It does not clear the original square from the screen. What am I doing wrong?

Here is a sample of drawing the square, then updating the screen in the run loop:

draw_square(100, 100, 100);

while (true) {
? // keyboard input handling here…

? // update screen
? SDL_UpdateWindowSurface(window);
}

And here is an example of my draw_square method:

void draw_square(int x, int y, int width)
{
? SDL_Rect rect = {x, y, width, width};
? SDL_FillRect(screenSurface, &rect, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));
}

What am I doing wrong?

–Andrew

You can “clear” a surface with: SDL_FillRect(screenSurface, NULL, 0x000000);

I would recommend following an SDL tutorial. They all try to get across
the style and flow of SDL usage and should be pretty easily translatable to
SDL2.

Jonny DOn Tue, Nov 12, 2013 at 5:33 PM, Andrew Havens wrote:

Another issue that I’m running into is that I am not seeing changes made
to my screen surface. I am testing this by drawing a square once, then
updating in the loop. It does not clear the original square from the
screen. What am I doing wrong?

Here is a sample of drawing the square, then updating the screen in the
run loop:

draw_square(100, 100, 100);

while (true) {
// keyboard input handling here…

// update screen
SDL_UpdateWindowSurface(window);
}

And here is an example of my draw_square method:

void draw_square(int x, int y, int width)
{
SDL_Rect rect = {x, y, width, width};
SDL_FillRect(screenSurface, &rect, SDL_MapRGB(screenSurface->format,
0xFF, 0xFF, 0xFF));
}

What am I doing wrong?

–Andrew


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Furthermore, it looks like you are rendering the square just once (before entering the loop). Move the draw_square call inside the loop.

– Aggelos KolaitisOn 13 ??? 2013, at 1:10 ?.?., Jonathan Dearborn wrote:

You can “clear” a surface with: SDL_FillRect(screenSurface, NULL, 0x000000);

I would recommend following an SDL tutorial. They all try to get across the style and flow of SDL usage and should be pretty easily translatable to SDL2.

Jonny D

On Tue, Nov 12, 2013 at 5:33 PM, Andrew Havens wrote:
Another issue that I’m running into is that I am not seeing changes made to my screen surface. I am testing this by drawing a square once, then updating in the loop. It does not clear the original square from the screen. What am I doing wrong?

Here is a sample of drawing the square, then updating the screen in the run loop:

draw_square(100, 100, 100);

while (true) {
// keyboard input handling here…

// update screen
SDL_UpdateWindowSurface(window);
}

And here is an example of my draw_square method:

void draw_square(int x, int y, int width)
{
SDL_Rect rect = {x, y, width, width};
SDL_FillRect(screenSurface, &rect, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));
}

What am I doing wrong?

–Andrew


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org