OpenGL extension without using wglprocaddress?

BlitzMax Forums/BlitzMax Programming/OpenGL extension without using wglprocaddress?

JoshK(Posted 2007) [#1]
I need to get the pointer to the extension function glDrawElementsInstancedEXT(). I used to use wglgetprocaddress() but then I started relying on Glew. How do I do this in a way so that it works on all platforms?

I really need this answer. For some reason retrieving the pointer to some functions corrupts some of my memory. Something must be wrong:

Extern
	Function wglGetProcAddress:Byte Ptr(name$)="wglGetProcAddress@4"
EndExtern


SetGraphicsDriver GLGraphicsDriver(),GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER
Graphics 1024,768,0
glewInit()


Global glUniformBufferEXT(a%,b%,c%) "win32"
Global glDrawElementsInstancedEXT(mode_:Int,count_:Int,type_:Int,indices:Byte Ptr,primcount:Int) "win32"

glDrawElementsInstancedEXT=wglGetProcAddress("glDrawElementsInstancedEXT")
glUniformBufferEXT=wglGetProcAddress("glUniformBufferEXT")



N(Posted 2007) [#2]
Use glew.
Import Pub.Glew

Function InitializeRenderer(..)
     glewInit()
End Function


glDrawElementsInstancedEXT will already be defined and will be loaded by glew after you call glewInit. glewInit must be called after your context has been initialized. That is, after GLGraphics or your preferred means of initializing the window.


JoshK(Posted 2007) [#3]
I am using new extensions that are not found in pub.glew.


Dreamora(Posted 2007) [#4]
As long as you have "win32" it will never work, thats Windows COM call convention.

You need to get your stuff as "C" to use it outside the windows world.

Question is more if it is of use.
On the Linux side, definitely not, if you reside on stuff not even in the current glew version (might be that the one in BM is a little outdated), as the linux drivers are nowhere near the windows drivers.
On OSX, you might find answers on this topic on the Apple Dev page, where you will find other important informations (how to enable threaded opengl support which drastically raises the performance of your OGL apps for example)


Koriolis(Posted 2007) [#5]
As long as you have "win32" it will never work, thats Windows COM call convention.
The function pointer returned by glgetprocaddress is a plain C function pointer. I can't find any connection with COM.
On the Linux side, definitely not,

There is glXGetProcAddressARB on Linux.

For the mac, check http://developer.apple.com/qa/qa2001/qa1188.html, they're talkinga bout aglGetProcAddress.

As far as I can tell it's just a matter of picking the right one depending on the platform.

EDIT:
In fact that's exactly what glew does. Lookup the definition of glewGetProcAddress in glew.c.
It's a define so it can't be exported, but get inspiration from that to write a function that does just the same and you're basically done.


JoshK(Posted 2007) [#6]
I grabbed the latest version from Sourceforge and it compiled without a problem.

If anyone is interested, you just have to replace the old c files with the new ones from sourceforge (don't forget the includes), then add this to glew.bmx:

Global glUniformBufferEXT(a%,b%,c%)="__glewUniformBufferEXT"
Global glDrawElementsInstancedEXT(mode_:Int,count_:Int,type_:Int,indices:Byte Ptr,primcount:Int)="__glewDrawElementsInstancedEXT"



Dreamora(Posted 2007) [#7]
Koriolis: yes it is plain C function pointer, but Leadwerks declared the function with "Win32" which is what I meant.


Koriolis(Posted 2007) [#8]
"win32" has nothing to do with COM, if I'm not mistaken it makes your function pointer use the stdcall convention, rather than the cdecl convention. *This* is what I meant.