Threw in texture loading/drawing.

Blending modes (color/texture) are problematic and texture coordinates
aren't yet perfect.
This commit is contained in:
Steven Fuller 2001-08-11 03:36:48 +00:00 committed by Patryk Obara
parent efc384b7b3
commit 9dadcb8024
6 changed files with 184 additions and 82 deletions

View file

@ -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()) {

View file

@ -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
}

View file

@ -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");
}

View file

@ -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;

View file

@ -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<AdditionalPixelFormat> 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<D3DTexture *>(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<SurfUnion>(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<<pixelFormat.bitsPerPixel : */ 0);
@ -1602,25 +1662,6 @@ namespace AwTl {
{
static MagicFileIdTree mfidt;
#ifdef _MSC_VER
// Touch the loaders.
{
mfidt.hack += reinterpret_cast<unsigned>(&rlcAwBmpLoader_187);
mfidt.hack += reinterpret_cast<unsigned>(&rlcAwIffLoader_428);
mfidt.hack += reinterpret_cast<unsigned>(&rlcAwIffLoader_429);
mfidt.hack += reinterpret_cast<unsigned>(&rlcAwIffLoader_430);
mfidt.hack += reinterpret_cast<unsigned>(&rlcAwPpmLoader_229);
mfidt.hack += reinterpret_cast<unsigned>(&rlcAwPgmLoader_230);
mfidt.hack += reinterpret_cast<unsigned>(&rlcAwPbmLoader_231);
mfidt.hack += reinterpret_cast<unsigned>(&rccIlbmBmhdChunk_4);
mfidt.hack += reinterpret_cast<unsigned>(&rccIlbmCmapChunk_5);
mfidt.hack += reinterpret_cast<unsigned>(&rccIlbmBodyChunk_6);
mfidt.hack += reinterpret_cast<unsigned>(&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;
}

View file

@ -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<unsigned>(_colP->r)>>pixelFormat.redRightShift<<pixelFormat.redLeftShift
|static_cast<unsigned>(_colP->g)>>pixelFormat.greenRightShift<<pixelFormat.greenLeftShift
|static_cast<unsigned>(_colP->b)>>pixelFormat.blueRightShift<<pixelFormat.blueLeftShift
/* TODO */
/*|pixelFormat.ddpf.dwRGBAlphaBitMask*/
;
|pixelFormat.dwRGBAlphaBitMask;
}
static inline unsigned DoConv(BYTE const * _colP, Colour const * _paletteP db_code1(DB_COMMA unsigned _paletteSize))
{
@ -224,6 +224,7 @@ namespace AwTl {
*_dstRowP.byteP++ = u.b[1];
*_dstRowP.byteP = u.b[2];
}
break;
}
case 32:
{