2007-01-15 12:09:25 -08:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
|
|
|
Copyright (C) 2005-2007 Warzone Resurrection Project
|
|
|
|
|
|
|
|
Warzone 2100 is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Warzone 2100 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-06-28 10:47:08 -07:00
|
|
|
/***************************************************************************/
|
|
|
|
/*
|
|
|
|
* piedraw.c
|
|
|
|
*
|
|
|
|
* updated render routines for 3D coloured shaded transparency rendering
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
#include <string.h>
|
2006-08-06 10:51:01 -07:00
|
|
|
#include <SDL/SDL_opengl.h>
|
2006-09-23 11:52:52 -07:00
|
|
|
#include <SDL/SDL_video.h>
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2006-06-02 12:34:58 -07:00
|
|
|
#include "lib/framework/frame.h"
|
|
|
|
#include "lib/ivis_common/ivisdef.h"
|
|
|
|
#include "lib/ivis_common/imd.h"
|
|
|
|
#include "lib/ivis_common/rendmode.h"
|
|
|
|
#include "lib/ivis_common/piefunc.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
#include "piematrix.h"
|
2006-06-02 12:34:58 -07:00
|
|
|
#include "lib/ivis_common/tex.h"
|
|
|
|
#include "lib/ivis_common/piedef.h"
|
|
|
|
#include "lib/ivis_common/piestate.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
#include "pietexture.h"
|
2006-06-02 12:34:58 -07:00
|
|
|
#include "lib/ivis_common/pieclip.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-03-24 15:53:18 -07:00
|
|
|
/// Stores the from and to verticles from an edge
|
|
|
|
typedef struct edge_
|
|
|
|
{
|
|
|
|
int from, to;
|
|
|
|
} EDGE;
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
extern BOOL drawing_interface;
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/*
|
|
|
|
* OpenGL extensions for shadows
|
|
|
|
*/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2007-03-28 08:08:57 -07:00
|
|
|
BOOL check_extension(const char* extension_name)
|
2007-02-17 14:29:21 -08:00
|
|
|
{
|
2006-08-30 08:06:49 -07:00
|
|
|
const char *extension_list = (const char *)glGetString(GL_EXTENSIONS);
|
2007-06-28 10:47:08 -07:00
|
|
|
unsigned int extension_name_length = strlen(extension_name);
|
2006-08-30 08:06:49 -07:00
|
|
|
const char *tmp = extension_list;
|
2007-06-28 10:47:08 -07:00
|
|
|
unsigned int first_extension_length;
|
|
|
|
|
|
|
|
if (!extension_name || !extension_list) return FALSE;
|
|
|
|
|
|
|
|
while (tmp[0]) {
|
|
|
|
first_extension_length = strcspn(tmp, " ");
|
|
|
|
|
|
|
|
if ( extension_name_length == first_extension_length
|
|
|
|
&& strncmp(extension_name, tmp, first_extension_length) == 0) {
|
2006-08-23 08:27:20 -07:00
|
|
|
debug( LOG_3D, "%s is supported.\n", extension_name );
|
2007-06-28 10:47:08 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
tmp += first_extension_length + 1;
|
|
|
|
}
|
|
|
|
|
2006-08-23 08:27:20 -07:00
|
|
|
debug( LOG_3D, "%s is not supported.\n", extension_name );
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// EXT_stencil_two_side
|
|
|
|
#ifndef GL_EXT_stencil_two_side
|
|
|
|
#define GL_STENCIL_TEST_TWO_SIDE_EXT 0x8910
|
|
|
|
#define GL_ACTIVE_STENCIL_FACE_EXT 0x8911
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GL_EXT_stencil_two_side
|
|
|
|
#define GL_EXT_stencil_two_side 1
|
|
|
|
typedef void (APIENTRY * PFNGLACTIVESTENCILFACEEXTPROC) (GLenum face);
|
|
|
|
#endif
|
|
|
|
|
2007-04-30 13:42:18 -07:00
|
|
|
#ifndef WZ_OS_MAC
|
2006-08-12 11:23:39 -07:00
|
|
|
PFNGLACTIVESTENCILFACEEXTPROC glActiveStencilFaceEXT;
|
2007-04-30 13:42:18 -07:00
|
|
|
#endif
|
2006-08-12 11:23:39 -07:00
|
|
|
|
2007-03-13 12:34:06 -07:00
|
|
|
/// Check if we can use one-pass stencil in the shadow draw code
|
2007-03-13 13:49:03 -07:00
|
|
|
static BOOL stencil_one_pass(void)
|
2007-02-17 14:29:21 -08:00
|
|
|
{
|
2007-03-13 12:34:06 -07:00
|
|
|
// tribool, -1: uninitialized, 0: FALSE, 1: TRUE
|
|
|
|
static int can_do_stencil_one_pass = -1;
|
|
|
|
|
|
|
|
if (can_do_stencil_one_pass < 0) {
|
|
|
|
can_do_stencil_one_pass = 0; // can't use it until we decide otherwise
|
2007-03-16 09:20:16 -07:00
|
|
|
|
2007-03-13 12:34:06 -07:00
|
|
|
// let's check if we have the needed extensions
|
2007-04-30 13:42:18 -07:00
|
|
|
#ifdef WZ_OS_MAC
|
|
|
|
can_do_stencil_one_pass = 1;
|
|
|
|
#else
|
2007-03-13 12:34:06 -07:00
|
|
|
if( check_extension("GL_EXT_stencil_two_side")
|
|
|
|
&& check_extension("GL_EXT_stencil_wrap"))
|
|
|
|
{
|
|
|
|
// retrieve the function pointer
|
|
|
|
glActiveStencilFaceEXT = (PFNGLACTIVESTENCILFACEEXTPROC) SDL_GL_GetProcAddress("glActiveStencilFaceEXT");
|
|
|
|
if(glActiveStencilFaceEXT)
|
|
|
|
{
|
|
|
|
// all went well
|
|
|
|
can_do_stencil_one_pass = 1;
|
|
|
|
}
|
|
|
|
}
|
2007-04-30 13:42:18 -07:00
|
|
|
#endif /* WZ_OS_MAC */
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2007-03-13 12:34:06 -07:00
|
|
|
return (1 == can_do_stencil_one_pass); // to get the types right
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/*
|
|
|
|
* Local Definitions
|
|
|
|
*/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/*
|
|
|
|
* Local Variables
|
|
|
|
*/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2007-04-10 03:47:20 -07:00
|
|
|
static Vector3f scrPoints[pie_MAX_POINTS];
|
2007-05-21 12:56:07 -07:00
|
|
|
static PIEVERTEXF pieVrts[pie_MAX_POLY_VERTS];
|
2007-06-28 10:47:08 -07:00
|
|
|
static SDWORD pieCount = 0;
|
|
|
|
static SDWORD tileCount = 0;
|
|
|
|
static SDWORD polyCount = 0;
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/*
|
|
|
|
* Local ProtoTypes
|
|
|
|
*/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
//pievertex draw poly (low level) //all modes from PIEVERTEX data
|
2007-03-24 15:53:18 -07:00
|
|
|
static inline void pie_PiePoly(PIEPOLY *poly, BOOL bClip);
|
|
|
|
static inline void pie_PiePolyFrame(PIEPOLY *poly, SDWORD frame, BOOL bClip);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/*
|
|
|
|
* Source
|
|
|
|
*/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
static BOOL lighting = FALSE;
|
2006-02-28 06:04:59 -08:00
|
|
|
static BOOL shadows = FALSE;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-05-26 11:25:15 -07:00
|
|
|
void pie_BeginLighting(const Vector3f * light)
|
2007-02-17 14:29:21 -08:00
|
|
|
{
|
2007-05-26 11:25:15 -07:00
|
|
|
const float pos[4] = {light->x, light->y, light->z, 0.0f};
|
|
|
|
const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
2007-05-29 07:09:10 -07:00
|
|
|
const float ambient[4] = {0.3f, 0.3f, 0.3f, 1.0f};
|
|
|
|
const float diffuse[4] = {0.8f, 0.8f, 0.8f, 1.0f};
|
|
|
|
const float specular[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, zero);
|
|
|
|
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
|
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, pos);
|
|
|
|
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
|
|
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
|
|
|
|
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
|
2007-05-29 07:10:32 -07:00
|
|
|
lighting = TRUE;
|
2006-02-28 06:04:59 -08:00
|
|
|
shadows = TRUE;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2007-02-17 14:29:21 -08:00
|
|
|
void pie_EndLighting(void)
|
|
|
|
{
|
2006-02-28 06:04:59 -08:00
|
|
|
shadows = FALSE;
|
2005-11-29 08:20:35 -08:00
|
|
|
lighting = FALSE;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-24 15:53:18 -07:00
|
|
|
static inline void
|
2007-05-26 13:49:35 -07:00
|
|
|
pie_Polygon(SDWORD numVerts, PIEVERTEXF* pVrts, BOOL light)
|
2006-02-18 10:54:37 -08:00
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
SDWORD i;
|
|
|
|
|
2007-05-21 12:42:05 -07:00
|
|
|
if (numVerts < 1)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
return;
|
2007-05-21 12:42:05 -07:00
|
|
|
}
|
|
|
|
else if (numVerts == 1)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
glBegin(GL_POINTS);
|
2007-05-21 12:42:05 -07:00
|
|
|
}
|
|
|
|
else if (numVerts == 2)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
glBegin(GL_LINE_STRIP);
|
2007-05-21 12:42:05 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (light)
|
|
|
|
{
|
2007-05-26 11:25:15 -07:00
|
|
|
float ambient[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
|
|
|
float diffuse[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
|
|
|
float specular[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
2005-12-26 22:12:51 -08:00
|
|
|
float shininess = 10;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2006-12-17 10:18:06 -08:00
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_NORMALIZE);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
|
|
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
|
|
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
|
|
|
|
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
|
|
|
|
}
|
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
2007-05-21 12:42:05 -07:00
|
|
|
if (light)
|
|
|
|
{
|
|
|
|
Vector3f p1 = { pVrts[0].sx, pVrts[0].sy, pVrts[0].sz },
|
|
|
|
p2 = { pVrts[1].sx, pVrts[1].sy, pVrts[1].sz },
|
|
|
|
p3 = { pVrts[2].sx, pVrts[2].sy, pVrts[2].sz },
|
|
|
|
v1, v2, n;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-03-16 09:20:16 -07:00
|
|
|
Vector3f_Sub(&v1, &p3, &p1);
|
|
|
|
Vector3f_Sub(&v2, &p2, &p1);
|
|
|
|
Vector3f_CP(&n, &v1, &v2);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-05-26 12:29:36 -07:00
|
|
|
glNormal3f(n.x, n.y, n.z);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|
2007-05-21 12:42:05 -07:00
|
|
|
for (i = 0; i < numVerts; i++)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
glColor4ub(pVrts[i].light.byte.r, pVrts[i].light.byte.g, pVrts[i].light.byte.b, pVrts[i].light.byte.a);
|
2007-05-26 13:49:35 -07:00
|
|
|
glTexCoord2f(pVrts[i].tu, pVrts[i].tv);
|
2007-06-28 10:47:08 -07:00
|
|
|
glVertex3f(pVrts[i].sx, pVrts[i].sy, pVrts[i].sz);
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* pie_Draw3dShape
|
|
|
|
*
|
|
|
|
* Project and render a pumpkin image to render surface
|
|
|
|
* Will support zbuffering, texturing, coloured lighting and alpha effects
|
2006-02-18 10:54:37 -08:00
|
|
|
* Avoids recalculating vertex projections for every poly
|
2007-06-28 10:47:08 -07:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
float matrix[16];
|
|
|
|
iIMDShape* shape;
|
|
|
|
int flag;
|
|
|
|
int flag_data;
|
2007-05-26 11:25:15 -07:00
|
|
|
Vector3f light;
|
2007-06-28 10:47:08 -07:00
|
|
|
} shadowcasting_shape_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
float matrix[16];
|
|
|
|
iIMDShape* shape;
|
|
|
|
int frame;
|
|
|
|
PIELIGHT colour;
|
|
|
|
PIELIGHT specular;
|
|
|
|
int flag;
|
|
|
|
int flag_data;
|
|
|
|
} transluscent_shape_t;
|
|
|
|
|
|
|
|
static shadowcasting_shape_t* scshapes = NULL;
|
|
|
|
static unsigned int scshapes_size = 0;
|
|
|
|
static unsigned int nb_scshapes = 0;
|
|
|
|
static transluscent_shape_t* tshapes = NULL;
|
|
|
|
static unsigned int tshapes_size = 0;
|
|
|
|
static unsigned int nb_tshapes = 0;
|
|
|
|
|
2007-05-21 11:57:11 -07:00
|
|
|
static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELIGHT specular, int pieFlag, int pieFlagData)
|
2007-02-17 14:29:21 -08:00
|
|
|
{
|
2007-06-02 16:01:29 -07:00
|
|
|
unsigned int n;
|
2007-05-21 12:56:07 -07:00
|
|
|
Vector3f *pVertices, *pPixels;
|
2007-05-21 11:57:11 -07:00
|
|
|
iIMDPoly *pPolys;
|
|
|
|
PIEPOLY piePoly;
|
|
|
|
VERTEXID *index;
|
|
|
|
BOOL light = lighting;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Set tranlucency */
|
2007-05-21 11:57:11 -07:00
|
|
|
if (pieFlag & pie_ADDITIVE)
|
|
|
|
{ //Assume also translucent
|
2007-06-28 10:47:08 -07:00
|
|
|
pie_SetFogStatus(FALSE);
|
|
|
|
pie_SetRendMode(REND_ADDITIVE_TEX);
|
|
|
|
colour.byte.a = (UBYTE)pieFlagData;
|
|
|
|
pie_SetBilinear(TRUE);
|
|
|
|
light = FALSE;
|
2007-05-21 11:57:11 -07:00
|
|
|
}
|
|
|
|
else if (pieFlag & pie_TRANSLUCENT)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
pie_SetFogStatus(FALSE);
|
|
|
|
pie_SetRendMode(REND_ALPHA_TEX);
|
|
|
|
colour.byte.a = (UBYTE)pieFlagData;
|
2006-02-18 10:54:37 -08:00
|
|
|
pie_SetBilinear(FALSE);//never bilinear with constant alpha, gives black edges
|
2007-06-28 10:47:08 -07:00
|
|
|
light = FALSE;
|
2007-05-21 11:57:11 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
if (pieFlag & pie_BUTTON)
|
|
|
|
{
|
|
|
|
pie_SetFogStatus(FALSE);
|
|
|
|
pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON);
|
2007-05-21 11:57:11 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
pie_SetFogStatus(TRUE);
|
|
|
|
}
|
|
|
|
pie_SetRendMode(REND_GOURAUD_TEX);
|
|
|
|
//if hardware fog then alpha is set else unused in decal mode
|
2007-05-21 11:57:11 -07:00
|
|
|
if (pieFlag & pie_NO_BILINEAR)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
pie_SetBilinear(FALSE);
|
2007-05-21 11:57:11 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
pie_SetBilinear(TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-21 11:57:11 -07:00
|
|
|
if (pieFlag & pie_RAISE)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
pieFlagData = (shape->ymax * (pie_RAISE_SCALE - pieFlagData))/pie_RAISE_SCALE;
|
|
|
|
}
|
|
|
|
|
|
|
|
pie_SetTexturePage(shape->texpage);
|
|
|
|
|
2006-02-18 10:54:37 -08:00
|
|
|
//now draw the shape
|
2007-06-28 10:47:08 -07:00
|
|
|
//rotate and project points from shape->points to scrPoints
|
2007-06-02 16:01:29 -07:00
|
|
|
for (pVertices = shape->points, pPixels = scrPoints;
|
|
|
|
pVertices < shape->points + shape->npoints;
|
|
|
|
pVertices++, pPixels++)
|
2007-05-21 11:57:11 -07:00
|
|
|
{
|
2007-06-02 16:01:29 -07:00
|
|
|
float tempY = pVertices->y;
|
2007-06-28 10:47:08 -07:00
|
|
|
if (pieFlag & pie_RAISE)
|
|
|
|
{
|
|
|
|
tempY = pVertices->y - pieFlagData;
|
2007-05-21 11:57:11 -07:00
|
|
|
if (tempY < 0)
|
|
|
|
tempY = 0;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
}
|
2007-06-02 16:01:29 -07:00
|
|
|
else if ( (pieFlag & pie_HEIGHT_SCALED) && pVertices->y > 0 )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-06-02 16:01:29 -07:00
|
|
|
tempY = (pVertices->y * pieFlagData) / pie_RAISE_SCALE;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
2007-04-10 03:47:20 -07:00
|
|
|
pPixels->x = pVertices->x;
|
|
|
|
pPixels->y = tempY;
|
|
|
|
pPixels->z = pVertices->z;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2007-06-02 16:01:29 -07:00
|
|
|
for (pPolys = shape->polys;
|
|
|
|
pPolys < shape->polys + shape->npolys;
|
|
|
|
pPolys++)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
piePoly.flags = pPolys->flags;
|
2007-06-02 16:01:29 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
if (pieFlag & pie_TRANSLUCENT)
|
|
|
|
{
|
2007-04-23 13:29:43 -07:00
|
|
|
/* There are no PIE files with PIE_ALPHA set, this is the only user, and
|
|
|
|
* this flag is never checked anywhere, except we check below that _some_
|
|
|
|
* flag is set. This is weird. FIXME. - Per */
|
2007-06-28 10:47:08 -07:00
|
|
|
piePoly.flags |= PIE_ALPHA;
|
|
|
|
}
|
|
|
|
else if (pieFlag & pie_ADDITIVE)
|
|
|
|
{
|
|
|
|
piePoly.flags &= (0xffffffff-PIE_COLOURKEYED);//dont treat additive images as colour keyed
|
|
|
|
}
|
2007-06-02 16:01:29 -07:00
|
|
|
|
|
|
|
for (n = 0, index = pPolys->pindex;
|
|
|
|
n < pPolys->npnts;
|
|
|
|
n++, index++)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-05-21 12:42:05 -07:00
|
|
|
pieVrts[n].sx = scrPoints[*index].x;
|
|
|
|
pieVrts[n].sy = scrPoints[*index].y;
|
|
|
|
pieVrts[n].sz = scrPoints[*index].z;
|
2007-06-28 10:47:08 -07:00
|
|
|
pieVrts[n].tu = pPolys->vrt[n].u;
|
|
|
|
pieVrts[n].tv = pPolys->vrt[n].v;
|
|
|
|
pieVrts[n].light.argb = colour.argb;
|
|
|
|
pieVrts[n].specular.argb = specular.argb;
|
|
|
|
}
|
|
|
|
piePoly.nVrts = pPolys->npnts;
|
2007-05-21 12:42:05 -07:00
|
|
|
piePoly.pVrts = pieVrts;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
piePoly.pTexAnim = pPolys->pTexAnim;
|
|
|
|
|
2007-05-21 12:42:05 -07:00
|
|
|
if (piePoly.flags > 0)
|
|
|
|
{
|
|
|
|
pie_PiePolyFrame(&piePoly, frame, light); // draw the polygon ...
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|
2007-06-02 16:01:29 -07:00
|
|
|
|
2007-05-21 12:42:05 -07:00
|
|
|
if (pieFlag & pie_BUTTON)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-24 15:53:18 -07:00
|
|
|
|
|
|
|
/// returns true if the edges are adjacent
|
2007-05-21 12:56:07 -07:00
|
|
|
static int compare_edge (EDGE *A, EDGE *B, const Vector3f *pVertices )
|
2007-03-28 11:31:35 -07:00
|
|
|
{
|
|
|
|
if(A->from == B->to)
|
|
|
|
{
|
|
|
|
if(A->to == B->from)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-05-21 12:56:07 -07:00
|
|
|
return Vector3f_compare(&pVertices[A->to], &pVertices[B->from]);
|
2007-03-28 11:31:35 -07:00
|
|
|
}
|
2007-04-28 13:21:16 -07:00
|
|
|
|
2007-05-21 12:56:07 -07:00
|
|
|
if(!Vector3f_compare(&pVertices[A->from], &pVertices[B->to]))
|
2007-03-28 11:31:35 -07:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-04-28 13:21:16 -07:00
|
|
|
|
2007-03-28 11:31:35 -07:00
|
|
|
if(A->to == B->from)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-05-21 12:56:07 -07:00
|
|
|
return Vector3f_compare(&pVertices[A->to], &pVertices[B->from]);
|
2007-03-24 15:53:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Add an edge to an edgelist
|
|
|
|
/// Makes sure only silhouette edges are present
|
2007-05-21 12:56:07 -07:00
|
|
|
static void addToEdgeList(int a, int b, EDGE *edgelist, int *edge_count, Vector3f *pVertices)
|
2007-03-24 15:53:18 -07:00
|
|
|
{
|
2007-05-21 11:57:11 -07:00
|
|
|
EDGE newEdge = {a, b};
|
2007-03-24 15:53:18 -07:00
|
|
|
int i;
|
|
|
|
BOOL foundMatching = FALSE;
|
|
|
|
|
2007-05-21 11:57:11 -07:00
|
|
|
for(i = 0; i < *edge_count; i++)
|
2007-03-24 15:53:18 -07:00
|
|
|
{
|
|
|
|
if(edgelist[i].from < 0)
|
|
|
|
{
|
|
|
|
// does not exist anymore
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(compare_edge(&newEdge, &edgelist[i], pVertices)) {
|
|
|
|
// remove the other too
|
|
|
|
edgelist[i].from = -1;
|
|
|
|
foundMatching = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!foundMatching)
|
|
|
|
{
|
|
|
|
edgelist[*edge_count] = newEdge;
|
|
|
|
(*edge_count)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-26 11:25:15 -07:00
|
|
|
|
2007-03-24 15:53:18 -07:00
|
|
|
/// scale the height according to the flags
|
|
|
|
static inline float scale_y(float y, int flag, int flag_data)
|
|
|
|
{
|
|
|
|
float tempY = y;
|
|
|
|
if (flag & pie_RAISE) {
|
|
|
|
tempY = y - flag_data;
|
|
|
|
if (y - flag_data < 0) tempY = 0;
|
|
|
|
} else if (flag & pie_HEIGHT_SCALED) {
|
|
|
|
if(y>0) {
|
|
|
|
tempY = (y * flag_data)/pie_RAISE_SCALE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tempY;
|
|
|
|
}
|
|
|
|
|
2007-05-26 11:25:15 -07:00
|
|
|
|
2007-03-24 15:53:18 -07:00
|
|
|
/// Draw the shadow for a shape
|
2007-03-16 09:20:16 -07:00
|
|
|
static void pie_DrawShadow(iIMDShape *shape, int flag, int flag_data, Vector3f* light)
|
2007-02-17 14:29:21 -08:00
|
|
|
{
|
2007-05-21 11:57:11 -07:00
|
|
|
int i, j, n;
|
2007-05-21 12:56:07 -07:00
|
|
|
Vector3f *pVertices;
|
2007-05-21 11:57:11 -07:00
|
|
|
iIMDPoly *pPolys;
|
2007-04-01 13:12:47 -07:00
|
|
|
int edge_count = 0;
|
2007-03-24 15:53:18 -07:00
|
|
|
static EDGE *edgelist = NULL;
|
2007-05-06 13:20:45 -07:00
|
|
|
static int edgelistsize = 256;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-03-24 15:53:18 -07:00
|
|
|
EDGE *drawlist = NULL;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-03-24 15:53:18 -07:00
|
|
|
if(!edgelist)
|
|
|
|
{
|
2007-04-23 15:08:53 -07:00
|
|
|
edgelist = (EDGE*)malloc(sizeof(EDGE)*edgelistsize);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
2007-03-24 15:53:18 -07:00
|
|
|
pVertices = shape->points;
|
|
|
|
if( flag & pie_STATIC_SHADOW && shape->shadowEdgeList )
|
|
|
|
{
|
2007-04-23 15:08:53 -07:00
|
|
|
drawlist = (EDGE*)shape->shadowEdgeList;
|
2007-03-24 15:53:18 -07:00
|
|
|
edge_count = shape->nShadowEdges;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-05-21 11:57:11 -07:00
|
|
|
|
|
|
|
for (i = 0, pPolys = shape->polys; i < shape->npolys; ++i, ++pPolys) {
|
2007-05-25 10:58:23 -07:00
|
|
|
Vector3f p[3], v[2], normal = {0.0f, 0.0f, 0.0f};
|
2007-03-24 15:53:18 -07:00
|
|
|
VERTEXID current, first;
|
2007-05-21 11:57:11 -07:00
|
|
|
for(j = 0; j < 3; j++)
|
2007-03-24 15:53:18 -07:00
|
|
|
{
|
|
|
|
current = pPolys->pindex[j];
|
|
|
|
Vector3f_Set(&p[j], pVertices[current].x, scale_y(pVertices[current].y, flag, flag_data), pVertices[current].z);
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-03-24 15:53:18 -07:00
|
|
|
Vector3f_Sub(&v[0], &p[2], &p[0]);
|
|
|
|
Vector3f_Sub(&v[1], &p[1], &p[0]);
|
|
|
|
Vector3f_CP(&normal, &v[0], &v[1]);
|
|
|
|
if (Vector3f_SP(&normal, light) > 0)
|
|
|
|
{
|
|
|
|
first = pPolys->pindex[0];
|
|
|
|
for (n = 1; n < pPolys->npnts; n++) {
|
|
|
|
// link to the previous vertex
|
|
|
|
addToEdgeList(pPolys->pindex[n-1], pPolys->pindex[n], edgelist, &edge_count, pVertices);
|
|
|
|
// check if the edgelist is still large enough
|
|
|
|
if(edge_count >= edgelistsize-1)
|
|
|
|
{
|
|
|
|
// enlarge
|
2007-04-23 15:08:53 -07:00
|
|
|
EDGE *newstack = (EDGE*)malloc(sizeof(EDGE)*edgelistsize*2);
|
2007-03-24 15:53:18 -07:00
|
|
|
memcpy(newstack, edgelist, sizeof(EDGE)*edgelistsize);
|
2007-04-15 03:43:05 -07:00
|
|
|
free(edgelist);
|
2007-03-24 15:53:18 -07:00
|
|
|
edgelistsize*=2;
|
|
|
|
edgelist = newstack;
|
|
|
|
debug(LOG_WARNING, "new edge list size: %i", edgelistsize);
|
|
|
|
}
|
2005-11-29 08:20:35 -08:00
|
|
|
}
|
2007-03-24 15:53:18 -07:00
|
|
|
// back to the first
|
2007-05-21 11:57:11 -07:00
|
|
|
addToEdgeList(pPolys->pindex[pPolys->npnts-1], first, edgelist, &edge_count, pVertices);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
2007-03-24 15:53:18 -07:00
|
|
|
}
|
|
|
|
//debug(LOG_WARNING, "we have %i edges", edge_count);
|
|
|
|
drawlist = edgelist;
|
|
|
|
|
|
|
|
if(flag & pie_STATIC_SHADOW)
|
|
|
|
{
|
|
|
|
// first compact the current edgelist
|
2007-05-21 11:57:11 -07:00
|
|
|
for(i = 0, j = 0; i < edge_count; i++)
|
2007-03-24 15:53:18 -07:00
|
|
|
{
|
2007-05-21 11:57:11 -07:00
|
|
|
if(edgelist[i].from < 0)
|
2007-03-24 15:53:18 -07:00
|
|
|
{
|
|
|
|
continue;
|
2005-11-29 08:20:35 -08:00
|
|
|
}
|
2007-03-24 15:53:18 -07:00
|
|
|
edgelist[j] = edgelist[i];
|
|
|
|
j++;
|
2005-11-29 08:20:35 -08:00
|
|
|
}
|
2007-03-24 15:53:18 -07:00
|
|
|
edge_count = j;
|
|
|
|
// then store it in the imd
|
|
|
|
shape->nShadowEdges = edge_count;
|
2007-05-21 11:57:11 -07:00
|
|
|
shape->shadowEdgeList = malloc(sizeof(EDGE) * shape->nShadowEdges);
|
|
|
|
memcpy(shape->shadowEdgeList, edgelist, sizeof(EDGE) * shape->nShadowEdges);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-24 15:53:18 -07:00
|
|
|
|
|
|
|
// draw the shadow volume
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
for(i=0;i<edge_count;i++)
|
|
|
|
{
|
2007-05-21 11:57:11 -07:00
|
|
|
int a = drawlist[i].from, b = drawlist[i].to;
|
2007-03-24 15:53:18 -07:00
|
|
|
if(a < 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
glVertex3f(pVertices[b].x, scale_y(pVertices[b].y, flag, flag_data), pVertices[b].z);
|
|
|
|
glVertex3f(pVertices[b].x+light->x, scale_y(pVertices[b].y, flag, flag_data)+light->y, pVertices[b].z+light->z);
|
|
|
|
glVertex3f(pVertices[a].x+light->x, scale_y(pVertices[a].y, flag, flag_data)+light->y, pVertices[a].z+light->z);
|
|
|
|
glVertex3f(pVertices[a].x, scale_y(pVertices[a].y, flag, flag_data), pVertices[a].z);
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
#ifdef SHOW_SHADOW_EDGES
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
|
2007-05-21 11:57:11 -07:00
|
|
|
glColor4ub(0xFF, 0, 0, 0xFF);
|
2007-03-24 15:53:18 -07:00
|
|
|
glBegin(GL_LINES);
|
2007-05-21 11:57:11 -07:00
|
|
|
for(i = 0; i < edge_count; i++)
|
2007-03-24 15:53:18 -07:00
|
|
|
{
|
2007-05-21 11:57:11 -07:00
|
|
|
int a = drawlist[i].from, b = drawlist[i].to;
|
|
|
|
if(a < 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-03-24 15:53:18 -07:00
|
|
|
glVertex3f(pVertices[b].x, scale_y(pVertices[b].y, flag, flag_data), pVertices[b].z);
|
|
|
|
glVertex3f(pVertices[a].x, scale_y(pVertices[a].y, flag, flag_data), pVertices[a].z);
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
#endif
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
2007-05-26 11:25:15 -07:00
|
|
|
static void inverse_matrix(const float * src, float * dst)
|
|
|
|
{
|
|
|
|
const float det = src[0]*src[5]*src[10] + src[4]*src[9]*src[2] + src[8]*src[1]*src[6] - src[2]*src[5]*src[8] - src[6]*src[9]*src[0] - src[10]*src[1]*src[4];
|
|
|
|
const float invdet = 1.0f/det;
|
|
|
|
|
|
|
|
dst[0] = invdet * (src[5]*src[10] - src[9]*src[6]);
|
|
|
|
dst[1] = invdet * (src[9]*src[2] - src[1]*src[10]);
|
|
|
|
dst[2] = invdet * (src[1]*src[6] - src[5]*src[2]);
|
|
|
|
dst[3] = invdet * (src[8]*src[6] - src[4]*src[10]);
|
|
|
|
dst[4] = invdet * (src[0]*src[10] - src[8]*src[2]);
|
|
|
|
dst[5] = invdet * (src[4]*src[2] - src[0]*src[6]);
|
|
|
|
dst[6] = invdet * (src[4]*src[9] - src[8]*src[5]);
|
|
|
|
dst[7] = invdet * (src[8]*src[1] - src[0]*src[9]);
|
|
|
|
dst[8] = invdet * (src[0]*src[5] - src[4]*src[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-18 10:54:37 -08:00
|
|
|
void pie_CleanUp( void )
|
|
|
|
{
|
|
|
|
free( tshapes );
|
|
|
|
free( scshapes );
|
2007-06-12 10:56:34 -07:00
|
|
|
tshapes = NULL;
|
|
|
|
scshapes = NULL;
|
2006-02-18 10:54:37 -08:00
|
|
|
}
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
void pie_Draw3DShape(iIMDShape *shape, int frame, int team, UDWORD col, UDWORD spec, int pieFlag, int pieFlagData)
|
|
|
|
{
|
|
|
|
PIELIGHT colour, specular;
|
|
|
|
|
|
|
|
pieCount++;
|
|
|
|
|
2007-06-02 16:01:29 -07:00
|
|
|
// Fix for transparent buildings and features!!
|
2007-02-10 08:39:39 -08:00
|
|
|
if( (pieFlag & pie_TRANSLUCENT) && (pieFlagData>220) )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-03-24 15:53:18 -07:00
|
|
|
// force to bilinear and non-transparent
|
|
|
|
pieFlag = pieFlag & ~pie_TRANSLUCENT;
|
|
|
|
pieFlagData = 0;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// WARZONE light as byte passed in colour so expand
|
2007-05-26 11:25:15 -07:00
|
|
|
if (col <= MAX_UB_LIGHT)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
colour.byte.a = 255;//no fog
|
|
|
|
colour.byte.r = (UBYTE)col;
|
|
|
|
colour.byte.g = (UBYTE)col;
|
|
|
|
colour.byte.b = (UBYTE)col;
|
2007-05-26 11:25:15 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
colour.argb = col;
|
|
|
|
}
|
|
|
|
specular.argb = spec;
|
|
|
|
|
2006-02-18 10:54:37 -08:00
|
|
|
if (frame == 0)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
frame = team;
|
|
|
|
}
|
|
|
|
|
2007-05-26 11:25:15 -07:00
|
|
|
if (drawing_interface || !shadows)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
pie_Draw3DShape2(shape, frame, colour, specular, pieFlag, pieFlagData);
|
2007-05-26 11:25:15 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pieFlag & (pie_ADDITIVE | pie_TRANSLUCENT))
|
|
|
|
{
|
|
|
|
if (tshapes_size <= nb_tshapes)
|
|
|
|
{
|
|
|
|
if (tshapes_size == 0)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
tshapes_size = 64;
|
|
|
|
tshapes = (transluscent_shape_t*)malloc(tshapes_size*sizeof(transluscent_shape_t));
|
2006-02-18 10:54:37 -08:00
|
|
|
memset( tshapes, 0, tshapes_size*sizeof(transluscent_shape_t) );
|
2007-05-26 11:25:15 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-02 16:01:29 -07:00
|
|
|
const unsigned int old_size = tshapes_size;
|
2007-06-28 10:47:08 -07:00
|
|
|
tshapes_size <<= 1;
|
|
|
|
tshapes = (transluscent_shape_t*)realloc(tshapes, tshapes_size*sizeof(transluscent_shape_t));
|
2006-02-18 10:54:37 -08:00
|
|
|
memset( &tshapes[old_size], 0, (tshapes_size-old_size)*sizeof(transluscent_shape_t) );
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
glGetFloatv(GL_MODELVIEW_MATRIX, tshapes[nb_tshapes].matrix);
|
|
|
|
tshapes[nb_tshapes].shape = shape;
|
|
|
|
tshapes[nb_tshapes].frame = frame;
|
|
|
|
tshapes[nb_tshapes].colour = colour;
|
|
|
|
tshapes[nb_tshapes].specular = specular;
|
|
|
|
tshapes[nb_tshapes].flag = pieFlag;
|
|
|
|
tshapes[nb_tshapes].flag_data = pieFlagData;
|
|
|
|
nb_tshapes++;
|
2007-05-26 11:25:15 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-24 15:53:18 -07:00
|
|
|
if(pieFlag & pie_SHADOW || pieFlag & pie_STATIC_SHADOW)
|
|
|
|
{
|
2007-06-02 16:01:29 -07:00
|
|
|
float distance;
|
|
|
|
|
2007-03-24 15:53:18 -07:00
|
|
|
// draw a shadow
|
2007-05-26 11:25:15 -07:00
|
|
|
if (scshapes_size <= nb_scshapes)
|
|
|
|
{
|
|
|
|
if (scshapes_size == 0)
|
|
|
|
{
|
2007-03-24 15:53:18 -07:00
|
|
|
scshapes_size = 64;
|
|
|
|
scshapes = (shadowcasting_shape_t*)malloc(scshapes_size*sizeof(shadowcasting_shape_t));
|
|
|
|
memset( scshapes, 0, scshapes_size*sizeof(shadowcasting_shape_t) );
|
2007-05-26 11:25:15 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-02 16:01:29 -07:00
|
|
|
const unsigned int old_size = scshapes_size;
|
2007-03-24 15:53:18 -07:00
|
|
|
scshapes_size <<= 1;
|
|
|
|
scshapes = (shadowcasting_shape_t*)realloc(scshapes, scshapes_size*sizeof(shadowcasting_shape_t));
|
|
|
|
memset( &scshapes[old_size], 0, (scshapes_size-old_size)*sizeof(shadowcasting_shape_t) );
|
|
|
|
}
|
|
|
|
}
|
2007-05-26 11:25:15 -07:00
|
|
|
|
2007-03-24 15:53:18 -07:00
|
|
|
glGetFloatv(GL_MODELVIEW_MATRIX, scshapes[nb_scshapes].matrix);
|
2007-05-26 11:25:15 -07:00
|
|
|
distance = scshapes[nb_scshapes].matrix[12] * scshapes[nb_scshapes].matrix[12];
|
|
|
|
distance += scshapes[nb_scshapes].matrix[13] * scshapes[nb_scshapes].matrix[13];
|
|
|
|
distance += scshapes[nb_scshapes].matrix[14] * scshapes[nb_scshapes].matrix[14];
|
|
|
|
|
2007-03-24 15:53:18 -07:00
|
|
|
// if object is too far in the fog don't generate a shadow.
|
2007-05-26 11:25:15 -07:00
|
|
|
if (distance < 6000*6000)
|
|
|
|
{
|
|
|
|
float invmat[9], pos_light0[4];
|
|
|
|
|
|
|
|
inverse_matrix( scshapes[nb_scshapes].matrix, invmat );
|
|
|
|
|
|
|
|
// Calculate the light position relative to the object
|
|
|
|
glGetLightfv(GL_LIGHT0, GL_POSITION, pos_light0);
|
|
|
|
scshapes[nb_scshapes].light.x = invmat[0] * pos_light0[0] + invmat[3] * pos_light0[1] + invmat[6] * pos_light0[2];
|
|
|
|
scshapes[nb_scshapes].light.y = invmat[1] * pos_light0[0] + invmat[4] * pos_light0[1] + invmat[7] * pos_light0[2];
|
|
|
|
scshapes[nb_scshapes].light.z = invmat[2] * pos_light0[0] + invmat[5] * pos_light0[1] + invmat[8] * pos_light0[2];
|
|
|
|
|
2007-03-24 15:53:18 -07:00
|
|
|
scshapes[nb_scshapes].shape = shape;
|
|
|
|
scshapes[nb_scshapes].flag = pieFlag;
|
|
|
|
scshapes[nb_scshapes].flag_data = pieFlagData;
|
2007-05-26 11:25:15 -07:00
|
|
|
|
2007-03-24 15:53:18 -07:00
|
|
|
nb_scshapes++;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pie_Draw3DShape2(shape, frame, colour, specular, pieFlag, pieFlagData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-26 11:25:15 -07:00
|
|
|
static void pie_ShadowDrawLoop(void)
|
2007-02-17 14:29:21 -08:00
|
|
|
{
|
2007-05-26 11:25:15 -07:00
|
|
|
unsigned int i = 0;
|
2007-02-17 14:29:21 -08:00
|
|
|
|
|
|
|
for (i = 0; i < nb_scshapes; i++)
|
|
|
|
{
|
2007-05-26 11:51:47 -07:00
|
|
|
glLoadMatrixf(scshapes[i].matrix);
|
2007-05-26 11:25:15 -07:00
|
|
|
pie_DrawShadow(scshapes[i].shape, scshapes[i].flag, scshapes[i].flag_data, &scshapes[i].light);
|
2007-02-17 14:29:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-26 11:25:15 -07:00
|
|
|
|
2007-03-13 13:49:03 -07:00
|
|
|
static void pie_DrawShadows(void)
|
2007-02-17 14:29:21 -08:00
|
|
|
{
|
2007-05-26 11:25:15 -07:00
|
|
|
const float width = pie_GetVideoBufferWidth();
|
|
|
|
const float height = pie_GetVideoBufferHeight();
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
pie_SetTexturePage(-1);
|
|
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
2005-11-29 08:20:35 -08:00
|
|
|
pie_SetColourKeyedBlack(FALSE);
|
2007-06-28 10:47:08 -07:00
|
|
|
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
|
|
|
glDepthFunc(GL_LESS);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
glEnable(GL_STENCIL_TEST);
|
|
|
|
|
|
|
|
if (stencil_one_pass()) {
|
|
|
|
glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
glStencilMask(~0);
|
|
|
|
glActiveStencilFaceEXT(GL_BACK);
|
|
|
|
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR_WRAP_EXT);
|
|
|
|
glStencilFunc(GL_ALWAYS, 0, ~0);
|
|
|
|
glActiveStencilFaceEXT(GL_FRONT);
|
|
|
|
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR_WRAP_EXT);
|
|
|
|
glStencilFunc(GL_ALWAYS, 0, ~0);
|
2006-08-29 09:10:06 -07:00
|
|
|
|
2007-05-26 11:25:15 -07:00
|
|
|
pie_ShadowDrawLoop();
|
2006-08-29 09:10:06 -07:00
|
|
|
glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
} else {
|
|
|
|
// Setup stencil for back faces.
|
|
|
|
glStencilMask(~0);
|
|
|
|
glStencilFunc(GL_ALWAYS, 0, ~0);
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
glCullFace(GL_BACK);
|
|
|
|
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
|
|
|
|
|
2007-05-26 11:25:15 -07:00
|
|
|
pie_ShadowDrawLoop();
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
// Setup stencil for front faces.
|
|
|
|
glCullFace(GL_FRONT);
|
|
|
|
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
|
|
|
|
|
2006-08-29 09:10:06 -07:00
|
|
|
// Draw shadows again
|
2007-05-26 11:25:15 -07:00
|
|
|
pie_ShadowDrawLoop();
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
|
|
|
glStencilMask(~0);
|
|
|
|
glStencilFunc(GL_LESS, 0, ~0);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glColor4f(0, 0, 0, 0.5);
|
|
|
|
|
|
|
|
pie_PerspectiveEnd();
|
|
|
|
glLoadIdentity();
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glBegin(GL_TRIANGLE_STRIP);
|
2007-05-26 12:14:23 -07:00
|
|
|
glVertex2f(0, 0);
|
|
|
|
glVertex2f(width, 0);
|
|
|
|
glVertex2f(0, height);
|
|
|
|
glVertex2f(width, height);
|
2007-06-28 10:47:08 -07:00
|
|
|
glEnd();
|
|
|
|
pie_PerspectiveBegin();
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
|
|
|
nb_scshapes = 0;
|
|
|
|
}
|
|
|
|
|
2007-02-17 14:29:21 -08:00
|
|
|
static void pie_DrawRemainingTransShapes(void)
|
|
|
|
{
|
2007-05-26 11:25:15 -07:00
|
|
|
unsigned int i = 0;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-05-26 11:25:15 -07:00
|
|
|
glPushMatrix();
|
2007-03-13 13:49:03 -07:00
|
|
|
for (i = 0; i < nb_tshapes; ++i)
|
2007-02-17 14:29:21 -08:00
|
|
|
{
|
2007-05-26 11:51:47 -07:00
|
|
|
glLoadMatrixf(tshapes[i].matrix);
|
2007-06-28 10:47:08 -07:00
|
|
|
pie_Draw3DShape2(tshapes[i].shape, tshapes[i].frame, tshapes[i].colour,
|
|
|
|
tshapes[i].specular, tshapes[i].flag, tshapes[i].flag_data);
|
|
|
|
}
|
2007-05-26 11:25:15 -07:00
|
|
|
glPopMatrix();
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
nb_tshapes = 0;
|
|
|
|
}
|
|
|
|
|
2007-03-13 13:49:03 -07:00
|
|
|
void pie_RemainingPasses(void)
|
2007-02-17 14:29:21 -08:00
|
|
|
{
|
2007-03-30 10:38:35 -07:00
|
|
|
if(shadows)
|
|
|
|
{
|
|
|
|
pie_DrawShadows();
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
pie_DrawRemainingTransShapes();
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* pie_Drawimage
|
|
|
|
*
|
|
|
|
* General purpose blit function
|
|
|
|
* Will support zbuffering, non_textured, coloured lighting and alpha effects
|
|
|
|
*
|
2006-02-18 10:54:37 -08:00
|
|
|
* replaces all ivis blit functions
|
2007-06-28 10:47:08 -07:00
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
void pie_DrawImage(PIEIMAGE *image, PIERECT *dest, PIESTYLE *style)
|
|
|
|
{
|
|
|
|
/* Set transparent color to be 0 red, 0 green, 0 blue, 0 alpha */
|
|
|
|
polyCount++;
|
|
|
|
|
|
|
|
pie_SetTexturePage(image->texPage);
|
|
|
|
|
|
|
|
style->colour.argb = pie_GetColour();
|
|
|
|
style->specular.argb = 0x00000000;
|
|
|
|
|
|
|
|
glColor4ub(style->colour.byte.r, style->colour.byte.g, style->colour.byte.b, style->colour.byte.a);
|
2007-06-14 14:56:36 -07:00
|
|
|
|
|
|
|
glBegin(GL_TRIANGLE_STRIP);
|
|
|
|
//set up 4 pie verts
|
|
|
|
glTexCoord2f(image->tu, image->tv);
|
|
|
|
glVertex2f(dest->x, dest->y);
|
|
|
|
|
|
|
|
glTexCoord2f(image->tu + image->tw, image->tv);
|
|
|
|
glVertex2f(dest->x + dest->w, dest->y);
|
|
|
|
|
|
|
|
glTexCoord2f(image->tu, image->tv + image->th);
|
|
|
|
glVertex2f(dest->x, dest->y + dest->h);
|
|
|
|
|
|
|
|
glTexCoord2f(image->tu + image->tw, image->tv + image->th);
|
|
|
|
glVertex2f(dest->x + dest->w, dest->y + dest->h);
|
2007-06-28 10:47:08 -07:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* pie_Drawimage270
|
|
|
|
*
|
|
|
|
* General purpose blit function
|
|
|
|
* Will support zbuffering, non_textured, coloured lighting and alpha effects
|
|
|
|
*
|
2006-02-18 10:54:37 -08:00
|
|
|
* replaces all ivis blit functions
|
2007-06-28 10:47:08 -07:00
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2007-02-19 09:18:50 -08:00
|
|
|
void pie_DrawImage270( PIEIMAGE *image, PIERECT *dest )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
PIELIGHT colour;
|
|
|
|
|
|
|
|
polyCount++;
|
|
|
|
|
|
|
|
pie_SetTexturePage(image->texPage);
|
|
|
|
|
|
|
|
colour.argb = pie_GetColour();
|
|
|
|
|
|
|
|
glColor4ub(colour.byte.r, colour.byte.g, colour.byte.b, colour.byte.a);
|
2007-06-14 14:56:36 -07:00
|
|
|
|
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
|
|
|
glTexCoord2f(image->tu + image->tw, image->tv);
|
|
|
|
glVertex2f(dest->x, dest->y);
|
|
|
|
|
|
|
|
glTexCoord2f(image->tu + image->tw, image->tv + image->th);
|
|
|
|
glVertex2f(dest->x + dest->h, dest->y);
|
|
|
|
|
|
|
|
glTexCoord2f(image->tu, image->tv + image->th);
|
|
|
|
glVertex2f(dest->x + dest->h, dest->y + dest->w);
|
|
|
|
|
|
|
|
glTexCoord2f(image->tu, image->tv);
|
|
|
|
glVertex2f(dest->x, dest->y + dest->w);
|
2007-06-28 10:47:08 -07:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* pie_DrawRect
|
|
|
|
*
|
|
|
|
* universal rectangle function for hardware
|
|
|
|
*
|
|
|
|
* Assumes render mode set up externally, draws filled rectangle
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2007-02-19 09:18:50 -08:00
|
|
|
void pie_DrawRect( SDWORD x0, SDWORD y0, SDWORD x1, SDWORD y1, UDWORD colour )
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
PIELIGHT c;
|
|
|
|
polyCount++;
|
|
|
|
|
|
|
|
c.argb = colour;
|
|
|
|
pie_SetColourKeyedBlack(FALSE);
|
|
|
|
|
|
|
|
glColor4ub(c.byte.r, c.byte.g, c.byte.b, c.byte.a);
|
|
|
|
glBegin(GL_TRIANGLE_STRIP);
|
|
|
|
glVertex2i(x0, y0);
|
|
|
|
glVertex2i(x1, y0);
|
|
|
|
glVertex2i(x0, y1);
|
|
|
|
glVertex2i(x1, y1);
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* pie_PiePoly
|
|
|
|
*
|
|
|
|
* universal poly draw function for hardware
|
|
|
|
*
|
|
|
|
* Assumes render mode set up externally
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2007-05-21 12:42:05 -07:00
|
|
|
static inline void pie_PiePoly(PIEPOLY *poly, BOOL light)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
polyCount++;
|
|
|
|
|
2007-05-21 12:42:05 -07:00
|
|
|
if (poly->nVrts >= 3)
|
|
|
|
{
|
|
|
|
if (poly->flags & PIE_COLOURKEYED)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
pie_SetColourKeyedBlack(TRUE);
|
2007-05-21 12:42:05 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
pie_SetColourKeyedBlack(FALSE);
|
|
|
|
}
|
2005-11-29 08:20:35 -08:00
|
|
|
pie_SetColourKeyedBlack(TRUE);
|
2007-05-21 12:42:05 -07:00
|
|
|
if (poly->flags & PIE_NO_CULL)
|
|
|
|
{
|
2005-11-29 08:20:35 -08:00
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
}
|
2007-05-26 13:49:35 -07:00
|
|
|
pie_Polygon(poly->nVrts, poly->pVrts, light);
|
2007-05-21 12:42:05 -07:00
|
|
|
if (poly->flags & PIE_NO_CULL)
|
|
|
|
{
|
2005-11-29 08:20:35 -08:00
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-24 15:53:18 -07:00
|
|
|
static inline void pie_PiePolyFrame(PIEPOLY *poly, SDWORD frame, BOOL light)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-06-02 16:01:29 -07:00
|
|
|
if ((poly->flags & iV_IMD_TEXANIM) && (frame != 0))
|
|
|
|
{
|
|
|
|
if (poly->pTexAnim != NULL)
|
|
|
|
{
|
|
|
|
if (poly->pTexAnim->nFrames >=0)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
frame %= poly->pTexAnim->nFrames;
|
2007-06-02 16:01:29 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
frame %= (-poly->pTexAnim->nFrames);
|
|
|
|
}
|
2007-06-02 16:01:29 -07:00
|
|
|
|
|
|
|
if (frame > 0)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
// HACK - fix this!!!!
|
2007-06-02 16:01:29 -07:00
|
|
|
const int framesPerLine = 256 / poly->pTexAnim->textureWidth;
|
2007-06-28 10:47:08 -07:00
|
|
|
//should be framesPerLine = iV_TEXTEX(texPage)->width / poly->pTexAnim->textureWidth;
|
2007-06-02 16:01:29 -07:00
|
|
|
int uFrame = 0, vFrame = 0, j = 0;
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
while (frame >= framesPerLine)
|
|
|
|
{
|
|
|
|
frame -= framesPerLine;
|
|
|
|
vFrame += poly->pTexAnim->textureHeight;
|
|
|
|
}
|
2007-06-02 16:01:29 -07:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
uFrame = frame * poly->pTexAnim->textureWidth;
|
2006-02-18 10:54:37 -08:00
|
|
|
|
2007-06-02 16:01:29 -07:00
|
|
|
for (j = 0; j < poly->nVrts; j++)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
poly->pVrts[j].tu += uFrame;
|
|
|
|
poly->pVrts[j].tv += vFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifndef NO_RENDER
|
|
|
|
//draw with new texture data
|
|
|
|
pie_PiePoly(poly, light);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2007-04-28 13:21:16 -07:00
|
|
|
void pie_DrawTexTriangle(PIEVERTEX *aVrts, void* psEffects)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-04-28 13:21:16 -07:00
|
|
|
GLfloat offset = 0;
|
2007-05-26 11:25:15 -07:00
|
|
|
unsigned int i = 0;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-04-28 13:21:16 -07:00
|
|
|
/* Since this is only used from within source for the terrain draw - we can backface cull the polygons.
|
2007-06-28 10:47:08 -07:00
|
|
|
*/
|
|
|
|
tileCount++;
|
|
|
|
pie_SetFogStatus(TRUE);
|
2007-03-27 06:56:36 -07:00
|
|
|
if (psEffects != NULL)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2007-02-22 04:07:44 -08:00
|
|
|
/* Translucent water with animation */
|
|
|
|
pie_SetRendMode(REND_ALPHA_TEX);
|
2007-06-28 10:47:08 -07:00
|
|
|
pie_SetColourKeyedBlack(FALSE);
|
2007-02-22 04:07:44 -08:00
|
|
|
offset = *((GLfloat*)psEffects);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
pie_SetBilinear(TRUE);
|
|
|
|
|
2007-02-22 04:07:44 -08:00
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
2007-06-14 14:56:36 -07:00
|
|
|
for ( i = 0; i < 3; i++ )
|
|
|
|
{
|
|
|
|
glColor4ub( aVrts[i].light.byte.r, aVrts[i].light.byte.g, aVrts[i].light.byte.b, aVrts[i].light.byte.a );
|
|
|
|
glTexCoord2f( aVrts[i].tu, aVrts[i].tv + offset );
|
|
|
|
glVertex3f( aVrts[i].sx, aVrts[i].sy, aVrts[i].sz );
|
|
|
|
}
|
2007-02-22 04:07:44 -08:00
|
|
|
glEnd();
|
2007-04-28 13:21:16 -07:00
|
|
|
|
2007-03-27 06:56:36 -07:00
|
|
|
if (psEffects != NULL)
|
|
|
|
{
|
|
|
|
/* Solid terrain */
|
|
|
|
pie_SetRendMode(REND_GOURAUD_TEX);
|
|
|
|
pie_SetColourKeyedBlack(TRUE);
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void pie_GetResetCounts(SDWORD* pPieCount, SDWORD* pTileCount, SDWORD* pPolyCount, SDWORD* pStateCount)
|
|
|
|
{
|
2006-02-18 10:54:37 -08:00
|
|
|
*pPieCount = pieCount;
|
2007-06-28 10:47:08 -07:00
|
|
|
*pTileCount = tileCount;
|
|
|
|
*pPolyCount = polyCount;
|
|
|
|
*pStateCount = pieStateCount;
|
|
|
|
|
|
|
|
pieCount = 0;
|
|
|
|
tileCount = 0;
|
|
|
|
polyCount = 0;
|
|
|
|
pieStateCount = 0;
|
|
|
|
return;
|
|
|
|
}
|