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
|
|
|
|
*/
|
2008-02-10 07:44:53 -08:00
|
|
|
/** \file
|
|
|
|
* Renderer setup and state control routines for 3D rendering.
|
2007-06-28 10:47:08 -07:00
|
|
|
*/
|
|
|
|
|
2008-04-20 05:52:19 -07:00
|
|
|
#include "lib/ivis_opengl/GLee.h"
|
2007-04-11 07:21:45 -07:00
|
|
|
#include "lib/framework/frame.h"
|
|
|
|
|
2007-11-24 03:49:51 -08:00
|
|
|
#include <SDL.h>
|
2008-03-30 08:44:50 -07:00
|
|
|
#include <SDL_mouse.h>
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2006-06-02 12:34:58 -07:00
|
|
|
#include "lib/ivis_common/piestate.h"
|
|
|
|
#include "lib/ivis_common/piedef.h"
|
|
|
|
#include "lib/ivis_common/tex.h"
|
2007-11-25 14:38:22 -08:00
|
|
|
#include "lib/ivis_common/piepalette.h"
|
2008-03-30 08:44:50 -07:00
|
|
|
#include "lib/ivis_common/rendmode.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Global Variables
|
|
|
|
*/
|
|
|
|
|
2008-03-30 08:44:50 -07:00
|
|
|
// Variables for the coloured mouse cursor
|
|
|
|
static CURSOR MouseCursor = 0;
|
|
|
|
static bool ColouredMouse = false;
|
|
|
|
static IMAGEFILE* MouseCursors = NULL;
|
|
|
|
static uint16_t MouseCursorIDs[CURSOR_MAX];
|
2008-11-08 13:37:32 -08:00
|
|
|
static bool MouseVisible = true;
|
2008-03-30 08:44:50 -07:00
|
|
|
|
2006-03-17 17:59:59 -08:00
|
|
|
extern RENDER_STATE rendStates;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Source
|
|
|
|
*/
|
|
|
|
|
2008-02-10 07:44:53 -08:00
|
|
|
void pie_SetDepthBufferStatus(DEPTH_MODE depthMode)
|
|
|
|
{
|
|
|
|
switch(depthMode)
|
|
|
|
{
|
2007-06-28 10:47:08 -07:00
|
|
|
case DEPTH_CMP_LEQ_WRT_ON:
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
break;
|
2008-02-10 07:44:53 -08:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
case DEPTH_CMP_ALWAYS_WRT_ON:
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
break;
|
2008-02-10 07:44:53 -08:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
case DEPTH_CMP_LEQ_WRT_OFF:
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
break;
|
2008-02-10 07:44:53 -08:00
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
case DEPTH_CMP_ALWAYS_WRT_OFF:
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(GL_FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-05 07:32:13 -07:00
|
|
|
/// Set the depth (z) offset
|
|
|
|
/// Negative values are closer to the screen
|
|
|
|
void pie_SetDepthOffset(float offset)
|
|
|
|
{
|
|
|
|
if(offset == 0.0f)
|
|
|
|
{
|
|
|
|
glDisable (GL_POLYGON_OFFSET_FILL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glPolygonOffset(offset, offset);
|
|
|
|
glEnable (GL_POLYGON_OFFSET_FILL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-20 13:46:26 -07:00
|
|
|
/// Set the OpenGL fog start and end
|
|
|
|
void pie_UpdateFogDistance(float begin, float end)
|
|
|
|
{
|
|
|
|
glFogf(GL_FOG_START, begin);
|
|
|
|
glFogf(GL_FOG_END, end);
|
|
|
|
}
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
//
|
|
|
|
// pie_SetFogStatus(BOOL val)
|
|
|
|
//
|
|
|
|
// Toggle fog on and off for rendering objects inside or outside the 3D world
|
|
|
|
//
|
|
|
|
|
|
|
|
void pie_SetFogStatus(BOOL val)
|
|
|
|
{
|
|
|
|
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) {
|
2007-11-25 15:06:24 -08:00
|
|
|
PIELIGHT fog = 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);
|
|
|
|
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
|
2008-03-24 09:51:17 -07:00
|
|
|
if (rendStates.fog != false)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2008-03-24 09:51:17 -07:00
|
|
|
rendStates.fog = false;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-10 07:03:58 -08:00
|
|
|
/** Selects a texture page and binds it for the current texture unit
|
|
|
|
* \param num a number indicating the texture page to bind. If this is a
|
|
|
|
* negative value (doesn't matter what value) it will disable texturing.
|
|
|
|
*/
|
2007-06-28 10:47:08 -07:00
|
|
|
void pie_SetTexturePage(SDWORD num)
|
|
|
|
{
|
2008-02-10 07:03:58 -08:00
|
|
|
// Only bind textures when they're not bound already
|
|
|
|
if (num != rendStates.texPage)
|
|
|
|
{
|
2008-03-21 07:34:30 -07:00
|
|
|
switch (num)
|
|
|
|
{
|
|
|
|
case TEXPAGE_NONE:
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
break;
|
|
|
|
case TEXPAGE_FONT:
|
|
|
|
// GLC will set the texture, we just need to enable texturing
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
break;
|
|
|
|
default:
|
2008-03-25 12:23:26 -07:00
|
|
|
if (rendStates.texPage == TEXPAGE_NONE || rendStates.texPage == TEXPAGE_FONT)
|
|
|
|
{
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
}
|
2008-03-21 07:34:30 -07:00
|
|
|
glBindTexture(GL_TEXTURE_2D, _TEX_PAGE[num].id);
|
|
|
|
}
|
2008-03-25 12:23:26 -07:00
|
|
|
rendStates.texPage = num;
|
2008-02-10 07:03:58 -08:00
|
|
|
}
|
|
|
|
}
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2007-12-26 17:05:37 -08:00
|
|
|
void pie_SetAlphaTest(BOOL keyingOn)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
if (keyingOn != rendStates.keyingOn)
|
|
|
|
{
|
|
|
|
rendStates.keyingOn = keyingOn;
|
|
|
|
pieStateCount++;
|
|
|
|
|
2008-03-24 09:51:17 -07:00
|
|
|
if (keyingOn == true) {
|
2007-06-28 10:47:08 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-17 17:59:59 -08:00
|
|
|
void pie_SetTranslucencyMode(TRANSLUCENCY_MODE transMode)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
default:
|
|
|
|
rendStates.transMode = TRANS_DECAL;
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-30 08:44:50 -07:00
|
|
|
void pie_InitColourMouse(IMAGEFILE* img, const uint16_t cursorIDs[CURSOR_MAX])
|
|
|
|
{
|
|
|
|
MouseCursors = img;
|
|
|
|
memcpy(MouseCursorIDs, cursorIDs, sizeof(MouseCursorIDs));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Selects the given mouse cursor.
|
|
|
|
* \param cursor mouse cursor to render
|
|
|
|
* \param coloured wether a coloured or black&white cursor should be used
|
|
|
|
*/
|
|
|
|
void pie_SetMouse(CURSOR cursor, bool coloured)
|
|
|
|
{
|
|
|
|
ASSERT(cursor < CURSOR_MAX, "Attempting to load non-existent cursor: %u", (unsigned int)cursor);
|
|
|
|
|
|
|
|
MouseCursor = cursor;
|
|
|
|
|
|
|
|
frameSetCursor(MouseCursor);
|
|
|
|
ColouredMouse = coloured;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Draws the current mouse cursor at the given coordinates
|
|
|
|
* \param X,Y mouse coordinates
|
|
|
|
*/
|
|
|
|
void pie_DrawMouse(unsigned int X, unsigned int Y)
|
|
|
|
{
|
2008-11-08 13:37:32 -08:00
|
|
|
if (ColouredMouse && MouseVisible)
|
|
|
|
{
|
|
|
|
ASSERT(MouseCursors != NULL, "Drawing coloured mouse cursor while no coloured mouse cursors have been loaded yet!");
|
2008-03-30 08:44:50 -07:00
|
|
|
|
2008-11-08 13:37:32 -08:00
|
|
|
iV_DrawImage(MouseCursors, MouseCursorIDs[MouseCursor], X, Y);
|
|
|
|
}
|
|
|
|
}
|
2008-03-30 08:44:50 -07:00
|
|
|
|
2008-11-08 13:37:32 -08:00
|
|
|
/** Set the visibility of the mouse cursor */
|
|
|
|
void pie_ShowMouse(bool visible)
|
|
|
|
{
|
|
|
|
MouseVisible = visible;
|
|
|
|
if (MouseVisible && !ColouredMouse)
|
|
|
|
{
|
|
|
|
SDL_ShowCursor(SDL_ENABLE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
|
|
|
}
|
2008-03-30 08:44:50 -07:00
|
|
|
}
|
2008-11-08 13:37:32 -08:00
|
|
|
|