diff --git a/src/main.c b/src/main.c index fc44070..a8c1aa7 100644 --- a/src/main.c +++ b/src/main.c @@ -70,6 +70,7 @@ int InitialiseWindowsSystem() glEnable(GL_BLEND); glEnable(GL_DEPTH_TEST); + glEnable(GL_TEXTURE_2D); #endif return 0; } @@ -356,7 +357,7 @@ void ThisFramesRenderingHasBegun() /* TODO: this should be in D3D_DrawBackdrop */ #if 1 - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT); #endif } @@ -435,10 +436,16 @@ int main(int argc, char *argv[]) AvP.CurrentEnv = AvP.StartingEnv = 0; /* are these even used? */ // AvP.PlayerType = I_Alien; - AvP.PlayerType = I_Marine; + +// AvP.PlayerType = I_Marine; +// SetLevelToLoad(AVP_ENVIRONMENT_DERELICT); /* starting marine level */ // SetLevelToLoad(AVP_ENVIRONMENT_INVASION); /* because the menus aren't implemented */ - SetLevelToLoad(AVP_ENVIRONMENT_DERELICT); /* starting marine level */ -// SetLevelToLoad(AVP_ENVIRONMENT_LEADWORKS_MP); + + + AvP.PlayerType = I_Predator; + SetLevelToLoad(AVP_ENVIRONMENT_WATERFALL); + +// SetLevelToLoad(AVP_ENVIRONMENT_LEADWORKS_MP); /* multiplayer // while(AvP_MainMenus()) { 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 } diff --git a/src/stubs.c b/src/stubs.c index ce16084..b895b0c 100644 --- a/src/stubs.c +++ b/src/stubs.c @@ -441,7 +441,9 @@ void SetFogDistance(int fogDistance) void CheckWireFrameMode(int shouldBeOn) { - fprintf(stderr, "CheckWireFrameMode(%d)\n", shouldBeOn); +// fprintf(stderr, "CheckWireFrameMode(%d)\n", shouldBeOn); + if (shouldBeOn) + fprintf(stderr, "CheckWireFrameMode(%d)\n", shouldBeOn); } void WriteEndCodeToExecuteBuffer() @@ -456,11 +458,6 @@ BOOL UnlockExecuteBufferAndPrepareForUse() return FALSE; } -void SecondFlushD3DZBuffer() -{ - fprintf(stderr, "SecondFlushD3DZBuffer()\n"); -} - void ReloadImageIntoD3DImmediateSurface(IMAGEHEADER* iheader) { fprintf(stderr, "ReloadImageIntoD3DImmediateSurface(%p)\n", iheader); @@ -486,14 +483,9 @@ void ReleaseD3DTexture(void* D3DTexture) fprintf(stderr, "ReleaseD3DTexture(%p)\n", D3DTexture); } -void FlushD3DZBuffer() -{ - fprintf(stderr, "FlushD3DZBuffer()\n"); -} - BOOL ExecuteBuffer() { - fprintf(stderr, "ExecuteBuffer()\n"); +// fprintf(stderr, "ExecuteBuffer()\n"); return FALSE; } @@ -671,17 +663,17 @@ int MouseVelY; void DirectReadKeyboard() { - fprintf(stderr, "DirectReadKeyboard()\n"); +// fprintf(stderr, "DirectReadKeyboard()\n"); } void DirectReadMouse() { - fprintf(stderr, "DirectReadMouse()\n"); +// fprintf(stderr, "DirectReadMouse()\n"); } void ReadJoysticks() { - fprintf(stderr, "ReadJoysticks()\n"); +// fprintf(stderr, "ReadJoysticks()\n"); } diff --git a/src/win95/aw.h b/src/win95/aw.h index ed35da4..70717b0 100644 --- a/src/win95/aw.h +++ b/src/win95/aw.h @@ -11,7 +11,6 @@ typedef struct DIRECTDRAWSURFACE int w; int h; unsigned char *data; - int type; } DIRECTDRAWSURFACE; typedef DIRECTDRAWSURFACE * LPDIRECTDRAWSURFACE; @@ -24,7 +23,6 @@ typedef struct DIRECT3DTEXTURE int w; int h; unsigned char *data; - int type; } DIRECT3DTEXTURE; typedef DIRECT3DTEXTURE * LPDIRECT3DTEXTURE; diff --git a/src/win95/awtexld.cpp b/src/win95/awtexld.cpp index 08067b8..f8b3610 100644 --- a/src/win95/awtexld.cpp +++ b/src/win95/awtexld.cpp @@ -416,8 +416,8 @@ DWORD AwBackupTexture::GetTransparentColour() void AwBackupTexture::ChoosePixelFormat(AwTl::CreateTextureParms const & _parmsR) { - fprintf(stderr, "AwBackupTexture::ChoosePixelFormat(...)\n"); -#if 0 +// fprintf(stderr, "AwBackupTexture::ChoosePixelFormat(...)\n"); + using namespace AwTl; pixelFormat.validB = false; // set invalid first @@ -431,26 +431,17 @@ void AwBackupTexture::ChoosePixelFormat(AwTl::CreateTextureParms const & _parmsR // transparency? m_bTranspMask = HasTransparentMask(fMyFlags & AW_TLF_TRANSP ? true : false); + - #if 0 - if (_parmsR.prevTexP.voidP) - { - // use the previous format - } - else if (_parmsR.prevTexB) - { - // use the previous format from one of the regiouns - } - else - #endif - if (_parmsR.loadTextureB || fMyFlags & AW_TLF_TEXTURE) { + fprintf(stderr, "AwBackupTexture::ChoosePixelFormat(...)\n"); +#if 0 // use a texture format unsigned nColours = GetNumColours(); unsigned nMinPalSize = GetMinPaletteSize(); - PixelFormat const * pFormat = &pfTextureFormat; + PixelFormat * pFormat = &pfTextureFormat; for (LIF itFormat(&listTextureFormats); !itFormat.done(); itFormat.next()) { @@ -467,9 +458,9 @@ void AwBackupTexture::ChoosePixelFormat(AwTl::CreateTextureParms const & _parmsR pFormat = pThisFormat; } } - + pixelFormat = *pFormat; - + #if DB_LEVEL >= 4 if (pixelFormat.palettizedB) { @@ -480,7 +471,7 @@ void AwBackupTexture::ChoosePixelFormat(AwTl::CreateTextureParms const & _parmsR if (pixelFormat.alphaB) { unsigned alpha_l_shft,alpha_r_shft; - SetBitShifts(&alpha_l_shft,&alpha_r_shft,pixelFormat.ddpf.dwRGBAlphaBitMask); + SetBitShifts(&alpha_l_shft,&alpha_r_shft,pixelFormat.dwRGBAlphaBitMask); db_logf4(("\tchosen %u-bit %u%u%u%u texture format", pixelFormat.bitsPerPixel, @@ -504,19 +495,89 @@ void AwBackupTexture::ChoosePixelFormat(AwTl::CreateTextureParms const & _parmsR { // use display surface format pixelFormat = pfSurfaceFormat; - } #endif + } + +/* Just convert the texture to 32bpp */ + pixelFormat.palettizedB = 0; + pixelFormat.alphaB = 0; + pixelFormat.validB = 1; + pixelFormat.bitsPerPixel = 32; + pixelFormat.redLeftShift = 0; + pixelFormat.greenLeftShift = 8; + pixelFormat.blueLeftShift = 16; + pixelFormat.redRightShift = 0; + pixelFormat.greenRightShift = 0; + pixelFormat.blueRightShift = 0; + pixelFormat.dwRGBAlphaBitMask = 0x00000000; + } +extern "C" { +extern int CreateOGLTexture(D3DTexture *, unsigned char *); +}; + AwTl::SurfUnion AwBackupTexture::CreateTexture(AwTl::CreateTextureParms const & _parmsR) { using namespace AwTl; - fprintf(stderr, "AwBackupTexture::CreateTexture(...) This is where we could convert the image to RGB/RGBA, and so on\n"); - - SurfUnion pRet = static_cast(new D3DTexture); +// fprintf(stderr, "AwBackupTexture::CreateTexture(...) This is where we could convert the image to RGB/RGBA, and so on\n"); - return pRet; + D3DTexture *Tex = new D3DTexture; + + unsigned char *buf = (unsigned char *)malloc(m_nWidth * m_nHeight * 4); + + Colour * paletteP = m_nPaletteSize ? GetPalette() : NULL; + + unsigned y = 0; + bool reversed_rowsB = AreRowsReversed(); + if (reversed_rowsB) + { + y = m_nHeight-1; + } + + for (int i, rowcount = m_nHeight; rowcount; --rowcount, i++) + { + PtrUnion src_rowP = GetRowPtr(y); + db_assert1(src_rowP.voidP); + + // allow loading of the next row from the file + LoadNextRow(src_rowP); + + // loop for copying data to surfaces + { + + { + // are we in the vertical range of this surface? + { + + // convert and copy the section of the row to the direct draw surface +// ConvertRow(pLoadInfo->surface_dataP,pLoadInfo->surface_width,src_rowP,pLoadInfo->left,pLoadInfo->width,paletteP db_code1(DB_COMMA m_nPaletteSize)); + + PtrUnion my_data = &buf[y*m_nWidth*4]; + + ConvertRow(my_data,m_nWidth,src_rowP,0,m_nWidth,paletteP db_code1(DB_COMMA m_nPaletteSize)); + + } + } + } + + // next row + if (reversed_rowsB) + --y; + else + ++y; + + } + +/* temp junk */ + Tex->w = m_nWidth; + Tex->h = m_nHeight; + Tex->data = NULL; + CreateOGLTexture(Tex, buf); /* this will set the id */ + free(buf); + + return static_cast(Tex); #if 0 // which flags to use? @@ -1394,9 +1455,8 @@ namespace AwTl { // CHECK_MEDIA_ERRORS("loading file headers") ON_ERROR_RETURN_NULL("loading file headers") -#if 0 ChoosePixelFormat(rParams); - +#if 0 if (!pixelFormat.validB) db_log3("AwCreateGraphic(): ERROR: pixel format not valid"); if (!driverDesc.ddP || !driverDesc.validB && rParams.loadTextureB) @@ -1406,7 +1466,7 @@ namespace AwTl { ON_ERROR_RETURN_NULL("initializing load") #endif - fprintf(stderr, "TexFileLoader::Load Pixel Format?! It's not implemented!\n"); +// fprintf(stderr, "TexFileLoader::Load Pixel Format?! It's not implemented!\n"); /* TODO */ AllocateBuffers(/* rParams.backupHP ? true : */ false, /* pixelFormat.palettizedB ? ? 1<(&rlcAwBmpLoader_187); - - mfidt.hack += reinterpret_cast(&rlcAwIffLoader_428); - mfidt.hack += reinterpret_cast(&rlcAwIffLoader_429); - mfidt.hack += reinterpret_cast(&rlcAwIffLoader_430); - - mfidt.hack += reinterpret_cast(&rlcAwPpmLoader_229); - mfidt.hack += reinterpret_cast(&rlcAwPgmLoader_230); - mfidt.hack += reinterpret_cast(&rlcAwPbmLoader_231); - - mfidt.hack += reinterpret_cast(&rccIlbmBmhdChunk_4); - mfidt.hack += reinterpret_cast(&rccIlbmCmapChunk_5); - mfidt.hack += reinterpret_cast(&rccIlbmBodyChunk_6); - mfidt.hack += reinterpret_cast(&rccIlbmGrabChunk_7); - } -#endif g_pMagicFileIdTree = &mfidt; MagicFileIdTree * pLayer = g_pMagicFileIdTree; @@ -2014,6 +2055,19 @@ fprintf(stderr, "AwSetPixelFormat(%p, %p)\n", _pfP, _ddpfP); _pfP->palettizedB = true; _pfP->validB = true; + +_pfP->palettizedB = 0; +_pfP->alphaB = 0; +_pfP->validB = 1; +_pfP->bitsPerPixel = 32; +_pfP->redLeftShift = 0; +_pfP->greenLeftShift = 8; +_pfP->blueLeftShift = 16; +_pfP->redRightShift = 0; +_pfP->greenRightShift = 0; +_pfP->blueRightShift = 0; +_pfP->dwRGBAlphaBitMask = 0xFF000000; + return AW_TLE_OK; } diff --git a/src/win95/awtexld.hpp b/src/win95/awtexld.hpp index e39ef39..34e287f 100644 --- a/src/win95/awtexld.hpp +++ b/src/win95/awtexld.hpp @@ -32,12 +32,14 @@ namespace AwTl { unsigned blueLeftShift; unsigned blueRightShift; + unsigned dwRGBAlphaBitMask; // DDPIXELFORMAT ddpf; }; // DO SOMTHING ABOUT THIS extern PixelFormat pixelFormat; - + extern PixelFormat pfSurfaceFormat; + class CreateTextureParms; /********************/ @@ -57,9 +59,7 @@ namespace AwTl { static_cast(_colP->r)>>pixelFormat.redRightShift<(_colP->g)>>pixelFormat.greenRightShift<(_colP->b)>>pixelFormat.blueRightShift<