项目场景:
运行一个opengl的小程序
问题描述:
这个小程序的代码如下:
//#include "./lib/glfw32/GLFW/glfw3.h"
//#pragma comment (lib, "lib/glfw32/glfw3.lib")
//#pragma comment (lib, "lib/glew32/glew32d.lib")
//#include<GL/glut.h>
#include <GL/glfw3.h>
#pragma comment (lib, "D:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/lib/glfw3.lib")
//#pragma comment (lib, "D:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\glew32s.lib")
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(480, 320, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Draw a triangle */
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0); // Red
glVertex3f(0.0, 1.0, 0.0);
glColor3f(0.0, 1.0, 0.0); // Green
glVertex3f(-1.0, -1.0, 0.0);
glColor3f(0.0, 0.0, 1.0); // Blue
glVertex3f(1.0, -1.0, 0.0);
glEnd();
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
运行之后报错:
原因分析:
找了属性配置,经过修改也还是报错.
最后想想有可能是缺小头文件的原因.
解决方案:
加了句
#include<GL/glut.h>
成功运行,debug和release都没问题