| 1 | /* $Id: opengl.cpp,v 1.9 2002-11-26 10:53: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 | int WIN32API ChoosePixelFormat(HDC hdc, CONST PIXELFORMATDESCRIPTOR* pformat)
|
|---|
| 122 | {
|
|---|
| 123 | if (glChoosePixelFormat == NULL)
|
|---|
| 124 | if (internalOpenGLEnable() == FALSE)
|
|---|
| 125 | return(0);
|
|---|
| 126 |
|
|---|
| 127 | return(glChoosePixelFormat(hdc, pformat));
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | int WIN32API DescribePixelFormat(HDC hdc, int iFormat, UINT nBytes,
|
|---|
| 131 | LPPIXELFORMATDESCRIPTOR pformat)
|
|---|
| 132 | {
|
|---|
| 133 | if (glDescribePixelFormat == NULL)
|
|---|
| 134 | if (internalOpenGLEnable() == FALSE)
|
|---|
| 135 | return(0);
|
|---|
| 136 |
|
|---|
| 137 | return(glDescribePixelFormat(hdc, iFormat, nBytes, pformat));
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | int WIN32API GetPixelFormat(HDC hdc)
|
|---|
| 141 | {
|
|---|
| 142 | if (glGetPixelFormat == NULL)
|
|---|
| 143 | if (internalOpenGLEnable() == FALSE)
|
|---|
| 144 | return(0);
|
|---|
| 145 |
|
|---|
| 146 | return(glGetPixelFormat(hdc));
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 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 |
|
|---|
| 161 | BOOL WIN32API SetPixelFormat(HDC hdc, int whatever,
|
|---|
| 162 | CONST PIXELFORMATDESCRIPTOR *pformat)
|
|---|
| 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 |
|
|---|
| 184 | BOOL WIN32API SwapBuffers(HDC hdc)
|
|---|
| 185 | {
|
|---|
| 186 | if (glSwapBuffers == NULL)
|
|---|
| 187 | if (internalOpenGLEnable() == FALSE)
|
|---|
| 188 | return(0);
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 | return(glSwapBuffers(hdc));
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|