Hi…I’m new here…
I have problem with my code… i want to render a background(texture) and an object…when i put a color to the object…the background also changed the same color… below are my code:
void PlaceBackground()
{
glPushMatrix();
glTranslatef(0.0f,0.0f,-6.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-8.4f, -6.3f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 8.4f, -6.3f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 8.4f, 6.3f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-8.4f, 6.3f, 1.0f);
glEnd();
glPopMatrix();
}
//End Draw background
//Draw Object
void PlaceSceneElements()
{
glTranslatef(x, y, z);
// rotate the scene for viewing
glRotatef(xpoz,1,0,0);
glRotatef(ypoz,0,0,1);
glPushMatrix();
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
glMaterialfv(GL_FRONT, GL_DIFFUSE, colorBronzeDiff);
glMaterialfv(GL_FRONT, GL_SPECULAR, colorBronzeSpec);
glMaterialf(GL_FRONT, GL_SHININESS, 50.0);
glColor4fv(colorBronzeDiff);
glBindTexture(GL_TEXTURE_2D, 0);
glutSolidTeapot(500);
glPopMatrix();
}
//End Draw Object
// main rendering function
void drawBackground()
{
//Render background
switch(picture)
{
case 0:
glBindTexture(GL_TEXTURE_2D, texture[0]);
PlaceBackground();
break;
case 1:
glBindTexture(GL_TEXTURE_2D, texture[1]);
PlaceBackground();
break;
};
}
int InitGL(GLvoid) // Create Some Everyday Functions
{
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // White Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
return TRUE;
}
int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
glTranslatef(0.0f,0.0f,-10.0f);
drawBackground();
glClear(GL_DEPTH_BUFFER_BIT);
PlaceSceneElements();
return TRUE;
}
anyone please help me…thanks…