Hi I am new to OpenGl and just got started.I was trying to make a program that draws a square where ever i click the mouse button.
It is not working.If anyone has any ideas please help.
**********CODE*****************************
#include<GL/glut.h>
#include<iostream>
#include<math.h>
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glTranslatef(9,5,0);
glutSwapBuffers();
}
void drawSquare()
{
glBegin(GL_QUADS);
glVertex2f(10.0, 10.0);
glVertex2f(-10.0, 10.0);
glVertex2f(-10.0, -10.0);
glVertex2f(10.0, -10.0);
glEnd();
}
void drawSquare1()
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(1.0,0.0,0.0);
glBegin(GL_QUADS);
glVertex2f(10.0, 10.0);
glVertex2f(-10.0, 10.0);
glVertex2f(-10.0, -10.0);
glVertex2f(10.0, -10.0);
glEnd();
}
void myMouse(int button,int state,int x,int y)
{
if((button == GLUT_LEFT_BUTTON) && (state == GLUT_DOWN))
{
drawSquare();
myDisplay();
}
else
drawSquare1();
}
void myinit()
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,50.0,0.0,50.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(0,0);
glutCreateWindow("SQUARE PROGRAM");
glutMouseFunc(myMouse);
glutDisplayFunc(myDisplay);
myinit();
glutMainLoop();
return 1;
}



