1

I built glfw, and the programs in test run just fine, however, when I try to write my own program it segfaults at the line while(!glfwWindowShouldClose(window)) and when I remove this it segfaults on glfwPollEvents(). I am compiling it with cc window.c -lglfw3 -lGLEW -lGL -lX11 -lGLU -lXxf86vm -lXrandr -lpthread -lXi -lm -lXinerama -lXcursor. Why do these functions segfault, and why don't the initialization functions. Full program included bellow.

#include <GL/glew.h> #include <GLFW/glfw3.h> int main(int argc, char** argv){ glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); GLFWwindow* window = glfwCreateWindow(800, 600, "gl", NULL, NULL); glfwMakeContextCurrent(window); //glewExperimental = GL_TRUE; glewInit(); glViewport(0, 0, 800, 600); while(!glfwWindowShouldClose(window)){ glfwPollEvents(); glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glfwSwapBuffers(window); } glfwTerminate(); return 0; } 
1
  • 3
    You never check window to make sure it's non-NULL. It's possible you're failing to create a window because of your specific combination of version and profile hints. Commented Dec 10, 2014 at 19:58

1 Answer 1

1

Just add this line to you initialization:

glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); 

And then it will work! ;-)

You are probably using a Mac, right? The explanation is right here: http://www.glfw.org/faq.html#how-do-i-create-an-opengl-30-context

Sign up to request clarification or add additional context in comments.

2 Comments

The libraries listed above are for X11 so it's more likely to be Linux.
I'm porting my app to Mac and this was one of the only issues I had. Your solution provided the answer. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.