PDA

View Full Version : a problem with the window



Hartman
10-29-2010, 10:59 AM
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 &amp;&amp; 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 &amp;&amp; state == GLUT_DOWN)
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}

void main(int argc, char **argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(screenWidth, screenHeight);
glutInitWindowPosition(100, 150);
glutCreateWindow("Draw Reac");
glutMouseFunc(myMouse);
myinit();
glutMainLoop();
}

strattonbrazil
10-29-2010, 02:16 PM
Where's your display function? That's like the most imporant function you can have in GLUT. It's what does the actual drawing. You need to specify that with glutDisplayFunc().

Hartman
10-29-2010, 10:04 PM
Thanks.I have added the glutDisplayFunc() to my program,and it now works properly. :)