我目前正试图用GLFW和GLEW绘制一个简单的三角形。
我在Win 8.1 x64 PC上使用CLion(它本身使用cmake和cygwin)。
我的问题是:glewInit()
在初始化时返回错误1(Missing GL version
)。人们(比如在this线程中)遇到了与OpenGL上下文相关的问题,但是在我调用glewInit()
之前已经创建了我的。
这是我的代码:
#include <iostream>
#include <stdlib.h>
#include <vector>
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
//...
if(!glfwInit()) {
std::cerr << "Couldn't initialize GLFW" << std::endl;
}
glfwSetErrorCallback(glfw_error_callback);
glfwWindowHint(GLFW_SAMPLES, 4); //16x antialiasing sisi rpz
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // OpenGL 3.3
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(width, height, title.c_str(), NULL, NULL);
if(window == NULL) {
std::cerr << "Failed to open GLFW window. Are your drivers up-to-date ?" << std::endl;
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
if(!glfwGetCurrentContext()) {
std::cerr << "Couldn't create OpenGL context" << std::endl;
exit(EXIT_FAILURE);
}
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if(err != GLEW_OK) {
std::cerr << "Failed to initialize glew : " << glewGetErrorString(err) << " (" << err << ")" << std::endl;
}
和我的CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.4)
project(MY_PROJECT)
set(SOURCE_FILES main.cpp Host.cpp GraphicWindow.cpp)
add_executable(MY_PROJECT ${SOURCE_FILES})
target_link_libraries(MY_PROJECT wsock32 ws2_32)
#GL stuff
include_directories(lib/glew-1.11.0/include/)
include_directories(lib/glfw-3.0.4.bin.WIN64/include/)
include_directories(lib/glm)
target_link_libraries(MY_PROJECT glfw3 glu32 gdi32 opengl32 glew)