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
|
|
|
/***************************************************************************/
|
|
|
|
/*
|
|
|
|
* pieState.c
|
|
|
|
*
|
|
|
|
* renderer setup and state control routines for 3D rendering
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
#include <string.h>
|
2006-03-17 17:59:59 -08:00
|
|
|
#ifdef _MSC_VER
|
2007-06-28 10:47:08 -07:00
|
|
|
#include <windows.h> //needed for gl.h! --Qamly
|
|
|
|
#endif
|
2006-10-09 12:22:24 -07:00
|
|
|
#include <SDL/SDL.h>
|
2006-08-12 03:45:49 -07:00
|
|
|
#include <SDL/SDL_opengl.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/piestate.h"
|
|
|
|
#include "lib/ivis_common/piedef.h"
|
|
|
|
#include "lib/ivis_common/tex.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/*
|
|
|
|
* Global Variables
|
|
|
|
*/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2006-03-17 17:59:59 -08:00
|
|
|
extern RENDER_STATE rendStates;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/*
|
|
|
|
* Source
|
|
|
|
*/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
void pie_SetDepthBufferStatus(DEPTH_MODE depthMode) {
|
|
|
|
switch(depthMode) {
|
|
|
|
case DEPTH_CMP_LEQ_WRT_ON:
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
break;
|
|
|
|
case DEPTH_CMP_ALWAYS_WRT_ON:
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
break;
|
|
|
|
case DEPTH_CMP_LEQ_WRT_OFF:
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
break;
|
|
|
|
case DEPTH_CMP_ALWAYS_WRT_OFF:
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************************************************************************
|
|
|
|
//
|
|
|
|
// pie_SetFogStatus(BOOL val)
|
|
|
|
//
|
|
|
|
// Toggle fog on and off for rendering objects inside or outside the 3D world
|
|
|
|
//
|
|
|
|
//***************************************************************************
|
|
|
|
|
|
|
|
void pie_SetFogStatus(BOOL val)
|
|
|
|
{
|
|
|
|
PIELIGHT fog;
|
|
|
|
float fog_colour[4];
|
|
|
|
|
|
|
|
if (rendStates.fogEnabled)
|
|
|
|
{
|
2006-03-17 17:59:59 -08:00
|
|
|
//fog enabled so toggle if required
|
2007-06-28 10:47:08 -07:00
|
|
|
if (rendStates.fog != val)
|
|
|
|
{
|
|
|
|
rendStates.fog = val;
|
|
|
|
|
|
|
|
if (rendStates.fog) {
|
|
|
|
fog.argb = pie_GetFogColour();
|
2006-09-08 13:02:49 -07:00
|
|
|
fog_colour[0] = fog.byte.r/255.0f;
|
|
|
|
fog_colour[1] = fog.byte.g/255.0f;
|
|
|
|
fog_colour[2] = fog.byte.b/255.0f;
|
|
|
|
fog_colour[3] = fog.byte.a/255.0f;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
glFogi(GL_FOG_MODE, GL_LINEAR);
|
|
|
|
glFogfv(GL_FOG_COLOR, fog_colour);
|
|
|
|
glFogf(GL_FOG_DENSITY, 0.35f);
|
|
|
|
glHint(GL_FOG_HINT, GL_DONT_CARE);
|
|
|
|
glFogf(GL_FOG_START, 5000.0f);
|
|
|
|
glFogf(GL_FOG_END, 7000.0f);
|
|
|
|
glEnable(GL_FOG);
|
|
|
|
} else {
|
|
|
|
glDisable(GL_FOG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-17 17:59:59 -08:00
|
|
|
//fog disabled so turn it off if not off already
|
2007-06-28 10:47:08 -07:00
|
|
|
if (rendStates.fog != FALSE)
|
|
|
|
{
|
|
|
|
rendStates.fog = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
void pie_SetTexturePage(SDWORD num)
|
|
|
|
{
|
|
|
|
#ifndef PIETOOL
|
|
|
|
if (num != rendStates.texPage) {
|
|
|
|
rendStates.texPage = num;
|
|
|
|
if (num < 0) {
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
} else {
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, _TEX_PAGE[num].textPage3dfx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
void pie_SetColourKeyedBlack(BOOL keyingOn)
|
|
|
|
{
|
|
|
|
#ifndef PIETOOL
|
|
|
|
if (keyingOn != rendStates.keyingOn)
|
|
|
|
{
|
|
|
|
rendStates.keyingOn = keyingOn;
|
|
|
|
pieStateCount++;
|
|
|
|
|
|
|
|
if (keyingOn == TRUE) {
|
|
|
|
glEnable(GL_ALPHA_TEST);
|
2006-09-08 13:02:49 -07:00
|
|
|
glAlphaFunc(GL_GREATER, 0.1f);
|
2007-06-28 10:47:08 -07:00
|
|
|
} else {
|
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
2006-03-17 17:59:59 -08:00
|
|
|
void pie_SetColourCombine(COLOUR_MODE colCombMode)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
#ifndef PIETOOL //ffs
|
|
|
|
|
|
|
|
if (colCombMode != rendStates.colourCombine) {
|
|
|
|
rendStates.colourCombine = colCombMode;
|
|
|
|
pieStateCount++;
|
|
|
|
switch (colCombMode) {
|
|
|
|
case COLOUR_FLAT_CONSTANT:
|
|
|
|
case COLOUR_FLAT_ITERATED:
|
|
|
|
pie_SetTexturePage(-1);
|
|
|
|
break;
|
2006-03-17 17:59:59 -08:00
|
|
|
case COLOUR_TEX_CONSTANT:
|
2007-06-28 10:47:08 -07:00
|
|
|
case COLOUR_TEX_ITERATED:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
2006-03-17 17:59:59 -08:00
|
|
|
void pie_SetTranslucencyMode(TRANSLUCENCY_MODE transMode)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
#ifndef PIETOOL
|
|
|
|
if (transMode != rendStates.transMode) {
|
|
|
|
rendStates.transMode = transMode;
|
|
|
|
switch (transMode) {
|
|
|
|
case TRANS_ALPHA:
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
break;
|
|
|
|
case TRANS_ADDITIVE:
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
|
|
|
break;
|
2006-03-17 17:59:59 -08:00
|
|
|
case TRANS_FILTER:
|
2007-06-28 10:47:08 -07:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_SRC_COLOR);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rendStates.transMode = TRANS_DECAL;
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
// set the constant colour used in text and flat render modes
|
|
|
|
/***************************************************************************/
|
|
|
|
void pie_SetColour(UDWORD colour)
|
|
|
|
{
|
|
|
|
if (colour != rendStates.colour) {
|
|
|
|
PIELIGHT c;
|
|
|
|
|
|
|
|
rendStates.colour = colour;
|
|
|
|
pieStateCount++;
|
|
|
|
|
|
|
|
c.argb = colour;
|
|
|
|
glColor4ub(c.byte.r, c.byte.g, c.byte.b, c.byte.a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
2006-10-09 12:22:24 -07:00
|
|
|
void pie_SetGammaValue(float val)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2006-10-09 12:22:24 -07:00
|
|
|
debug(LOG_VIDEO, "%s(%f)", __FUNCTION__, val);
|
|
|
|
SDL_SetGamma(val, val, val);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|