Window size != viewport size under OpenGL

I’ve been looking at a lot of OpenGL-related stuff, and I think I know how to set up an OpenGL viewport that’s not the same “logical size” as the pixel size of the window it’s displaying in, and have it scale everything automagically. Problem is, all the stuff I find assumes that you’re creating the window yourself with Windows API functions. If SDL is creating the window for me, is there any specific stuff I should know about before calling glViewport()?

Hi,

Make sure you call SDL_SetVideoMode() and glVeiwport() in pairs; i.e.,
if you resize the screen, you have to call SDL, then GL.

Other than that, it’s pretty straight forward - you just create a GL
viewport within the bounds of the window - e.g.

SDL_SetVideoMode(800, 600, 32, SDL_OPENGL | SDL_RESIZABLE);

will give you a GL drawing context that is 800x600.

If you then call:

glViewport(0,0,400, 300);

You’ll get a viewport in the top-left quarter of the window.

Remember that, on Windows, 1.2 will destroy your GL context info when
you call SDL_SetVideoMode() (someone has submitted a patch, but I’m not
sure if/what version it has been integrated into), so you’ll have to
re-initialise GL everytime you resize. Given that a resize event is
quite infrequent (and user’s can/will expect some delay), it’s probably
okay to be lazy and just re-init GL after every resize (i.e., get it
working, worry about optimisation later…)

Also remember (as pointed out in the documentation) that you have to
call SDL_GL_SetAttribute() BEFORE calling SDL_SetVideoMode().

Hope this clarifies enough for you.

Jitsu Love,

Eddy

PS. wGL equivalent on X11 is XGL. Both provide essentially the same
functionality. SDL abstracts this to provide a single interface on both
platforms. That is, underneath SDL on Windows is a wGL context and on
Linux, a GLX context, it’s just that you don’t call wGL_… or GLX_…
to manipulate them…

Mason Wheeler wrote:> I’ve been looking at a lot of OpenGL-related stuff, and I think I know

how to set up an OpenGL viewport that’s not the same “logical size” as
the pixel size of the window it’s displaying in, and have it scale
everything automagically. Problem is, all the stuff I find assumes that
you’re creating the window yourself with Windows API functions. If SDL
is creating the window for me, is there any specific stuff I should know
about before calling glViewport()?



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