I am new to OpenGL and I am trying to create a game in which I have a raw image as the background. When the game starts, I show this image, and I want it to be clickable on it and then display another image. I tried to use the function glutMouseFunc, but when I try to run the program, I get a message saying that the program has stopped working. Here are some parts of my code: I have a global variable onMouse; if I press the mouse button, the variable takes the value 1, and if it has the value 1, I try to load the second image.
int onMouse;
void mouseClicks(int button, int state, int x, int y) {
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
onMouse = 1;
}
}
And this is the main function:
texture = LoadTextureRAW( "2 Lock screen.raw", TRUE );
glutMouseFunc(mouseClicks);
if(onMouse == 1){
texture = LoadTextureRAW( "in_game.raw", TRUE );
}
What am I doing wrong?
EDIT , - . :
glutCreateWindow("Game");
texture = LoadTextureRAW( "2 Lock screen.raw", 1 );
glutDisplayFunc(display);
glutMouseFunc(mouseClicks);
glutKeyboardFunc(key);
glutMainLoop();
if(onMouse == 1){
texture = LoadTextureRAW( "in_game.raw", 2 );
glutDisplayFunc(display);
}
, :
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, texture );
glPushMatrix();
glBegin( GL_QUADS );
glTexCoord2d(1.0,0.0); glVertex3d(1.0,1.0, 1.0);
glTexCoord2d(0.0,0.0); glVertex3d(-1.0,1.0,1.0);
glTexCoord2d(0.0,1.0); glVertex3d(-1.0,-1.0, -1.0);
glTexCoord2d(1.0,1.0); glVertex3d(1.0,-1.0, 1.0);
glEnd();
glPopMatrix();
glutSwapBuffers();
FreeTexture( texture );