# define GLUT_DISABLE_ATEXIT_HACK
# include <stdlib.h>
# include <math.h>
# include <windows.h>
# include <GL/glut.h>
# define DEG_TO_RAD 0.017453
GLfloat theta=0.0;
const GLfloat R=0.5f;
int Singleb,doubleb;
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f(R*sin(DEG_TO_RAD*theta),R*cos(DEG_TO_RAD*theta));
glVertex2f(-R*sin(DEG_TO_RAD*theta),R*cos(DEG_TO_RAD*theta));
glVertex2f(-R*sin(DEG_TO_RAD*theta),-R*cos(DEG_TO_RAD*theta));
glVertex2f(R*sin(DEG_TO_RAD*theta),-R*cos(DEG_TO_RAD*theta));
glEnd();
glutSwapBuffers();
}
void spinDisplay()
{
theta += 2.0;
if(theta>360.0) theta-=360.0;
glutSetWindow(Singleb);
glutPostWindowRedisplay(Singleb);
glutSetWindow(doubleb);
glutPostWindowRedisplay(doubleb);
}
void mouse(int btn,int state,int x,int y){
if(btn==GLUT_LEFT_BUTTON&&state==GLUT_DOWN)
glutIdleFunc(spinDisplay);
if(btn==GLUT_MIDDLE_BUTTON&&state==GLUT_DOWN)
glutIdleFunc(NULL);
}
void myReshape(int w ,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-0.2,0.2,-0.2,0.2);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void mykey(unsigned char key, int x, int y){
if(key=='Q'||key=='q') exit(0);
}
void quit_menu(int id){
if(id==1) exit(0);
}
void init()
{
glClearColor(1.0,1.0,0.0,0.0);
glColor3f(0.5,0.5,0.5);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.0,1.0,-1.0,1.0);
}
int main (int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
Singleb=glutCreateWindow("single buffered");
init();
glutDisplayFunc(myDisplay);
glutReshapeFunc(myReshape);
glutIdleFunc(spinDisplay);
glutKeyboardFunc(mykey);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(100,100);
doubleb=glutCreateWindow("double buffered");
init();
glutDisplayFunc(myDisplay);
glutReshapeFunc(myReshape);
glutIdleFunc(spinDisplay);
glutMouseFunc(mouse);
glutCreateMenu(quit_menu);
glutAddMenuEntry("quit",1);
glutMainLoop();
return 0;
}

哪位大神給看看到底哪里 不對啊,新人求大神幫忙啊,為什么運行不出來呢。
uj5u.com熱心網友回復:
為什么 看著 這么像 VS 呢?而不是 C++Builder
uj5u.com熱心網友回復:
小裴同學,你需要把相關的lib檔案添加到工程中。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/125631.html
標籤:基礎類
上一篇:c++
