2001-08-08 06:14:20 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <GL/glext.h>
|
|
|
|
|
|
|
|
#include "fixer.h"
|
|
|
|
|
|
|
|
#include "3dc.h"
|
|
|
|
#include "platform.h"
|
2001-08-10 20:19:00 +00:00
|
|
|
#include "inline.h"
|
2001-08-08 06:14:20 +00:00
|
|
|
#include "module.h"
|
|
|
|
#include "stratdef.h"
|
|
|
|
#include "projfont.h"
|
|
|
|
#include "krender.h"
|
|
|
|
#include "kshape.h"
|
|
|
|
#include "prototyp.h"
|
|
|
|
#include "d3d_hud.h"
|
2001-08-10 20:19:00 +00:00
|
|
|
#include "avp_userprofile.h"
|
2001-08-11 03:36:48 +00:00
|
|
|
#include "aw.h"
|
2001-08-08 06:14:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
extern IMAGEHEADER ImageHeaderArray[];
|
|
|
|
extern VIEWDESCRIPTORBLOCK *Global_VDB_Ptr;
|
2001-08-10 02:37:25 +00:00
|
|
|
extern unsigned char GammaValues[256];
|
|
|
|
extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
|
2001-08-10 20:19:00 +00:00
|
|
|
extern int SpecialFXImageNumber;
|
2001-08-08 06:14:20 +00:00
|
|
|
|
2001-08-11 03:36:48 +00:00
|
|
|
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;
|
|
|
|
}
|
2001-08-08 06:14:20 +00:00
|
|
|
|
2001-08-10 20:19:00 +00:00
|
|
|
#define TRANSLUCENCY_ONEONE 33
|
|
|
|
void CheckTranslucencyModeIsCorrect(int mode) /* TODO: use correct enum */
|
|
|
|
{
|
|
|
|
switch(RenderPolygon.TranslucencyMode) {
|
|
|
|
case TRANSLUCENCY_OFF:
|
|
|
|
glBlendFunc(GL_ONE, GL_ZERO);
|
|
|
|
break;
|
|
|
|
case TRANSLUCENCY_NORMAL:
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
break;
|
|
|
|
case TRANSLUCENCY_COLOUR:
|
|
|
|
glBlendFunc(GL_ZERO, GL_SRC_COLOR);
|
|
|
|
break;
|
|
|
|
case TRANSLUCENCY_INVCOLOUR:
|
|
|
|
glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
|
|
|
|
break;
|
|
|
|
case TRANSLUCENCY_GLOWING:
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
|
|
|
break;
|
|
|
|
case TRANSLUCENCY_DARKENINGCOLOUR:
|
|
|
|
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
|
|
|
break;
|
|
|
|
case TRANSLUCENCY_JUSTSETZ:
|
|
|
|
glBlendFunc(GL_ZERO, GL_ONE);
|
|
|
|
break;
|
|
|
|
case TRANSLUCENCY_ONEONE:
|
|
|
|
glBlendFunc(GL_ONE, GL_ONE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "RenderPolygon.TranslucencyMode: invalid %d\n", RenderPolygon.TranslucencyMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-08 06:14:20 +00:00
|
|
|
void D3D_ZBufferedGouraudTexturedPolygon_Output(POLYHEADER *inputPolyPtr, RENDERVERTEX *renderVerticesPtr)
|
|
|
|
{
|
2001-08-09 06:23:42 +00:00
|
|
|
#if 1
|
2001-08-08 06:14:20 +00:00
|
|
|
int texoffset;
|
2001-08-11 03:36:48 +00:00
|
|
|
D3DTexture *TextureHandle;
|
2001-08-08 06:14:20 +00:00
|
|
|
int i;
|
2001-08-08 15:49:59 +00:00
|
|
|
GLfloat ZNear, zvalue;
|
2001-08-11 03:36:48 +00:00
|
|
|
// GLfloat ZFar;
|
|
|
|
float RecipW, RecipH;
|
|
|
|
|
|
|
|
// glDisable(GL_TEXTURE_2D);
|
|
|
|
|
2001-08-08 15:49:59 +00:00
|
|
|
ZNear = (GLfloat) (Global_VDB_Ptr->VDB_ClipZ * GlobalScale);
|
2001-08-10 20:19:00 +00:00
|
|
|
// ZFar = 18000.0f; /* TODO: is this good enough? */
|
2001-08-08 06:14:20 +00:00
|
|
|
|
|
|
|
texoffset = inputPolyPtr->PolyColour & ClrTxDefn;
|
|
|
|
if (texoffset) {
|
2001-08-11 03:36:48 +00:00
|
|
|
TextureHandle = (void *)ImageHeaderArray[texoffset].D3DTexture;
|
2001-08-08 06:14:20 +00:00
|
|
|
} else {
|
|
|
|
TextureHandle = CurrTextureHandle;
|
|
|
|
}
|
|
|
|
|
2001-08-09 06:23:42 +00:00
|
|
|
// fprintf(stderr, "D3D_ZBufferedGouraudTexturedPolygon_Output(%p, %p)\n", inputPolyPtr, renderVerticesPtr);
|
|
|
|
// fprintf(stderr, "\tRenderPolygon.NumberOfVertices = %d\n", RenderPolygon.NumberOfVertices);
|
|
|
|
// fprintf(stderr, "\ttexoffset = %d (ptr = %p)\n", texoffset, texoffset ? (void *)ImageHeaderArray[texoffset].D3DHandle : CurrTextureHandle);
|
2001-08-08 15:49:59 +00:00
|
|
|
|
2001-08-10 20:19:00 +00:00
|
|
|
CheckTranslucencyModeIsCorrect(RenderPolygon.TranslucencyMode);
|
2001-08-08 15:49:59 +00:00
|
|
|
|
2001-08-10 02:37:25 +00:00
|
|
|
/*
|
|
|
|
if (SecondaryColorExt)
|
|
|
|
glEnable(GL_COLOR_SUM_EXT);
|
|
|
|
*/
|
2001-08-11 03:36:48 +00:00
|
|
|
RecipW = (1.0f/65536.0f)/128.0f;
|
|
|
|
RecipH = (1.0f/65536.0f)/128.0f;
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, TextureHandle->id);
|
|
|
|
|
2001-08-08 06:14:20 +00:00
|
|
|
glBegin(GL_POLYGON);
|
|
|
|
for (i = 0; i < RenderPolygon.NumberOfVertices; i++) {
|
2001-08-10 02:37:25 +00:00
|
|
|
RENDERVERTEX *vertices = &renderVerticesPtr[i];
|
2001-08-08 06:14:20 +00:00
|
|
|
GLfloat x, y, z;
|
|
|
|
int x1, y1;
|
2001-08-11 03:36:48 +00:00
|
|
|
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);
|
2001-08-08 06:14:20 +00:00
|
|
|
|
2001-08-08 15:49:59 +00: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;
|
|
|
|
x = x1;
|
|
|
|
y = y1;
|
|
|
|
|
2001-08-10 02:37:25 +00:00
|
|
|
// x = (x - 319.0)/319.0;
|
|
|
|
// y = -(y - 239.0)/239.0;
|
|
|
|
x = (x - ScreenDescriptorBlock.SDB_CentreX)/ScreenDescriptorBlock.SDB_CentreX;
|
|
|
|
y = -(y - ScreenDescriptorBlock.SDB_CentreY)/ScreenDescriptorBlock.SDB_CentreY;
|
2001-08-08 15:49:59 +00:00
|
|
|
|
2001-08-09 07:03:00 +00:00
|
|
|
zvalue = vertices->Z+HeadUpDisplayZOffset;
|
2001-08-10 02:37:25 +00:00
|
|
|
zvalue = 1.0 - 2*ZNear/zvalue; /* currently maps [ZNear, inf) to [-1, 1], probably could be more precise with a ZFar */
|
2001-08-10 20:19:00 +00:00
|
|
|
// zvalue = 2.0 * (zvalue - ZNear) / (ZFar - ZNear) - 1.0;
|
2001-08-09 07:03:00 +00:00
|
|
|
z = zvalue;
|
2001-08-08 15:49:59 +00:00
|
|
|
|
2001-08-10 02:37:25 +00:00
|
|
|
glColor4ub(GammaValues[vertices->R], GammaValues[vertices->G], GammaValues[vertices->B], vertices->A);
|
|
|
|
/*
|
|
|
|
if (SecondaryColorExt)
|
|
|
|
glSecondaryColor3ub(GammaValues[vertices->SpecularR], GammaValues[vertices->SpecularG], GammaValues[vertices->SpecularB]);
|
|
|
|
*/
|
2001-08-08 06:14:20 +00:00
|
|
|
glVertex3f(x, y, z);
|
2001-08-11 03:36:48 +00:00
|
|
|
|
2001-08-09 06:23:42 +00:00
|
|
|
// 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);
|
2001-08-09 07:03:00 +00:00
|
|
|
// fprintf(stderr, "GREP: z = %d, znear = %f, zvalue = %f, z = %f\n", vertices->Z, ZNear, zvalue, z);
|
2001-08-08 06:14:20 +00:00
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
CurrTextureHandle = TextureHandle;
|
2001-08-10 02:37:25 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
/* This *tries* to emulate SecondaryColorExt */
|
|
|
|
/* if (!SecondaryColorExt || WantSecondaryColorHack) */ {
|
2001-08-10 20:19:00 +00:00
|
|
|
CheckTranslucencyModeIsCorrect(TRANSLUCENCY_ONEONE);
|
2001-08-10 02:37:25 +00:00
|
|
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
|
|
|
|
glDepthMask(GL_FALSE);
|
2001-08-11 03:36:48 +00:00
|
|
|
glDisable(GL_TEXTURE_2D);
|
2001-08-10 02:37:25 +00:00
|
|
|
|
|
|
|
glBegin(GL_POLYGON);
|
|
|
|
for (i = 0; i < RenderPolygon.NumberOfVertices; i++) {
|
|
|
|
RENDERVERTEX *vertices = &renderVerticesPtr[i];
|
|
|
|
GLfloat x, y, z;
|
|
|
|
int x1, y1;
|
|
|
|
|
|
|
|
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;
|
|
|
|
x = x1;
|
|
|
|
y = y1;
|
|
|
|
|
2001-08-11 03:36:48 +00:00
|
|
|
// 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;
|
|
|
|
|
2001-08-10 02:37:25 +00:00
|
|
|
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;
|
|
|
|
|
2001-08-11 03:36:48 +00:00
|
|
|
glColor4b(GammaValues[vertices->SpecularR], GammaValues[vertices->SpecularG], GammaValues[vertices->SpecularB], 255);
|
2001-08-10 02:37:25 +00:00
|
|
|
glVertex3f(x, y, z);
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
2001-08-11 03:36:48 +00:00
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
2001-08-10 02:37:25 +00:00
|
|
|
}
|
2001-08-09 06:23:42 +00:00
|
|
|
#endif
|
2001-08-08 06:14:20 +00:00
|
|
|
}
|
2001-08-09 22:34:20 +00:00
|
|
|
|
|
|
|
void D3D_Particle_Output(PARTICLE *particlePtr, RENDERVERTEX *renderVerticesPtr)
|
|
|
|
{
|
2001-08-10 20:19:00 +00:00
|
|
|
PARTICLE_DESC *particleDescPtr = &ParticleDescription[particlePtr->ParticleID];
|
|
|
|
int texoffset = SpecialFXImageNumber;
|
|
|
|
GLfloat ZNear;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (particleDescPtr->IsLit && !(particlePtr->ParticleID==PARTICLE_ALIEN_BLOOD && CurrentVisionMode==VISION_MODE_PRED_SEEALIENS) )
|
|
|
|
{
|
|
|
|
int intensity = LightIntensityAtPoint(&particlePtr->Position);
|
|
|
|
|
|
|
|
if (particlePtr->ParticleID==PARTICLE_SMOKECLOUD || particlePtr->ParticleID==PARTICLE_ANDROID_BLOOD)
|
|
|
|
{
|
|
|
|
int r, g, b, a;
|
|
|
|
|
2001-08-10 21:37:14 +00:00
|
|
|
r = (particlePtr->Colour >> 24) & 0xFF;
|
|
|
|
g = (particlePtr->Colour >> 16) & 0xFF;
|
|
|
|
b = (particlePtr->Colour >> 8) & 0xFF;
|
|
|
|
a = (particlePtr->Colour >> 0) & 0xFF;
|
2001-08-10 20:19:00 +00:00
|
|
|
|
|
|
|
glColor4ub(
|
|
|
|
MUL_FIXED(intensity,r),
|
|
|
|
MUL_FIXED(intensity,g),
|
|
|
|
MUL_FIXED(intensity,g),
|
|
|
|
a
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
glColor4ub(
|
|
|
|
MUL_FIXED(intensity,particleDescPtr->RedScale[CurrentVisionMode]),
|
|
|
|
MUL_FIXED(intensity,particleDescPtr->GreenScale[CurrentVisionMode]),
|
|
|
|
MUL_FIXED(intensity,particleDescPtr->BlueScale[CurrentVisionMode]),
|
|
|
|
particleDescPtr->Alpha
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int r, g, b, a;
|
|
|
|
|
2001-08-10 21:37:14 +00:00
|
|
|
r = (particlePtr->Colour >> 24) & 0xFF;
|
|
|
|
g = (particlePtr->Colour >> 16) & 0xFF;
|
|
|
|
b = (particlePtr->Colour >> 8) & 0xFF;
|
|
|
|
a = (particlePtr->Colour >> 0) & 0xFF;
|
2001-08-10 20:19:00 +00:00
|
|
|
|
|
|
|
glColor4ub(r, g, b, a);
|
|
|
|
}
|
|
|
|
if (RAINBOWBLOOD_CHEATMODE) {
|
|
|
|
glColor4ub(FastRandom()&255, FastRandom()&255, FastRandom()&255, particleDescPtr->Alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
ZNear = (GLfloat) (Global_VDB_Ptr->VDB_ClipZ * GlobalScale);
|
|
|
|
|
|
|
|
CheckTranslucencyModeIsCorrect(particleDescPtr->TranslucencyType);
|
|
|
|
|
|
|
|
glBegin(GL_POLYGON);
|
|
|
|
for (i = 0; i < RenderPolygon.NumberOfVertices; i++) {
|
|
|
|
RENDERVERTEX *vertices = &renderVerticesPtr[i];
|
|
|
|
|
|
|
|
int x1, y1;
|
|
|
|
GLfloat x, y, z, zvalue;
|
|
|
|
|
|
|
|
x1 = (vertices->X*(Global_VDB_Ptr->VDB_ProjX+1))/vertices->Z+Global_VDB_Ptr->VDB_CentreX;
|
|
|
|
if (x1<Global_VDB_Ptr->VDB_ClipLeft) {
|
|
|
|
x1=Global_VDB_Ptr->VDB_ClipLeft;
|
|
|
|
} else if (x1>Global_VDB_Ptr->VDB_ClipRight) {
|
|
|
|
x1=Global_VDB_Ptr->VDB_ClipRight;
|
|
|
|
}
|
|
|
|
|
|
|
|
y1 = (vertices->Y*(Global_VDB_Ptr->VDB_ProjY+1))/vertices->Z+Global_VDB_Ptr->VDB_CentreY;
|
|
|
|
if (y1<Global_VDB_Ptr->VDB_ClipUp) {
|
|
|
|
y1=Global_VDB_Ptr->VDB_ClipUp;
|
|
|
|
} else if (y1>Global_VDB_Ptr->VDB_ClipDown) {
|
|
|
|
y1=Global_VDB_Ptr->VDB_ClipDown;
|
|
|
|
}
|
|
|
|
x = x1;
|
|
|
|
y = y1;
|
|
|
|
|
|
|
|
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 */
|
|
|
|
// zvalue = 2.0 * (zvalue - ZNear) / (ZFar - ZNear) - 1.0;
|
|
|
|
z = zvalue;
|
|
|
|
|
|
|
|
glVertex3f(x, y, z);
|
|
|
|
}
|
|
|
|
glEnd();
|
2001-08-09 22:34:20 +00:00
|
|
|
}
|