SDL blits with OpenGL

I am porting my game design to use OpenGL accel.

I want to draw my border with icons and the command console on top of my
OpenGL
map so the use can select game options.

Can I use SDL_BlitSurface with OpenGL?

I am trying to use OpenGL textures for the items but the OpenGL
coordinate system is messing with my head (yeah am a newbie with
OpenGL). If I translate to 0.0,0.0,0.0 I cannot see to textured quad I
drew.

Any ideas?–
Robin Forster, Systems Engineer,
http://www.rsforster.ottawa.on.ca/

Ok ignore the previous I got it with SDL_OPENGLBLIT or whatever. Now I
have a new problem.

I set my viewport at init time:

glViewport(100,124,600,400);

Then when I draw a frame I clear the color buffer:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

then the dumb thing clears all 800x600 pixels of my sdl window. It says
in the redbook that OPENGL only clears the viewport portion… Is this
an SDL problem? Is there a work around?

Robin.

Robin Forster wrote:>

I am porting my game design to use OpenGL accel.

I want to draw my border with icons and the command console on top of my
OpenGL
map so the use can select game options.

Can I use SDL_BlitSurface with OpenGL?

I am trying to use OpenGL textures for the items but the OpenGL
coordinate system is messing with my head (yeah am a newbie with
OpenGL). If I translate to 0.0,0.0,0.0 I cannot see to textured quad I
drew.

Any ideas?


Robin Forster, Systems Engineer,
http://www.rsforster.ottawa.on.ca/


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


Robin Forster, Systems Engineer,
http://www.rsforster.ottawa.on.ca/

I am porting my game design to use OpenGL accel.

Uh-oh. :wink:

I want to draw my border with icons and the command console on top of my
OpenGL map so the use can select game options.

Can I use SDL_BlitSurface with OpenGL?

Short answer: No. Abridged long answer: Yes, but you really don’t want
to it sounds like. Here’s how it works in OpenGL:

// If we changed this, change it back (you probably don't need it)
glViewport (0, 0, scr_width, scr_height);

glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0, scr_width, scr_height, 0, -99999, 99999);

glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();

glDisable (GL_DEPTH_TEST);
glDisable (GL_CULL_FACE);

The above will allow you to use 2D coordinates just fine. Namely, you
should be able to glBindTexture2D, glBegin (GL_QUADS), glVertex2f …
with screen coordinates and expect it to work. I’ll refer you to the
OpenGL manpages (or reference manual, which was closer at hand for me at
the moment since nvidia doesn’t provide manpages) as to what these
functions do exactly.

The game in which the above is used, we alter the glViewport to keep the
game from drawing over the area where the status display goes, so that’s
why we change it back. You don’t want a depth test here - last drawn is
last seen. You almost always want this for 2D overlay drawing, and the
drawing itself is faster without a depth test anyway.

Do this at the end of your draw loop. At the beginning of your draw loop
you will need to reset your glOrtho, depth testing, etc, etc to the
defaults you want them to be. OpenGL is a state machine and when you make
something be set a certain way - it’s set dammit!

I am trying to use OpenGL textures for the items but the OpenGL
coordinate system is messing with my head (yeah am a newbie with
OpenGL). If I translate to 0.0,0.0,0.0 I cannot see to textured quad I
drew.

Nah, if you translate to identity matrix (it’s faster just to reset it
BTW), probably you just put it past your frustum’s near-clip plane. If
you open your red book and find where they talk about projection, they
probably show an eye or a camera with some diagonal lines from it
connecting to a pyramid on its side with its top cut off. (I guess it
would actually be a ziggurat, but I disgress…)

Basically, you need to translate so you’re just inside the clip plane and
calcuate where to draw everything with depth testing off so it writes on
top. But that’s ridiculous just to do a 2D overlay! Instead, we just
redefine the screen’s coordinate system to put the identity where we want
it, and draw on top.

I’m better at doings than teachings, so I hope some of that made sense.On Sun, Sep 30, 2001 at 03:24:28PM -0400, Robin Forster wrote:


Joseph Carter Free software developer

  • HomeySan waits for the papa john’s pizza to show up
    mm. papa john’s.
    hopefully they send the cute delivery driver
    they dont have that here.
    <Dr_Stein> why? you gonna eat the driver instead?

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20010930/8071614c/attachment-0007.pgp

Thanks a million… I was getting sick of the SDL blits which where
giving me a framerate of 4 fps hehe. I need to buy a book on OpenGL
do you have any good suggestions (reply to sender if its off topic).

Robin.

Joseph Carter wrote:>

On Sun, Sep 30, 2001 at 03:24:28PM -0400, Robin Forster wrote:

I am porting my game design to use OpenGL accel.

Uh-oh. :wink:

I want to draw my border with icons and the command console on top of my
OpenGL map so the use can select game options.

Can I use SDL_BlitSurface with OpenGL?

Short answer: No. Abridged long answer: Yes, but you really don’t want
to it sounds like. Here’s how it works in OpenGL:

    // If we changed this, change it back (you probably don't need it)
    glViewport (0, 0, scr_width, scr_height);

    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    glOrtho (0, scr_width, scr_height, 0, -99999, 99999);

    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity ();

    glDisable (GL_DEPTH_TEST);
    glDisable (GL_CULL_FACE);

The above will allow you to use 2D coordinates just fine. Namely, you
should be able to glBindTexture2D, glBegin (GL_QUADS), glVertex2f …
with screen coordinates and expect it to work. I’ll refer you to the
OpenGL manpages (or reference manual, which was closer at hand for me at
the moment since nvidia doesn’t provide manpages) as to what these
functions do exactly.

The game in which the above is used, we alter the glViewport to keep the
game from drawing over the area where the status display goes, so that’s
why we change it back. You don’t want a depth test here - last drawn is
last seen. You almost always want this for 2D overlay drawing, and the
drawing itself is faster without a depth test anyway.

Do this at the end of your draw loop. At the beginning of your draw loop
you will need to reset your glOrtho, depth testing, etc, etc to the
defaults you want them to be. OpenGL is a state machine and when you make
something be set a certain way - it’s set dammit!

I am trying to use OpenGL textures for the items but the OpenGL
coordinate system is messing with my head (yeah am a newbie with
OpenGL). If I translate to 0.0,0.0,0.0 I cannot see to textured quad I
drew.

Nah, if you translate to identity matrix (it’s faster just to reset it
BTW), probably you just put it past your frustum’s near-clip plane. If
you open your red book and find where they talk about projection, they
probably show an eye or a camera with some diagonal lines from it
connecting to a pyramid on its side with its top cut off. (I guess it
would actually be a ziggurat, but I disgress…)

Basically, you need to translate so you’re just inside the clip plane and
calcuate where to draw everything with depth testing off so it writes on
top. But that’s ridiculous just to do a 2D overlay! Instead, we just
redefine the screen’s coordinate system to put the identity where we want
it, and draw on top.

I’m better at doings than teachings, so I hope some of that made sense.


Joseph Carter Free software developer

  • HomeySan waits for the papa john’s pizza to show up
    mm. papa john’s.
    hopefully they send the cute delivery driver
    they dont have that here.
    <Dr_Stein> why? you gonna eat the driver instead?


    Part 1.2Type: application/pgp-signature


Robin Forster, Systems Engineer,
http://www.rsforster.ottawa.on.ca/