hello every one
im try to make a rectabgle and triangle by clicking on the icons of rectangle and triangle
here is my code if any one can help
#include<stdio.h>
#include<conio.h>
#include<glut.h>
int s,t;
int screenHeight=800, screenWidth = 600;
void display()
{
glClear(GL_COLOR_BUFFER_BIT ); //Screen clear karnay k lia
glColor3f(1.0,1.0,0.30); // current pen color
glRecti(500,0,600,800); // panel
glColor3f(0.0,0.0,0.0);
glRecti(510,600,570,700);//Rectangle
glBegin(GL_POLYGON); //for triangle
glVertex2f(510,440); //points for triangle left
glVertex2f(570,440); //right
glVertex2f(540,540); //top
glEnd(); // yahan tak
glColor3f(1.0,0.0,0.0);
glRecti(520,350,560,380);
glColor3f(0.0,1.0,0.0);
glRecti(520,280,560,310);
glColor3f(0.0,0.0,1.0);
glRecti(520,250,560,220);
glColor3f(0.0,0.0,0.0);
glBegin(GL_LINES);
glVertex2i(500,410);
glVertex2i(600,410);
glEnd();
glFlush(); //Graphics show k lia
}
void myInit()
{
int screenHeight=800, screenWidth = 600;
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D(0,screenWidth,0,screenHeight);
}
void myMouse(int button,int state,int x,int y)
{
if(button==GLUT_LEFT_BUTTON)
{
if(x>510&&x<570 && y>screenHeight-600&&y<screenHeight-700)//if square
{
/*s=1;//for square
glColor3f(0.0,0.0,0.0);
glRecti(250,350,350,450);
glFlush();
}
if(510<=x<=570 && screenHeight-440<=y<=screenHeight-540)//if triangle
{
/*t=1;//for triangle
glColor3f(0.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(250,350);
glVertex2f(330,350);
glVertex2f(285,450);
glEnd();
glFlush();*/
}
}
}
void processMenuEvents(int option)
{
/* switch(option)
{
case 1:
if(s==1)
{
glColor3f(1.0,0.0,0.0);
glRecti(250,350,350,450);
glFlush();
}
if(t==1)
{
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(250,350);
glVertex2f(350,350);
glVertex2f(275,400);
glEnd();
glFlush();
}
break;
case 2:
if(s==1)
{
glColor3f(0.0,1.0,0.0);
glRecti(250,350,350,450);
glFlush();
}
if(t==1)
{
glColor3f(0.0,1.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(250,350);
glVertex2f(350,350);
glVertex2f(275,400);
glEnd();
glFlush();
}
break;
case 3:
if(s==1)
{
glColor3f(0.0,0.0,1.0);
glRecti(250,350,350,450);
glFlush();
}
if(t==1)
{
glColor3f(0.0,0.0,1.0);
glBegin(GL_POLYGON);
glVertex2f(250,350);
glVertex2f(350,350);
glVertex2f(275,400);
glEnd();
glFlush();
}
break;
}*/
}
void main()
{
int screenHeight =800, screenWidth =600;
glutInitWindowPosition(0,0);
glutInitWindowSize(screenHeight,screenWidth); //window ka size
glutCreateWindow("Window");
myInit();
//glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE);// color scheme rgb ha or double buffer use ho rhe han
glClearColor(1.0,1.0,1.0,1.0); //windows background color
glutDisplayFunc(display); //for displaying object
glutMouseFunc(myMouse);
glutCreateMenu(processMenuEvents);
glutAddMenuEntry("Red",1);
glutAddMenuEntry("Green",2);
glutAddMenuEntry("Blue",3);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
getch();
}