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: GL didn't work in OSX, but in Windows

Threaded View

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2013
    Posts
    4

    GL didn't work in OSX, but in Windows

    Hi,
    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)
    {
        glfwSetErrorCallback(ErrorCallback);
     
        //************************************
        // Initialize GLFW
        //************************************
        if (!glfwInit())
            exit(EXIT_FAILURE);
     
        //************************************
        // Create Window
        //************************************
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
        glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        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";
            glfwTerminate();
            exit(EXIT_FAILURE);
        }
        //const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
        //const float ScreenWidth = (float)(mode->width);
        //glfwSetWindowPos(window, (ScreenWidth - (float)WINDOW_WIDTH)*0.5, 0);
        glfwSetWindowPos(window, 0, 0);
     
        glfwMakeContextCurrent(window);
     
        //************************************
        // 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;
        FluidSim.Initialize();
     
        while (!glfwWindowShouldClose(window))
        {
            float currentTime = (float)glfwGetTime();
            float inverseFPS = currentTime - previousTime;
            previousTime = currentTime;
     
            FluidSim.Update(inverseFPS);
            FluidSim.Render();
     
            glfwSwapBuffers(window);
            glfwPollEvents();
        }
     
        glfwDestroyWindow(window);
        glfwTerminate();
     
        exit(EXIT_SUCCESS);
     
    }
     
    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 09:45 AM.

Posting Permissions

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