Announcement

Collapse
No announcement yet.

Get OpenGL version

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get OpenGL version

    I was looking for a minimal way to get the OpenGL version ... so it turns out the function opengl32.dll!glGetString(%GL_VERSION) is for this.
    (There are newer ways to get the version info as described in that link, but they're not fully backwards compatible with older versions which i need so i'm happy to stick with this for my purposes)

    However, I was perplexed when the glGetString call failed when i first tried it ...its such a simple function - just give it a DWORD, and get a DWORD back! ... but with the help of some previous source code posts I was able to get it working ... but it requires:
    1) a hDc to a dialog (ive used CreateWindowEx for PBCC support)
    2) a call to SetPixelFormat()
    3) a call to wglCreateContext()
    4) a call to wglMakeCurrent()
    Only then does the glGetString call seem to work.

    Anyway, it works! but is this really the simplest way to get the OpenGL version? (OpenGL virgin here)

    Code:
    #COMPILE EXE
    #INCLUDE "win32api.inc"
    
    '%GL_VENDOR                         = &H1F00???
    '%GL_RENDERER                       = &H1F01???
    %GL_VERSION                        = &H1F02???
    '%GL_EXTENSIONS                     = &H1F03???
    
    DECLARE FUNCTION glGetString LIB "opengl32.dll" ALIAS "glGetString" (BYVAL dwID AS DWORD) AS DWORD
    
    
    FUNCTION WindowProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS DWORD
        FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
    END FUNCTION
    
    
    FUNCTION PBMAIN () AS LONG
      LOCAL hDlg, hDc, hRc, hCur AS DWORD, szClass AS ASCIIZ * 96, pfd AS PIXELFORMATDESCRIPTOR, wcx AS WNDCLASSEX, szPtr AS ASCIIZ PTR
    
      szClass           = "OpenGL Version Check"
      wcx.cbSize        = SIZEOF(wcx)
      wcx.lpfnWndProc   = CODEPTR(WindowProc)
      wcx.lpszClassName = VARPTR(szClass)
      RegisterClassEx wcx
    
      hDlg = CreateWindowEx(0, szClass, "", 0, 0, 0, 0, 0, 0, 0, 0, BYVAL 0)
      hDc = GetDC(hDlg)
    
      SetPixelFormat(hDC, ChoosePixelFormat(hDC, pfd), pfd)
    
      hRC = wglCreateContext(hDC)
    
      hCur = wglMakeCurrent (hDC, hRC)
    
      szPtr = glGetString(%GL_VERSION)
      ? "OPENGL VERSION = " & @szPtr
    
    WAITKEY$
    END FUNCTION
    Last edited by Wayne Diamond; 6 Sep 2014, 09:03 AM.
    -
Working...
X