最近我在看opengl
给你个代码吧:
#include <windows.h>
#define GLUT_DISABLE_ATEXIT_HACK
#include <math.h>
#include <gl/gl.h>
#include <gl/glut.h>
void myInit()
{
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0f,0.0f,0.0f);
glPointSize(4.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,640.0,0.0,480.0);
}
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void myMouse(int button, int state, int x, int y)
{
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
glRecti(x,480-y,x+10,480-y+10);
}else if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN){
glClear(GL_COLOR_BUFFER_BIT);
}
glFlush();
}
void myMovedMouse(int mouseX, int mouseY)
{
glRecti(mouseX,480-mouseY,mouseX+1,480-mouseY+1);
glFlush();
}
int main(int argc, char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640,480);
glutCreateWindow("my first attempt");
glutDisplayFunc(myDisplay);
glutMouseFunc(myMouse);
glutMotionFunc(myMovedMouse);
myInit();
glutMainLoop();
}