opengl fix

This commit is contained in:
Billingsly Wetherfordshire
2012-10-12 17:33:37 -05:00
parent 1d30798363
commit d1965590ab

View File

@@ -8,13 +8,13 @@
#
## This module is a wrapper around `opengl`:idx:. If you define the symbol
## ``useGlew`` this wrapper does not use Nimrod's ``dynlib`` mechanism,
## but `glew`:idx: instead. However, this shouldn't be necessary anymore; even
## extension loading for the different operating systems is handled here.
##
## You need to call ``loadExtensions`` after a rendering context has been
## ``useGlew`` this wrapper does not use Nimrod's ``dynlib`` mechanism,
## but `glew`:idx: instead. However, this shouldn't be necessary anymore; even
## extension loading for the different operating systems is handled here.
##
## You need to call ``loadExtensions`` after a rendering context has been
## created to load any extension proc that your code uses.
when defined(linux):
import X, XLib, XUtil
elif defined(windows):
@@ -39,58 +39,58 @@ when defined(useGlew):
{.pragma: wgl, header: "<GL/wglew.h>".}
{.pragma: glu, dynlib: gludll.}
else:
# quite complex ... thanks to extension support for various platforms:
import dynlib
let oglHandle = LoadLib(ogldll)
if isNil(oglHandle): quit("could not load: " & ogldll)
when defined(windows):
var wglGetProcAddress = cast[proc (s: cstring): pointer {.stdcall.}](
symAddr(oglHandle, "wglGetProcAddress"))
elif defined(linux):
var glXGetProcAddress = cast[proc (s: cstring): pointer {.cdecl.}](
symAddr(oglHandle, "glXGetProcAddress"))
var glXGetProcAddressARB = cast[proc (s: cstring): pointer {.cdecl.}](
symAddr(oglHandle, "glXGetProcAddressARB"))
proc glGetProc(h: TLibHandle; procName: cstring): pointer =
when defined(windows):
result = symAddr(h, procname)
if result != nil: return
if not isNil(wglGetProcAddress): result = wglGetProcAddress(ProcName)
elif defined(linux):
if not isNil(glXGetProcAddress): result = glXGetProcAddress(ProcName)
if result != nil: return
if not isNil(glXGetProcAddressARB):
result = glXGetProcAddressARB(ProcName)
if result != nil: return
result = symAddr(h, procname)
else:
result = symAddr(h, procName)
if result == nil: raiseInvalidLibrary(procName)
var gluHandle: TLibHandle
proc gluGetProc(procname: cstring): pointer =
if gluHandle == nil:
gluHandle = LoadLib(gludll)
if gluHandle == nil: quit("could not load: " & gludll)
result = glGetProc(gluHandle, procname)
# undocumented 'dynlib' feature: the string literal is replaced by
# the imported proc name:
{.pragma: ogl, dynlib: glGetProc(oglHandle, "").}
# quite complex ... thanks to extension support for various platforms:
import dynlib
let oglHandle = LoadLib(ogldll)
if isNil(oglHandle): quit("could not load: " & ogldll)
when defined(windows):
var wglGetProcAddress = cast[proc (s: cstring): pointer {.stdcall.}](
symAddr(oglHandle, "wglGetProcAddress"))
elif defined(linux):
var glXGetProcAddress = cast[proc (s: cstring): pointer {.cdecl.}](
symAddr(oglHandle, "glXGetProcAddress"))
var glXGetProcAddressARB = cast[proc (s: cstring): pointer {.cdecl.}](
symAddr(oglHandle, "glXGetProcAddressARB"))
proc glGetProc(h: TLibHandle; procName: cstring): pointer =
when defined(windows):
result = symAddr(h, procname)
if result != nil: return
if not isNil(wglGetProcAddress): result = wglGetProcAddress(ProcName)
elif defined(linux):
if not isNil(glXGetProcAddress): result = glXGetProcAddress(ProcName)
if result != nil: return
if not isNil(glXGetProcAddressARB):
result = glXGetProcAddressARB(ProcName)
if result != nil: return
result = symAddr(h, procname)
else:
result = symAddr(h, procName)
if result == nil: raiseInvalidLibrary(procName)
var gluHandle: TLibHandle
proc gluGetProc(procname: cstring): pointer =
if gluHandle == nil:
gluHandle = LoadLib(gludll)
if gluHandle == nil: quit("could not load: " & gludll)
result = glGetProc(gluHandle, procname)
# undocumented 'dynlib' feature: the string literal is replaced by
# the imported proc name:
{.pragma: ogl, dynlib: glGetProc(oglHandle, "0").}
{.pragma: oglx, dynlib: glGetProc(oglHandle, "0").}
{.pragma: wgl, dynlib: glGetProc(oglHandle, "").}
{.pragma: glu, dynlib: gluGetProc("").}
proc nimLoadProcs0() {.importc.}
template loadExtensions*() =
## call this after your rendering context has been setup if you use
## extensions.
bind nimLoadProcs0
{.pragma: wgl, dynlib: glGetProc(oglHandle, "0").}
{.pragma: glu, dynlib: gluGetProc("").}
proc nimLoadProcs0() {.importc.}
template loadExtensions*() =
## call this after your rendering context has been setup if you use
## extensions.
bind nimLoadProcs0
nimLoadProcs0()
#==============================================================================
@@ -9104,7 +9104,7 @@ proc glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN*(rc: GLuint,
proc glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN*(rc: PGLuint,
tc: PGLfloat, c: PGLfloat, n: PGLfloat, v: PGLfloat){.stdcall, importc, ogl.}
# window support functions
when defined(windows):
when defined(windows):
when not defined(wglGetProcAddress):
proc wglGetProcAddress*(ProcName: cstring): Pointer{.stdcall, importc, wgl.}
proc wglCopyContext*(p1: HGLRC, p2: HGLRC, p3: int): BOOL{.stdcall, importc, wgl.}
@@ -9446,11 +9446,11 @@ when defined(LINUX):
stdcall, importc, oglx.}
proc glXGetSelectedEvent*(dpy: PDisplay, draw: GLXDrawable,
event_mask: PGLuint){.stdcall, importc, oglx.}
# GLX_VERSION_1_4
# GLX_VERSION_1_4
when not defined(glXGetProcAddress):
proc glXGetProcAddress*(name: cstring): pointer{.stdcall, importc, oglx.}
# GLX_ARB_get_proc_address
when not defined(glXGetProcAddressARB):
when not defined(glXGetProcAddressARB):
proc glXGetProcAddressARB*(name: cstring): pointer{.stdcall, importc, oglx.}
# GLX_ARB_create_context
proc glXCreateContextAttribsARB*(dpy: PDisplay, config: GLXFBConfig,