Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

OglMisc.c

Go to the documentation of this file.
00001 /****************************************************************************************/
00002 /*  OglMisc.c                                                                           */
00003 /*                                                                                      */
00004 /*  Author: George McBay (gfm@my-deja.com)                                              */
00005 /*  Description: Miscellaneous support functions for OpenGL driver                      */
00006 /*                                                                                      */
00007 /*  The contents of this file are subject to the Genesis3D Public License               */
00008 /*  Version 1.01 (the "License"); you may not use this file except in                   */
00009 /*  compliance with the License. You may obtain a copy of the License at                */
00010 /*  http://www.genesis3d.com                                                            */
00011 /*                                                                                      */
00012 /*  Software distributed under the License is distributed on an "AS IS"                 */
00013 /*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
00014 /*  the License for the specific language governing rights and limitations              */
00015 /*  under the License.                                                                  */
00016 /*                                                                                      */
00017 /*                                                                                      */
00018 /****************************************************************************************/
00019 
00020 #include <windows.h>
00021 #include <gl/gl.h>
00022 
00023 #include "DCommon.h"
00024 #include "OglMisc.h"
00025 
00026 
00027 // Set up the OpenGL viewing frustum using an orthographic projection (as Genesis does all of
00028 // its transforms in the engine... We're just here to rasterize polygons).
00029 void InitMatrices(int width, int height)
00030 {
00031         glMatrixMode(GL_PROJECTION);
00032         glLoadIdentity();
00033         glOrtho(0.0f, (GLfloat)width, 0.0f, (GLfloat)height, 0.0f, 1.0f);
00034         glMatrixMode(GL_MODELVIEW);
00035         glLoadIdentity();
00036         glViewport(0, 0, width, height);
00037 
00038         glScalef(1.0f, -1.0f, 1.0f);
00039         glTranslatef(0, 0 - (GLfloat)height, 0.0);
00040 }
00041 
00042 
00043 // Checks to see if a specific OpenGL extention is present.  Used to look for multitexture 
00044 // support.
00045 geBoolean ExtensionExists(const char *extension)
00046 {
00047         const GLubyte *extensions = NULL;
00048         const GLubyte *begin;
00049         GLubyte *cursor, *end;
00050 
00051         cursor = (GLubyte *) strchr(extension, ' ');
00052 
00053         if(cursor || *extension == '\0')
00054         {
00055                 return GE_FALSE;
00056         }
00057 
00058         extensions = glGetString(GL_EXTENSIONS);
00059 
00060         begin = extensions;
00061         
00062         while(GE_TRUE) 
00063         {
00064                 cursor = (GLubyte *) strstr((const char *) begin, extension);
00065 
00066                 if(!cursor)
00067                 {
00068                         break;
00069                 }
00070 
00071                 end = cursor + strlen(extension);
00072 
00073                 if(cursor == begin || *(cursor - 1) == ' ')
00074                 {
00075                         if (*end == ' ' || *end == '\0')
00076                         {
00077                                 return GE_TRUE;
00078                         }
00079                 }
00080                 
00081                 begin = end;
00082         }
00083 
00084         return GE_FALSE;
00085 }
00086 
00087 
00088 // Takes a GE_PIXELFORMAT_24BIT_RGB bitmap and converts it to a GE_PIXELFORMAT_32BIT_ABGR,
00089 // replacing colorkey pixels with alpha information.
00090 void CkBlit24_32(GLubyte *dstPtr, GLint dstWidth, GLint dstHeight, GLubyte *srcPtr, GLint srcWidth, 
00091                                  GLint srcHeight)
00092 {
00093         GLint width, height;
00094         GLubyte *nextLine;
00095 
00096         memset(dstPtr, 0x00, dstWidth * dstHeight * 4);
00097 
00098 
00099         for(height = 0; height < srcHeight; height++)
00100         {
00101                 nextLine = (dstPtr + (dstWidth * 4));
00102 
00103                 for(width = 0; width < srcWidth; width++)
00104                 {
00105                         if(!(*srcPtr == 0x00 && *(srcPtr + 1) == 0x00 && *(srcPtr + 2) == 0x01))
00106                         {
00107                                 *dstPtr = *srcPtr;
00108                                 *(dstPtr + 1) = *(srcPtr + 1);
00109                                 *(dstPtr + 2) = *(srcPtr + 2);
00110                                 *(dstPtr + 3) = 0xFF;
00111                         }
00112 
00113                         srcPtr += 3;
00114                         dstPtr += 4;
00115                 }
00116 
00117                 dstPtr = nextLine;
00118         }
00119 }
00120 
00121 
00122 void Blit32(GLubyte *dstPtr, GLint dstPitch, GLubyte *srcPtr, GLint srcWidth, GLint srcHeight,
00123                         GLint srcPitch)
00124 {
00125         GLint count;
00126 
00127         for(count = 0; count < srcHeight; count++)
00128         {
00129                 memcpy(dstPtr, srcPtr, srcWidth * 4);
00130                 srcPtr += srcPitch * 4;
00131                 dstPtr += dstPitch * 4;
00132         }
00133 }

Generated on Tue Sep 30 12:36:03 2003 for GTestAndEngine by doxygen 1.3.2