Hi,
I’m working on the OpenGL package and I want to make it finally usable in a
nice and clean way on all platforms.
The problem is, that one needs pointer for the GL functions, which you can
only get, after initialization of the OpenGL context.
But initializing the context and creating a window shouldn’t be part of the
OpenGL package.
So I tried two different approaches, which both seem to have their
downsides:
1.
Initialize OpenGL context when including the OpenGL package
This is bad, because this makes the OpenGL package dependent on some third
party OpenGL context creation library.
2.
Load the functions later with a loading Function.
Bad, because the function definitions are not visible for any other module,
that relies on the OpenGL package.
My ideal solution would be, to evaluate a macro when the function is called
and not when the module is included.
Like this, I can define all the OpenGL functions already in the OpenGL
module, and when you call them the first time,
the right function ptr gets inserted into the ccall, or an error is raised,
when OpenGL context is not initialized.
this could look like this:
module OpenGL
macro getFuncPointer(name::ASCIIString)
return getProcAddress(name)
end
glGetString(name::GLenum) = ccall(@getFuncPointer("glGetString"), ...., ....,
name)
export glGetString
end
using OpenGL
...create OpenGL context
#define getProcAddress
global const getProcAddress = glutGetProcAddress # If using GLUT for GL context
creation
#call gl Functions
glGetString(GL_VERSION)
Any ideas how to do this in a clean way?
Cheers,
Simon