为什么运行成功的代码新建一个工程就出错?
下面是我的一段OpenGL代码,画一个三角形。这个代码的工程文件以前运行成功,现在打开运行也成功。
OpenGl是按照这篇文章配置的,
http://blog.csdn.net/xiajun07061225/article/details/6869040
。应该没有问题。
但是我现在新建一个工程,把代码完全复制过来就出错。我记得当时也没有另外配置什么东西啊,为什么现在新建工程代码不变也出错呢?
下面是代码:
#include <GL/glut.h>void init(){ glClearColor(0.0,0.0,0.0,0.0); glShadeModel(GL_SMOOTH);//渲染模式}void triangle(){ glBegin(GL_TRIANGLES); glColor3f(1.0,0.0,0.0); glVertex2f(5.0,5.0); glColor3f(0.0,1.0,0.0); glVertex2f(25.0,5.0); glColor3f(0.0,0.0,1.0); glVertex2f(5.0,25.0); glEnd();}void display(){ glClear(GL_COLOR_BUFFER_BIT); triangle(); glFlush();}void reshape(int w,int h){ glViewport(0,0,(GLsizei)w,(GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w <= h) gluOrtho2D(0.0,30.0,0.0,30.0 * (GLfloat)h / (GLfloat)w);//定义二维投影矩阵 else gluOrtho2D(0.0,30.0 * (GLfloat)w / (GLfloat)h,0.0,30.0); glMatrixMode(GL_MODELVIEW);}int main(int argc,char** argv){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(100,100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0;}