diff options
| author | Steven Fuller <relnev@icculus.org> | 2001-08-11 03:36:48 +0000 |
|---|---|---|
| committer | Patryk Obara <dreamer.tan@gmail.com> | 2019-08-20 02:22:36 +0200 |
| commit | 9dadcb80240ed2e8df118d92940a954f0e7e669e (patch) | |
| tree | 5feefeb5d8a7d1c56678750110afecc84cbc7b7f /src/opengl.c | |
| parent | efc384b7b35943fa96249f747bfa08d22f96242a (diff) | |
Threw in texture loading/drawing.
Blending modes (color/texture) are problematic and texture coordinates
aren't yet perfect.
Diffstat (limited to 'src/opengl.c')
| -rw-r--r-- | src/opengl.c | 74 |
1 files changed, 62 insertions, 12 deletions
diff --git a/src/opengl.c b/src/opengl.c index c8a9e53..0ed405e 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -19,6 +19,7 @@ #include "prototyp.h" #include "d3d_hud.h" #include "avp_userprofile.h" +#include "aw.h" extern IMAGEHEADER ImageHeaderArray[]; @@ -27,7 +28,38 @@ extern unsigned char GammaValues[256]; extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock; extern int SpecialFXImageNumber; -static void *CurrTextureHandle; +static D3DTexture *CurrTextureHandle; + +void FlushD3DZBuffer() +{ + glClear(GL_DEPTH_BUFFER_BIT); +} + +void SecondFlushD3DZBuffer() +{ + glClear(GL_DEPTH_BUFFER_BIT); +} + +GLuint CreateOGLTexture(D3DTexture *tex, unsigned char *buf) +{ + GLuint h; + + glGenTextures(1, &h); + + glBindTexture(GL_TEXTURE_2D, h); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex->w, tex->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + tex->id = h; + + return h; +} #define TRANSLUCENCY_ONEONE 33 void CheckTranslucencyModeIsCorrect(int mode) /* TODO: use correct enum */ @@ -66,17 +98,20 @@ void D3D_ZBufferedGouraudTexturedPolygon_Output(POLYHEADER *inputPolyPtr, RENDER { #if 1 int texoffset; - void *TextureHandle; + D3DTexture *TextureHandle; int i; GLfloat ZNear, zvalue; -// GLflaot ZFar; - +// GLfloat ZFar; + float RecipW, RecipH; + +// glDisable(GL_TEXTURE_2D); + ZNear = (GLfloat) (Global_VDB_Ptr->VDB_ClipZ * GlobalScale); // ZFar = 18000.0f; /* TODO: is this good enough? */ texoffset = inputPolyPtr->PolyColour & ClrTxDefn; if (texoffset) { - TextureHandle = (void *)ImageHeaderArray[texoffset].D3DHandle; + TextureHandle = (void *)ImageHeaderArray[texoffset].D3DTexture; } else { TextureHandle = CurrTextureHandle; } @@ -91,12 +126,23 @@ void D3D_ZBufferedGouraudTexturedPolygon_Output(POLYHEADER *inputPolyPtr, RENDER if (SecondaryColorExt) glEnable(GL_COLOR_SUM_EXT); */ - + RecipW = (1.0f/65536.0f)/128.0f; + RecipH = (1.0f/65536.0f)/128.0f; + + glBindTexture(GL_TEXTURE_2D, TextureHandle->id); + glBegin(GL_POLYGON); for (i = 0; i < RenderPolygon.NumberOfVertices; i++) { RENDERVERTEX *vertices = &renderVerticesPtr[i]; GLfloat x, y, z; int x1, y1; + GLfloat s, t; + +/* this currently doesn't work quite right */ + s = ((float)vertices->U) * RecipW + (1.0f/256.0f); + t = ((float)vertices->V) * RecipH + (1.0f/256.0f); + z = (65536.0f)/(vertices->Z); + glTexCoord4f(s, t, 0, 1.00); x1 = (vertices->X*(Global_VDB_Ptr->VDB_ProjX+1))/vertices->Z+Global_VDB_Ptr->VDB_CentreX; y1 = (vertices->Y*(Global_VDB_Ptr->VDB_ProjY+1))/vertices->Z+Global_VDB_Ptr->VDB_CentreY; @@ -119,7 +165,7 @@ void D3D_ZBufferedGouraudTexturedPolygon_Output(POLYHEADER *inputPolyPtr, RENDER glSecondaryColor3ub(GammaValues[vertices->SpecularR], GammaValues[vertices->SpecularG], GammaValues[vertices->SpecularB]); */ glVertex3f(x, y, z); - + // fprintf(stderr, "Vertex %d: (%f, %f, %f)\n\t[%d, %d, %d]->[%d, %d] (%d, %d, %d, %d)\n", i, x, y, z, vertices->X, vertices->Y, vertices->Z, x1, y1, vertices->R, vertices->G, vertices->B, vertices->A); // fprintf(stderr, "GREP: z = %d, znear = %f, zvalue = %f, z = %f\n", vertices->Z, ZNear, zvalue, z); } @@ -133,6 +179,7 @@ return; CheckTranslucencyModeIsCorrect(TRANSLUCENCY_ONEONE); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); glDepthMask(GL_FALSE); + glDisable(GL_TEXTURE_2D); glBegin(GL_POLYGON); for (i = 0; i < RenderPolygon.NumberOfVertices; i++) { @@ -145,20 +192,23 @@ return; x = x1; y = y1; - x = (x - 320.0)/320.0; - y = -(y - 240.0)/240.0; - +// x = (x - 320.0)/320.0; +// y = -(y - 240.0)/240.0; + x = (x - ScreenDescriptorBlock.SDB_CentreX)/ScreenDescriptorBlock.SDB_CentreX; + y = -(y - ScreenDescriptorBlock.SDB_CentreY)/ScreenDescriptorBlock.SDB_CentreY; + zvalue = vertices->Z+HeadUpDisplayZOffset; zvalue = 1.0 - 2*ZNear/zvalue; /* currently maps [ZNear, inf) to [-1, 1], probably could be more precise with a ZFar */ z = zvalue; - glColor4ub(GammaValues[vertices->SpecularR], GammaValues[vertices->SpecularG], GammaValues[vertices->SpecularB], 255); + glColor4b(GammaValues[vertices->SpecularR], GammaValues[vertices->SpecularG], GammaValues[vertices->SpecularB], 255); glVertex3f(x, y, z); } glEnd(); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glDepthMask(GL_TRUE); + glDepthMask(GL_TRUE); + glEnable(GL_TEXTURE_2D); } #endif } |
