Hi,
I meet the problem when I use scroll mouse in the subwindow created by glut. When I scroll up the scroll button, code crash. Other mouse buttons have no problem. Scroll down the scroll button has no problem too. If you run the attached code, move mouse to the center and scroll up the mouse, you will know what I mean.
I don’t know whether it is a bug of glut or not. Does anyone know how to fix this problem?
Thanks.
//
//gcc -O3 -o mouse mouse.c -L/usr/X11R6/lib -lGL -lGLU -lX11 -lglut -lXmu
//
#include <GL/glut.h>
#include <stdlib.h>
static GLfloat spin = 0.0;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(spin, 0.0, 0.0, 1.0);
glColor3f(0.0, 1.0, 0.0);
glRectf(-0.5, -0.5, 0.5, 0.5);
glPopMatrix();
glutSwapBuffers();
}
void mdisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glRectf(-40.0, -40.0, 40.0, 40.0);
glutSwapBuffers();
}
void spinDisplay(void)
{
spin = spin + 2.0;
if (spin > 360.0)
spin = spin - 360.0;
glutPostRedisplay();
}
void reshape(int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void mouse(int button, int state, int x, int y)
{
switch (button) {
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN)
glutIdleFunc(spinDisplay);
break;
case GLUT_MIDDLE_BUTTON:
if (state == GLUT_DOWN)
glutIdleFunc(NULL);
break;
default:
break;
}
}
int subwin(int mwin)
{
int swin;
swin = glutCreateSubWindow (mwin,50,50,150,150);
glClearColor (0.0, 0.0, 1.0, 0.0);
glutDisplayFunc(display);
glutMouseFunc(mouse);
return 0;
}
int mainwin()
{
int mwin;
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
mwin = glutCreateWindow (“main”);
glClearColor (0.0, 0.0, 0.0, 0.0);
glutDisplayFunc(mdisplay);
glutReshapeFunc(reshape);
return mwin;
}
int main(int argc, char** argv)
{
int mwin,swin;
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
mwin = mainwin();
subwin(mwin);
glutMainLoop();
return 0;
}