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

OGLDrv.c File Reference

#include <windows.h>
#include <stdio.h>
#include <math.h>
#include <gl/gl.h>
#include "OglDrv.h"
#include "OglMisc.h"
#include "THandle.h"
#include "Render.h"
#include "Win32.h"

Go to the source code of this file.

Defines

#define NUM_PIXEL_FORMATS   (sizeof(PixelFormats)/sizeof(geRDriver_PixelFormat))

Functions

geBoolean DRIVERCC SetFogEnable (geBoolean Enable, float r, float g, float b, float Start, float End)
geBoolean DRIVERCC DrvInit (DRV_DriverHook *Hook)
geBoolean DRIVERCC DrvShutdown (void)
geBoolean DRIVERCC DrvUpdateWindow (void)
geBoolean DRIVERCC DrvSetActive (geBoolean Active)
geBoolean DRIVERCC SetGamma (float Gamma)
geBoolean DRIVERCC GetGamma (float *Gamma)
DllExport BOOL DriverHook (DRV_Driver **Driver)
geBoolean DRIVERCC EnumModes (int32 Driver, char *DriverName, DRV_ENUM_MODES_CB *Cb, void *Context)
geBoolean DRIVERCC EnumSubDrivers (DRV_ENUM_DRV_CB *Cb, void *Context)
geBoolean DRIVERCC EnumPixelFormats (DRV_ENUM_PFORMAT_CB *Cb, void *Context)
void SetLastDrvError (int32 Error, char *ErrorStr)
geBoolean DRIVERCC ScreenShot (const char *Name)

Variables

int32 LastError
char LastErrorStr [255]
GLfloat CurrentGamma = 1.0f
DRV_Window ClientWindow
DRV_CacheInfo CacheInfo
GLint maxTextureSize = 0
GLboolean multitexture = GE_FALSE
PFNGLACTIVETEXTUREARBPROC glActiveTextureARB
PFNGLMULTITEXCOORD4FARBPROC glMultiTexCoord4fARB
DRV_Driver OGLDRV
DRV_EngineSettings EngineSettings
geRDriver_PixelFormat PixelFormats []


Define Documentation

#define NUM_PIXEL_FORMATS   (sizeof(PixelFormats)/sizeof(geRDriver_PixelFormat))
 

Definition at line 317 of file OGLDrv.c.


Function Documentation

DllExport BOOL DriverHook DRV_Driver **  Driver  ) 
 

Definition at line 263 of file OGLDrv.c.

References DRV_EngineSettings::CanSupportFlags, DllExport, DRV_ERROR_NONE, DRV_SUPPORT_ALPHA, DRV_SUPPORT_COLORKEY, DRV_Driver::EngineSettings, EngineSettings, GE_TRUE, LastErrorStr, DRV_Driver::LastErrorStr, OGLDRV, DRV_EngineSettings::PreferenceFlags, and SetLastDrvError().

00264 {
00265 
00266         EngineSettings.CanSupportFlags = (DRV_SUPPORT_ALPHA | DRV_SUPPORT_COLORKEY);
00267         EngineSettings.PreferenceFlags = 0;
00268 
00269         OGLDRV.EngineSettings = &EngineSettings;
00270     
00271         *Driver = &OGLDRV;
00272 
00273         // Make sure the error string ptr is not null, or invalid!!!
00274     OGLDRV.LastErrorStr = LastErrorStr;
00275 
00276         SetLastDrvError(DRV_ERROR_NONE, "OGL:  No error.");
00277 
00278         return GE_TRUE;
00279 }

geBoolean DRIVERCC DrvInit DRV_DriverHook Hook  ) 
 

Definition at line 123 of file OGLDrv.c.

References tagRECT::bottom, ClientWindow, DRIVERCC, DRV_ERROR_GENERIC, ExtensionExists(), GE_FALSE, GE_TRUE, geBoolean, GL_TEXTURE0_ARB, GL_TEXTURE1_ARB, glActiveTextureARB, glMultiTexCoord4fARB, DRV_Window::Height, DRV_DriverHook::Height, DRV_Window::hWnd, DRV_DriverHook::hWnd, InitMatrices(), tagRECT::left, maxTextureSize, multitexture, NULL, tagRECT::right, SetFogEnable(), SetFullscreen(), SetGLPixelFormat(), SetLastDrvError(), THandle_Startup(), tagRECT::top, DRV_Window::Width, DRV_DriverHook::Width, and WindowSetup().

00124 {
00125         RECT            WRect;
00126         
00127 
00128         WindowSetup(Hook);
00129         
00130         if(Hook->Width == -1 && Hook->Height == -1)
00131         {
00132                 GetClientRect(Hook->hWnd, &WRect);
00133                 
00134                 Hook->Width = (WRect.right - WRect.left);
00135                 Hook->Height = (WRect.bottom - WRect.top);
00136         }
00137         else if(!SetFullscreen(Hook))
00138         {
00139                 return GE_FALSE;
00140         } 
00141 
00142         SetGLPixelFormat(Hook);
00143 
00144         ClientWindow.Width = Hook->Width;
00145         ClientWindow.Height = Hook->Height;
00146         ClientWindow.hWnd = Hook->hWnd;
00147         
00148 #ifdef USE_LIGHTMAPS
00149         if(ExtensionExists("GL_ARB_multitexture"))
00150         {
00151                 glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC)wglGetProcAddress("glActiveTextureARB");
00152                 glMultiTexCoord4fARB = (PFNGLMULTITEXCOORD4FARBPROC)wglGetProcAddress("glMultiTexCoord4fARB");
00153 
00154                 if(glActiveTextureARB != NULL && glMultiTexCoord4fARB != NULL)
00155                 {
00156                         multitexture = GL_TRUE;
00157                 }
00158         }
00159         else 
00160 #endif
00161         {
00162                 multitexture = GL_FALSE;
00163         } 
00164 
00165 
00166         glPixelStorei(GL_PACK_ALIGNMENT, 1);
00167         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
00168 
00169         glEnable(GL_TEXTURE_2D);
00170         glEnable(GL_DEPTH_TEST);
00171 
00172         glEnable(GL_BLEND);    
00173         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00174 
00175         glShadeModel(GL_SMOOTH);
00176         glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
00177 
00178         if(multitexture)
00179         {
00180                 glActiveTextureARB(GL_TEXTURE1_ARB);
00181 
00182                 glDisable(GL_TEXTURE_1D);
00183                 glDisable(GL_TEXTURE_2D);               
00184 
00185                 glActiveTextureARB(GL_TEXTURE0_ARB);
00186         } 
00187 
00188         SetFogEnable(GE_FALSE, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
00189 
00190         InitMatrices(ClientWindow.Width, ClientWindow.Height);
00191 
00192         glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
00193 
00194         glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
00195 
00196         if (!THandle_Startup())
00197         {
00198                 SetLastDrvError(DRV_ERROR_GENERIC, "OGL_DrvInit:  THandle_Startup failed...\n");
00199                 return GE_FALSE;
00200         }
00201 
00202         return GE_TRUE;
00203 }

geBoolean DRIVERCC DrvSetActive geBoolean  Active  ) 
 

Definition at line 225 of file OGLDrv.c.

References DRIVERCC, GE_TRUE, and geBoolean.

00226 {
00227 
00228         return  GE_TRUE;
00229 }

geBoolean DRIVERCC DrvShutdown void   ) 
 

Definition at line 206 of file OGLDrv.c.

References DRIVERCC, GE_TRUE, geBoolean, and WindowCleanup().

00207 {
00208         // Tell OpenGL to finish whatever is in the pipe, because we're closing up shop.
00209         glFinish();
00210 
00211         WindowCleanup();
00212 
00213         return GE_TRUE;
00214 }

geBoolean DRIVERCC DrvUpdateWindow void   ) 
 

Definition at line 218 of file OGLDrv.c.

References DRIVERCC, GE_TRUE, and geBoolean.

00219 {
00220 
00221         return  GE_TRUE;
00222 }

geBoolean DRIVERCC EnumModes int32  Driver,
char *  DriverName,
DRV_ENUM_MODES_CB Cb,
void *  Context
 

Definition at line 282 of file OGLDrv.c.

References DRIVERCC, EnumNativeModes(), GE_TRUE, and geBoolean.

00284 {
00285         GLint modeCount = 0;
00286 
00287         modeCount = EnumNativeModes(Cb, Context);
00288 
00289         return GE_TRUE;
00290 }

geBoolean DRIVERCC EnumPixelFormats DRV_ENUM_PFORMAT_CB Cb,
void *  Context
 

Definition at line 320 of file OGLDrv.c.

References DRIVERCC, GE_TRUE, geBoolean, NUM_PIXEL_FORMATS, and PixelFormats.

00321 {
00322         GLint i;
00323 
00324         for(i = 0; i < NUM_PIXEL_FORMATS; i++)
00325         {
00326                 if(!Cb(&PixelFormats[i], Context))
00327                 {
00328                         return GE_TRUE;
00329                 }
00330         }
00331 
00332         return GE_TRUE;
00333 }

geBoolean DRIVERCC EnumSubDrivers DRV_ENUM_DRV_CB Cb,
void *  Context
 

Definition at line 293 of file OGLDrv.c.

References DRIVERCC, DRV_VMAJS, DRV_VMINS, GE_TRUE, and geBoolean.

00294 {
00295 
00296         if(!Cb(0, "OpenGL Driver v"DRV_VMAJS"."DRV_VMINS".", Context))
00297         {
00298                 return GE_TRUE;
00299         }
00300 
00301         return GE_TRUE;
00302 }

geBoolean DRIVERCC GetGamma float *  Gamma  ) 
 

Definition at line 253 of file OGLDrv.c.

References CurrentGamma, DRIVERCC, geBoolean, and TRUE.

00254 {
00255         *Gamma = CurrentGamma;
00256         
00257         return TRUE;
00258 }

geBoolean DRIVERCC ScreenShot const char *  Name  ) 
 

Definition at line 357 of file OGLDrv.c.

References ClientWindow, DRIVERCC, GE_FALSE, GE_TRUE, geBoolean, GL_BGR_EXT, DRV_Window::Height, NULL, and DRV_Window::Width.

00358 {
00359         unsigned char tgaHeader[18];
00360         GLubyte *buffer;
00361         FILE *fp;
00362         char *newName;
00363         int nameLen;
00364 
00365         buffer = (GLubyte *)malloc(sizeof(GLubyte) * ClientWindow.Width * ClientWindow.Height * 3);     
00366 
00367         glFinish();
00368 
00369         glReadPixels(0, 0, ClientWindow.Width, ClientWindow.Height, 
00370                 GL_BGR_EXT, GL_UNSIGNED_BYTE, buffer);
00371  
00372         memset(tgaHeader, 0, sizeof(tgaHeader));
00373         tgaHeader[2] = 2;
00374         tgaHeader[12] = (unsigned char)ClientWindow.Width;
00375         tgaHeader[13] = (unsigned char)((unsigned long)ClientWindow.Width >> 8);
00376         tgaHeader[14] = (unsigned char)ClientWindow.Height;
00377         tgaHeader[15] = (unsigned char)((unsigned long)ClientWindow.Height >> 8);
00378         tgaHeader[16] = 24;
00379  
00380         // Convert the extention (if one exists) to .tga.  They probably expect a .bmp.
00381         newName = strdup(Name);
00382 
00383         nameLen = strlen(newName);
00384 
00385         if(nameLen > 3)
00386         {
00387                 if(newName[nameLen - 4] == '.')
00388                 {
00389                         strcpy(newName + nameLen - 3, "tga");
00390                 }
00391         }
00392 
00393     fp = fopen(newName, "wb");
00394     
00395         free(newName);
00396 
00397         if(fp == NULL) 
00398         {
00399                 free(buffer);
00400         return GE_FALSE;
00401     }
00402  
00403     fwrite(tgaHeader, 1, 18, fp);
00404     fwrite(buffer, 3, ClientWindow.Width * ClientWindow.Height, fp);
00405     fclose(fp);
00406  
00407         free(buffer);
00408         
00409         return GE_TRUE;
00410 }

geBoolean DRIVERCC SetFogEnable geBoolean  Enable,
float  r,
float  g,
float  b,
float  Start,
float  End
 

Definition at line 116 of file OGLDrv.c.

References DRIVERCC, GE_TRUE, and geBoolean.

Referenced by DrvInit().

00117 {
00118 
00119         return GE_TRUE;
00120 }

geBoolean DRIVERCC SetGamma float  Gamma  ) 
 

Definition at line 232 of file OGLDrv.c.

References CurrentGamma, DRIVERCC, GE_TRUE, and geBoolean.

00233 {       
00234         GLfloat lut[256];
00235         GLint   i;
00236         
00237         CurrentGamma = Gamma;
00238         
00239         for(i = 0; i < 256; i++)
00240         {
00241                 lut[i] = (GLfloat)pow(i / 255.0, 1.0 / CurrentGamma);
00242         }
00243 
00244         glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
00245         glPixelMapfv(GL_PIXEL_MAP_R_TO_R, 256, lut);
00246         glPixelMapfv(GL_PIXEL_MAP_G_TO_G, 256, lut);
00247         glPixelMapfv(GL_PIXEL_MAP_B_TO_B, 256, lut); 
00248 
00249         return GE_TRUE;
00250 }

void SetLastDrvError int32  Error,
char *  ErrorStr
 

Definition at line 336 of file OGLDrv.c.

References Error, DRV_Driver::LastError, LastError, DRV_Driver::LastErrorStr, LastErrorStr, and OGLDRV.

00337 {
00338         LastError = Error;
00339         
00340         if(ErrorStr)
00341         {
00342                 strcpy(LastErrorStr, ErrorStr);
00343         }
00344         else
00345         {
00346                 LastErrorStr[0] = 0;
00347         }
00348 
00349         OGLDRV.LastErrorStr = LastErrorStr;
00350         OGLDRV.LastError = LastError;
00351 }


Variable Documentation

DRV_CacheInfo CacheInfo [static]
 

Definition at line 37 of file OGLDrv.c.

DRV_Window ClientWindow
 

Definition at line 36 of file OGLDrv.c.

GLfloat CurrentGamma = 1.0f
 

Definition at line 35 of file OGLDrv.c.

Referenced by GetGamma(), and SetGamma().

DRV_EngineSettings EngineSettings
 

Definition at line 261 of file OGLDrv.c.

PFNGLACTIVETEXTUREARBPROC glActiveTextureARB
 

Definition at line 43 of file OGLDrv.c.

Referenced by DrvInit(), and Render_WorldPolyMultitexture().

PFNGLMULTITEXCOORD4FARBPROC glMultiTexCoord4fARB
 

Definition at line 44 of file OGLDrv.c.

Referenced by DrvInit(), and Render_WorldPolyMultitexture().

int32 LastError
 

Definition at line 32 of file OGLDrv.c.

char LastErrorStr[255]
 

Definition at line 33 of file OGLDrv.c.

GLint maxTextureSize = 0
 

Definition at line 39 of file OGLDrv.c.

Referenced by DrawDecal(), DrvInit(), THandle_Create(), and THandle_Update().

GLboolean multitexture = GE_FALSE
 

Definition at line 42 of file OGLDrv.c.

Referenced by DrvInit(), and Render_WorldPoly().

DRV_Driver OGLDRV
 

Definition at line 48 of file OGLDrv.c.

Referenced by BeginScene(), BeginWorld(), DriverHook(), Render_GouraudPoly(), Render_WorldPoly(), and SetLastDrvError().

geRDriver_PixelFormat PixelFormats[]
 

Initial value:

Definition at line 310 of file OGLDrv.c.


Generated on Tue Sep 30 12:37:49 2003 for GTestAndEngine by doxygen 1.3.2