Question

hi i am making a simple game using openGl only ..... i made a main menu , set a background for it and some options , how ever when i Drawing the menu the background image turns to greenish color , by the way the last string in the menu i color it green and when i color it blue for example the background image turns to the same color plz help i will but the MainMenuDispaly function .

here is the pic

here is what i do :

every thing was done right except this :(

void MainMenuDis()
{
  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glBindTexture(GL_TEXTURE_2D,texture);
  glEnable (GL_TEXTURE_2D);
  glBegin(GL_QUADS);
    glTexCoord2f(0,1);
    glVertex3f(-5,5,-6);
    glTexCoord2f(0,0);
    glVertex3f(-5,-5,-6);
    glTexCoord2f(1,0);
    glVertex3f(5,-5,-6);
    glTexCoord2f(1,1);
    glVertex3f(5,5,-6);
  glEnd();

  glDisable(GL_TEXTURE_2D);

  for(int i = 0 ; i  < 5 ; ++i)
  {
    MainMenuList[i].DrawString(GLUT_BITMAP_9_BY_15);
  }

  Navigate.DrawString(GLUT_BITMAP_HELVETICA_12);

  glutSwapBuffers ();
  glFlush ();
}
Was it helpful?

Solution

Your problem is, that you forgot that OpenGL is a state machine. I.e. it keeps the state of what it does last and applies it to the rest of it. You're drawing a textured quad, but that also incorporates all the other state you defined. Including the color you've set to draw your menu entries (which you shouldn't draw using glutBitmapString in the long term).

So you've to bring OpenGL into a state that is apropriate for drawing a textured quad. Now you should really use shaders and vertex arrays (in VBOs), because in modern OpenGL all the drawing details are controlled by the used shader, which is switched with a single line.

`glUseProgram(…);`

In your case however, using immediate mode in fixed function pipeline you've to set a number of things:

  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glDisable(GL_DEPTH_TEST);
  glDisable(GL_LIGHTING);
  glColor3f(1.,1.,1.);
  /* and probably a few more depending on what you're setting elsewhere */

  glBindTexture(GL_TEXTURE_2D,texture);
  glEnable (GL_TEXTURE_2D);
  glBegin(GL_QUADS);
      …
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top