Use: WinMe, visual C++6.
Dear All,
The program is supposed to display dots at mouse-click position within the created window.
Instead: Initially no output at mouse-clicks(empty background) most of the time. Sometimes later they appear without mouse-clicks, and sometimes later the dots disappear, usually when shifting the window. Sometimes, it shows in the MS-DOS windows but it later disappear.
The code:
#include <windows.h>
#include <gl/Gl.h>
#include <gl/glut.h>
#define screenHeight 480
void myInit(void) {
glClearColor(0.0,0.0,0.0,0.0);
glColor3f(1.0f, 0.0f, 1.0f);
glPointSize(4.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
void drawDot(GLint x, GLint y) {
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
}
void myDisplay(void) {
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void myMouse(int button, int state, int x, int y) {
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
drawDot(x, screenHeight - y);
else if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
exit(-1);
}
void main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(100,150);
glutCreateWindow(“my first attempt”);
glutMouseFunc(myMouse);
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}
Question:
What cause the strange behavior? And how to solve it?
Thanks in advance.
jovialone