PDA

View Full Version : Drawing appears but suddenly goes away



programmer17
01-16-2012, 02:17 PM
Hi, I have a problem.
I have a menu.
newgame
help

Whenever the user clicks it the co-ordinates are checked and the specific function if called.
Problem is the contents of the function help are only seen when I keep on holding down but not as soon as I remove it gets deleted.

I will present the code below.



[CODE]int main(int argc, char *argv[])
{
glutInit (&argc, argv);
glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RG B);
glutInitWindowPosition (1,1);
glutInitWindowSize (900,650);
glutCreateWindow ("Mastermind");
glDepthFunc(GL_NEVER);
glutReshapeFunc(changesize);
if (checkmainmenu == true)
{
glutDisplayFunc(draw_background);
}
glutMouseFunc(mouseButton);
glutMainLoop();
}
void draw_title()
{

if (checkmainmenu == true)
{
glutPrint(-1.5, 3,GLUT_BITMAP_TIMES_ROMAN_24, "", 1.0, 1.0, 1.0);
}
}
void draw_background()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0, 0.3, 0.5, 0);
glLoadIdentity();
glEnable(GL_COLOR_MATERIAL); //Enable color
glDepthFunc(GL_DOUBLE);
gluLookAt(0.0f, 0.0f, 10.0f,0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
draw_title();
if (checkmainmenu == true)
{
menu.draw_mainmenu();
}
glutSwapBuffers();
}
void Cmainmenu :: draw_mainmenu()
{
menu.draw_newgame();
menu.draw_stats();
menu.draw_load();
menu. draw_help();
menu.draw_end();
}

void handlemouse( int x, int y, int button)
{
std :: cout << x << " "<< y;
if (checkmainmenu == true)
{
useroption(x,y);
}

}
void new_game()
{
if(checknewgame == true)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0, 0.3, 0.5, 0);
glLoadIdentity();
glEnable(GL_COLOR_MATERIAL); //Enable color
glDepthFunc(GL_DOUBLE);
gluLookAt(0.0f, 0.0f, 10.0f,0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
glutSwapBuffers();
}
}
void draw_gamebackground()
{
for (float y = 5.9; y > -0.8; y = y - 0.7)
{
glBegin(GL_LINES);
glColor3f(1.0, 0,0);
glVertex2f( -4,y );
glColor3f(1, 0,0);
glVertex2f( 2.8,y );
glEnd();
}

}
void helper()
{
if (checkhelp == true)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0, 0.3, 0.5, 0);
gluLookAt(0.0f, 0.0f, 10.0f,0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
glEnable(GL_COLOR_MATERIAL);

glutSwapBuffers();
}
}
void useroption(int x, int y)
{
if ((x > 292 &amp;&amp; x < 527)&amp;&amp; (y < 207 &amp;&amp; y > 167))
{
checkmainmenu = false;
checknewgame = true;
new_game();

}
else if ((x > 292 &amp;&amp; x < 527)&amp;&amp; (y < 284 &amp;&amp; y > 247))
{
//statsdisplayer();
//newgame = false;
checkmainmenu = false;
//stats= true;
//help= false;
}
else if ((x > 292 &amp;&amp; x < 527)&amp;&amp; (y < 361 &amp;&amp; y > 324))
{
//statsdisplayer();
//newgame = false;
checkmainmenu = false;
//stats= true;
//help= false;
}
else if ((x > 292 &amp;&amp; x < 527)&amp;&amp; (y < 442 &amp;&amp; y > 401))
{

checkmainmenu = false;
checkhelp = true;
checknewgame = false;
helper();
}
else if ((x > 292 &amp;&amp; x < 527)&amp;&amp; (y < 520 &amp;&amp; y > 490))
{
ending();
}
}

void mouseButton(int button, int state, int x, int y)
{

if ((button == GLUT_LEFT_BUTTON) &amp;&amp; (state == GLUT_DOWN))
{
handlemouse(x,y, button);
}
}

Anything with the check in front are the boolean variables that keep track of where the program is.

Thank you very much.

Captain Code
02-02-2012, 09:53 AM
In your nwe_game(0 function you have

glDepthFunc(GL_DOUBLE);


I'm not sure that is valid. More common is to use GL_LESS.