ew-engine/hq engine src/gl_crosshair.c

326 lines
7.2 KiB
C

/*
Copyright (C) 1996-1997 Id Software, Inc.
This program 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.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
//
// this file is specific to the crosshair, since we use several crosshairs
//
#include "quakedef.h"
#define MAX_CROSSHAIR 10
//
// Integers
//
int crosshair_initialised = true;
//
// External pictures used for loading (see below)
//
byte crosshair1[32][32];
extern cvar_t gamedir;
//
// Structures
//
typedef struct
{
float xsize; // x value
float ysize; // y value
float alpha; // alpha value
float red; // rgb values
float green;
float blue;
} cflags_t;
typedef struct
{
// a slim structure, but it's all about looks, isn't it?
cflags_t flags; // additional flags
float delay; //Tei extension for animated skybox
char name[80];
} crosshair_t;
crosshair_t crosshairs[MAX_CROSSHAIR]; //max 9 crosshairs (FIXME: 10 overwrites 1)
extern char moddir[255];
//=============================================================================
/* Main function */
//=============================================================================
//Crosshair stuff
int crosshair_texture[11];
/*
==============
Crosshair_Init
==============
*/
void Crosshair_Init (void)
{
int i;
for (i=1; i<11; i++)
crosshair_texture[i] = loadtextureimage (va("gfx/crosshairs/crosshair%i", i), false, true);
}
/*
==============
Draw_Crosshair
==============
*/
void Draw_Crosshair (int num)
{
int x = 0;
int y = 0;
x = (vid.width /2) - 16;
y = (vid.height/2) - 8;
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture (GL_TEXTURE_2D, crosshair_texture[num]);
glBegin (GL_QUADS);
glTexCoord2f (0,0); glVertex2f (x, y);
glTexCoord2f (1,0); glVertex2f (x + 32, y);
glTexCoord2f (1,1); glVertex2f (x + 32, y + 32);
glTexCoord2f (0,1); glVertex2f (x, y + 32);
glEnd ();
// restore display settings
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}
//End Crosshair Stuff
//==========================================================================
#if 1 //def ANIMATEDSKYBOX
extern cvar_t level;
#define MAX_SKYBOX 100
int skybox_initialised;
int actual_skybox;
float timetodelay;
int skynum;
int skybox_texture[MAX_SKYBOX][6];
crosshair_t skybox[MAX_SKYBOX]; //max 9 skybox (FIXME: 10 overwrites 1)
extern int skytexture[6];
void ResetRSkybox()
{
// Con_Printf("Reset rskybox\n");
//skybox_initialised = false;
actual_skybox = 0;
timetodelay = 0;
// skynum = 0;
}
void CheckForNextSkybox()
{
int t;
if(!skybox_initialised)
return;
if(actual_skybox>=MAX_SKYBOX)
{
Con_Printf("Debug: bad rskybox number\n");
actual_skybox = 0;
}
//Con_Printf("skybox is.. '%s', num %d, delay %f, %f, %f , skynum %d\n",skybox[actual_skybox].name, actual_skybox, skybox[actual_skybox].delay,timetodelay,cl.time,skynum);
if (timetodelay<cl.time)
{
actual_skybox++;
if(actual_skybox>skynum || !skybox[actual_skybox].delay)
actual_skybox = 0;
for(t=0;t<6;t++)
skytexture[t] = skybox_texture[actual_skybox][t];
timetodelay = cl.time + skybox[actual_skybox].delay;
}
}
void SetActualFeaturesSkybox()
{
glColor3f(skybox[actual_skybox].flags.red, skybox[actual_skybox].flags.green ,skybox[actual_skybox].flags.blue);
}
void Skybox_Init (void)
{
// int x, y;
// byte data[32][32][4];
FILE *f;
int instructure, texture_num,t;
char ch[1024], file[1024];
char tmp[1024];
char flag[1024];
float value;
char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
//Global reset
ResetRSkybox();
skybox_initialised = false;
skynum = 0;
ch[0] = 0;
tmp[0] = 0; // 2?
file[0] = 0;
flag[0] = 0;
//
// Open script
//
//Con_Printf("Check for rskybox...\n");
//Tei better rscript loading
COM_FOpenFile(va("%s/scripts/%s/skybox.txt",moddir,level.string), &f);
//if (!f)
// Con_Printf("No rskybox file '%s'\n",va("%s/scripts/%s/skybox.txt",moddir,level.string));
//COM_FOpenFile(va("%s/scripts/skybox.txt",moddir), &f);
if (!f || feof(f))
{
COM_FOpenFile("scripts/skybox.txt",&f);
if (!f || feof(f) )
{
Con_Printf(" &f9000 *Failed to load rskybox script.&r\n");
skybox_initialised = false; // disable crosshair engine, and revert all crosshairs back to the default crosshair
}
}
if (f)
// Con_Printf("No rskybox file '%s'\n","scripts/skybox.txt");
// else
skybox_initialised = true;
instructure = 0;
if (skybox_initialised)
{
Con_Printf(" *Loaded skybox script\n");
while (!feof(f)) // loop trough this until we find an eof (end of file)
{
fscanf(f,"%s",ch);
if (instructure) // decide if where are in the script
{
if (!_stricmp(ch,"file"))
{
fscanf(f,"%s",file);
for(t=0;t<6;t++)
skybox_texture[texture_num][t] = loadtextureimage (va("gfx/env/%s%s",file,suf[t]), false, true);
skynum++;
skybox[texture_num].flags.red = 1;
skybox[texture_num].flags.green = 1;
skybox[texture_num].flags.blue = 1;
skybox[texture_num].delay = 0;
strcpy(skybox[texture_num].name,file);
}
if (!_stricmp(ch,"delay"))
{
fscanf(f,"%f",&value);
skybox[texture_num].delay = value;
}
if (!_stricmp(ch,"set"))
{
fscanf(f,"%s",flag);
fscanf(f,"%f",&value);
if (!_stricmp(flag, "alpha"))
{
skybox[texture_num].flags.alpha = value;
// Con_Printf("Alpha is %f\n", value);
}
else if (!_stricmp(flag, "xsize"))
{
skybox[texture_num].flags.xsize = value;
// Con_Printf("Xsize is %f\n", value);
}
else if (!_stricmp(flag, "ysize"))
{
skybox[texture_num].flags.ysize = value;
// Con_Printf("Ysize is %f\n", value);
}
else if (!_stricmp(flag, "red"))
{
skybox[texture_num].flags.red = value;
// Con_Printf("Red is %f\n", value);
}
else if (!_stricmp(flag, "green"))
{
skybox[texture_num].flags.green = value;
// Con_Printf("Green is %f\n", value);
}
else if (!_stricmp(flag, "blue"))
{
skybox[texture_num].flags.blue = value;
// Con_Printf("Blue is %f\n", value);
}
}
else if (!_stricmp(ch,"}"))
{
instructure = 0;
}
}
else
{
if (_stricmp(ch,"{"))
{
strcpy(tmp,ch);
texture_num = (int)(*tmp - '0'); // nasty conversion
}
else
{
instructure = 1;
}
}
}
fclose(f); // close file
}
}
#endif