| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include <filesystem> |
| 22 | |
| 23 | #if defined(WIN32) |
| 24 | #include <gl/GL.h> |
| 25 | #else |
| 26 | #include <SDL_opengl.h> |
| 27 | #endif |
| 28 | |
| 29 | #include "descent.h" |
| 30 | #include "module.h" |
| 31 | |
| 32 | #if defined(WIN32) |
| 33 | #define GLFUNCCALL __stdcall |
| 34 | #elif defined(POSIX) |
| 35 | #include <unistd.h> |
| 36 | #define GLFUNCCALL |
| 37 | #endif |
| 38 | |
| 39 | // ryan's adds. 04/18/2000. |
| 40 | // There was a bunch of stuff that was, I guess, not supported by |
| 41 | // Mesa when Outrage did the original port. So buttloads of code |
| 42 | // involving glActiveTextureARB() were #ifdef'd to only WIN32. |
| 43 | // To make use of the extension more generic, platforms that can handle |
| 44 | // it (Linux and Win32, as far as I care), define |
| 45 | // _USE_OGL_ACTIVE_TEXTURES, and check that define instead of WIN32 when |
| 46 | // using the extension. |
| 47 | #if (!defined(_USE_OGL_ACTIVE_TEXTURES)) |
| 48 | #if (defined(WIN32)) |
| 49 | #define _USE_OGL_ACTIVE_TEXTURES |
| 50 | #endif |
| 51 | #endif |
| 52 | // end ryan's adds. |
| 53 | |
| 54 | #ifdef DECLARE_OPENGL |
| 55 | #define DYNAEXTERN(_ty, _name) _ty _name = NULL |
| 56 | #else |
| 57 | #define DYNAEXTERN(_ty, _name) extern _ty _name; |
| 58 | #endif |
| 59 | |
| 60 | typedef void(GLFUNCCALL *glAlphaFunc_fp)(GLenum func, GLclampf ref); |
| 61 | typedef void(GLFUNCCALL *glBegin_fp)(GLenum mode); |
| 62 | typedef void(GLFUNCCALL *glBindTexture_fp)(GLenum target, GLuint texture); |
| 63 | typedef void(GLFUNCCALL *glBlendFunc_fp)(GLenum sfactor, GLenum dfactor); |
| 64 | typedef void(GLFUNCCALL *glClear_fp)(GLbitfield mask); |
| 65 | typedef void(GLFUNCCALL *glClearColor_fp)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); |
| 66 | typedef void(GLFUNCCALL *glClearDepth_fp)(GLclampd depth); |
| 67 | typedef void(GLFUNCCALL *glColor3ub_fp)(GLubyte red, GLubyte green, GLubyte blue); |
| 68 | typedef void(GLFUNCCALL *glColor4ub_fp)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); |
| 69 | typedef void(GLFUNCCALL *glColor4f_fp)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); |
| 70 | typedef void(GLFUNCCALL *glColorPointer_fp)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); |
| 71 | typedef void(GLFUNCCALL *glNormalPointer_fp)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); |
| 72 | typedef void(GLFUNCCALL *glDeleteTextures_fp)(GLsizei n, const GLuint *textures); |
| 73 | typedef void(GLFUNCCALL *glDepthFunc_fp)(GLenum func); |
| 74 | typedef void(GLFUNCCALL *glDepthMask_fp)(GLboolean flag); |
| 75 | typedef void(GLFUNCCALL *glDepthRange_fp)(GLclampd zNear, GLclampd zFar); |
| 76 | typedef void(GLFUNCCALL *glDisable_fp)(GLenum cap); |
| 77 | typedef void(GLFUNCCALL *glDisableClientState_fp)(GLenum array); |
| 78 | typedef void(GLFUNCCALL *glDrawArrays_fp)(GLenum mode, GLint first, GLsizei count); |
| 79 | typedef void(GLFUNCCALL *glDrawElements_fp)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); |
| 80 | typedef void(GLFUNCCALL *glDrawPixels_fp)(GLsizei width, GLsizei height, GLenum format, GLenum type, |
| 81 | const GLvoid *pixels); |
| 82 | typedef void(GLFUNCCALL *glEnable_fp)(GLenum cap); |
| 83 | typedef void(GLFUNCCALL *glEnableClientState_fp)(GLenum array); |
| 84 | typedef void(GLFUNCCALL *glEnd_fp)(void); |
| 85 | typedef void(GLFUNCCALL *glFlush_fp)(void); |
| 86 | typedef void(GLFUNCCALL *glFogf_fp)(GLenum pname, GLfloat param); |
| 87 | typedef void(GLFUNCCALL *glFogfv_fp)(GLenum pname, const GLfloat *params); |
| 88 | typedef void(GLFUNCCALL *glFogi_fp)(GLenum pname, GLint param); |
| 89 | typedef GLenum(GLFUNCCALL *glGetError_fp)(void); |
| 90 | typedef const GLubyte *(GLFUNCCALL *glGetString_fp)(GLenum name); |
| 91 | typedef void(GLFUNCCALL *glHint_fp)(GLenum target, GLenum mode); |
| 92 | typedef void(GLFUNCCALL *glLoadIdentity_fp)(void); |
| 93 | typedef void(GLFUNCCALL *glMatrixMode_fp)(GLenum mode); |
| 94 | typedef void(GLFUNCCALL *glLoadMatrixf_fp)(const GLfloat *m); |
| 95 | typedef void(GLFUNCCALL *glOrtho_fp)(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble); |
| 96 | typedef void(GLFUNCCALL *glPixelStorei_fp)(GLenum pname, GLint param); |
| 97 | typedef void(GLFUNCCALL *glPixelTransferi_fp)(GLenum pname, GLint param); |
| 98 | typedef void(GLFUNCCALL *glPolygonOffset_fp)(GLfloat factor, GLfloat units); |
| 99 | typedef void(GLFUNCCALL *glReadPixels_fp)(GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid *); |
| 100 | typedef void(GLFUNCCALL *glScissor_fp)(GLint x, GLint y, GLsizei width, GLsizei height); |
| 101 | typedef void(GLFUNCCALL *glShadeModel_fp)(GLenum mode); |
| 102 | typedef void(GLFUNCCALL *glTexCoordPointer_fp)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); |
| 103 | typedef void(GLFUNCCALL *glTexEnvf_fp)(GLenum target, GLenum pname, GLfloat param); |
| 104 | typedef void(GLFUNCCALL *glTexImage2D_fp)(GLenum target, GLint level, GLint internalformat, GLsizei width, |
| 105 | GLsizei height, GLint border, GLenum format, GLenum type, |
| 106 | const GLvoid *pixels); |
| 107 | typedef void(GLFUNCCALL *glTexParameteri_fp)(GLenum target, GLenum pname, GLint param); |
| 108 | typedef void(GLFUNCCALL *glTexSubImage2D_fp)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, |
| 109 | GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); |
| 110 | typedef void(GLFUNCCALL *glVertex2i_fp)(GLint, GLint); |
| 111 | typedef void(GLFUNCCALL *glVertex3f_fp)(GLfloat, GLfloat, GLfloat); |
| 112 | typedef void(GLFUNCCALL *glVertexPointer_fp)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); |
| 113 | typedef void(GLFUNCCALL *glViewport_fp)(GLint x, GLint y, GLsizei width, GLsizei height); |
| 114 | typedef void(GLFUNCCALL *glColor4fv_fp)(const GLfloat *v); |
| 115 | typedef void(GLFUNCCALL *glVertex3fv_fp)(const GLfloat *v); |
| 116 | typedef void(GLFUNCCALL *glTexCoord4fv_fp)(const GLfloat *v); |
| 117 | typedef void(GLFUNCCALL *glTexCoord2f_fp)(const GLfloat p1, const GLfloat p2); |
| 118 | typedef void(GLFUNCCALL *glGetIntegerv_fp)(GLenum pname, GLint *params); |
| 119 | typedef GLuint(GLFUNCCALL *glGenLists_fp)(GLsizei range); |
| 120 | typedef void(GLFUNCCALL *glNewList_fp)(GLuint list, GLenum mode); |
| 121 | typedef void(GLFUNCCALL *glEndList_fp)(void); |
| 122 | typedef void(GLFUNCCALL *glCallLists_fp)(GLsizei n, GLenum type, const GLvoid *lists); |
| 123 | typedef void(GLFUNCCALL *glListBase_fp)(GLuint base); |
| 124 | typedef void(GLFUNCCALL *glPushAttrib_fp)(GLbitfield mask); |
| 125 | typedef void(GLFUNCCALL *glPopAttrib_fp)(void); |
| 126 | typedef void(GLFUNCCALL *glColor3f_fp)(GLfloat red, GLfloat green, GLfloat blue); |
| 127 | typedef void(GLFUNCCALL *glRasterPos2i_fp)(GLint x, GLint y); |
| 128 | typedef void(GLFUNCCALL *glBitmap_fp)(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, |
| 129 | GLfloat ymove, const GLubyte *bitmap); |
| 130 | |
| 131 | // FBO entry points for render-to-texture ... |
| 132 | typedef void (GLFUNCCALL *glGenFramebuffersEXT_fp) (GLsizei n, GLuint *framebuffers); |
| 133 | typedef void (GLFUNCCALL *glGenRenderbuffersEXT_fp) (GLsizei n, GLuint *renderbuffers); |
| 134 | typedef void (GLFUNCCALL *glBindFramebufferEXT_fp) (GLenum target, GLuint framebuffer); |
| 135 | typedef void (GLFUNCCALL *glBindRenderbufferEXT_fp)(GLenum target, GLuint renderbuffer); |
| 136 | typedef void (GLFUNCCALL *glRenderbufferStorageEXT_fp) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); |
| 137 | typedef void (GLFUNCCALL *glFramebufferRenderbufferEXT_fp) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); |
| 138 | typedef GLenum (GLFUNCCALL *glCheckFramebufferStatusEXT_fp) (GLenum target); |
| 139 | typedef void (GLFUNCCALL *glDeleteRenderbuffersEXT_fp) (GLsizei n, const GLuint *renderbuffers); |
| 140 | typedef void (GLFUNCCALL *glDeleteFramebuffersEXT_fp) (GLsizei n, const GLuint *framebuffers); |
| 141 | typedef void (GLFUNCCALL *glBlitFramebufferEXT_fp) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); |
| 142 | |
| 143 | #if defined(WIN32) |
| 144 | typedef HGLRC(GLFUNCCALL *wglCreateContext_fp)(HDC); |
| 145 | typedef BOOL(GLFUNCCALL *wglDeleteContext_fp)(HGLRC); |
| 146 | typedef BOOL(GLFUNCCALL *wglMakeCurrent_fp)(HDC, HGLRC); |
| 147 | typedef PROC(GLFUNCCALL *wglGetProcAddress_fp)(LPCSTR); |
| 148 | |
| 149 | DYNAEXTERN(wglCreateContext_fp, dwglCreateContext); |
| 150 | DYNAEXTERN(wglDeleteContext_fp, dwglDeleteContext); |
| 151 | DYNAEXTERN(wglMakeCurrent_fp, dwglMakeCurrent); |
| 152 | DYNAEXTERN(wglGetProcAddress_fp, dwglGetProcAddress); |
| 153 | #endif |
| 154 | |
| 155 | DYNAEXTERN(glAlphaFunc_fp, dglAlphaFunc); |
| 156 | DYNAEXTERN(glBegin_fp, dglBegin); |
| 157 | DYNAEXTERN(glBindTexture_fp, dglBindTexture); |
| 158 | DYNAEXTERN(glBlendFunc_fp, dglBlendFunc); |
| 159 | DYNAEXTERN(glClear_fp, dglClear); |
| 160 | DYNAEXTERN(glClearColor_fp, dglClearColor); |
| 161 | DYNAEXTERN(glClearDepth_fp, dglClearDepth); |
| 162 | DYNAEXTERN(glColor3ub_fp, dglColor3ub); |
| 163 | DYNAEXTERN(glColor4ub_fp, dglColor4ub); |
| 164 | DYNAEXTERN(glColor4f_fp, dglColor4f); |
| 165 | DYNAEXTERN(glColorPointer_fp, dglColorPointer); |
| 166 | DYNAEXTERN(glNormalPointer_fp, dglNormalPointer); |
| 167 | DYNAEXTERN(glDeleteTextures_fp, dglDeleteTextures); |
| 168 | DYNAEXTERN(glDepthFunc_fp, dglDepthFunc); |
| 169 | DYNAEXTERN(glDepthMask_fp, dglDepthMask); |
| 170 | DYNAEXTERN(glDepthRange_fp, dglDepthRange); |
| 171 | DYNAEXTERN(glDisable_fp, dglDisable); |
| 172 | DYNAEXTERN(glDisableClientState_fp, dglDisableClientState); |
| 173 | DYNAEXTERN(glDrawArrays_fp, dglDrawArrays); |
| 174 | DYNAEXTERN(glDrawElements_fp, dglDrawElements); |
| 175 | DYNAEXTERN(glDrawPixels_fp, dglDrawPixels); |
| 176 | DYNAEXTERN(glEnable_fp, dglEnable); |
| 177 | DYNAEXTERN(glEnableClientState_fp, dglEnableClientState); |
| 178 | DYNAEXTERN(glEnd_fp, dglEnd); |
| 179 | DYNAEXTERN(glFlush_fp, dglFlush); |
| 180 | DYNAEXTERN(glFogf_fp, dglFogf); |
| 181 | DYNAEXTERN(glFogfv_fp, dglFogfv); |
| 182 | DYNAEXTERN(glFogi_fp, dglFogi); |
| 183 | DYNAEXTERN(glGetError_fp, dglGetError); |
| 184 | DYNAEXTERN(glGetString_fp, dglGetString); |
| 185 | DYNAEXTERN(glHint_fp, dglHint); |
| 186 | DYNAEXTERN(glLoadIdentity_fp, dglLoadIdentity); |
| 187 | DYNAEXTERN(glLoadMatrixf_fp, dglLoadMatrixf); |
| 188 | DYNAEXTERN(glMatrixMode_fp, dglMatrixMode); |
| 189 | DYNAEXTERN(glOrtho_fp, dglOrtho); |
| 190 | DYNAEXTERN(glPixelStorei_fp, dglPixelStorei); |
| 191 | DYNAEXTERN(glPixelTransferi_fp, dglPixelTransferi); |
| 192 | DYNAEXTERN(glPolygonOffset_fp, dglPolygonOffset); |
| 193 | DYNAEXTERN(glReadPixels_fp, dglReadPixels); |
| 194 | DYNAEXTERN(glScissor_fp, dglScissor); |
| 195 | DYNAEXTERN(glShadeModel_fp, dglShadeModel); |
| 196 | DYNAEXTERN(glTexCoordPointer_fp, dglTexCoordPointer); |
| 197 | DYNAEXTERN(glTexEnvf_fp, dglTexEnvf); |
| 198 | DYNAEXTERN(glTexImage2D_fp, dglTexImage2D); |
| 199 | DYNAEXTERN(glTexParameteri_fp, dglTexParameteri); |
| 200 | DYNAEXTERN(glTexSubImage2D_fp, dglTexSubImage2D); |
| 201 | DYNAEXTERN(glVertex2i_fp, dglVertex2i); |
| 202 | DYNAEXTERN(glVertex3f_fp, dglVertex3f); |
| 203 | DYNAEXTERN(glVertexPointer_fp, dglVertexPointer); |
| 204 | DYNAEXTERN(glViewport_fp, dglViewport); |
| 205 | DYNAEXTERN(glColor4fv_fp, dglColor4fv); |
| 206 | DYNAEXTERN(glVertex3fv_fp, dglVertex3fv); |
| 207 | DYNAEXTERN(glTexCoord4fv_fp, dglTexCoord4fv); |
| 208 | |
| 209 | DYNAEXTERN(glGenFramebuffersEXT_fp, dglGenFramebuffersEXT); |
| 210 | DYNAEXTERN(glGenRenderbuffersEXT_fp, dglGenRenderbuffersEXT); |
| 211 | DYNAEXTERN(glBindFramebufferEXT_fp, dglBindFramebufferEXT); |
| 212 | DYNAEXTERN(glBindRenderbufferEXT_fp, dglBindRenderbufferEXT); |
| 213 | DYNAEXTERN(glRenderbufferStorageEXT_fp, dglRenderbufferStorageEXT); |
| 214 | DYNAEXTERN(glFramebufferRenderbufferEXT_fp, dglFramebufferRenderbufferEXT); |
| 215 | DYNAEXTERN(glCheckFramebufferStatusEXT_fp, dglCheckFramebufferStatusEXT); |
| 216 | DYNAEXTERN(glDeleteFramebuffersEXT_fp, dglDeleteFramebuffersEXT); |
| 217 | DYNAEXTERN(glDeleteRenderbuffersEXT_fp, dglDeleteRenderbuffersEXT); |
| 218 | DYNAEXTERN(glBlitFramebufferEXT_fp, dglBlitFramebufferEXT); |
| 219 | |
| 220 | #ifdef DECLARE_OPENGL |
| 221 | static module OpenGLDLLInst; |
| 222 | |
| 223 | static void *__SDL_mod_GetSymbol(const char *funcStr) { |
| 224 | void *retVal = NULL; |
| 225 | |
| 226 | mprintf(0, "Looking up GL function [%s]... ", funcStr); |
| 227 | |
| 228 | retVal = SDL_GL_GetProcAddress(funcStr); |
| 229 | |
| 230 | if (retVal == NULL) |
| 231 | fprintf(stderr, " Could not find GL symbol [%s]!\n\n", funcStr); |
| 232 | else { |
| 233 | mprintf(0, "Found at (%p).\n", retVal); |
| 234 | } // else |
| 235 | |
| 236 | return (retVal); |
| 237 | } // __SDL_mod_GetSymbol |
| 238 | |
| 239 | /****************** WARNING: NASTY HACK! ***********************/ |
| 240 | #define mod_GetSymbol(x, funcStr, y) __SDL_mod_GetSymbol(funcStr) |
| 241 | /****************** WARNING: NASTY HACK! ***********************/ |
| 242 | |
| 243 | extern char loadedLibrary[_MAX_PATH]; |
| 244 | |
| 245 | module *LoadOpenGLDLL(const char *dllname) { |
| 246 | mprintf(0, "Loading OpenGL dll...\n"); |
| 247 | |
| 248 | std::filesystem::path tmp = std::filesystem::current_path(); |
| 249 | std::filesystem::current_path(orig_pwd); |
| 250 | int rc = SDL_GL_LoadLibrary(dllname[0] ? dllname : nullptr); |
| 251 | std::filesystem::current_path(tmp); |
| 252 | |
| 253 | if (rc < 0) { |
| 254 | const char *sdlErr = SDL_GetError(); |
| 255 | mprintf(0, "OpenGL: Couldn't open library [%s].\n", dllname[0] ? dllname : "system default"); |
| 256 | mprintf(0, "OpenGL: SDL error is [%s].", sdlErr); |
| 257 | return NULL; |
| 258 | } |
| 259 | |
| 260 | strcpy(loadedLibrary, dllname); |
| 261 | |
| 262 | |
| 263 | dglAlphaFunc = (glAlphaFunc_fp)mod_GetSymbol(&OpenGLDLLInst, "glAlphaFunc", 255); |
| 264 | if (!dglAlphaFunc) |
| 265 | goto dll_error; |
| 266 | |
| 267 | dglBegin = (glBegin_fp)mod_GetSymbol(&OpenGLDLLInst, "glBegin", 255); |
| 268 | if (!dglBegin) |
| 269 | goto dll_error; |
| 270 | |
| 271 | dglBindTexture = (glBindTexture_fp)mod_GetSymbol(&OpenGLDLLInst, "glBindTexture", 255); |
| 272 | if (!dglBindTexture) |
| 273 | goto dll_error; |
| 274 | |
| 275 | dglBlendFunc = (glBlendFunc_fp)mod_GetSymbol(&OpenGLDLLInst, "glBlendFunc", 255); |
| 276 | if (!dglBlendFunc) |
| 277 | goto dll_error; |
| 278 | |
| 279 | dglClear = (glClear_fp)mod_GetSymbol(&OpenGLDLLInst, "glClear", 255); |
| 280 | if (!dglClear) |
| 281 | goto dll_error; |
| 282 | |
| 283 | dglClearColor = (glClearColor_fp)mod_GetSymbol(&OpenGLDLLInst, "glClearColor", 255); |
| 284 | if (!dglClearColor) |
| 285 | goto dll_error; |
| 286 | |
| 287 | dglClearDepth = (glClearDepth_fp)mod_GetSymbol(&OpenGLDLLInst, "glClearDepth", 255); |
| 288 | if (!dglClearDepth) |
| 289 | goto dll_error; |
| 290 | |
| 291 | dglColor3ub = (glColor3ub_fp)mod_GetSymbol(&OpenGLDLLInst, "glColor3ub", 255); |
| 292 | if (!dglColor3ub) |
| 293 | goto dll_error; |
| 294 | |
| 295 | dglColor4ub = (glColor4ub_fp)mod_GetSymbol(&OpenGLDLLInst, "glColor4ub", 255); |
| 296 | if (!dglColor4ub) |
| 297 | goto dll_error; |
| 298 | |
| 299 | dglColor4f = (glColor4f_fp)mod_GetSymbol(&OpenGLDLLInst, "glColor4f", 255); |
| 300 | if (!dglColor4f) |
| 301 | goto dll_error; |
| 302 | |
| 303 | dglColorPointer = (glColorPointer_fp)mod_GetSymbol(&OpenGLDLLInst, "glColorPointer", 255); |
| 304 | if (!dglColorPointer) |
| 305 | goto dll_error; |
| 306 | |
| 307 | dglNormalPointer = (glNormalPointer_fp)mod_GetSymbol(&OpenGLDLLInst, "glNormalPointer", 255); |
| 308 | if (!dglNormalPointer) |
| 309 | goto dll_error; |
| 310 | |
| 311 | dglDeleteTextures = (glDeleteTextures_fp)mod_GetSymbol(&OpenGLDLLInst, "glDeleteTextures", 255); |
| 312 | if (!dglDeleteTextures) |
| 313 | goto dll_error; |
| 314 | |
| 315 | dglDepthFunc = (glDepthFunc_fp)mod_GetSymbol(&OpenGLDLLInst, "glDepthFunc", 255); |
| 316 | if (!dglDepthFunc) |
| 317 | goto dll_error; |
| 318 | |
| 319 | dglDepthMask = (glDepthMask_fp)mod_GetSymbol(&OpenGLDLLInst, "glDepthMask", 255); |
| 320 | if (!dglDepthMask) |
| 321 | goto dll_error; |
| 322 | |
| 323 | dglDepthRange = (glDepthRange_fp)mod_GetSymbol(&OpenGLDLLInst, "glDepthRange", 255); |
| 324 | if (!dglDepthRange) |
| 325 | goto dll_error; |
| 326 | |
| 327 | dglDisable = (glDisable_fp)mod_GetSymbol(&OpenGLDLLInst, "glDisable", 255); |
| 328 | if (!dglDisable) |
| 329 | goto dll_error; |
| 330 | |
| 331 | dglDisableClientState = (glDisableClientState_fp)mod_GetSymbol(&OpenGLDLLInst, "glDisableClientState", 255); |
| 332 | if (!dglDisableClientState) |
| 333 | goto dll_error; |
| 334 | |
| 335 | dglDrawArrays = (glDrawArrays_fp)mod_GetSymbol(&OpenGLDLLInst, "glDrawArrays", 255); |
| 336 | if (!dglDrawArrays) |
| 337 | goto dll_error; |
| 338 | |
| 339 | dglDrawElements = (glDrawElements_fp)mod_GetSymbol(&OpenGLDLLInst, "glDrawElements", 255); |
| 340 | if (!dglDrawElements) |
| 341 | goto dll_error; |
| 342 | |
| 343 | dglDrawPixels = (glDrawPixels_fp)mod_GetSymbol(&OpenGLDLLInst, "glDrawPixels", 255); |
| 344 | if (!dglDrawPixels) |
| 345 | goto dll_error; |
| 346 | |
| 347 | dglEnable = (glEnable_fp)mod_GetSymbol(&OpenGLDLLInst, "glEnable", 255); |
| 348 | if (!dglEnable) |
| 349 | goto dll_error; |
| 350 | |
| 351 | dglEnableClientState = (glEnableClientState_fp)mod_GetSymbol(&OpenGLDLLInst, "glEnableClientState", 255); |
| 352 | if (!dglEnableClientState) |
| 353 | goto dll_error; |
| 354 | |
| 355 | dglEnd = (glEnd_fp)mod_GetSymbol(&OpenGLDLLInst, "glEnd", 255); |
| 356 | if (!dglEnd) |
| 357 | goto dll_error; |
| 358 | |
| 359 | dglFlush = (glFlush_fp)mod_GetSymbol(&OpenGLDLLInst, "glFlush", 255); |
| 360 | if (!dglFlush) |
| 361 | goto dll_error; |
| 362 | |
| 363 | dglFogf = (glFogf_fp)mod_GetSymbol(&OpenGLDLLInst, "glFogf", 255); |
| 364 | if (!dglFogf) |
| 365 | goto dll_error; |
| 366 | |
| 367 | dglFogfv = (glFogfv_fp)mod_GetSymbol(&OpenGLDLLInst, "glFogfv", 255); |
| 368 | if (!dglFogfv) |
| 369 | goto dll_error; |
| 370 | |
| 371 | dglFogi = (glFogi_fp)mod_GetSymbol(&OpenGLDLLInst, "glFogi", 255); |
| 372 | if (!dglFogi) |
| 373 | goto dll_error; |
| 374 | |
| 375 | dglGetError = (glGetError_fp)mod_GetSymbol(&OpenGLDLLInst, "glGetError", 255); |
| 376 | if (!dglGetError) |
| 377 | goto dll_error; |
| 378 | |
| 379 | dglGetString = (glGetString_fp)mod_GetSymbol(&OpenGLDLLInst, "glGetString", 255); |
| 380 | if (!dglGetString) |
| 381 | goto dll_error; |
| 382 | |
| 383 | dglHint = (glHint_fp)mod_GetSymbol(&OpenGLDLLInst, "glHint", 255); |
| 384 | if (!dglHint) |
| 385 | goto dll_error; |
| 386 | |
| 387 | dglLoadIdentity = (glLoadIdentity_fp)mod_GetSymbol(&OpenGLDLLInst, "glLoadIdentity", 255); |
| 388 | if (!dglLoadIdentity) |
| 389 | goto dll_error; |
| 390 | |
| 391 | dglLoadMatrixf = (glLoadMatrixf_fp)mod_GetSymbol(&OpenGLDLLInst, "glLoadMatrixf", 255); |
| 392 | if (!dglLoadMatrixf) |
| 393 | goto dll_error; |
| 394 | |
| 395 | dglMatrixMode = (glMatrixMode_fp)mod_GetSymbol(&OpenGLDLLInst, "glMatrixMode", 255); |
| 396 | if (!dglMatrixMode) |
| 397 | goto dll_error; |
| 398 | |
| 399 | dglOrtho = (glOrtho_fp)mod_GetSymbol(&OpenGLDLLInst, "glOrtho", 255); |
| 400 | if (!dglOrtho) |
| 401 | goto dll_error; |
| 402 | |
| 403 | dglPixelStorei = (glPixelStorei_fp)mod_GetSymbol(&OpenGLDLLInst, "glPixelStorei", 255); |
| 404 | if (!dglPixelStorei) |
| 405 | goto dll_error; |
| 406 | |
| 407 | dglPixelTransferi = (glPixelTransferi_fp)mod_GetSymbol(&OpenGLDLLInst, "glPixelTransferi", 255); |
| 408 | if (!dglPixelTransferi) |
| 409 | goto dll_error; |
| 410 | |
| 411 | dglPolygonOffset = (glPolygonOffset_fp)mod_GetSymbol(&OpenGLDLLInst, "glPolygonOffset", 255); |
| 412 | if (!dglPolygonOffset) |
| 413 | goto dll_error; |
| 414 | |
| 415 | dglReadPixels = (glReadPixels_fp)mod_GetSymbol(&OpenGLDLLInst, "glReadPixels", 255); |
| 416 | if (!dglReadPixels) |
| 417 | goto dll_error; |
| 418 | |
| 419 | dglScissor = (glScissor_fp)mod_GetSymbol(&OpenGLDLLInst, "glScissor", 255); |
| 420 | if (!dglScissor) |
| 421 | goto dll_error; |
| 422 | |
| 423 | dglShadeModel = (glShadeModel_fp)mod_GetSymbol(&OpenGLDLLInst, "glShadeModel", 255); |
| 424 | if (!dglShadeModel) |
| 425 | goto dll_error; |
| 426 | |
| 427 | dglTexCoordPointer = (glTexCoordPointer_fp)mod_GetSymbol(&OpenGLDLLInst, "glTexCoordPointer", 255); |
| 428 | if (!dglTexCoordPointer) |
| 429 | goto dll_error; |
| 430 | |
| 431 | dglTexEnvf = (glTexEnvf_fp)mod_GetSymbol(&OpenGLDLLInst, "glTexEnvf", 255); |
| 432 | if (!dglTexEnvf) |
| 433 | goto dll_error; |
| 434 | |
| 435 | dglTexImage2D = (glTexImage2D_fp)mod_GetSymbol(&OpenGLDLLInst, "glTexImage2D", 255); |
| 436 | if (!dglTexImage2D) |
| 437 | goto dll_error; |
| 438 | |
| 439 | dglTexParameteri = (glTexParameteri_fp)mod_GetSymbol(&OpenGLDLLInst, "glTexParameteri", 255); |
| 440 | if (!dglTexParameteri) |
| 441 | goto dll_error; |
| 442 | |
| 443 | dglTexSubImage2D = (glTexSubImage2D_fp)mod_GetSymbol(&OpenGLDLLInst, "glTexSubImage2D", 255); |
| 444 | if (!dglTexSubImage2D) |
| 445 | goto dll_error; |
| 446 | |
| 447 | dglVertex2i = (glVertex2i_fp)mod_GetSymbol(&OpenGLDLLInst, "glVertex2i", 255); |
| 448 | if (!dglVertex2i) |
| 449 | goto dll_error; |
| 450 | |
| 451 | dglVertex3f = (glVertex3f_fp)mod_GetSymbol(&OpenGLDLLInst, "glVertex3f", 255); |
| 452 | if (!dglVertex3f) |
| 453 | goto dll_error; |
| 454 | |
| 455 | dglVertexPointer = (glVertexPointer_fp)mod_GetSymbol(&OpenGLDLLInst, "glVertexPointer", 255); |
| 456 | if (!dglVertexPointer) |
| 457 | goto dll_error; |
| 458 | |
| 459 | dglViewport = (glViewport_fp)mod_GetSymbol(&OpenGLDLLInst, "glViewport", 255); |
| 460 | if (!dglViewport) |
| 461 | goto dll_error; |
| 462 | |
| 463 | dglColor4fv = (glColor4fv_fp)mod_GetSymbol(&OpenGLDLLInst, "glColor4fv", 255); |
| 464 | if (!dglColor4fv) |
| 465 | goto dll_error; |
| 466 | |
| 467 | dglVertex3fv = (glVertex3fv_fp)mod_GetSymbol(&OpenGLDLLInst, "glVertex3fv", 255); |
| 468 | if (!dglVertex3fv) |
| 469 | goto dll_error; |
| 470 | |
| 471 | dglTexCoord4fv = (glTexCoord4fv_fp)mod_GetSymbol(&OpenGLDLLInst, "glTexCoord4fv", 255); |
| 472 | if (!dglTexCoord4fv) |
| 473 | goto dll_error; |
| 474 | |
| 475 | #if defined(WIN32) |
| 476 | dwglCreateContext = (wglCreateContext_fp)mod_GetSymbol(&OpenGLDLLInst, "wglCreateContext", 255); |
| 477 | if (!dwglCreateContext) |
| 478 | goto dll_error; |
| 479 | |
| 480 | dwglDeleteContext = (wglDeleteContext_fp)mod_GetSymbol(&OpenGLDLLInst, "wglDeleteContext", 255); |
| 481 | if (!dwglDeleteContext) |
| 482 | goto dll_error; |
| 483 | |
| 484 | dwglMakeCurrent = (wglMakeCurrent_fp)mod_GetSymbol(&OpenGLDLLInst, "wglMakeCurrent", 255); |
| 485 | if (!dwglMakeCurrent) |
| 486 | goto dll_error; |
| 487 | |
| 488 | dwglGetProcAddress = (wglGetProcAddress_fp)mod_GetSymbol(&OpenGLDLLInst, "wglGetProcAddress", 255); |
| 489 | if (!dwglGetProcAddress) |
| 490 | goto dll_error; |
| 491 | #elif defined(POSIX) |
| 492 | |
| 493 | // bk000614 - have to fix globals |
| 494 | extern glAlphaFunc_fp dglAlphaFunc; |
| 495 | extern glBegin_fp dglBegin; |
| 496 | extern glBindTexture_fp dglBindTexture; |
| 497 | extern glBlendFunc_fp dglBlendFunc; |
| 498 | extern glClear_fp dglClear; |
| 499 | extern glClearColor_fp dglClearColor; |
| 500 | extern glClearDepth_fp dglClearDepth; |
| 501 | extern glColor3ub_fp dglColor3ub; |
| 502 | extern glColor4f_fp dglColor4f; |
| 503 | extern glColor4fv_fp dglColor4fv; |
| 504 | extern glColor4ub_fp dglColor4ub; |
| 505 | extern glColorPointer_fp dglColorPointer; |
| 506 | extern glDeleteTextures_fp dglDeleteTextures; |
| 507 | extern glDepthFunc_fp dglDepthFunc; |
| 508 | extern glDepthMask_fp dglDepthMask; |
| 509 | extern glDepthRange_fp dglDepthRange; |
| 510 | extern glDisable_fp dglDisable; |
| 511 | extern glDisableClientState_fp dglDisableClientState; |
| 512 | extern glDrawArrays_fp dglDrawArrays; |
| 513 | extern glDrawPixels_fp dglDrawPixels; |
| 514 | extern glEnable_fp dglEnable; |
| 515 | extern glEnableClientState_fp dglEnableClientState; |
| 516 | extern glEnd_fp dglEnd; |
| 517 | extern glFlush_fp dglFlush; |
| 518 | extern glFogf_fp dglFogf; |
| 519 | extern glFogfv_fp dglFogfv; |
| 520 | extern glFogi_fp dglFogi; |
| 521 | extern glGetError_fp dglGetError; |
| 522 | extern glGetString_fp dglGetString; |
| 523 | extern glGetIntegerv_fp dglGetIntegerv; |
| 524 | extern glHint_fp dglHint; |
| 525 | extern glLoadIdentity_fp dglLoadIdentity; |
| 526 | extern glMatrixMode_fp dglMatrixMode; |
| 527 | extern glOrtho_fp dglOrtho; |
| 528 | extern glPixelStorei_fp dglPixelStorei; |
| 529 | extern glPixelTransferi_fp dglPixelTransferi; |
| 530 | extern glPolygonOffset_fp dglPolygonOffset; |
| 531 | extern glReadPixels_fp dglReadPixels; |
| 532 | extern glScissor_fp dglScissor; |
| 533 | extern glShadeModel_fp dglShadeModel; |
| 534 | extern glTexCoord2f_fp dglTexCoord2f; |
| 535 | extern glTexCoord4fv_fp dglTexCoord4fv; |
| 536 | extern glTexCoordPointer_fp dglTexCoordPointer; |
| 537 | extern glTexEnvf_fp dglTexEnvf; |
| 538 | extern glTexImage2D_fp dglTexImage2D; |
| 539 | extern glTexParameteri_fp dglTexParameteri; |
| 540 | extern glTexSubImage2D_fp dglTexSubImage2D; |
| 541 | extern glVertex2i_fp dglVertex2i; |
| 542 | extern glVertex3f_fp dglVertex3f; |
| 543 | extern glVertex3fv_fp dglVertex3fv; |
| 544 | extern glVertexPointer_fp dglVertexPointer; |
| 545 | extern glViewport_fp dglViewport; |
| 546 | |
| 547 | module *LoadOpenGLDLL(const char *dllname); |
| 548 | |
| 549 | #else |
| 550 | #endif |
| 551 | mprintf(0, "OpenGL dll loading successful.\n"); |
| 552 | |
| 553 | return &OpenGLDLLInst; |
| 554 | |
| 555 | dll_error: |
| 556 | mprintf(0, "Error loading opengl dll!\n"); |
| 557 | mod_FreeModule(&OpenGLDLLInst); |
| 558 | return NULL; |
| 559 | } |
| 560 | #endif |