Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: GL didn't work in OSX, but in Windows

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2013

    GL didn't work in OSX, but in Windows

    I try to simulate fluid using opengl 3.2 on Mac with Intel HD Graphics 3000. GLFW3 and GLEW are used to help me create the window and be able to use opengl 3.2 functions.
    The program runs without error, everything in the scene is motionless (opengl can draw objects and the immovable fluid). When I use the same code in Windows with Nvidia Geforce. It works! The fluid flows into the scene. I think the problem may arise from the GLFW and GLEW initialization. This is my code:

    Code :
    #include <iostream>
    #include <GL/glew.h>
    #include <GLFW/glfw3.h>
    #include "Fluid.h"
    using namespace std;
    const int   WINDOW_WIDTH      = ViewportWidth;
    const int   WINDOW_HEIGHT     = ViewportHeight;
    const char* WINDOW_TITLE      = "Fluid 2D - GLSL";
    // Callback Functions
    void ErrorCallback(int error, const char* description);
    void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
    int main(int argc, char **argv)
        // Initialize GLFW
        if (!glfwInit())
        // Create Window
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
        glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
        //glfwWindowHint(GLFW_SAMPLES, 4);
        //glfwWindowHint(GLFW_RED_BITS, 8);
        //glfwWindowHint(GLFW_GREEN_BITS, 8);
        //glfwWindowHint(GLFW_BLUE_BITS, 8);
        //glfwWindowHint(GLFW_ALPHA_BITS, 8);
        //glfwWindowHint(GLFW_DEPTH_BITS, 24);
        GLFWwindow* window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE, NULL, NULL);
        if (!window)
            cout << "Fail to create window.\n";
        //const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
        //const float ScreenWidth = (float)(mode->width);
        //glfwSetWindowPos(window, (ScreenWidth - (float)WINDOW_WIDTH)*0.5, 0);
        glfwSetWindowPos(window, 0, 0);
        // Display Information
        cout << "Renderer \t\t:\t" << glGetString(GL_RENDERER) << endl;
        cout << "OpenGL Version \t:\t" << glGetString(GL_VERSION) << endl;
        cout << "GLSL Version \t:\t" << glGetString(GL_SHADING_LANGUAGE_VERSION) << endl;
        cout << "GLFW Version \t:\t" << glfwGetVersionString() << endl;
        // Initialize GLEW
        glewExperimental = GL_TRUE;
        GLenum err = glewInit();
        if (GLEW_OK != err){
            // Problem: glewInit failed, something is seriously wrong.
            printf("Error: %s\n", glewGetErrorString(err));
            return 1;
        printf("GLEW Version \t:\t%s\n", glewGetString(GLEW_VERSION));
        if (glewIsSupported("GL_VERSION_3_2"))
    		cout << "OpenGL 3.2 API is available." << endl;
    	else {
    		cout << "OpenGL 3.2 API is not available." << endl;
    		return 1;
        // Setup Callback Functions
        glfwSetKeyCallback(window, KeyCallback);
        // Enter Main Loop
        float previousTime = 0;
        // Fluid Object
        Fluid FluidSim;
        while (!glfwWindowShouldClose(window))
            float currentTime = (float)glfwGetTime();
            float inverseFPS = currentTime - previousTime;
            previousTime = currentTime;
    void ErrorCallback(int error, const char* description)
        cout << description << endl;
    void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
        if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
            glfwSetWindowShouldClose(window, GL_TRUE);

    Anyone know how to fix this problem?
    Million thanks in advance.
    Last edited by hesheit; 10-07-2013 at 10:45 AM.

  2. #2
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Start with the "how to debug" steps over in this thread.

    Start debugging by looking for errors, like INVALID_OPERATION on every draw call. Then make sure your code is Core-Profile safe, for example you have a VAO, all attributes are in VBOs, you're using a #140 or later version shader, etc.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2013
    Thank for your response.

    I can fix it without using Opengl Profiler, I changed the opengl context to 2.1 with GLSL version 120, It works!
    I think there is something wrong when using opengl context 3.2 on Mac.
    Some opengl functions we don't know may not be used in Opengl 3.2. context, although GLFW and GLEW tell us it's ready to use.

Posting Permissions

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