Glew initialisation failed : Missing GL version (GLFW)

邮差的信 提交于 2019-12-11 02:36:28

问题


I'm currently trying to draw a simple triangle with GLFW and GLEW.

I'm using CLion (which is itself using cmake with cygwin) on a Win 8.1 x64 PC.

My problem is : glewInit() returns error 1 (Missing GL version) when initialized. People (like in this thread) had a problem related to the OpenGL context, but mine is already created before I call glewInit().

Here is my code :

#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;
}

and my 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)

来源:https://stackoverflow.com/questions/26074793/glew-initialisation-failed-missing-gl-version-glfw

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!