Register
Handmade Hero»Forums»Code»OpenGL Function pointer loading
83 posts
OpenGL Function pointer loading
1 week ago Edited by C_Worm on Jan. 11, 2021, 12:56 p.m. Reason: Initial post
Hey im trying to load OpenGL funciton pointers from scratch

Here im setting up the old OpenGL context, that can only call gl-functions from version 1.1 ( I think?)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
void Win32_CreateOldOpenGLContext(WIN32_PLATFORM *win32)
{
    
    // Set the pfd to what we would like to have. ( Suggested pfd )
    PIXELFORMATDESCRIPTOR pfd = {};
    pfd.nSize = sizeof(pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 32;
    pfd.cDepthBits = 24;
    pfd.cStencilBits = 8;
    pfd.iLayerType = PFD_MAIN_PLANE;
    
    // Windows chooses the pixel format that best fits our needs from the pfd
    HDC our_dc = GetDC(win32->hwnd);
    i32 pix_format = ChoosePixelFormat(our_dc, &pfd);
    
    // Set the pixel format that windows decided was the best
    SetPixelFormat(our_dc, pix_format, &pfd);
    
    // Create the OpenGL context
    win32->gl_rendering_context = wglCreateContext(our_dc);
    
    // Make it the current active context
    wglMakeCurrent(our_dc, win32->gl_rendering_context);
    
    // When gl context is activated we can load funtion pointers
    
}




After that i try to load a function pointer to get glUseProgram:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
     
    ....
    WIN32_PLATFORM win32 = Win32_WindowSetup(hInstance, cj_engine_OpenGL_windowName);
    
    ShowWindow(win32.hwnd, nShowCmd);
    
    Win32_CreateOldOpenGLContext(&win32);

    typedef void WINAPI PFNGLUSEPROGRAMPROC (GLuint program); 
    PFNGLUSEPROGRAMPROC *glUseProgram;
    glUseProgram = (PFNGLUSEPROGRAMPROC*)wglGetProcAddress("glUseProgram");
    
    glUseProgram(0);
    .....



Howevever if i call
1
    glUseProgram();



i get
1
error C2198: 'PFNGLUSEPROGRAMPROC (__cdecl *)': too few arguments for call




What i want is the error to say something more in style of this:
1
error C2198: glUseProgram: too few arguments for call


How could i achieve this?

I mean i want the actuall function name to be called in errors, not the "function pointer declaration type" if that makes sence.


thanks.
Simon Anciaux
938 posts
OpenGL Function pointer loading
1 week ago
glUseProgram in the code is a variable (containing a function pointer). So it doesn't have parameter and the compiler gives you the name corresponding to the function type as it's the relevant information.

If you are OK with changing the function declaration names you could change the code to something like:

1
2
3
typedef void WINAPI glUseProgram_proc (GLuint program); 
glUseProgram_proc *glUseProgram;
glUseProgram = (glUseProgram_proc*)wglGetProcAddress("glUseProgram");


The error message should be easier to read.
83 posts
OpenGL Function pointer loading
6 days, 23 hours ago
Allright, thank's!