SDL, OpenGL, and Drawing only part of the screen

Fellow SDL enthusiasts,
I have a program using SDL and OpenGL, and whenever I need to refresh
the screen vI call SDL_GL_SwapBuffers();. But on slower computers,
it takes a while to render the whole screen, and it therefore looks
choppy. Is there a way to only refresh part of the screen, for
example like the part that has changed?

I was thinking about using glViewport to only draw to part of the
screen but I still have to use SDL_GL_SwapBuffers();. to make the
changes visible.

Is there a way I can only refresh part of the screen?

-Trevor
http://www.lackeyccg.com

Trevor Agnitti wrote:

I have a program using SDL and OpenGL, and whenever I need to refresh
the screen vI call SDL_GL_SwapBuffers();. But on slower computers, it
takes a while to render the whole screen, and it therefore looks
choppy. Is there a way to only refresh part of the screen, for example
like the part that has changed?

If you’re using double-buffering, no. Think about it: that would require
copying the parts in question from the back buffer to the front buffer,
which would surely be slower than just swapping the two buffers.

However, nothing stops you from drawing only the parts that have
changed. Just don’t glClear() before drawing. But keep in mind that
(with double-buffering) what you have in the back buffer may be either
from the last frame (if the driver did a buffer copy) or from two frames
ago (if it did a buffer swap). (Actually, I’m not even sure whether it’s
guaranteed to be one of these two. Look that up before you rely on it.)

I was thinking about using glViewport to only draw to part of the screen
but I still have to use SDL_GL_SwapBuffers();. to make the changes visible.

Is there a way I can only refresh part of the screen?

You could use single-buffered OpenGL, then a glFlush() should be enough
to make your drawings show up (I imagine - I don’t think I’ve ever tried
that). At the price of flickering, though, depending on what you do.

-Christian

I was thinking about using glViewport to only draw to part of the screen
but I still have to use SDL_GL_SwapBuffers();. to make the changes visible.

Is there a way I can only refresh part of the screen?

glViewport doesn’t work like that…generally you redraw the whole frame
each time and swap the buffers (which is different than how a 2D app,
which benefits from less drawing, works).

If you have even basic hardware acceleration and can reasonably ask if
there’s a way to avoid drawing parts of the screen, OpenGL is not your
bottleneck! You might be hitting a slow path (use a display list instead
of immediate mode, for example), or there’s something you can optimize
in the application itself (if you have 100 things to draw and you know
that 99 of them are off screen, only draw the one instead of having
OpenGL cull it for you).

–ryan.

Hi,

Why are you using OpenGL anyway ?

Is you game 3-d ?

If no then don’t use OpenGL and use the basic S.D.L. graphic functions
(which support drawing small parts of the screen)…

Jesse
SLNTHERO at AOL.com (mailto:SLNTHERO at AOL.com)
Silent Hero Productions®
http://www.SilentHeroProductions.com (http://www.SilentHeroProductions.com)

In a message dated 10/8/2006 6:26:51 P.M. Eastern Standard Time,
icculus at icculus.org writes:

I was thinking about using glViewport to only draw to part of the screen
but I still have to use SDL_GL_SwapBuffers();. to make the changes visible.

Is there a way I can only refresh part of the screen?

glViewport doesn’t work like that…generally you redraw the whole frame
each time and swap the buffers (which is different than how a 2D app,
which benefits from less drawing, works).

If you have even basic hardware acceleration and can reasonably ask if
there’s a way to avoid drawing parts of the screen, OpenGL is not your
bottleneck! You might be hitting a slow path (use a display list instead
of immediate mode, for example), or there’s something you can optimize
in the application itself (if you have 100 things to draw and you know
that 99 of them are off screen, only draw the one instead of having
OpenGL cull it for you).

–ryan._______________________________________________
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl