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 4 of 4

Thread: static GLEW question

  1. #1
    Junior Member Regular Contributor
    Join Date
    May 2017
    Posts
    101

    static GLEW question

    Finished converting the following code to x64. In the process, with the #define GLEW static, I only needed GLFW3 and freeglut includes. I converted libglfw3dll.a to libglfw3.a and used the dll to make sure it would work as suggested on the glew site. Its working, that's great, but is the #define GLEW still necessary -- seems to work with just a regular DLL. Should I keep it there or not.

    Code :
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    #define GLEW_STATIC
    #include <GL/glew.h>
    #include <GL/glfw3.h>
    #include <GL/freeglut.h>
     
    int main(void)
    {
        GLFWwindow* window;
     
        // Initialize the library
        if (!glfwInit())
            return -1;
     
        // Create a windowed mode window and its OpenGL context
        window = glfwCreateWindow(320, 240, "x64 test", NULL, NULL);
        if (!window)
        {
            glfwTerminate();
            return -1;
        }
     
        // Make the window's context current
        glfwMakeContextCurrent(window);
     
        //Start of GLEW thing
        glewExperimental = GL_TRUE;
        glewInit();
     
     
        GLuint vertexBuffer;
        glGenBuffers( 1, &vertexBuffer );
     
        printf( "%u\n", vertexBuffer );
        //End of GLEW thing
     
        // Loop until the user closes the window
        while (!glfwWindowShouldClose(window))
        {
            // Render here
     
     
            // Swap front and back buffers
            glfwSwapBuffers(window);
     
            // Poll for and process events
            glfwPollEvents();
        }
     
        glfwTerminate();
        return 0;
    }


    output:

    x64 black window

  2. #2
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    466
    glew, glfw and freeglut come each with a static and a dynamic library (these are different files!). if you use the static version of glew you have to define GLEW_STATIC before including <GL/glew.h>. and if you use the static version of freeglut you have to define FREEGLUT_STATIC. glfw does not need such a #define statement.

    if you link statically, you final .exe will be bigger and you dont need any .dlls. if dynamically, your final .exe will be smaller but you have to put the corresponding .dlls either beside the .exe or into Windows/System32 (32bit version) or Windows/SysWOW64 (64bit version)

    to create a window you only need 1 library: glfw OR freeglut, but not both
    to load the GL functionality you need glew

    (your example above doesnt need <GL/freeglut.h>)

    https://www.khronos.org/opengl/wiki/...enGL_Functions
    https://www.khronos.org/opengl/wiki/...oading_Library

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,828
    Quote Originally Posted by john_connor View Post
    if dynamically, your final .exe will be smaller but you have to put the corresponding .dlls either beside the .exe or into Windows/System32 (32bit version) or Windows/SysWOW64 (64bit version)
    On a 32-bit version of Windows, 32-bit DLLs go in System32, 16-bit DLLs go in System.

    On a 64-bit version of Windows, 64-bit DLLs go in System32, 32-bit DLLs go in SysWOW64.

    IOW, the native DLLs go in System32, the legacy DLLs go somewhere else. A similar structure exists for programs: native programs go in "Program Files", 32-bit programs on 64-bit systems go in "Program Files (x86)".

  4. #4
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    466
    thanks for clarifying ... wasnt sure about that (i always link statically if possible )

Posting Permissions

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