#include<GL/glut.h>
#include<stdlib.h>
#include<time.h>
const int screenWidth=640;
const int screenHeight=480;
void myInit()
{
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(1.0,0.0,0.0);
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);
}
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
//glFlush();
}
void myMouse(int button,int state,int x,int y)
{
if(button==GLUT_RIGHT_BUTTON)glClear(GL_COLOR_BUFFER_BIT);
// glClear(GL_COLOR_BUFFER_BIT);
}
void myMovedMouse(int mouseX,int mouseY)
{
GLint x=mouseX;
GLint y=screenHeight-mouseY;
GLint brushsize=15;
glRecti(x,y,x+brushsize,y+brushsize);
glFlush();
glEnd();
}
void
mymenu(int value)
{
if(value == 1)
{
glRecti(0,0,50,50);
glFlush();
}
if(value == 2)
{
glBegin(GL_LINES);
glVertex2i(0,0);
glVertex2i(100,100);
glEnd();
glFlush();
}
}
int main(int argc, char **argv)
{
int k=0;
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(screenWidth,screenHeight);
glutCreateWindow("mouse cliks");
glutDisplayFunc(myDisplay);
glutMouseFunc(myMouse);
glutMotionFunc(myMovedMouse);
k=glutCreateMenu(mymenu); // single menu, no need for id
//glutAddSubMenu ("raj", k);
//glutAddSubMenu ("j", k);
glutAddMenuEntry("Rectangle", 1);
glutAddMenuEntry("line", 2);
glutAttachMenu(GLUT_RIGHT_BUTTON);
myInit();
glutMainLoop();
}
#include<stdlib.h>
#include<time.h>
const int screenWidth=640;
const int screenHeight=480;
void myInit()
{
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(1.0,0.0,0.0);
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);
}
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
//glFlush();
}
void myMouse(int button,int state,int x,int y)
{
if(button==GLUT_RIGHT_BUTTON)glClear(GL_COLOR_BUFFER_BIT);
// glClear(GL_COLOR_BUFFER_BIT);
}
void myMovedMouse(int mouseX,int mouseY)
{
GLint x=mouseX;
GLint y=screenHeight-mouseY;
GLint brushsize=15;
glRecti(x,y,x+brushsize,y+brushsize);
glFlush();
glEnd();
}
void
mymenu(int value)
{
if(value == 1)
{
glRecti(0,0,50,50);
glFlush();
}
if(value == 2)
{
glBegin(GL_LINES);
glVertex2i(0,0);
glVertex2i(100,100);
glEnd();
glFlush();
}
}
int main(int argc, char **argv)
{
int k=0;
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(screenWidth,screenHeight);
glutCreateWindow("mouse cliks");
glutDisplayFunc(myDisplay);
glutMouseFunc(myMouse);
glutMotionFunc(myMovedMouse);
k=glutCreateMenu(mymenu); // single menu, no need for id
//glutAddSubMenu ("raj", k);
//glutAddSubMenu ("j", k);
glutAddMenuEntry("Rectangle", 1);
glutAddMenuEntry("line", 2);
glutAttachMenu(GLUT_RIGHT_BUTTON);
myInit();
glutMainLoop();
}
No comments:
Post a Comment