读书人

Cannot open include file: #039;GL/glut.

发布时间: 2012-08-10 12:19:33 作者: rapoo

Cannot open include file: 'GL/glut.h': No such file or directory
这个代码,不能运行,请帮忙看看
报错:
fatal error C1083: Cannot open include file: 'GL/glut.h': No such file or directory


#include <stdlib.h>
#include <GL/glut.h>
void background(void)
{
 glClearColor(0.0,0.0,0.0,0.0);//设置背景颜色为黑色
}

void myDisplay(void)
{
 glClear(GL_COLOR_BUFFER_BIT);//buffer设置为颜色可写

 glBegin(GL_TRIANGLES);//开始画三角形
 glShadeModel(GL_SMOOTH);//设置为光滑明暗模式

 glColor3f(1.0,0.0,0.0);//设置第一个顶点为红色
 glVertex2f(-1.0,-1.0);//设置第一个顶点的坐标为(-1.0,-1.0)

 glColor3f(0.0,1.0,0.0);//设置第二个顶点为绿色
 glVertex2f(0.0,-1.0);//设置第二个顶点的坐标为(0.0,-1.0)

 glColor3f(0.0,0.0,1.0);//设置第三个顶点为蓝色
 glVertex2f(-0.5,1.0);//设置第三个顶点的坐标为(-0.5,1.0)
 glEnd();//三角形结束

 glFlush();//强制OpenGL函数在有限时间内运行
}

void myReshape(GLsizei w,GLsizei h)
{
 glViewport(0,0,w,h);//设置视口

 glMatrixMode(GL_PROJECTION);//指明当前矩阵为GL_PROJECTION
 glLoadIdentity();//将当前矩阵置换为单位阵

 if(w <= h)
  gluOrtho2D(-1.0,1.5,-1.5,1.5*(GLfloat)h/(GLfloat)w);//定义二维正视投影矩阵
 else
  gluOrtho2D(-1.0,1.5*(GLfloat)w/(GLfloat)h,-1.5,1.5);
  glMatrixMode(GL_MODELVIEW);//指明当前矩阵为GL_MODELVIEW
}

int main(int argc,char ** argv)
{
 glutInit(&argc,argv);
 glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
 glutInitWindowSize(400,400);
 glutInitWindowPosition(200,200);

 glutCreateWindow("Triangle");

 background();
 glutReshapeFunc(myReshape);
 glutDisplayFunc(myDisplay);

 glutMainLoop();
 return(0);
}

[解决办法]
include 路径出了问题

或者根本没有安装 glut 库

读书人网 >VC/MFC

热点推荐