[10583] | 1 | /* $Id: opengl.cpp,v 1.12 2004-04-14 09:44:36 sandervl Exp $ */
|
---|
[97] | 2 |
|
---|
[4] | 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 | */
|
---|
[526] | 11 |
|
---|
| 12 |
|
---|
| 13 | /****************************************************************************
|
---|
| 14 | * Includes *
|
---|
| 15 | ****************************************************************************/
|
---|
| 16 |
|
---|
[4] | 17 | #include <os2win.h>
|
---|
| 18 | #include <stdarg.h>
|
---|
| 19 | #include <string.h>
|
---|
[526] | 20 | #include <odinwrap.h>
|
---|
[4] | 21 | #include "misc.h"
|
---|
| 22 | #include "unicode.h"
|
---|
| 23 |
|
---|
[2802] | 24 | #define DBG_LOCALLOG DBG_opengl
|
---|
| 25 | #include "dbglocal.h"
|
---|
[526] | 26 |
|
---|
[2802] | 27 |
|
---|
[526] | 28 | ODINDEBUGCHANNEL(GDI32-OPENGL)
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | /****************************************************************************
|
---|
| 32 | * Definitions *
|
---|
| 33 | ****************************************************************************/
|
---|
| 34 |
|
---|
[4] | 35 | typedef int (* WIN32API CHOOSEPIXELFMT) (HDC, CONST PIXELFORMATDESCRIPTOR *);
|
---|
| 36 | typedef BOOL (* WIN32API SETPIXELFMT) (HDC, int, CONST PIXELFORMATDESCRIPTOR *);
|
---|
| 37 | typedef BOOL (* WIN32API SWAPBUFFERS) (HDC hdc);
|
---|
[2526] | 38 | typedef int (* WIN32API DESCRIBEPIXELFMT) (HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
|
---|
[2527] | 39 | typedef int (* WIN32API GETPIXELFMT) (HDC);
|
---|
[4] | 40 |
|
---|
| 41 |
|
---|
[526] | 42 | /****************************************************************************
|
---|
| 43 | * Module Global Variables *
|
---|
| 44 | ****************************************************************************/
|
---|
[4] | 45 |
|
---|
[2526] | 46 | static CHOOSEPIXELFMT glChoosePixelFormat = NULL;
|
---|
| 47 | static SETPIXELFMT glSetPixelFormat = NULL;
|
---|
| 48 | static SWAPBUFFERS glSwapBuffers = NULL;
|
---|
| 49 | static DESCRIBEPIXELFMT glDescribePixelFormat = NULL;
|
---|
[2527] | 50 | static GETPIXELFMT glGetPixelFormat = NULL;
|
---|
[2526] | 51 | static HINSTANCE hOpenGL = NULL;
|
---|
[526] | 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)
|
---|
[4] | 67 | {
|
---|
[526] | 68 | if(hOpenGL == NULL)
|
---|
| 69 | {
|
---|
[2661] | 70 | hOpenGL = LoadLibraryA("OPENGL32.DLL");
|
---|
[526] | 71 | if(hOpenGL == NULL)
|
---|
| 72 | return(FALSE);
|
---|
| 73 | }
|
---|
[4] | 74 |
|
---|
| 75 | if(glChoosePixelFormat == NULL) {
|
---|
[2661] | 76 | glChoosePixelFormat = (CHOOSEPIXELFMT)GetProcAddress(hOpenGL, "wglChoosePixelFormat");
|
---|
[4] | 77 | if(glChoosePixelFormat == NULL)
|
---|
| 78 | return(0);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | if(glSetPixelFormat == NULL) {
|
---|
[2661] | 82 | glSetPixelFormat = (SETPIXELFMT)GetProcAddress(hOpenGL, "wglSetPixelFormat");
|
---|
[4] | 83 | if(glSetPixelFormat == NULL)
|
---|
| 84 | return(FALSE);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | if(glSwapBuffers == NULL) {
|
---|
[2661] | 88 | glSwapBuffers = (SWAPBUFFERS)GetProcAddress(hOpenGL, "wglSwapBuffers");
|
---|
[4] | 89 | if(glSwapBuffers == NULL)
|
---|
| 90 | return(FALSE);
|
---|
| 91 | }
|
---|
[526] | 92 |
|
---|
[2526] | 93 | if(glDescribePixelFormat == NULL) {
|
---|
[2661] | 94 | glDescribePixelFormat = (DESCRIBEPIXELFMT)GetProcAddress(hOpenGL, "wglDescribePixelFormat");
|
---|
[2526] | 95 | if(glDescribePixelFormat == NULL)
|
---|
| 96 | return(FALSE);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[2527] | 99 | if(glGetPixelFormat == NULL) {
|
---|
[2661] | 100 | glGetPixelFormat = (GETPIXELFMT)GetProcAddress(hOpenGL, "wglGetPixelFormat");
|
---|
[2527] | 101 | if(glGetPixelFormat == NULL)
|
---|
| 102 | return(FALSE);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[2526] | 105 | return(TRUE); /* OpenGL is initialized and enabled*/
|
---|
[4] | 106 | }
|
---|
[526] | 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 |
|
---|
[10582] | 121 | int WIN32API ChoosePixelFormat(HDC hdc, const LPPIXELFORMATDESCRIPTOR pformat)
|
---|
[526] | 122 | {
|
---|
| 123 | if (glChoosePixelFormat == NULL)
|
---|
| 124 | if (internalOpenGLEnable() == FALSE)
|
---|
| 125 | return(0);
|
---|
| 126 |
|
---|
| 127 | return(glChoosePixelFormat(hdc, pformat));
|
---|
| 128 | }
|
---|
| 129 |
|
---|
[9429] | 130 | int WIN32API DescribePixelFormat(HDC hdc, int iFormat, UINT nBytes,
|
---|
| 131 | LPPIXELFORMATDESCRIPTOR pformat)
|
---|
[2526] | 132 | {
|
---|
| 133 | if (glDescribePixelFormat == NULL)
|
---|
| 134 | if (internalOpenGLEnable() == FALSE)
|
---|
| 135 | return(0);
|
---|
[526] | 136 |
|
---|
[2526] | 137 | return(glDescribePixelFormat(hdc, iFormat, nBytes, pformat));
|
---|
| 138 | }
|
---|
| 139 |
|
---|
[9429] | 140 | int WIN32API GetPixelFormat(HDC hdc)
|
---|
[2527] | 141 | {
|
---|
| 142 | if (glGetPixelFormat == NULL)
|
---|
| 143 | if (internalOpenGLEnable() == FALSE)
|
---|
| 144 | return(0);
|
---|
[2526] | 145 |
|
---|
[2527] | 146 | return(glGetPixelFormat(hdc));
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[526] | 149 | /*****************************************************************************
|
---|
| 150 | * Name :
|
---|
| 151 | * Purpose :
|
---|
| 152 | * Parameters:
|
---|
| 153 | * Variables :
|
---|
| 154 | * Result :
|
---|
| 155 | * Remark :
|
---|
| 156 | * Status :
|
---|
| 157 | *
|
---|
| 158 | * Author : Patrick Haller [Fri, 1998/02/27 11:55]
|
---|
| 159 | *****************************************************************************/
|
---|
| 160 |
|
---|
[9429] | 161 | BOOL WIN32API SetPixelFormat(HDC hdc, int whatever,
|
---|
| 162 | CONST PIXELFORMATDESCRIPTOR *pformat)
|
---|
[526] | 163 | {
|
---|
| 164 | if (glSetPixelFormat == NULL)
|
---|
| 165 | if (internalOpenGLEnable() == FALSE)
|
---|
| 166 | return(0);
|
---|
| 167 |
|
---|
| 168 | return(glSetPixelFormat(hdc, whatever, pformat));
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 |
|
---|
| 172 | /*****************************************************************************
|
---|
| 173 | * Name :
|
---|
| 174 | * Purpose :
|
---|
| 175 | * Parameters:
|
---|
| 176 | * Variables :
|
---|
| 177 | * Result :
|
---|
| 178 | * Remark :
|
---|
| 179 | * Status :
|
---|
| 180 | *
|
---|
| 181 | * Author : Patrick Haller [Fri, 1998/02/27 11:55]
|
---|
| 182 | *****************************************************************************/
|
---|
| 183 |
|
---|
[9429] | 184 | BOOL WIN32API SwapBuffers(HDC hdc)
|
---|
[526] | 185 | {
|
---|
| 186 | if (glSwapBuffers == NULL)
|
---|
| 187 | if (internalOpenGLEnable() == FALSE)
|
---|
| 188 | return(0);
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | return(glSwapBuffers(hdc));
|
---|
| 192 | }
|
---|
| 193 |
|
---|