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)