Background picture and OpenGL

Hi,

i load an image that has exactly the size of my SDL window.

I’d like to set this picture as the background picture and
draw some OpenGL in front of it.

Can anybody tell me how to do that in SDL?

Or is this a complete OpenGL issue (then i’ll ask somewhere
else)?

Thanks for any hints,
Torsten.

Hi Torsten,

What you want to do is set your screen to orthographic mode to draw the
background.

orthographic = 2d-ish so you can more easily draw a pciture to fill the
whole background of the screen.

http://www.gametutorials.com/Tutorials/OpenGL/OpenGL_Pg2.htm

go there and check out “masking and ortho mode” to figure out ortho mode,
it’s pretty easy (:> ----- Original Message -----

From: tmohr@s.netic.de (Torsten Mohr)
To:
Sent: Monday, May 03, 2004 11:55 AM
Subject: [SDL] Background picture and OpenGL

Hi,

i load an image that has exactly the size of my SDL window.

I’d like to set this picture as the background picture and
draw some OpenGL in front of it.

Can anybody tell me how to do that in SDL?

Or is this a complete OpenGL issue (then i’ll ask somewhere
else)?

Thanks for any hints,
Torsten.


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

Make a huge quad that covers the entire window area and then apply your
texture on it.
It is only a OpenGL issue, not a SDL one. Remember that your textures
sides must be in power of 2 so OpenGL can render it.
That quad will have a Z value higher than the other objects in your
scene so it appears to be in the background.

Hope this help,
Bruce Sinner

Torsten Mohr wrote:>Hi,

i load an image that has exactly the size of my SDL window.

I’d like to set this picture as the background picture and
draw some OpenGL in front of it.

Can anybody tell me how to do that in SDL?

Or is this a complete OpenGL issue (then i’ll ask somewhere
else)?

Thanks for any hints,
Torsten.


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

Torsten Mohr wrote:

Hi,

i load an image that has exactly the size of my SDL window.

I’d like to set this picture as the background picture and
draw some OpenGL in front of it.

Can anybody tell me how to do that in SDL?

I wonder wether SDL_OPENGLBLIT passed to SDL_SetVideoMode could help (see
documentation). If not, you’ll need an ortographic projection via OpenGL.

regards,
Kornel Kisielewicz

SDL_OPENGLBLIT is being phased out im pretty sure so best not to use that> ----- Original Message -----

From: raskolnikov@o2.pl (Kornel Kisieleiwcz)
To:
Sent: Monday, May 03, 2004 11:52 AM
Subject: Re: [SDL] Background picture and OpenGL

Torsten Mohr wrote:

Hi,

i load an image that has exactly the size of my SDL window.

I’d like to set this picture as the background picture and
draw some OpenGL in front of it.

Can anybody tell me how to do that in SDL?

I wonder wether SDL_OPENGLBLIT passed to SDL_SetVideoMode could help (see
documentation). If not, you’ll need an ortographic projection via OpenGL.

regards,
Kornel Kisielewicz


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

Hi,

thank you all for your hints.

I wrote the image directly to the background buffer
and then cleared the depth buffer. All works fine now.

Best regards,
Torsten.

static void gl_draw(void) {
glViewport(0, 0, xwidth, yheight);

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glShadeModel(GL_FLAT);
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
glCullFace(GL_FRONT|GL_BACK);
glDisable(GL_BLEND);
glDisable(GL_ALPHA);

glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);

glRasterPos2f(-1.0, -1.0);
glDrawPixels(xwidth, yheight, GL_RGB, GL_UNSIGNED_BYTE, as->pixels);

glClear(GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)xwidth/(GLfloat)yheight, 0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);


glLoadIdentity();
gluLookAt(cam_x, cam_y, cam_z,
	0.0, 0.0, 0.0,
	0.0, 0.0, 1.0);

draw_axes();

SDL_GL_SwapBuffers();

}> Hi,

i load an image that has exactly the size of my SDL window.

I’d like to set this picture as the background picture and
draw some OpenGL in front of it.

Can anybody tell me how to do that in SDL?

Or is this a complete OpenGL issue (then i’ll ask somewhere
else)?

Thanks for any hints,
Torsten.


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

glRasterPos2f(-1.0, -1.0);
glDrawPixels(xwidth, yheight, GL_RGB, GL_UNSIGNED_BYTE, as->pixels);

glDrawPixels is very slow function
Better way is to draw one large textured polygon
f.e:

glBindTexture (GL_TEXTURE_2D, texBackround);
glTexImage2d (la-la-la, as->pixels);
/* If image is not power of two,
you should call gluScaleImage */

glBindTexture (GL_TEXTURE_2D, texBackround);
glOrtho (0, width, 0, height, -5, 5);
glDisable (GL_DEPTH_TEST);
glBegin (GL_TRIANGLE_STRIP);
{
glTexCoord2f (0, 1);
glVertex2f (0, height);
glTexCoord2f (0, 0);
glVertex2f (0, 0);
glTexCoord2f (1, 1);
glVertex2f (widht, height);
glTexCoord2f (1, 0);
glVertex2f (width, 0);
}
glEnd ();
glEnable (GL_DEPTH_TEST);____________
Oh, Elbereth, Gilthoniel!!!

ALakazam (Skidanov Alexander) wrote:

glRasterPos2f(-1.0, -1.0);
glDrawPixels(xwidth, yheight, GL_RGB, GL_UNSIGNED_BYTE, as->pixels);

glDrawPixels is very slow function
Better way is to draw one large textured polygon
f.e:

No, this is card and data size dependent.

Take a look at this benchmark :
http://icps.u-strasbg.fr/~marchesin/bench.ps
The X axis is the texture width (or height as the textures are square)
and the Y axis is the transfer time (no unit given, as I don’t remember
how many textures were transfered to obtain these timings).
You see that on a firegl, drawpixels is faster, and that on the geforce
4, the texture approach is faster.

Stephane