Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Loading extensions from scratch, win32 & OpenGL

  1. #1
    Intern Contributor
    Join Date
    Jul 2013
    Posts
    79

    Loading extensions from scratch, win32 & OpenGL

    Hi all,
    Inspite of all advices I'm trying to load opengl function-pointers. I'm using code::blocks and mingw and added
    #include <wglext.h>
    #include <glext.h>

    to a functioning opengl-template for a start. I've parsed the extensions-string and found ONE wgl-function: wgl-swapinterval. The entrance to other wgl-functions are supposed to be extracted from the extension wglGetExtensionsStringARB, but this extension is not exposed in the 242 available extensions that I have parsed from 'the other' extension-string [glGetString(GL_EXTENSIONS)]. So I've made a shot in the dark writing:

    PFNWGLGETEXTENSIONSSTRINGARBPROC * wglGetExtensionsStringARB;
    wglGetExtensionsStringARB =(PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");

    after getting a current rendercontext.
    The *wglGetExtensionsStringARB is not NULL, but I don't know how to take it from here. If it's supposed to be a string right away, it doesn't respon like it in
    printf(wglGetExtensionsStringARB);
    Should the functionpointer be 'instantiated' further [as say freeglut key- & mouse-function pointers are 'instantiated' in main() ] ?

    I'm armed with "Open Superbible 5", "OpenGL Programming Guide", "OpenGL ES 2.0" and the web ... none of them go much further than their own frameworks. If someone has a good link, I would be greatful. I'm currently scrutinizing
    http://www.opengl.org/wiki/Load_OpenGL_Functions

  2. #2
    Intern Newbie
    Join Date
    Jan 2014
    Posts
    40
    wglGetExtensionsStringARB is a function pointer. After initializing the pointer to the correct address, you simply call the function ("dereference" the pointer) by adding parentheses and expected arguments:

    Code :
    // declare funtion pointer
    PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB;
     
    // initialize function pointer to the address returned by wglGetProcAddress
    wglGetExtensionsStringARB =(PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");
     
    // call the function 
    wglGetExtensionsStringARB()

    AFAIK wglGetExtensionsStringARB() itself should return a string (char*) containing space-separated extension names. You use this string to check if wanted extension is supported and then proceed to attain function pointers pertaining to that extension. You get the pointers same way you've got wglGetExtensionsStringARB pointer, by calling wglGetProcAddress.

    It's much easier to use glew though.
    Last edited by nenad*; 01-26-2014 at 02:34 PM. Reason: pointer to pointer typo in code

  3. #3
    Intern Contributor
    Join Date
    Jul 2013
    Posts
    79
    Hi nenad*,
    When adding this line in code
    wglGetExtensionsStringARB() ;
    I get the error that wglGetExtensionsStringARB() is not a function.
    I think that I already tried something like this
    char *txt = wglGetExtensionsStringARB() ;
    and got the same error.

    I just tested this:
    PFNWGLGETEXTENSIONSSTRINGARBPROC * wglGetExtensionsStringARB;
    wglGetExtensionsStringARB =(PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");

    if( wglGetExtensionsStringARB != NULL ){
    printf("wglGetExtensionsStringARB sucessful?\n") ;
    // printf(wglGetExtensionsStringARB);
    const char *txt = wglGetExtensionsStringARB() ; -> error-provoking code
    printf( txt ) ;
    }
    else{
    printf("wglGetExtensionsStringARB erroneous?\n") ;
    }
    and get the error: called object is not a function.
    But my previous test is in accordance with your suggestion, and the usage I found online "OpenGL SuperBible":

    http://books.google.dk/books?id=odgd...0usage&f=false

    so something might be very wrong.

    //////////
    I do use GLEW & GLFW, but I got to read Notices & Copyrights and was left with worries that I would have to offer my source-code in the open as a consequence. Having the profound problems of loading myself I've been back at the Notices .. I think that I'm off the hook as to presenting my sources. I don't mind about the binary (it's supposed to be a gift to the world ;o).
    Frankly, I don't think that I survive loading myself ..
    Last edited by CarstenT; 01-26-2014 at 01:34 PM.

  4. #4
    Intern Newbie
    Join Date
    Jan 2014
    Posts
    40
    Quote Originally Posted by CarstenT View Post
    I get the error that wglGetExtensionsStringARB() is not a function.
    Right. I think this is because you mistakenly declared wglGetExtensionsStringARB as a pointer to pointer. The type PFNWGLGETEXTENSIONSSTRINGARBPROC is already a pointer type (note the PFN prefix, meaning: pointer to function).

    So instead:
    PFNWGLGETEXTENSIONSSTRINGARBPROC * wglGetExtensionsStringARB;

    the declaration should lose the asterisk and look like:
    PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB;

    Try this out for start and see if the thing compiles.
    Last edited by nenad*; 01-26-2014 at 02:39 PM.

  5. #5
    Intern Contributor
    Join Date
    Jul 2013
    Posts
    79
    Hi nenad;

    Well seen! Yes, it compiles but now complains on "too few arguments" for function wglGetExtensionsStringARB().
    I added the device-context, hDC as argument. The compiler warning is that function expected 'HDC' but argument is of type 'struct HDC__**'
    It runs but the output-string contains nothing.
    In accordance to this:
    https://developer.nvidia.com/sites/d...xelBuffers.pdf
    I stuffed in the current render context, and an eqvivalent compiler warning appears:
    expected 'HDC' but argument is of type 'struct HGLRC__**'
    still nothing in the output-string.

    If I look back: I just reinstalled the opengl-driver named something like '320..' . It's an older one from 2008. The version I can querry is 3.3 ok. Still the wglGetExtensionsStringARB may be younger than 2008? As mentioned the wglGetExtensionsStringARB does not appear in the extension-string [glGetString(GL_EXTENSIONS)].
    I choose the older version to omit the concomitant mega-install of some 'windows framework 4.0'. The errors could conform to this ..?
    The wglext.h and glext.h are newly copy/pasted from the opengl registry.

  6. #6
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    457
    You're passing the context handle in (which is of type HGLRC), use the same HDC you used to create the context.
    Code :
    rc = wglCreateContext(dc);
    ...
    extensions = wglGetExtensionsStringARB(dc);

    Here's the extension specification: http://www.opengl.org/registry/specs...ons_string.txt

  7. #7
    Intern Contributor
    Join Date
    Jul 2013
    Posts
    79
    Hi Dan,

    I tried both the device-context and the render-context. Both gives a compiler warning (as described above), but compile. The output is an empty string.
    I added the function
    const char *wglGetExtensionsStringARB(HDC hdc);
    to the top of my .cpp. It did not change anything.

    The link to the specs you provided (thanks) says
    "If there are no extensions then the empty string is returned."
    ... !?

    I've tried to follow the instructions on how to 'do-opengl-yourself' .. that implies starting out with a dummy context, use it for getting the wglChoosePixelFormatARB and then build another proper context.
    I just checked that I do get opengl 3.3 and the equivalent shader-version. Doesn't that mean that I can use all the buffer options and neglect the fixed-function stuff?
    I'm new and not sophisticated in my needs .. I think that these abilities suffice (for now). After all .. there are 242 other extensions to use [or what?].
    I've got a GLEW/GLFW project running ok (using a core profile), so unless GLEW does magic, I'm supposed to be able to too?

    ... EDIT
    I had a look at the opengl-extensionViewer.
    It detects 267 extensions. The discrepency to the 242 I find [one WGL] is 25 .. and there are 27 WGL-functions found.
    wglGetExtensionsStringARB is not one of them, but another eqvivalent: WGL_EXT_extensions_string.
    Is this part of another Microsoft-go-hide-and-seek game?
    Last edited by CarstenT; 01-27-2014 at 04:13 AM.

  8. #8
    Intern Newbie
    Join Date
    Jan 2014
    Posts
    40
    Could you tell us what precisely is that you want to do? What functionality do you need for your application?

    Couldn't the pixel format be set simply via win32 funcion ChoosePixelFormat()?

  9. #9
    Intern Contributor
    Join Date
    Jul 2013
    Posts
    79
    Hi nenad,


    Ok, I've copy/pasted some of my functional code into the program. First task is compiling a shader

    vertShader = glCreateShader(GL_VERTEX_SHADER);

    GL_VERTEX_SHADER is not recognized.

    ---------
    If I should try to probe for
    WGL_EXT_extensions_string
    can I assume that the type would be
    PFN_WGLEXTENSIONSSTRING_PROC -- without the underscores?

    [after programming-excesses my web-tv only shows half a movie in bites, but I get to see those bites twice, so I prefer to ask rather than reinstall driver]

  10. #10
    Intern Newbie
    Join Date
    Jan 2014
    Posts
    40
    Quote Originally Posted by CarstenT View Post

    vertShader = glCreateShader(GL_VERTEX_SHADER);

    GL_VERTEX_SHADER is not recognized.
    Since you're going the extension route shouldn't that be:

    Code :
    glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB)

    You'll of course need to check if ARB_vertex_shader extension is supported and obtain the pointer to glCreateShaderObjectARB() via wglGetProcAddress()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •