Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Segmentation fault on glClearBuffer*

  1. #1
    Newbie Newbie
    Join Date
    Sep 2013
    Posts
    2

    Segmentation fault on glClearBuffer*

    I'm trying to go through the OpenGL SuperBible 6th ed., but was having a bit of trouble using the provided sb6.h framework for setting up windows and whatnot. I have done some legacy OpenGL using GLFW for windowing, so I figured I could just wrap the code in GLFW rather than what the book provides.

    However, I am segfaulting whenever I reach glClearBufferfv:

    Code :
    #include <GL/glew.h>
    #include <GLFW/glfw3.h>
     
    #include <stdlib.h>
    #include <stdio.h>
     
    static void errorCallback(int error, const char *description)
    {
      fputs(description, stderr);
    }
     
    static void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
    {
      if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
        glfwSetWindowShouldClose(window, GL_TRUE);
      }
    }
     
    static const GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
     
    int main(void)
    {
      glewExperimental = true;
      glewInit();
     
      GLFWwindow *window;
     
      glfwSetErrorCallback(errorCallback);
     
      if (!glfwInit()) {
        return EXIT_FAILURE;
      }
     
      window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
      if (!window) {
        glfwTerminate();
        return EXIT_FAILURE;
      }
     
      glfwMakeContextCurrent(window);
     
      glfwSetKeyCallback(window, keyCallback);
     
      int width, height;
      glfwGetFramebufferSize(window, &width, &height);
      glViewport(0, 0, width, height);
     
      int maxBuffers = 0;
      glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxBuffers);
     
      printf("GL_MAX_DRAW_BUFFERS = %d\n", maxBuffers);
     
      while (!glfwWindowShouldClose(window)) {
        glClearBufferfv(GL_COLOR, (GLint) 0, red);
     
        glfwSwapBuffers(window);
        glfwPollEvents();
      }
     
      glfwDestroyWindow(window);
     
      glfwTerminate();
     
      return EXIT_SUCCESS;
    }

    According to my glewinfo, my hardware supports up to GL_VERSION_4_0, but I'm guessing I'm missing something else. According to the OpenGL reference, glGetError() should be flagged, but when I set up a sigaction to caught the segfault, I got GL_NO_ERROR. Any help would be appreciated.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    720
    You are initializing GLEW before creating an OpenGL context (AFAIK GLFW does that as part of glfwCreateWindow). Since GLEW needs to query the OpenGL context for (extension) functions you must initialize GLEW after creating the OpenGL context and making it current.

  3. #3
    Newbie Newbie
    Join Date
    Sep 2013
    Posts
    2
    That was it. Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •