openGL getProcAddress

hi

since windows still is shipped with openGL 1.1 i have to get some
commands like glActiveTextureARB via SDL_GetProcAddress() which works
fine. however i need some constants to work with those commands, like
GL_TEXTURE0_ARB etc. how do i get those, i surely can’t pull them out of
the dll too?

eik

First, you need to check for the extensions. Use a function like this:

SDL_bool HasExtension (char *ext)
{
const char *p;
const char *last;
int len;
int i;

p = glGetString (GL_EXTENSIONS);

if (!p)
    return SDL_FALSE;

len = strlen (ext);
last = p + strlen (p);

while (p < last)
{
    i = strcspn (p, " ");
    if (len == i && strncmp(ext, p, i) == 0)
        return SDL_TRUE;

    p += (i + 1);
}

return SDL_FALSE;

}

DO NOT FALL INTO THE TEMPTATION TO USE strstr () OR strtok ()!!! Use of
strstr () is pretty much guaranteed to break the first time someone
decides to name an extension GL_FOO_something and another
GL_FOO_something_else, so don’t do that! Also, you should never modify
the string returned by glGetString (), which strtok () does for you quite
handily (and illegally in this case…)

You’ll need to declare a function pointer for each function you wish to
use, and it should not be named the same as the function in the file, but
should be similar. Use the qgl namespace, all of the Quake’s did so it’s
quite permanently taken for this purpose. Here are a few examples:

extern void (APIENTRY * qglActiveTextureARB) (GLenum);
extern void (APIENTRY * qglLockArraysEXT) (GLint, GLsizei);
extern void (APIENTRY * qglUnlockArraysEXT) (void);

Note, that should be extern “C” for C++ code… To assign the function
pointers, do this:

if (HasExtension ("GL_ARB_multitexture"))
{
    use_mtex = SDL_TRUE;
    if (! (qglActiveTextureARB =
        SDL_GL_GetProcAddress ("glActiveTextureARB")))
        use_mtex = SDL_FALSE;
}
if (HasExtension ("GL_EXT_compiled_vertex_array"))
{
    use_cva = SDL_TRUE;
    if (! (qglLockArraysEXT =
        SDL_GL_GetProcAddress ("glLockArraysEXT")))
        use_cva = SDL_FALSE;
    if (! (qglUnlockArraysEXT =
        SDL_GL_GetProcAddress ("glUnlockArraysEXT")))
        use_cva = SDL_FALSE;
}

Obviously I’m missing a few functions you’d need for GL_ARB_multitexture
above, but you get the idea.

Note, this is generally a lot of hard work - and I’ve done most of it
already. If you’re interested, send me an email off-list and I’ll send
you my DynGL generation 3 code. It makes all OpenGL loading completely
dynamic. You don’t even need a GL/gl.h when you compile (and in fact, if
you use DynGL I recommend that you don’t include one…) The code needs a
few more minor tweaks before I put it online, but those are mostly in the
documentation.On Thu, May 16, 2002 at 09:26:07PM +0200, Eike Umlauf wrote:

since windows still is shipped with openGL 1.1 i have to get some
commands like glActiveTextureARB via SDL_GetProcAddress() which works
fine. however i need some constants to work with those commands, like
GL_TEXTURE0_ARB etc. how do i get those, i surely can’t pull them out of
the dll too?


Joseph Carter The guy with a rocket launcher

im fcucking druk

  • Knghtbrd makes sure to log everything Crow- says tonight …
    heheh
    He said he’d marry me! damnit!!
    dude no way
    MrBump - he’s not THAT drunk
    Knghtbrd: I’m crushed :o)

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020516/97c2198e/attachment.pgp

Note #2, in the header which defines these, do this at the top:

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h> /* for APIENTRY */
#undef WIN32_LEAN_AND_MEAN
#else
#define APIENTRY
#endif

Sorry about that.On Thu, May 16, 2002 at 02:31:17PM -0700, Joseph Carter wrote:

You’ll need to declare a function pointer for each function you wish to
use, and it should not be named the same as the function in the file, but
should be similar. Use the qgl namespace, all of the Quake’s did so it’s
quite permanently taken for this purpose. Here are a few examples:

extern void (APIENTRY * qglActiveTextureARB) (GLenum);
extern void (APIENTRY * qglLockArraysEXT) (GLint, GLsizei);
extern void (APIENTRY * qglUnlockArraysEXT) (void);

Note, that should be extern “C” for C++ code… To assign the function


Joseph Carter You want fries with that?

  • knghtbrd can already envision: “Subject: [INTENT TO PREPARE TO PROPOSE
    FILING OF BUG REPORT] Typos in the policy document”

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020516/e89ed00c/attachment.pgp

First, you need to check for the extensions. Use a function like this:

erm, okay, i didn’t actually check if the extension existed like this. i
did exactly as described in the doc project:

typedef void (*GL_ActiveTextureARB_Func)(unsigned int);
GL_ActiveTextureARB_Func glActiveTextureARB_ptr = 0;
glActiveTextureARB_ptr=(GL_ActiveTextureARB_Func)SDL_GL_GetProcAddress(“glActiveTextureARB”);

this seems to work fine as the prog still runs and
glActiveTextureARB_ptr is a valid non-NULL address, so i believe that
works.

the problem is, i obviously need parameters for
glActiveTextureARB_ptr(), but when i try to compile
glActiveTextureARB_ptr(GL_TEXTURE0_ARB);
i get an error cause GL_TEXTURE0_ARB is nowhere defined. so how on earth
do i get that constant?
i’ve searched on google for GL_TEXTURE0_ARB and think it should be
0x84C0 (found it in a quake2 header i think) but when i run my prog with
that value it crashes badly.

so where to get that constant?

thx
eik

since windows still is shipped with openGL 1.1 i have to get some
commands like glActiveTextureARB via SDL_GetProcAddress() which works
fine. however i need some constants to work with those commands, like
GL_TEXTURE0_ARB etc. how do i get those, i surely can’t pull them out of
the dll too?

These (should) have standard values across platforms. Just use the headers.

–ryan.

[…]

i get an error cause GL_TEXTURE0_ARB is nowhere defined. so how on earth
do i get that constant?
i’ve searched on google for GL_TEXTURE0_ARB and think it should be
0x84C0 (found it in a quake2 header i think) but when i run my prog with
that value it crashes badly.

so where to get that constant?

http://www.opengl.org/developers/documentation/extensions.html

The link you’ll find there of interest is

http://oss.sgi.com/projects/ogl-sample/registry/

You should be able to find from there basically all of the docs for the
OpenGL extensions. These are the docs used by people writing the OpenGL
drivers, so they have the constants you need. You can also get better
OpenGL headers from places like NVIDIA, and I include many common
extensions’ constants in my DynGL code. Here are the constants for
GL_ARB_multitexture from the Mesa headers:

#ifndef GL_ARB_multitexture
#define GL_TEXTURE0_ARB 0x84C0
#define GL_TEXTURE1_ARB 0x84C1
#define GL_TEXTURE2_ARB 0x84C2
#define GL_TEXTURE3_ARB 0x84C3
#define GL_TEXTURE4_ARB 0x84C4
#define GL_TEXTURE5_ARB 0x84C5
#define GL_TEXTURE6_ARB 0x84C6
#define GL_TEXTURE7_ARB 0x84C7
#define GL_TEXTURE8_ARB 0x84C8
#define GL_TEXTURE9_ARB 0x84C9
#define GL_TEXTURE10_ARB 0x84CA
#define GL_TEXTURE11_ARB 0x84CB
#define GL_TEXTURE12_ARB 0x84CC
#define GL_TEXTURE13_ARB 0x84CD
#define GL_TEXTURE14_ARB 0x84CE
#define GL_TEXTURE15_ARB 0x84CF
#define GL_TEXTURE16_ARB 0x84D0
#define GL_TEXTURE17_ARB 0x84D1
#define GL_TEXTURE18_ARB 0x84D2
#define GL_TEXTURE19_ARB 0x84D3
#define GL_TEXTURE20_ARB 0x84D4
#define GL_TEXTURE21_ARB 0x84D5
#define GL_TEXTURE22_ARB 0x84D6
#define GL_TEXTURE23_ARB 0x84D7
#define GL_TEXTURE24_ARB 0x84D8
#define GL_TEXTURE25_ARB 0x84D9
#define GL_TEXTURE26_ARB 0x84DA
#define GL_TEXTURE27_ARB 0x84DB
#define GL_TEXTURE28_ARB 0x84DC
#define GL_TEXTURE29_ARB 0x84DD
#define GL_TEXTURE30_ARB 0x84DE
#define GL_TEXTURE31_ARB 0x84DF
#define GL_ACTIVE_TEXTURE_ARB 0x84E0
#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1
#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2
#endif

Yes, Mesa supports up to 32 TMUs in its headers. Where you’ll get a card
with support for 32 TMUs that you can actually afford is your problem, of
course. ;)On Fri, May 17, 2002 at 12:07:25AM +0200, Eike Umlauf wrote:


Joseph Carter Do not write in this space

if (cb) ((cb->obj)->*(cb->ui_func))();
tausq: who the HELL wrote that ?
me :slight_smile:

  • knghtbrd flogs tausq

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020516/759b0769/attachment.pgp

http://www.opengl.org/developers/documentation/extensions.html

The link you’ll find there of interest is

http://oss.sgi.com/projects/ogl-sample/registry/

ahh yes now it’s a lot clearer to me… but my code still crashes
although the extensions have been loaded and the constants are alright…
any idea why glActiveTextureARB might want to crash? do i need to
initialize some stuff before using it?

thx
eik–

“there are 2 sides of the force: the upper and the lower”

You need to make sure the function pointer was actually found. Also, you
must not try to get any functions before you SDL_InitVideoMode ().On Fri, May 17, 2002 at 12:52:32AM +0200, Eike Umlauf wrote:

http://www.opengl.org/developers/documentation/extensions.html

The link you’ll find there of interest is

http://oss.sgi.com/projects/ogl-sample/registry/

ahh yes now it’s a lot clearer to me… but my code still crashes
although the extensions have been loaded and the constants are alright…
any idea why glActiveTextureARB might want to crash? do i need to
initialize some stuff before using it?


Joseph Carter Certified free software nut

Z.O.I.D.: Zombie Optimized for Infiltration and Destruction

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020516/ff916d0f/attachment.pgp

You need to make sure the function pointer was actually found. Also, you
must not try to get any functions before you SDL_InitVideoMode ().

so, if the pointer i got from SDL_GL_GetProcAddress is not NULL
everything should be fine, shouldn’t it?
i also try to get the functions after intializing the video mode.

eik

That’s correct, yes.On Fri, May 17, 2002 at 01:37:09AM +0200, Eike Umlauf wrote:

You need to make sure the function pointer was actually found. Also, you
must not try to get any functions before you SDL_InitVideoMode ().

so, if the pointer i got from SDL_GL_GetProcAddress is not NULL
everything should be fine, shouldn’t it?
i also try to get the functions after intializing the video mode.


Joseph Carter Intelligent backside at large

It is important to note that the primary reason the Roman Empire
fail is that they had no concept of zero… thus they could not
test the success or failure of their C programs.

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020516/51e07079/attachment.pgp

so, if the pointer i got from SDL_GL_GetProcAddress is not NULL
everything should be fine, shouldn’t it?
i also try to get the functions after intializing the video mode.

That’s correct, yes.

aaargh i give up, even if i load something simple like glEnable with
getProcAddress, i’m unable to use it without crashing my application.
has anyone ever written a little demo-program that uses
SDL_GL_GetProcAddress that i might borrow to find out what i’m doing
wrong? i can’t think of any mistake anymore…

thx
eik

glEnable isn’t an extension. Give me a day or so to polish up my DynGL
code’s docs (I’ve been very busy today and haven’t had time) and try it
out. Basically, I do all of the hard work for you. It works for everyone
using Project Twilight so far, and that’s a good number of people.On Fri, May 17, 2002 at 02:42:52AM +0200, Eike Umlauf wrote:

so, if the pointer i got from SDL_GL_GetProcAddress is not NULL
everything should be fine, shouldn’t it?
i also try to get the functions after intializing the video mode.

That’s correct, yes.

aaargh i give up, even if i load something simple like glEnable with
getProcAddress, i’m unable to use it without crashing my application.
has anyone ever written a little demo-program that uses
SDL_GL_GetProcAddress that i might borrow to find out what i’m doing
wrong? i can’t think of any mistake anymore…


Joseph Carter Have chainsaw will travel

Mercury, isn’t debugging X a little like finding perfectly
bugfree code in windows ??
WildCode: Debugging X is like trying to run a straight line
through a maze.
You just need to bend space-time so that the corners move around
you and you won’t have any problems. (=:]

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020516/e4170fb1/attachment.pgp

glEnable isn’t an extension.

yes but i should be able to get it with getProcAddress anyway.

Give me a day or so to polish up my DynGL
code’s docs (I’ve been very busy today and haven’t had time) and try it
out. Basically, I do all of the hard work for you. It works for everyone
using Project Twilight so far, and that’s a good number of people.

ok thx for your trouble

eik

glEnable isn’t an extension.

yes but i should be able to get it with getProcAddress anyway.

Yes, SDL_GL_GetProcAddress, as of 1.2.4 at least (I don’t know how far
back it has worked) does fall back to GetProcAddress in win32 if
wglGetProcAddress does not return something meaningful.

Give me a day or so to polish up my DynGL
code’s docs (I’ve been very busy today and haven’t had time) and try it
out. Basically, I do all of the hard work for you. It works for everyone
using Project Twilight so far, and that’s a good number of people.

ok thx for your trouble

No problem - I’ll post an announcement here when I’ve got the page online
with the DynGL stuff on it.On Fri, May 17, 2002 at 10:01:51AM +0200, Eike Umlauf wrote:


Joseph Carter Sooner or later, BOOM!

anyone around?
no, we’re all irregular polygons

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020517/68ec95e1/attachment.pgp

This sounds very much like wrong calling conventions on the GL functions.
Calling conventions define e.g. whether parameters are pushed onto the stack
left-to-right or right-to-left, and whether caller or callee clean the stack.

In Windows, you’ll see that GL functions or declared something like

GLint APIENTRY glFoo(…);

This means your function pointers need to look like this

GLint (APIENTRY * ptr_glFoo)(…);

You’ll need some macros to get it to compile on non-Windows platforms, e.g.

#ifndef APIENTRY
#define APIENTRY /* something here */
#endif

You should consult the platform’s gl.h for what APIENTRY should be (on Linux,
you can omit it, i.e. #define it to be empty)

cu,
NicolaiAm Freitag, 17. Mai 2002 02:42 schrieb Eike Umlauf:

so, if the pointer i got from SDL_GL_GetProcAddress is not NULL
everything should be fine, shouldn’t it?
i also try to get the functions after intializing the video mode.

That’s correct, yes.

aaargh i give up, even if i load something simple like glEnable with
getProcAddress, i’m unable to use it without crashing my application.
has anyone ever written a little demo-program that uses
SDL_GL_GetProcAddress that i might borrow to find out what i’m doing
wrong? i can’t think of any mistake anymore…