PDA

View Full Version : static GLEW question



technologist
01-06-2018, 06:18 PM
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.



#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

john_connor
01-06-2018, 10:38 PM
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/Load_OpenGL_Functions
https://www.khronos.org/opengl/wiki/OpenGL_Loading_Library

GClements
01-07-2018, 08:50 AM
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)".

john_connor
01-07-2018, 10:18 AM
thanks for clarifying ... wasnt sure about that (i always link statically if possible ;))