Results 1 to 5 of 5

Thread: Newbie extension question

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2000
    Location
    Morrisville, NC
    Posts
    27

    Newbie extension question

    Hi...

    In my attempt to deal with extensions I'm confused as to how to declare my function pointer variables. The examples that I see do something like this to declare the function prototypes:

    #ifdef _WIN32
    typedef void (APIENTRY * PFNGLPOINTPARAMETERFEXTPROC)(GLenum pname, GLfloat param);
    typedef void (APIENTRY * PFNGLPOINTPARAMETERFVEXTPROC)(GLenum pname, const GLfloat *params);
    #endif

    Then, define the variables like:

    #ifdef _WIN32
    PFNGLPOINTPARAMETERFEXTPROC glPointParameterfEXT;
    PFNGLPOINTPARAMETERFVEXTPROC glPointParameterfvEXT;
    #endif


    The problem that I can't get is determining the function name of glPointParameterfvEXT. I see that I could extract it from PFNGLPOINTPARAMETERFVEXTPROC, but that would be terribly tedious if I have a lot of extensions.

    So I'm wondering if there is an .h file that will have the gl* extension function defined somewhere? Or does everybody know to call the PFNGLPOINTPARAMETERFVEXTPROC function pointer to glPointParameterfvEXT? Or is this in some other file besides gl.h/glext.h?

    Thanks a bunch...

    Bode

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Holland
    Posts
    179

    Re: Newbie extension question

    Originally posted by Bode:
    Hi...

    In my attempt to deal with extensions I'm confused as to how to declare my function pointer variables. The examples that I see do something like this to declare the function prototypes:

    #ifdef _WIN32
    typedef void (APIENTRY * PFNGLPOINTPARAMETERFEXTPROC)(GLenum pname, GLfloat param);
    typedef void (APIENTRY * PFNGLPOINTPARAMETERFVEXTPROC)(GLenum pname, const GLfloat *params);
    #endif

    Then, define the variables like:

    #ifdef _WIN32
    PFNGLPOINTPARAMETERFEXTPROC glPointParameterfEXT;
    PFNGLPOINTPARAMETERFVEXTPROC glPointParameterfvEXT;
    #endif


    The problem that I can't get is determining the function name of glPointParameterfvEXT. I see that I could extract it from PFNGLPOINTPARAMETERFVEXTPROC, but that would be terribly tedious if I have a lot of extensions.

    So I'm wondering if there is an .h file that will have the gl* extension function defined somewhere? Or does everybody know to call the PFNGLPOINTPARAMETERFVEXTPROC function pointer to glPointParameterfvEXT? Or is this in some other file besides gl.h/glext.h?

    Thanks a bunch...

    Bode
    Bode,

    The glext.h file will define the PFNGLBLABLABLAEXTPROC pointers. It's up to you to declare a pointer of that type and call the platform specific function to fill the pointer with the correct address. For windows this is:

    (PFNGLBLABLABLAEXTPROC)wglGetProcAddress( "glBlaBlaBlaEXT")

    For other platforms there are corresponding calls.

    AFAIK there is no .h file around that declares the required character strings to pass to wglGetProcAddress, but they are quite easy to derive from the PFNGLBLABLABLA definition: small caps gl, capitalise each word and an all caps finish like 'EXT', 'NV' etc.

    You could search around the net for classes/files that implement a bunch of extensions for you, but as I said it's relatively simple to code for yourself (just a lot of repetetive work if you want to use a lot of extensions).

    I'm assuming you are familiar with the following:
    - verify extension support during compile-time with #ifdef ExtensionName
    - verify extension support during runtime by querying glGetString(GL_EXTENSIONS) for the ExtensionName
    - only use the extension functions if support is available and wglGetProcAddress returned a valid pointer

    HTH

    Jean-Marc.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Newbie extension question

    Just thought I'd add a quick point. It sounds like you think that the instance of the function pointer needs to be named something specific. This isn't the case. You could do this if you wanted.

    PFNGLPOINTPARAMETERFEXTPROC glICanNameThisFunctionWhateverIWant;

    It will still be a pointer to a function of the same type. How it actually points to the function it needs in the DLL is by assigning it with wglGetProcAddress the way that JML described.

    Granted, it's not very practical to give the function pointers odd names, but there's technically nothing that stops you from doing so.
    Deiussum
    Software Engineer and OpenGL enthusiast

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2000
    Location
    Morrisville, NC
    Posts
    27

    Re: Newbie extension question

    Thanks Guys...

    It's starting to make more sense now.

    But I have just one more question. I see that a lot of programs use glGetString(GL_EXTENSIONS) to determine available extensions, then call wglGetProcAddress().
    Why don't they just call wglGetProcAddress() to determine if the extension is available, and if it returns a NULL, then use your software implementation? Is wglGetProcAddress() such a heavy function that it should only be used sparingly? (hence the reason to pretest with glGetString() )

    Bode

  5. #5
    Senior Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Holland
    Posts
    179

    Re: Newbie extension question

    Originally posted by Bode:
    Thanks Guys...

    Why don't they just call wglGetProcAddress() to determine if the extension is available, and if it returns a NULL, then use your software implementation? Is wglGetProcAddress() such a heavy function that it should only be used sparingly? (hence the reason to pretest with glGetString() )

    Bode
    You could do that, however for quite a few extensions testing for a single occurrence in GL_EXTENSIONS is cheaper than calling a zillion wglGetProcAdresses.
    Besides, the 'official' rules say you should check the GL_EXTENSIONS first, and then get the addresses. There is no guarantee that a successful wglGetProcAddress gives you an officially supported extension.

    Jean-Marc.

Similar Threads

  1. Newbie question
    By lkeene in forum OpenCL
    Replies: 2
    Last Post: 07-21-2009, 12:29 PM
  2. Newbie question
    By Yvo G. in forum OpenGL: User Software
    Replies: 1
    Last Post: 05-04-2009, 02:35 PM
  3. Newbie question
    By avicko in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 03-03-2003, 11:21 PM
  4. Extension Question
    By ntz123 in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 01-13-2003, 06:03 PM
  5. Extension question
    By steveo in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-15-2000, 08:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean