Could u find the error in this code

Hai

I want to draw a background and then some 3D objects. But when i draw the 3D objects my background disappears. Please mention whats wrong with this code

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

/****** Drawing Background Texture*******/

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glOrtho(0.0f,w,0.0f,h, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glPushAttrib(GL_LIGHTING_BIT);
glLoadIdentity();
glShadeModel(GL_FLAT);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );

const GLfloat fw((GLfloat) w);
const GLfloat fh((GLfloat) h);

glBegin(GL_QUADS);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( fw, fh, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0, fh, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0, 0, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( fw, 0, 0.0f);
glEnd();

glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glPopAttrib();
/*******End Background Texture *********/

/***Draw 3D objects and rotation/

glViewport(0 + AutoScrollPosition.X, 0 - (nRange - Height) - AutoScrollPosition.Y, nRange, nRange );

// Reset projection matrix stack
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

glShadeModel(GL_FLAT);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);

// Establish clipping volume (left, right, bottom, top, near, far)

glOrtho ((-nRange/2.0), (nRange/2.0), (nRange/2.0 ), -(nRange/2.0), -(nRange/2.0), (nRange/2.0));

// Reset Model view matrix stack
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glRotatef(60,1.0,1.0,0.0);
glRotatef(45 * rot,0.0,1.0,0.0);

glScalef(scale3D,scale3D,scale3D);
DrawObject()

Whats wrong with this code.

Please help :confused:
Thanks :slight_smile:

Should work for the very first frame.
If that are all OpenGL calls per redraw the second time you come to the background code, you have blending still enabled and the GL_DECAL texture environment mode will also use alpha for calculations.
You should disable the blending and use GL_REPLACE for the background.

Hi,

Thanks for ur help.

I changed the code like this,

In my background drawing i disabled the blending and changed the GL_DECAL to GL_REPLACE in glTextEnvi function.

glDisable(GL_BLEND);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );

But i am still facing the same problem. :frowning:

Regards

Anish

You didn’t restore glPolygonMode state after this call: glPolygonMode(GL_FRONT_AND_BACK,GL_LINE)

yooyo

Hi yooyo,

Great. Its working now.
Very much thanks :slight_smile:

You dont know how happy I am :stuck_out_tongue: