The Z-coords for your quad are right at the near culling plane. Try
drawing the quad at a depth of 0.0. You will then probably need to
fiddle with the depth buffer a bit, or the 3d scene you’re trying to
draw might be occluded behind your backing quad.
To start, change those Z coordinates and see if that fixes it. If that
works, before you start drawing things in 3d, to ensure they are not
improperly occluded, I suggest
glDisable(GL_DEPTH_TEST);
/* draw the quad in orthographic projection /
glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
/ draw my 3d scene */
This will prevent the background from occluding anything drawn later in
3D (if that is what you want…), with pretty good performance. As
others have said, clearing the actual framebuffer isn’t necessary,
because you’re going to draw over it all anyway.
Hello,
After reading all the messages from this thread I have the next
code but i’m not able to display the background bitmap: A BMP,
1024x768, 24 bpp
Any comment ?? And sorry for a lengthy message.
Thanks,
Jorge
//
// This code was created by Jeff Molofee '99
// (ported to SDL by Sam Lantinga '2000)
//
// If you’ve found this code useful, please let me know.
//
// Visit me at www.demonews.com/hosted/nehe
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include “SDL.h”
GLuint textureId;
GLvoid LoadGLTextures(GLvoid)
{
SDL_Surface *image;
image = SDL_LoadBMP( "escenari.bmp" );
if ( image == NULL ) {
fprintf(stderr, "Unable to load background: %s\n", SDL_GetError());
exit(1);
}
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, image->w, image->h, 0, GL_RGB,
GL_UNSIGNED_BYTE, image->pixels);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->w, image->h, GL_RGB,
GL_UNSIGNED_BYTE, image->pixels);
}
GLvoid InitGL( GLsizei Width, GLsizei Height )
{
glViewport(0, 0, Width, Height);
LoadGLTextures();
glEnable(GL_TEXTURE_2D);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
void DrawGLScene( GLsizei Width, GLsizei Height )
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho( 0, Width, Height, 0, -1.0, 1.0 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glBindTexture(GL_TEXTURE_2D, textureId);
glBegin(GL_QUADS);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();
glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
SDL_GL_SwapBuffers();
}
int main(int argc, char **argv)
{
int done;
SDL_Event event;
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, “Unable to initialize SDL: %s\n”, SDL_GetError());
exit(1);
}
if ( SDL_SetVideoMode(1024, 768, 0, SDL_OPENGL) == NULL ) {
fprintf(stderr, “Unable to create OpenGL screen: %s\n”, SDL_GetError
());
SDL_Quit();
exit(1);
}
InitGL(1024, 768);
/* Loop, drawing and checking events */
done = 0;
while ( !done ) {
DrawGLScene(1024, 768);
while ( SDL_PollEvent(&event) ) {
if ( event.type == SDL_QUIT ) {
done = 1;
}
else if ( event.type == SDL_KEYDOWN ) {
switch ( event.key.keysym.sym ) {
case SDLK_ESCAPE:
done = 1;
break;
default:
break;
}
}
}
}
SDL_Quit();
return 1;
}________________________________________________________________________________
Este mensaje se dirige exclusivamente a su destinatario y puede contener
informaci?n CONFIDENCIAL sometida a secreto profesional o cuya divulgaci?n
est? prohibida en virtud de la legislaci?n vigente. Si ha recibido este
mensaje por error, le rogamos que nos lo comunique inmediatamente por esta
misma v?a o por tel?fono (34 93 739 67 00) y proceda a su destrucci?n.
N?tese que el correo electr?nico v?a Internet no permite asegurar ni la
confidencialidad de los mensajes que se transmiten ni la correcta recepci?n
de los mismos. En el caso de que el destinatario de este mensaje no
consintiera la utilizaci?n del correo electr?nico v?a Internet, rogamos lo
ponga en nuestro conocimiento de manera inmediata. This message is
intended exclusively for its addressee and may contain information that is
CONFIDENTIAL and protected by a professional privilege or which disclosure
is prohibited by law. If this message has been received in error, please
immediately notify us via e-mail or by telephone (34 93 739 67 00) and
delete it. Please note that Internet e-mail does not guarantee the
confidentiality or the proper receipt of the messages sent. If the
addressee of this message does not consent to the use of Internet e-mail,
please communicate it to us immediately.