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.
int main(int argc, char *argv[])
{
glutInit (&argc, argv);
glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGB);
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 && x < 527)&& (y < 207 && y > 167))
{
checkmainmenu = false;
checknewgame = true;
new_game();
}
else if ((x > 292 && x < 527)&& (y < 284 && y > 247))
{
//statsdisplayer();
//newgame = false;
checkmainmenu = false;
//stats= true;
//help= false;
}
else if ((x > 292 && x < 527)&& (y < 361 && y > 324))
{
//statsdisplayer();
//newgame = false;
checkmainmenu = false;
//stats= true;
//help= false;
}
else if ((x > 292 && x < 527)&& (y < 442 && y > 401))
{
checkmainmenu = false;
checkhelp = true;
checknewgame = false;
helper();
}
else if ((x > 292 && x < 527)&& (y < 520 && y > 490))
{
ending();
}
}
void mouseButton(int button, int state, int x, int y)
{
if ((button == GLUT_LEFT_BUTTON) && (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.