Just so people cannot say that I was never nice about OPENGLBLIT,On Mon, Jan 28, 2002 at 03:23:07PM -0500, Frank J. Ramsay wrote:
Thanks, this is exactly the info I needed.
No it’s not. If you use SDL_OPENGLBLIT, I can guarantee that your program
will not work on some people’s hardware and that it will be slow even
where it does work. VERY slow. Essentially, it sucks.
As a fan of the principle of doing it right or not bothering to do it at
all, I highly suggest you note the following two functions, you can find
them and their context in SDL12/test/testgl.c:
void SDL_GL_Enter2DMode()
{
SDL_Surface *screen = SDL_GetVideoSurface();
/* Note, there may be other things you need to change,
depending on how you have your OpenGL state set up.
*/
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
/* This allows alpha blending of 2D textures with the scene */
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glViewport(0, 0, screen->w, screen->h);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
}
void SDL_GL_Leave2DMode()
{
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glPopAttrib();
}
Simple usage instructions:
- Draw 3D stuff
- SDL_GL_Enter2DMode
- Draw your 2D stuff using glTexCoord2f/glVertex2f
- SDL_GL_Leave2DMode
The coordinates are actual pixel values of the OpenGL window.
SDL_GL_Enter2DMode sets up OpenGL’s coordinate space to start with 0,0 in
the upper left corner, with single pixel increments. Isn’t that better
than using the often incompatible and exponentially slower SDL_OPENGLBLIT?
Let’s review: SDL_OPENGLBLIT does not always work. It is always slow.
As in, it will cut your framerate down to a fraction of whatever it is
now. It works by taking all the hard work your graphics card put into
rendering your 3D really really fast and copying it off into a 2D buffer
so it can paint on top of it. This takes a very, very long time. Much
longer than any straight 2D blit. A program which gets 90fps can easily
be cut down to 30 as a result of SDL_OPENGLBLIT. DO NOT use it if you
know what’s good for you, and your code.
OTOH, you should already know how to load a texture into OpenGL. Even
NeHe is capible of demonstrating how to do that reasonably well, so it
can’t exactly be a hard thing to do. (Oh c’mon, you guys knew I’d have to
say something about NeHe in here right?) The above functions are pretty
simple to understand if you spend about 20 minutes with the redbook. It
will keep your fps up closer to 90, too. OPENGL good! OPENGLBLIT bad!
–
Joseph Carter Have chainsaw will travel
I can just see it now: nomination-terrorism
– Manoj
haha! i nominate manoj.
– seeS
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020128/2c31430f/attachment.pgp