问题描述
我正在尝试使用GLFW和GLEW。目前,我的代码有效,并且我看到一个带有三角形的窗口:
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <stdlib.h>
#include <time.h>
#include "constants.h"
int main(void) {
GLFWwindow* window;
if (!glfwInit()) {
glfwTerminate();
return -1;
}
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(WINDOW_WIDTH,WINDOW_HEIGHT,"Window",NULL,NULL);
if (!window) {
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
// if (glewInit() != GLEW_OK) {
// fprintf(stderr,"failure");
// return -1;
// }
glfwSetInputMode(window,GLFW_STICKY_KEYS,GL_TRUE);
while (glfwGetKey(window,GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window) == 0) {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex2f(0,0);
glVertex2f(0,1);
glVertex2f(1,0);
glEnd();
glfwSwapBuffers(window); /* Swap front and back buffers */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
上面的代码有效。但是,当我取消注释时:
if (glewInit() != GLEW_OK) {
fprintf(stderr,"failure");
return -1;
}
程序以静默方式退出。我用断点确认了main
函数甚至没有被调用。如果有帮助,这是我的编译命令:
g++ -g main.cpp -I\glfw-3.3.2\include -I\glew-2.1.0\include -L\glfw-3.3.2\lib-mingw-w64 -L\glew-2.1.0\lib\Release\x64 -lglfw3 -lgdi32 -lopengl32 -luser32 -lshell32 -lglew32 -o main.exe
我一生都无法解决。我在制作OpenGL窗口后调用glewInit
,在glew
之前导入glfw
。我在做什么错了?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)