Hi guys,
I just began to learn OpenGL and this is my first topic in this Furum.
When I run the program below, the window flashes and i can’t see any thing clearly or i can’t do any operation.Can anyone help me?
#include<gl/glut.h>
#include <gl/gl.h>
const int screenWidth = 640;
const int screenHeight = 480;
class GLintPoint
{
public:
GLint x, y;
};
void myinit()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glColor3f(0.0, 0.0, 0.0);
glPointSize(2.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble)screenWidth, 0.0, (GLdouble)screenHeight);
}
void myMouse(int button, int state, int x, int y)
{
static GLintPoint corner[2];
static int numCorners = 0;
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
corner[numCorners].x = x;
corner[numCorners].y = screenHeight - y;
numCorners++;
if(numCorners == 2)
{
glRecti(corner[0].x, corner[0].y, corner[1].x, corner[1].y);
numCorners = 0;
}
}
else
if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(screenWidth, screenHeight);
glutInitWindowPosition(100, 150);
glutCreateWindow(“Draw Reac”);
glutMouseFunc(myMouse);
myinit();
glutMainLoop();
}