*** empty log message ***
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@932 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
+133
-38
@@ -194,6 +194,10 @@ void blendbox(int x1, int y1, int x2, int y2, bool border, int tex)
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
VARP(fov, 90, 100, 120);
|
||||
VAR(fog, 64, 180, 1024);
|
||||
VAR(fogcolour, 0, 0x8099B3, 0xFFFFFF);
|
||||
|
||||
physent *camera1 = NULL;
|
||||
|
||||
void trypitch(int i) { camera1->pitch = (float)i; }
|
||||
@@ -231,6 +235,112 @@ void transplayer()
|
||||
glTranslatef(-camera1->o.x, -camera1->o.z, -camera1->o.y);
|
||||
}
|
||||
|
||||
void genclipmatrix(float a, float b, float c, float d, GLfloat matrix[16])
|
||||
{
|
||||
// transform the clip plane into camera space
|
||||
GLdouble clip[4] = {a, b, c, d};
|
||||
glClipPlane(GL_CLIP_PLANE0, clip);
|
||||
glGetClipPlane(GL_CLIP_PLANE0, clip);
|
||||
|
||||
glGetFloatv(GL_PROJECTION_MATRIX, matrix);
|
||||
float x = ((clip[0]<0 ? -1 : (clip[0]>0 ? 1 : 0)) + matrix[8]) / matrix[0],
|
||||
y = ((clip[1]<0 ? -1 : (clip[1]>0 ? 1 : 0)) + matrix[9]) / matrix[5],
|
||||
w = (1 + matrix[10]) / matrix[14],
|
||||
scale = 2 / (x*clip[0] + y*clip[1] - clip[2] + w*clip[3]);
|
||||
matrix[2] = clip[0]*scale;
|
||||
matrix[6] = clip[1]*scale;
|
||||
matrix[10] = clip[2]*scale + 1.0f;
|
||||
matrix[14] = clip[3]*scale;
|
||||
}
|
||||
|
||||
bool reflecting = false;
|
||||
GLuint reflecttex = 0;
|
||||
int reflectlastsize = 0;
|
||||
|
||||
VARP(reflectres, 6, 7, 10);
|
||||
VARP(waterreflect, 0, 1, 1);
|
||||
|
||||
void drawreflection(float hf, int w, int h, float changelod)
|
||||
{
|
||||
reflecting = true;
|
||||
|
||||
int size = 1<<reflectres;
|
||||
while(size > w || size > h) size /= 2;
|
||||
if(size!=reflectlastsize)
|
||||
{
|
||||
glDeleteTextures(1, &reflecttex);
|
||||
reflecttex = 0;
|
||||
}
|
||||
if(!reflecttex)
|
||||
{
|
||||
glGenTextures(1, &reflecttex);
|
||||
createtexture(reflecttex, size, size, NULL, 3, false, GL_RGB);
|
||||
reflectlastsize = size;
|
||||
}
|
||||
|
||||
resetcubes();
|
||||
|
||||
render_world(camera1->o.x, camera1->o.y, hf, changelod,
|
||||
(int)camera1->yaw, -(int)camera1->pitch, (float)fov, size, size);
|
||||
|
||||
setupstrips();
|
||||
|
||||
glCullFace(GL_BACK);
|
||||
glViewport(0, 0, size, size);
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
transplayer();
|
||||
glTranslatef(0, 2*hf, 0);
|
||||
glScalef(1, -1, 1);
|
||||
|
||||
GLfloat clipmat[16];
|
||||
genclipmatrix(0, 1, 0, 0.1f-hf, clipmat);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadMatrixf(clipmat);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
renderstripssky();
|
||||
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glRotatef(camera1->pitch, -1, 0, 0);
|
||||
glRotatef(camera1->yaw, 0, 1, 0);
|
||||
glRotatef(90, 1, 0, 0);
|
||||
glScalef(1, 1, -1);
|
||||
glColor3f(1, 1, 1);
|
||||
glDisable(GL_FOG);
|
||||
glDepthFunc(GL_GREATER);
|
||||
draw_envbox(fog*4/3);
|
||||
glDepthFunc(GL_LESS);
|
||||
glEnable(GL_FOG);
|
||||
glPopMatrix();
|
||||
|
||||
overbright(2);
|
||||
|
||||
renderstrips();
|
||||
renderentities();
|
||||
renderclients();
|
||||
|
||||
overbright(1);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
glCullFace(GL_FRONT);
|
||||
glViewport(0, 0, w, h);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, reflecttex);
|
||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, size, size);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
reflecting = false;
|
||||
}
|
||||
|
||||
bool minimap = false, minimapdirty = true;
|
||||
int minimaplastsize = 0;
|
||||
GLuint minimaptex = 0;
|
||||
@@ -244,13 +354,12 @@ COMMAND(clearminimap, ARG_NONE);
|
||||
|
||||
VARFP(minimapres, 7, 9, 10, clearminimap());
|
||||
|
||||
void drawminimap()
|
||||
void drawminimap(int w, int h)
|
||||
{
|
||||
if(!minimapdirty) return;
|
||||
|
||||
extern int scr_w, scr_h;
|
||||
int size = 1<<minimapres;
|
||||
while(size > scr_w || size > scr_h) size /= 2;
|
||||
while(size > w || size > h) size /= 2;
|
||||
if(size!=minimaplastsize)
|
||||
{
|
||||
glDeleteTextures(1, &minimaptex);
|
||||
@@ -304,7 +413,7 @@ void drawminimap()
|
||||
overbright(1);
|
||||
|
||||
float hf = hdr.waterlevel-0.3f;
|
||||
renderwater(hf);
|
||||
renderwater(hf, 0);
|
||||
|
||||
minimap = false;
|
||||
|
||||
@@ -316,17 +425,12 @@ void drawminimap()
|
||||
glEnable(GL_FOG);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
glViewport(0, 0, scr_w, scr_h);
|
||||
glViewport(0, 0, w, h);
|
||||
glClearDepth(1.0);
|
||||
}
|
||||
|
||||
VARP(fov, 90, 100, 120);
|
||||
|
||||
int xtraverts;
|
||||
|
||||
VAR(fog, 64, 180, 1024);
|
||||
VAR(fogcolour, 0, 0x8099B3, 0xFFFFFF);
|
||||
|
||||
void drawhudgun(int w, int h, float aspect, int farplane)
|
||||
{
|
||||
if(scoped && player1->gunselect==GUN_SNIPER) return;
|
||||
@@ -391,24 +495,9 @@ void readdepth(int w, int h, vec &pos)
|
||||
pos.z = (float)worldz;
|
||||
}
|
||||
|
||||
void invertperspective()
|
||||
{
|
||||
// This only generates a valid inverse matrix for matrices generated by gluPerspective()
|
||||
GLdouble inv[16];
|
||||
memset(inv, 0, sizeof(inv));
|
||||
|
||||
inv[0*4+0] = 1.0/pm[0*4+0];
|
||||
inv[1*4+1] = 1.0/pm[1*4+1];
|
||||
inv[2*4+3] = 1.0/pm[3*4+2];
|
||||
inv[3*4+2] = -1.0;
|
||||
inv[3*4+3] = pm[2*4+2]/pm[3*4+2];
|
||||
|
||||
glLoadMatrixd(inv);
|
||||
}
|
||||
|
||||
void gl_drawframe(int w, int h, float changelod, float curfps)
|
||||
{
|
||||
drawminimap();
|
||||
drawminimap(w, h);
|
||||
|
||||
recomputecamera();
|
||||
|
||||
@@ -423,22 +512,29 @@ void gl_drawframe(int w, int h, float changelod, float curfps)
|
||||
glFogfv(GL_FOG_COLOR, fogc);
|
||||
glClearColor(fogc[0], fogc[1], fogc[2], 1.0f);
|
||||
|
||||
if(underwater)
|
||||
{
|
||||
fovy += sinf(lastmillis/1000.0f)*2.0f;
|
||||
aspect += sinf(lastmillis/1000.0f+PI)*0.1f;
|
||||
glFogi(GL_FOG_START, 0);
|
||||
glFogi(GL_FOG_END, (fog+96)/8);
|
||||
}
|
||||
|
||||
glClear((outsidemap(camera1) ? GL_COLOR_BUFFER_BIT : 0) | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
int farplane = fog*5/2;
|
||||
gluPerspective(fovy, aspect, 0.15f, farplane);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
if(underwater)
|
||||
{
|
||||
fovy += sinf(lastmillis/1000.0f)*2.0f;
|
||||
aspect += sinf(lastmillis/1000.0f+PI)*0.1f;
|
||||
float wfogc[4] = { hdr.watercolor[0]/255.0f, hdr.watercolor[1]/255.0f, hdr.watercolor[2]/255.0f, 1.0f };
|
||||
glFogfv(GL_FOG_COLOR, wfogc);
|
||||
glFogi(GL_FOG_START, 0);
|
||||
glFogi(GL_FOG_END, (fog+96)/8);
|
||||
}
|
||||
else if(waterreflect)
|
||||
{
|
||||
extern int wx1;
|
||||
if(wx1>=0) drawreflection(hf, w, h, changelod);
|
||||
}
|
||||
|
||||
glClear((outsidemap(camera1) ? GL_COLOR_BUFFER_BIT : 0) | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
transplayer();
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
@@ -495,7 +591,7 @@ void gl_drawframe(int w, int h, float changelod, float curfps)
|
||||
render_particles(curtime);
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
int nquads = renderwater(hf);
|
||||
int nquads = renderwater(hf, !waterreflect || underwater ? 0 : reflecttex);
|
||||
|
||||
glDisable(GL_FOG);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
@@ -508,7 +604,6 @@ void gl_drawframe(int w, int h, float changelod, float curfps)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
}
|
||||
|
||||
invertperspective();
|
||||
extern vector<vertex> verts;
|
||||
gl_drawhud(w, h, (int)curfps, nquads, verts.length(), underwater);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user