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;
|
|
|
|
|
|
|
|
|
2001-08-11 21:04:45 +00:00
|
|
|
#define TRANSLUCENCY_ONEONE 33
|
2001-08-11 03:36:48 +00:00
|
|
|
|
2001-08-12 01:26:18 +00:00
|
|
|
static enum TRANSLUCENCY_TYPE CurrentTranslucencyMode = TRANSLUCENCY_OFF; /* opengl state variable */
|
2001-08-11 21:04:45 +00:00
|
|
|
static GLuint CurrentlyBoundTexture = 0; /* opengl state variable */
|
2001-08-11 07:10:38 +00:00
|
|
|
|
2001-08-11 21:04:45 +00:00
|
|
|
static void CheckBoundTextureIsCorrect(GLuint tex)
|
2001-08-11 07:10:38 +00:00
|
|
|
{
|
2001-08-11 21:04:45 +00:00
|
|
|
if (tex == CurrentlyBoundTexture)
|
|
|
|
return;
|
2001-08-11 07:10:38 +00:00
|
|
|
|
2001-08-11 21:04:45 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, tex);
|
2001-08-11 03:36:48 +00:00
|
|
|
|
2001-08-11 21:04:45 +00:00
|
|
|
CurrentlyBoundTexture = tex;
|
2001-08-11 03:36:48 +00:00
|
|
|
}
|
2001-08-11 21:04:45 +00:00
|
|
|
|
2001-08-12 01:26:18 +00:00
|
|
|
static void CheckTranslucencyModeIsCorrect(enum TRANSLUCENCY_TYPE mode)
|
2001-08-10 20:19:00 +00:00
|
|
|
{
|
2001-08-11 21:04:45 +00:00
|
|
|
if (CurrentTranslucencyMode == mode)
|
|
|
|
return;
|
|
|
|
|
2001-08-12 01:26:18 +00:00
|
|
|
switch(mode) {
|
2001-08-10 20:19:00 +00:00
|
|
|
case TRANSLUCENCY_OFF:
|
2001-08-12 01:26:18 +00:00
|
|
|
if (TRIPTASTIC_CHEATMODE||MOTIONBLUR_CHEATMODE) {
|
|
|
|
// glBlendMode(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
|
|
|
|
/* TODO: this may not be properly set... */
|
|
|
|
} else {
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_ONE, GL_ZERO);
|
|
|
|
}
|
2001-08-10 20:19:00 +00:00
|
|
|
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-11 21:04:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-12 01:26:18 +00:00
|
|
|
if (mode != TRANSLUCENCY_OFF && CurrentTranslucencyMode == TRANSLUCENCY_OFF)
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
2001-08-11 21:04:45 +00:00
|
|
|
CurrentTranslucencyMode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SelectPolygonBeginType(int points)
|
|
|
|
{
|
|
|
|
/* switch code that uses this to a triangle only drawer */
|
|
|
|
switch(points) {
|
|
|
|
case 1:
|
|
|
|
glBegin(GL_POINTS);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
glBegin(GL_POLYGON);
|
|
|
|
break;
|
2001-08-10 20:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-11 21:04:45 +00:00
|
|
|
GLuint CreateOGLTexture(D3DTexture *tex, unsigned char *buf)
|
|
|
|
{
|
|
|
|
GLuint h;
|
|
|
|
|
|
|
|
glGenTextures(1, &h);
|
2001-08-12 04:42:44 +00:00
|
|
|
|
|
|
|
/* TODO: d3d code doesn't explicitly enable repeating but some levels (namely predator beginning level waterfall) have clamped textures */
|
2001-08-11 21:04:45 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, h);
|
2001-08-12 04:42:44 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
2001-08-11 21:04:45 +00:00
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
|
2001-08-12 01:26:18 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex->w, tex->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf);
|
2001-08-11 21:04:45 +00:00
|
|
|
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
|
|
|
|
tex->id = h;
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, CurrentlyBoundTexture); /* restore current */
|
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ** */
|
|
|
|
|
|
|
|
void FlushD3DZBuffer()
|
|
|
|
{
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SecondFlushD3DZBuffer()
|
|
|
|
{
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3D_DecalSystem_Setup()
|
|
|
|
{
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3D_DecalSystem_End()
|
|
|
|
{
|
2001-08-12 01:26:18 +00:00
|
|
|
glDepthMask(GL_TRUE);
|
2001-08-11 21:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ** */
|
|
|
|
|
2001-08-08 06:14:20 +00:00
|
|
|
void D3D_ZBufferedGouraudTexturedPolygon_Output(POLYHEADER *inputPolyPtr, RENDERVERTEX *renderVerticesPtr)
|
|
|
|
{
|
|
|
|
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
|
|
|
float RecipW, RecipH;
|
|
|
|
|
|
|
|
|
2001-08-08 15:49:59 +00:00
|
|
|
ZNear = (GLfloat) (Global_VDB_Ptr->VDB_ClipZ * GlobalScale);
|
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-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;
|
|
|
|
|
2001-08-11 21:04:45 +00:00
|
|
|
CheckBoundTextureIsCorrect(TextureHandle->id);
|
2001-08-11 03:36:48 +00:00
|
|
|
|
2001-08-12 04:42:44 +00:00
|
|
|
// glBegin(GL_POLYGON);
|
|
|
|
SelectPolygonBeginType(RenderPolygon.NumberOfVertices);
|
2001-08-08 06:14:20 +00:00
|
|
|
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;
|
2001-08-11 21:04:45 +00:00
|
|
|
GLfloat rhw = 1.0/(float)vertices->Z;
|
|
|
|
|
2001-08-11 03:36:48 +00:00
|
|
|
s = ((float)vertices->U) * RecipW + (1.0f/256.0f);
|
|
|
|
t = ((float)vertices->V) * RecipH + (1.0f/256.0f);
|
2001-08-11 21:04:45 +00:00
|
|
|
|
2001-08-12 04:42:44 +00:00
|
|
|
// if (s < 0.0 || t < 0.0 || s >= 1.0 || t >= 1.0)
|
|
|
|
// fprintf(stderr, "HEY! s = %f, t = %f (%d, %d)\n", s, t, vertices->U, vertices->V);
|
|
|
|
|
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;
|
2001-08-11 21:04:45 +00:00
|
|
|
|
|
|
|
#if 0
|
2001-08-11 07:10:38 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2001-08-11 21:04:45 +00:00
|
|
|
#endif
|
2001-08-08 15:49:59 +00:00
|
|
|
x = x1;
|
|
|
|
y = y1;
|
|
|
|
|
2001-08-10 02:37:25 +00:00
|
|
|
x = (x - ScreenDescriptorBlock.SDB_CentreX)/ScreenDescriptorBlock.SDB_CentreX;
|
|
|
|
y = -(y - ScreenDescriptorBlock.SDB_CentreY)/ScreenDescriptorBlock.SDB_CentreY;
|
2001-08-11 21:04:45 +00:00
|
|
|
|
2001-08-09 07:03:00 +00:00
|
|
|
zvalue = vertices->Z+HeadUpDisplayZOffset;
|
2001-08-11 21:04:45 +00:00
|
|
|
z = 1.0 - 2*ZNear/zvalue;
|
|
|
|
|
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-11 21:04:45 +00:00
|
|
|
|
|
|
|
/* they both work. */
|
|
|
|
#if 0
|
|
|
|
glTexCoord4f(s*rhw, t*rhw, 0, rhw);
|
2001-08-08 06:14:20 +00:00
|
|
|
glVertex3f(x, y, z);
|
2001-08-11 21:04:45 +00:00
|
|
|
#else
|
|
|
|
glTexCoord2f(s, t);
|
|
|
|
glVertex4f(x/rhw, y/rhw, z/rhw, 1/rhw);
|
|
|
|
#endif
|
2001-08-11 03:36:48 +00:00
|
|
|
|
2001-08-08 06:14:20 +00:00
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
CurrTextureHandle = TextureHandle;
|
2001-08-10 02:37:25 +00:00
|
|
|
|
2001-08-11 21:04:45 +00:00
|
|
|
#if 0
|
|
|
|
/* note: the specular color doesn't seem to be enabled in the original d3d code? */
|
|
|
|
/* couldn't find the feature in the voodoo 1 specs (the minimum required card) */
|
2001-08-10 02:37:25 +00:00
|
|
|
/* 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 - 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
|
|
|
|
2001-08-12 06:52:36 +00:00
|
|
|
void D3D_Decal_Output(DECAL *decalPtr, RENDERVERTEX *renderVerticesPtr)
|
|
|
|
{
|
|
|
|
DECAL_DESC *decalDescPtr = &DecalDescription[decalPtr->DecalID];
|
|
|
|
int texoffset;
|
|
|
|
D3DTexture *TextureHandle;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
float ZNear;
|
|
|
|
float RecipW, RecipH;
|
|
|
|
int r, g, b, a;
|
|
|
|
|
|
|
|
ZNear = (float) (Global_VDB_Ptr->VDB_ClipZ * GlobalScale);
|
|
|
|
|
|
|
|
CheckTranslucencyModeIsCorrect(decalDescPtr->TranslucencyType);
|
|
|
|
|
|
|
|
if (decalPtr->DecalID == DECAL_FMV) {
|
|
|
|
/* not (yet) implemented */
|
|
|
|
return;
|
|
|
|
} else if (decalPtr->DecalID == DECAL_SHAFTOFLIGHT||decalPtr->DecalID == DECAL_SHAFTOFLIGHT_OUTER) {
|
|
|
|
CheckBoundTextureIsCorrect(0);
|
|
|
|
|
|
|
|
RecipW = 1.0 / 256.0; /* ignored */
|
|
|
|
RecipH = 1.0 / 256.0;
|
|
|
|
} else {
|
|
|
|
texoffset = SpecialFXImageNumber;
|
|
|
|
|
|
|
|
TextureHandle = ImageHeaderArray[texoffset].D3DTexture;
|
|
|
|
|
|
|
|
if (TextureHandle->w == 256) {
|
|
|
|
RecipW = 1.0 / 256.0;
|
|
|
|
} else {
|
|
|
|
float width = (float) TextureHandle->w;
|
|
|
|
RecipW = 1.0 / width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TextureHandle->h == 256) {
|
|
|
|
RecipH = 1.0 / 256.0;
|
|
|
|
} else {
|
|
|
|
float height = (float) TextureHandle->h;
|
|
|
|
RecipH = 1.0 / height;
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckBoundTextureIsCorrect(TextureHandle->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (decalDescPtr->IsLit) {
|
|
|
|
int intensity = LightIntensityAtPoint(decalPtr->Vertices);
|
|
|
|
|
|
|
|
r = MUL_FIXED(intensity,decalDescPtr->RedScale[CurrentVisionMode]);
|
|
|
|
g = MUL_FIXED(intensity,decalDescPtr->GreenScale[CurrentVisionMode]);
|
|
|
|
b = MUL_FIXED(intensity,decalDescPtr->BlueScale[CurrentVisionMode]);
|
|
|
|
a = decalDescPtr->Alpha;
|
|
|
|
} else {
|
|
|
|
r = decalDescPtr->RedScale[CurrentVisionMode];
|
|
|
|
g = decalDescPtr->GreenScale[CurrentVisionMode];
|
|
|
|
b = decalDescPtr->BlueScale[CurrentVisionMode];
|
|
|
|
a = decalDescPtr->Alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RAINBOWBLOOD_CHEATMODE) {
|
|
|
|
r = FastRandom()&255;
|
|
|
|
g = FastRandom()&255;
|
|
|
|
b = FastRandom()&255;
|
|
|
|
a = decalDescPtr->Alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
glColor4ub(r, g, b, a);
|
|
|
|
|
|
|
|
SelectPolygonBeginType(RenderPolygon.NumberOfVertices);
|
|
|
|
for (i = 0; i < RenderPolygon.NumberOfVertices; i++) {
|
|
|
|
RENDERVERTEX *vertices = &renderVerticesPtr[i];
|
|
|
|
|
|
|
|
GLfloat x, y, z, zvalue;
|
|
|
|
GLfloat s, t, rhw;
|
|
|
|
int x1, y1;
|
|
|
|
|
|
|
|
rhw = 1.0 / vertices->Z;
|
|
|
|
|
|
|
|
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;
|
|
|
|
#if 0
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
x = x1;
|
|
|
|
y = y1;
|
|
|
|
|
|
|
|
x = (x - ScreenDescriptorBlock.SDB_CentreX)/ScreenDescriptorBlock.SDB_CentreX;
|
|
|
|
y = -(y - ScreenDescriptorBlock.SDB_CentreY)/ScreenDescriptorBlock.SDB_CentreY;
|
|
|
|
|
|
|
|
s = ((float)(vertices->U>>16)+.5) * RecipW;
|
|
|
|
t = ((float)(vertices->V>>16)+.5) * RecipH;
|
|
|
|
|
|
|
|
zvalue = vertices->Z+HeadUpDisplayZOffset;
|
|
|
|
z = 1.0 - 2*ZNear/zvalue;
|
|
|
|
|
|
|
|
// zvalue = vertices->Z+HeadUpDisplayZOffset;
|
|
|
|
// zvalue = ((zvalue-ZNear)/zvalue);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
glTexCoord4f(s*rhw, t*rhw, 0, rhw);
|
|
|
|
glVertex3f(x, y, z);
|
|
|
|
#else
|
|
|
|
glTexCoord2f(s, t);
|
|
|
|
glVertex4f(x/rhw, y/rhw, z/rhw, 1/rhw);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-08-09 22:34:20 +00:00
|
|
|
void D3D_Particle_Output(PARTICLE *particlePtr, RENDERVERTEX *renderVerticesPtr)
|
|
|
|
{
|
2001-08-12 01:26:18 +00:00
|
|
|
PARTICLE_DESC *particleDescPtr = &ParticleDescription[particlePtr->ParticleID];
|
2001-08-10 20:19:00 +00:00
|
|
|
int texoffset = SpecialFXImageNumber;
|
|
|
|
GLfloat ZNear;
|
|
|
|
int i;
|
2001-08-11 07:10:38 +00:00
|
|
|
float RecipW, RecipH;
|
|
|
|
|
|
|
|
D3DTexture *TextureHandle;
|
2001-08-12 01:26:18 +00:00
|
|
|
|
2001-08-11 07:10:38 +00:00
|
|
|
TextureHandle = ImageHeaderArray[texoffset].D3DTexture;
|
|
|
|
|
2001-08-11 21:04:45 +00:00
|
|
|
ZNear = (GLfloat) (Global_VDB_Ptr->VDB_ClipZ * GlobalScale);
|
|
|
|
|
|
|
|
CheckBoundTextureIsCorrect(TextureHandle->id);
|
|
|
|
CheckTranslucencyModeIsCorrect(particleDescPtr->TranslucencyType);
|
2001-08-12 01:26:18 +00:00
|
|
|
|
2001-08-11 07:10:38 +00:00
|
|
|
// if(ImageHeaderArray[texoffset].ImageWidth==256) {
|
|
|
|
if (TextureHandle->w == 256) {
|
|
|
|
RecipW = 1.0 / 256.0;
|
|
|
|
} else {
|
|
|
|
// float width = (float) ImageHeaderArray[texoffset].ImageWidth;
|
|
|
|
float width = (float) TextureHandle->w;
|
|
|
|
|
|
|
|
RecipW = (1.0 / width);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if(ImageHeaderArray[texoffset].ImageHeight==256) {
|
|
|
|
if (TextureHandle->h == 256) {
|
|
|
|
RecipH = 1.0 / 256.0;
|
|
|
|
} else {
|
|
|
|
// float height = (float) ImageHeaderArray[texoffset].ImageHeight;
|
|
|
|
float height = (float) TextureHandle->h;
|
|
|
|
|
|
|
|
RecipH = (1.0 / height);
|
|
|
|
}
|
2001-08-10 20:19:00 +00:00
|
|
|
|
|
|
|
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-12 02:30:17 +00:00
|
|
|
/* this should be OK. (ColourComponents was RGBA while RGBA_MAKE is BGRA (little endian) */
|
2001-08-12 01:26:18 +00:00
|
|
|
r = (particlePtr->Colour >> 0) & 0xFF;
|
|
|
|
g = (particlePtr->Colour >> 8) & 0xFF;
|
|
|
|
b = (particlePtr->Colour >> 16) & 0xFF;
|
|
|
|
a = (particlePtr->Colour >> 24) & 0xFF;
|
2001-08-10 20:19:00 +00:00
|
|
|
|
|
|
|
glColor4ub(
|
|
|
|
MUL_FIXED(intensity,r),
|
|
|
|
MUL_FIXED(intensity,g),
|
2001-08-12 01:26:18 +00:00
|
|
|
MUL_FIXED(intensity,b),
|
2001-08-10 20:19:00 +00:00
|
|
|
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-12 02:30:17 +00:00
|
|
|
b = (particlePtr->Colour >> 0) & 0xFF;
|
2001-08-12 01:26:18 +00:00
|
|
|
g = (particlePtr->Colour >> 8) & 0xFF;
|
2001-08-12 02:30:17 +00:00
|
|
|
r = (particlePtr->Colour >> 16) & 0xFF;
|
2001-08-12 01:26:18 +00:00
|
|
|
a = (particlePtr->Colour >> 24) & 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);
|
|
|
|
}
|
2001-08-11 21:04:45 +00:00
|
|
|
|
|
|
|
//glBegin(GL_POLYGON);
|
2001-08-12 04:42:44 +00:00
|
|
|
SelectPolygonBeginType(RenderPolygon.NumberOfVertices);
|
2001-08-10 20:19:00 +00:00
|
|
|
for (i = 0; i < RenderPolygon.NumberOfVertices; i++) {
|
|
|
|
RENDERVERTEX *vertices = &renderVerticesPtr[i];
|
|
|
|
|
|
|
|
int x1, y1;
|
2001-08-11 21:04:45 +00:00
|
|
|
GLfloat x, y, z;
|
2001-08-11 07:10:38 +00:00
|
|
|
GLfloat s, t;
|
2001-08-11 21:04:45 +00:00
|
|
|
GLfloat rhw = 1/(float)vertices->Z;
|
2001-08-11 07:10:38 +00:00
|
|
|
|
|
|
|
s = ((float)(vertices->U>>16)+.5) * RecipW;
|
|
|
|
t = ((float)(vertices->V>>16)+.5) * RecipH;
|
2001-08-11 21:04:45 +00:00
|
|
|
|
2001-08-10 20:19:00 +00:00
|
|
|
|
|
|
|
x1 = (vertices->X*(Global_VDB_Ptr->VDB_ProjX+1))/vertices->Z+Global_VDB_Ptr->VDB_CentreX;
|
2001-08-11 21:04:45 +00:00
|
|
|
y1 = (vertices->Y*(Global_VDB_Ptr->VDB_ProjY+1))/vertices->Z+Global_VDB_Ptr->VDB_CentreY;
|
|
|
|
|
|
|
|
#if 0
|
2001-08-10 20:19:00 +00:00
|
|
|
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;
|
|
|
|
}
|
2001-08-11 21:04:45 +00:00
|
|
|
|
2001-08-10 20:19:00 +00:00
|
|
|
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;
|
|
|
|
}
|
2001-08-11 21:04:45 +00:00
|
|
|
#endif
|
|
|
|
|
2001-08-10 20:19:00 +00:00
|
|
|
x = x1;
|
|
|
|
y = y1;
|
|
|
|
|
|
|
|
x = (x - ScreenDescriptorBlock.SDB_CentreX)/ScreenDescriptorBlock.SDB_CentreX;
|
|
|
|
y = -(y - ScreenDescriptorBlock.SDB_CentreY)/ScreenDescriptorBlock.SDB_CentreY;
|
|
|
|
|
2001-08-11 07:10:38 +00:00
|
|
|
if (particleDescPtr->IsDrawnInFront) {
|
2001-08-11 21:04:45 +00:00
|
|
|
z = -1.0f;
|
2001-08-11 07:10:38 +00:00
|
|
|
} else if (particleDescPtr->IsDrawnAtBack) {
|
2001-08-11 21:04:45 +00:00
|
|
|
z = 1.0f;
|
2001-08-11 07:10:38 +00:00
|
|
|
} else {
|
2001-08-11 21:04:45 +00:00
|
|
|
z = 1.0 - 2*ZNear/((float)vertices->Z); /* currently maps [ZNear, inf) to [-1, 1], probably could be more precise with a ZFar */
|
2001-08-11 07:10:38 +00:00
|
|
|
}
|
2001-08-11 21:04:45 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
glTexCoord4f(s*rhw, t*rhw, 0, rhw);
|
2001-08-10 20:19:00 +00:00
|
|
|
glVertex3f(x, y, z);
|
2001-08-11 21:04:45 +00:00
|
|
|
#else
|
|
|
|
glTexCoord2f(s, t);
|
|
|
|
glVertex4f(x/rhw, y/rhw, z/rhw, 1/rhw);
|
|
|
|
#endif
|
2001-08-10 20:19:00 +00:00
|
|
|
}
|
|
|
|
glEnd();
|
2001-08-09 22:34:20 +00:00
|
|
|
}
|
2001-08-12 04:42:44 +00:00
|
|
|
|
|
|
|
void D3D_PredatorThermalVisionPolygon_Output(POLYHEADER *inputPolyPtr, RENDERVERTEX *renderVerticesPtr)
|
|
|
|
{
|
|
|
|
float ZNear;
|
|
|
|
int i;
|
|
|
|
ZNear = (float) (Global_VDB_Ptr->VDB_ClipZ * GlobalScale);
|
|
|
|
|
|
|
|
CheckBoundTextureIsCorrect(0); /* disable texturing */
|
|
|
|
CheckTranslucencyModeIsCorrect(TRANSLUCENCY_OFF);
|
|
|
|
|
|
|
|
SelectPolygonBeginType(RenderPolygon.NumberOfVertices);
|
|
|
|
for (i = 0; i < RenderPolygon.NumberOfVertices; i++) {
|
|
|
|
RENDERVERTEX *vertices = &renderVerticesPtr[i];
|
|
|
|
|
|
|
|
int x1, y1;
|
|
|
|
GLfloat x, y, z;
|
|
|
|
float rhw, zvalue;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
x = x1;
|
|
|
|
y = y1;
|
|
|
|
|
|
|
|
x = (x - ScreenDescriptorBlock.SDB_CentreX)/ScreenDescriptorBlock.SDB_CentreX;
|
|
|
|
y = -(y - ScreenDescriptorBlock.SDB_CentreY)/ScreenDescriptorBlock.SDB_CentreY;
|
|
|
|
|
|
|
|
zvalue = vertices->Z+HeadUpDisplayZOffset;
|
|
|
|
z = 1.0 - 2*ZNear/zvalue;
|
|
|
|
|
|
|
|
// zvalue = vertices->Z+HeadUpDisplayZOffset;
|
|
|
|
// zvalue = ((zvalue-ZNear)/zvalue);
|
|
|
|
|
|
|
|
rhw = 1.0/(float)vertices->Z;
|
|
|
|
|
|
|
|
glColor4ub(vertices->R, vertices->G, vertices->B, vertices->A);
|
|
|
|
glVertex4f(x/rhw, y/rhw, z/rhw, 1/rhw);
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3D_PredatorScreenInversionOverlay()
|
|
|
|
{
|
|
|
|
CheckTranslucencyModeIsCorrect(TRANSLUCENCY_DARKENINGCOLOUR);
|
|
|
|
CheckBoundTextureIsCorrect(0);
|
|
|
|
glDepthFunc(GL_ALWAYS);
|
|
|
|
|
|
|
|
SelectPolygonBeginType(3); /* triangles */
|
|
|
|
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
glVertex3f(-1.0f, -1.0f, 1.0f);
|
|
|
|
glVertex3f( 1.0f, -1.0f, 1.0f);
|
|
|
|
glVertex3f(-1.0f, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
glVertex3f( 1.0f, -1.0f, 0.0f);
|
|
|
|
glVertex3f( 1.0f, 1.0f, 0.0f);
|
|
|
|
glVertex3f(-1.0f, 1.0f, 0.0f);
|
|
|
|
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
}
|
2001-08-12 06:52:36 +00:00
|
|
|
|
|
|
|
void D3D_HUD_Setup()
|
|
|
|
{
|
|
|
|
CheckTranslucencyModeIsCorrect(TRANSLUCENCY_GLOWING);
|
|
|
|
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void D3D_HUDQuad_Output(int imageNumber, struct VertexTag *quadVerticesPtr, unsigned int colour)
|
|
|
|
{
|
|
|
|
float RecipW, RecipH;
|
|
|
|
int i;
|
|
|
|
D3DTexture *tex = ImageHeaderArray[imageNumber].D3DTexture;
|
|
|
|
GLfloat x[4], y[4], s[4], t[4];
|
|
|
|
int r, g, b, a;
|
|
|
|
|
|
|
|
CheckTranslucencyModeIsCorrect(TRANSLUCENCY_GLOWING);
|
|
|
|
CheckBoundTextureIsCorrect(tex->id);
|
|
|
|
|
|
|
|
if (tex->w == 128) {
|
|
|
|
RecipW = 1.0f / 128.0f;
|
|
|
|
} else {
|
|
|
|
float width = (float) tex->w;
|
|
|
|
RecipW = (1.0f / width);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tex->h == 128) {
|
|
|
|
RecipH = 1.0f / 128.0f;
|
|
|
|
} else {
|
|
|
|
float height = (float) tex->h;
|
|
|
|
RecipH = (1.0f / height);
|
|
|
|
}
|
|
|
|
|
|
|
|
b = (colour >> 0) & 0xFF;
|
|
|
|
g = (colour >> 8) & 0xFF;
|
|
|
|
r = (colour >> 16) & 0xFF;
|
|
|
|
a = (colour >> 24) & 0xFF;
|
|
|
|
|
|
|
|
glColor4ub(r, g, b, a);
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
x[i] = quadVerticesPtr[i].X;
|
|
|
|
x[i] = (x[i] - ScreenDescriptorBlock.SDB_CentreX)/ScreenDescriptorBlock.SDB_CentreX;
|
|
|
|
y[i] = quadVerticesPtr[i].Y;
|
|
|
|
y[i] = -(y[i] - ScreenDescriptorBlock.SDB_CentreY)/ScreenDescriptorBlock.SDB_CentreY;
|
|
|
|
|
|
|
|
s[i] = ((float)quadVerticesPtr[i].U)*RecipW;
|
|
|
|
t[i] = ((float)quadVerticesPtr[i].V)*RecipH;
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectPolygonBeginType(3); /* triangles */
|
|
|
|
|
|
|
|
glTexCoord2f(s[0], t[0]);
|
|
|
|
glVertex3f(x[0], y[0], -1.0f);
|
|
|
|
glTexCoord2f(s[1], t[1]);
|
|
|
|
glVertex3f(x[1], y[1], -1.0f);
|
|
|
|
glTexCoord2f(s[3], t[3]);
|
|
|
|
glVertex3f(x[3], y[3], -1.0f);
|
|
|
|
|
|
|
|
glTexCoord2f(s[1], t[1]);
|
|
|
|
glVertex3f(x[1], y[1], -1.0f);
|
|
|
|
glTexCoord2f(s[2], t[2]);
|
|
|
|
glVertex3f(x[2], y[2], -1.0f);
|
|
|
|
glTexCoord2f(s[3], t[3]);
|
|
|
|
glVertex3f(x[3], y[3], -1.0f);
|
|
|
|
|
|
|
|
glEnd();
|
|
|
|
}
|