Im working on a project with opengl using glew and glfw
The project is larger but only the initialisation code doesnt work correctly. Im using glew 2.2.0_1 and glfw 3.3.8 (btw. I ran this in a debugger so Im 100% sure the glewInit() is causing the segfault. And if I put this in a file without the rest of the code its also causing a segfault)
The code is:
#include <GL/glew.h>
#include <GLFW/glfw3.h>
const int WIDTH = 640;
const int HEIGHT = 480;
int main(int argc, char **argv) {
// Set up GLFW and create window
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "Spinning Cube", nullptr, nullptr);
glfwMakeContextCurrent(window);
if (!window) {
return 1;
}
// Set up GLEW
glewInit();
// ...
}
Is it a library error or am I doing something wrong? (For anybody asking this code compiles without any warnings or errors)
With the macOS operating system, you must create an OpenGL Core Profile context with the forward compatibility flag set:
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);