| 1 | /* $Id: opengl.cpp,v 1.8 2000-02-16 14:18:11 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * GDI32 OpenGl stubs | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl) | 
|---|
| 7 | * | 
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 9 | * | 
|---|
| 10 | */ | 
|---|
| 11 |  | 
|---|
| 12 |  | 
|---|
| 13 | /**************************************************************************** | 
|---|
| 14 | * Includes                                                                 * | 
|---|
| 15 | ****************************************************************************/ | 
|---|
| 16 |  | 
|---|
| 17 | #include <os2win.h> | 
|---|
| 18 | #include <stdarg.h> | 
|---|
| 19 | #include <string.h> | 
|---|
| 20 | #include <odinwrap.h> | 
|---|
| 21 | #include "misc.h" | 
|---|
| 22 | #include "unicode.h" | 
|---|
| 23 |  | 
|---|
| 24 | #define DBG_LOCALLOG    DBG_opengl | 
|---|
| 25 | #include "dbglocal.h" | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 | ODINDEBUGCHANNEL(GDI32-OPENGL) | 
|---|
| 29 |  | 
|---|
| 30 |  | 
|---|
| 31 | /**************************************************************************** | 
|---|
| 32 | * Definitions                                                              * | 
|---|
| 33 | ****************************************************************************/ | 
|---|
| 34 |  | 
|---|
| 35 | typedef int  (* WIN32API CHOOSEPIXELFMT) (HDC, CONST PIXELFORMATDESCRIPTOR *); | 
|---|
| 36 | typedef BOOL (* WIN32API SETPIXELFMT) (HDC, int, CONST PIXELFORMATDESCRIPTOR *); | 
|---|
| 37 | typedef BOOL (* WIN32API SWAPBUFFERS) (HDC hdc); | 
|---|
| 38 | typedef int  (* WIN32API DESCRIBEPIXELFMT) (HDC, int, UINT, LPPIXELFORMATDESCRIPTOR); | 
|---|
| 39 | typedef int  (* WIN32API GETPIXELFMT) (HDC); | 
|---|
| 40 |  | 
|---|
| 41 |  | 
|---|
| 42 | /**************************************************************************** | 
|---|
| 43 | * Module Global Variables                                                  * | 
|---|
| 44 | ****************************************************************************/ | 
|---|
| 45 |  | 
|---|
| 46 | static CHOOSEPIXELFMT    glChoosePixelFormat   = NULL; | 
|---|
| 47 | static SETPIXELFMT       glSetPixelFormat      = NULL; | 
|---|
| 48 | static SWAPBUFFERS       glSwapBuffers         = NULL; | 
|---|
| 49 | static DESCRIBEPIXELFMT  glDescribePixelFormat = NULL; | 
|---|
| 50 | static GETPIXELFMT       glGetPixelFormat      = NULL; | 
|---|
| 51 | static HINSTANCE         hOpenGL               = NULL; | 
|---|
| 52 |  | 
|---|
| 53 |  | 
|---|
| 54 | /***************************************************************************** | 
|---|
| 55 | * Name      : internalOpenGLEnable | 
|---|
| 56 | * Purpose   : check if loaded, load OpenGL.DLL on demand | 
|---|
| 57 | * Parameters: | 
|---|
| 58 | * Variables : | 
|---|
| 59 | * Result    : | 
|---|
| 60 | * Remark    : | 
|---|
| 61 | * Status    : | 
|---|
| 62 | * | 
|---|
| 63 | * Author    : Patrick Haller [Fri, 1998/02/27 11:55] | 
|---|
| 64 | *****************************************************************************/ | 
|---|
| 65 |  | 
|---|
| 66 | static BOOL internalOpenGLEnable(void) | 
|---|
| 67 | { | 
|---|
| 68 | if(hOpenGL == NULL) | 
|---|
| 69 | { | 
|---|
| 70 | hOpenGL = LoadLibraryA("OPENGL32.DLL"); | 
|---|
| 71 | if(hOpenGL == NULL) | 
|---|
| 72 | return(FALSE); | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | if(glChoosePixelFormat == NULL) { | 
|---|
| 76 | glChoosePixelFormat = (CHOOSEPIXELFMT)GetProcAddress(hOpenGL, "wglChoosePixelFormat"); | 
|---|
| 77 | if(glChoosePixelFormat == NULL) | 
|---|
| 78 | return(0); | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | if(glSetPixelFormat == NULL) { | 
|---|
| 82 | glSetPixelFormat = (SETPIXELFMT)GetProcAddress(hOpenGL, "wglSetPixelFormat"); | 
|---|
| 83 | if(glSetPixelFormat == NULL) | 
|---|
| 84 | return(FALSE); | 
|---|
| 85 | } | 
|---|
| 86 |  | 
|---|
| 87 | if(glSwapBuffers == NULL) { | 
|---|
| 88 | glSwapBuffers = (SWAPBUFFERS)GetProcAddress(hOpenGL, "wglSwapBuffers"); | 
|---|
| 89 | if(glSwapBuffers == NULL) | 
|---|
| 90 | return(FALSE); | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | if(glDescribePixelFormat == NULL) { | 
|---|
| 94 | glDescribePixelFormat = (DESCRIBEPIXELFMT)GetProcAddress(hOpenGL, "wglDescribePixelFormat"); | 
|---|
| 95 | if(glDescribePixelFormat == NULL) | 
|---|
| 96 | return(FALSE); | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 | if(glGetPixelFormat == NULL) { | 
|---|
| 100 | glGetPixelFormat = (GETPIXELFMT)GetProcAddress(hOpenGL, "wglGetPixelFormat"); | 
|---|
| 101 | if(glGetPixelFormat == NULL) | 
|---|
| 102 | return(FALSE); | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | return(TRUE);                        /* OpenGL is initialized and enabled*/ | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|
| 108 |  | 
|---|
| 109 | /***************************************************************************** | 
|---|
| 110 | * Name      : | 
|---|
| 111 | * Purpose   : | 
|---|
| 112 | * Parameters: | 
|---|
| 113 | * Variables : | 
|---|
| 114 | * Result    : | 
|---|
| 115 | * Remark    : | 
|---|
| 116 | * Status    : | 
|---|
| 117 | * | 
|---|
| 118 | * Author    : Patrick Haller [Fri, 1998/02/27 11:55] | 
|---|
| 119 | *****************************************************************************/ | 
|---|
| 120 |  | 
|---|
| 121 | ODINFUNCTION2(int,ChoosePixelFormat,HDC,                         hdc, | 
|---|
| 122 | CONST PIXELFORMATDESCRIPTOR*,pformat) | 
|---|
| 123 | { | 
|---|
| 124 | if (glChoosePixelFormat == NULL) | 
|---|
| 125 | if (internalOpenGLEnable() == FALSE) | 
|---|
| 126 | return(0); | 
|---|
| 127 |  | 
|---|
| 128 | return(glChoosePixelFormat(hdc, pformat)); | 
|---|
| 129 | } | 
|---|
| 130 |  | 
|---|
| 131 | ODINFUNCTION4(int,DescribePixelFormat,HDC,hdc, | 
|---|
| 132 | int,iFormat, | 
|---|
| 133 | UINT,nBytes, | 
|---|
| 134 | LPPIXELFORMATDESCRIPTOR,pformat) | 
|---|
| 135 | { | 
|---|
| 136 | if (glDescribePixelFormat == NULL) | 
|---|
| 137 | if (internalOpenGLEnable() == FALSE) | 
|---|
| 138 | return(0); | 
|---|
| 139 |  | 
|---|
| 140 | return(glDescribePixelFormat(hdc, iFormat, nBytes, pformat)); | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | ODINFUNCTION1(int,GetPixelFormat,HDC,hdc) | 
|---|
| 144 | { | 
|---|
| 145 | if (glGetPixelFormat == NULL) | 
|---|
| 146 | if (internalOpenGLEnable() == FALSE) | 
|---|
| 147 | return(0); | 
|---|
| 148 |  | 
|---|
| 149 | return(glGetPixelFormat(hdc)); | 
|---|
| 150 | } | 
|---|
| 151 |  | 
|---|
| 152 | /***************************************************************************** | 
|---|
| 153 | * Name      : | 
|---|
| 154 | * Purpose   : | 
|---|
| 155 | * Parameters: | 
|---|
| 156 | * Variables : | 
|---|
| 157 | * Result    : | 
|---|
| 158 | * Remark    : | 
|---|
| 159 | * Status    : | 
|---|
| 160 | * | 
|---|
| 161 | * Author    : Patrick Haller [Fri, 1998/02/27 11:55] | 
|---|
| 162 | *****************************************************************************/ | 
|---|
| 163 |  | 
|---|
| 164 | ODINFUNCTION3(BOOL,SetPixelFormat,HDC,                          hdc, | 
|---|
| 165 | int,                          whatever, | 
|---|
| 166 | CONST PIXELFORMATDESCRIPTOR*, pformat) | 
|---|
| 167 | { | 
|---|
| 168 | if (glSetPixelFormat == NULL) | 
|---|
| 169 | if (internalOpenGLEnable() == FALSE) | 
|---|
| 170 | return(0); | 
|---|
| 171 |  | 
|---|
| 172 | return(glSetPixelFormat(hdc, whatever, pformat)); | 
|---|
| 173 | } | 
|---|
| 174 |  | 
|---|
| 175 |  | 
|---|
| 176 | /***************************************************************************** | 
|---|
| 177 | * Name      : | 
|---|
| 178 | * Purpose   : | 
|---|
| 179 | * Parameters: | 
|---|
| 180 | * Variables : | 
|---|
| 181 | * Result    : | 
|---|
| 182 | * Remark    : | 
|---|
| 183 | * Status    : | 
|---|
| 184 | * | 
|---|
| 185 | * Author    : Patrick Haller [Fri, 1998/02/27 11:55] | 
|---|
| 186 | *****************************************************************************/ | 
|---|
| 187 |  | 
|---|
| 188 | ODINFUNCTION1(BOOL,SwapBuffers,HDC,hdc) | 
|---|
| 189 | { | 
|---|
| 190 | if (glSwapBuffers == NULL) | 
|---|
| 191 | if (internalOpenGLEnable() == FALSE) | 
|---|
| 192 | return(0); | 
|---|
| 193 |  | 
|---|
| 194 |  | 
|---|
| 195 | return(glSwapBuffers(hdc)); | 
|---|
| 196 | } | 
|---|
| 197 |  | 
|---|