mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
Cleaned up fisheye code which totally ignored QF coding style.
Also attempt to fix an init bug in R_InitFishEyeOnce (add gl_cube_map_capable = false to else).
This commit is contained in:
parent
76eb7917a7
commit
83f0901c17
1 changed files with 66 additions and 46 deletions
|
@ -591,13 +591,16 @@ R_BuildFisheyeLookup (int width, int height, float fov)
|
|||
#define CHKGLERR(s) \
|
||||
do { \
|
||||
GLint err = qfglGetError(); \
|
||||
if (err != GL_NO_ERROR) printf ("%s: gl error %d\n", s, (int)err); \
|
||||
if (err != GL_NO_ERROR) \
|
||||
printf ("%s: gl error %d\n", s, (int) err); \
|
||||
} while (0);
|
||||
|
||||
#define NO(x) \
|
||||
do { \
|
||||
if (x < 0) x += 360; \
|
||||
else if (x >= 360) x -= 360; \
|
||||
if (x < 0) \
|
||||
x += 360; \
|
||||
else if (x >= 360) \
|
||||
x -= 360; \
|
||||
} while (0)
|
||||
|
||||
static void
|
||||
|
@ -620,7 +623,8 @@ R_RenderCubeSide (int side)
|
|||
// n_roll = roll;
|
||||
|
||||
switch (side) {
|
||||
case BOX_FRONT: break;
|
||||
case BOX_FRONT:
|
||||
break;
|
||||
case BOX_RIGHT:
|
||||
n_pitch = roll;
|
||||
n_yaw -= 90;
|
||||
|
@ -631,9 +635,9 @@ R_RenderCubeSide (int side)
|
|||
n_yaw += 90;
|
||||
n_roll = pitch;
|
||||
// static int f = 0;
|
||||
//if (!(f++%100)) printf("%4d %4d %4d | %4d %4d %4d\n",
|
||||
//(int)pitch, (int)yaw, (int)roll,
|
||||
//(int)n_pitch, (int)n_yaw, (int)n_roll);
|
||||
// if (!(f++ % 100))
|
||||
// printf ("%4d %4d %4d | %4d %4d %4d\n", (int) pitch, (int) yaw,
|
||||
// (int) roll, (int) n_pitch, (int) n_yaw, (int) n_roll);
|
||||
break;
|
||||
case BOX_TOP:
|
||||
n_pitch -= 90;
|
||||
|
@ -646,7 +650,9 @@ R_RenderCubeSide (int side)
|
|||
n_yaw += 180;
|
||||
break;
|
||||
}
|
||||
NO(n_pitch); NO(n_yaw); NO(n_roll);
|
||||
NO (n_pitch);
|
||||
NO (n_yaw);
|
||||
NO (n_roll);
|
||||
r_refdef.viewangles[PITCH] = n_pitch;
|
||||
r_refdef.viewangles[YAW] = n_yaw;
|
||||
r_refdef.viewangles[ROLL] = n_roll;
|
||||
|
@ -673,14 +679,18 @@ R_InitFishEyeOnce (void)
|
|||
{
|
||||
static qboolean fisheye_init_once_completed = false;
|
||||
|
||||
if (fisheye_init_once_completed) return 1;
|
||||
if (fisheye_init_once_completed)
|
||||
return 1;
|
||||
Con_Printf ("GL_ARB_texture_cube_map ");
|
||||
if (QFGL_ExtensionPresent ("GL_ARB_texture_cube_map")) {
|
||||
qfglGetIntegerv (GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, &gl_cube_map_maxtex);
|
||||
Con_Printf ("present, max texture size %d.\n", (int)gl_cube_map_maxtex);
|
||||
qfglGetIntegerv (GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB,
|
||||
&gl_cube_map_maxtex);
|
||||
Con_Printf ("present, max texture size %d.\n",
|
||||
(int) gl_cube_map_maxtex);
|
||||
gl_cube_map_capable = true;
|
||||
} else {
|
||||
Con_Printf ("not found.\n");
|
||||
gl_cube_map_capable = false;
|
||||
}
|
||||
fisheye_init_once_completed = true;
|
||||
return 1;
|
||||
|
@ -701,8 +711,10 @@ R_InitFishEye (void)
|
|||
|
||||
int i, x, y, min_wh, wh_changed = 0;
|
||||
|
||||
if (!R_InitFishEyeOnce()) return 0;
|
||||
if (!gl_cube_map_capable) return 0;
|
||||
if (!R_InitFishEyeOnce())
|
||||
return 0;
|
||||
if (!gl_cube_map_capable)
|
||||
return 0;
|
||||
|
||||
// There is a problem when max texture size is bigger than
|
||||
// min(width, height), it shows up as black fat stripes at the edges
|
||||
|
@ -724,11 +736,14 @@ R_InitFishEye (void)
|
|||
qfglGenTextures (1, &cube_map_tex);
|
||||
qfglBindTexture (GL_TEXTURE_CUBE_MAP_ARB, cube_map_tex);
|
||||
for (i = 0; i < 6; ++i) {
|
||||
qfglTexImage2D (box2cube_map[i], 0, 3, gl_cube_map_size, gl_cube_map_size,
|
||||
0, GL_RGB, GL_UNSIGNED_SHORT, NULL);
|
||||
qfglTexImage2D (box2cube_map[i], 0, 3, gl_cube_map_size,
|
||||
gl_cube_map_size, 0, GL_RGB, GL_UNSIGNED_SHORT,
|
||||
NULL);
|
||||
}
|
||||
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER,
|
||||
GL_LINEAR);
|
||||
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER,
|
||||
GL_LINEAR);
|
||||
qfglDisable (GL_TEXTURE_CUBE_MAP_ARB);
|
||||
}
|
||||
if (wh_changed || pfov != fov) {
|
||||
|
@ -738,12 +753,14 @@ R_InitFishEye (void)
|
|||
pheight = height;
|
||||
pfov = fov;
|
||||
|
||||
R_BuildFisheyeLookup (gl_cube_map_size, gl_cube_map_size, ((float)fov)*M_PI/180.0);
|
||||
R_BuildFisheyeLookup (gl_cube_map_size, gl_cube_map_size,
|
||||
((float) fov) * M_PI / 180.0);
|
||||
|
||||
fisheye_grid = qfglGenLists (1);
|
||||
qfglNewList (fisheye_grid, GL_COMPILE);
|
||||
qfglLoadIdentity ();
|
||||
qfglTranslatef (-gl_cube_map_size/2, -gl_cube_map_size/2, -gl_cube_map_size/2);
|
||||
qfglTranslatef (-gl_cube_map_size / 2, -gl_cube_map_size / 2,
|
||||
-gl_cube_map_size / 2);
|
||||
|
||||
qfglDisable (GL_DEPTH_TEST);
|
||||
qfglCullFace (GL_BACK);
|
||||
|
@ -755,10 +772,13 @@ R_InitFishEye (void)
|
|||
|
||||
for (y = 0; y < gl_cube_map_size; y += gl_cube_map_step) {
|
||||
for (x = 0; x <= gl_cube_map_size; x += gl_cube_map_step) { // quad_strip, X should be inclusive
|
||||
struct xyz *v = &FisheyeLookupTbl[x/gl_cube_map_step][y/gl_cube_map_step+1];
|
||||
qfglTexCoord3f (v->x, v->y, v->z); qfglVertex2i (x, y+gl_cube_map_step);
|
||||
struct xyz *v = &FisheyeLookupTbl[x / gl_cube_map_step]
|
||||
[y / gl_cube_map_step + 1];
|
||||
qfglTexCoord3f (v->x, v->y, v->z);
|
||||
qfglVertex2i (x, y + gl_cube_map_step);
|
||||
--v;
|
||||
qfglTexCoord3f (v->x, v->y, v->z); qfglVertex2i (x, y);
|
||||
qfglTexCoord3f (v->x, v->y, v->z);
|
||||
qfglVertex2i (x, y);
|
||||
}
|
||||
}
|
||||
qfglEnd ();
|
||||
|
|
Loading…
Reference in a new issue