3D attenuation texture works now
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 6 Oct 2002 03:24:47 +0000 (03:24 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 6 Oct 2002 03:24:47 +0000 (03:24 +0000)
also fixed the commandline options -width and such (untested)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2504 d7cf8633-e32d-0410-b094-e92efae38249

gl_backend.c
gl_models.c
gl_rsurf.c
gl_textures.c
glquake.h
r_shadow.c
r_shadow.h
vid_shared.c

index 2de66cd..48d4982 100644 (file)
@@ -295,14 +295,18 @@ void GL_SetupTextureState(void)
                unit->arrayenabled = false;
                qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
                if (gl_texture3d)
+               {
                        qglTexCoordPointer(3, GL_FLOAT, sizeof(float[4]), varray_texcoord[i]);CHECKGLERROR
+               }
                else
+               {
                        qglTexCoordPointer(2, GL_FLOAT, sizeof(float[4]), varray_texcoord[i]);CHECKGLERROR
+               }
                qglDisable(GL_TEXTURE_1D);CHECKGLERROR
                qglDisable(GL_TEXTURE_2D);CHECKGLERROR
                if (gl_texture3d)
                {
-                       qglDisable(GL_TEXTURE_3D_EXT);CHECKGLERROR
+                       qglDisable(GL_TEXTURE_3D);CHECKGLERROR
                }
                if (gl_texturecubemap)
                {
@@ -506,7 +510,7 @@ void R_Mesh_Finish(void)
                qglDisable(GL_TEXTURE_2D);CHECKGLERROR
                if (gl_texture3d)
                {
-                       qglDisable(GL_TEXTURE_3D_EXT);CHECKGLERROR
+                       qglDisable(GL_TEXTURE_3D);CHECKGLERROR
                }
                if (gl_texturecubemap)
                {
@@ -668,14 +672,14 @@ void R_Mesh_TextureState(const rmeshstate_t *m)
                                if (m->tex3d[i])
                                {
                                        if (unit->t3d == 0)
-                                               qglEnable(GL_TEXTURE_3D_EXT);CHECKGLERROR
+                                               qglEnable(GL_TEXTURE_3D);CHECKGLERROR
                                }
                                else
                                {
                                        if (unit->t3d)
-                                               qglDisable(GL_TEXTURE_3D_EXT);CHECKGLERROR
+                                               qglDisable(GL_TEXTURE_3D);CHECKGLERROR
                                }
-                               qglBindTexture(GL_TEXTURE_3D_EXT, (unit->t3d = m->tex3d[i]));CHECKGLERROR
+                               qglBindTexture(GL_TEXTURE_3D, (unit->t3d = m->tex3d[i]));CHECKGLERROR
                        }
                        if (unit->tcubemap != m->texcubemap[i])
                        {
index 30ba77f..c55f9c3 100644 (file)
@@ -581,7 +581,7 @@ void R_Model_Alias_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, f
 {
        R_Mesh_ResizeCheck(ent->model->numverts);
        R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm);
-       R_Shadow_VertexLight(ent->model->numverts, varray_vertex, aliasvertnorm, relativelightorigin, lightradius * lightradius, lightdistbias, lightsubtract, lightcolor);
+       R_Shadow_Light(ent->model->numverts, aliasvertnorm, relativelightorigin, lightradius, lightdistbias, lightsubtract, lightcolor);
        GL_UseColorArray();
        R_Mesh_Draw(ent->model->numverts, ent->model->numtris, ent->model->mdlmd2data_indices);
 }
index 592ec34..5593a63 100644 (file)
@@ -1912,7 +1912,7 @@ void R_Model_Brush_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, f
                                {
                                        R_Mesh_ResizeCheck(mesh->numverts);
                                        memcpy(varray_vertex, mesh->verts, mesh->numverts * sizeof(float[4]));
-                                       R_Shadow_VertexLight(mesh->numverts, varray_vertex, mesh->normals, relativelightorigin, lightradius2, lightdistbias, lightsubtract, lightcolor);
+                                       R_Shadow_Light(mesh->numverts, mesh->normals, relativelightorigin, lightradius, lightdistbias, lightsubtract, lightcolor);
                                        R_Mesh_Draw(mesh->numverts, mesh->numtriangles, mesh->index);
                                }
                        }
index 66f8228..f06ac7d 100644 (file)
@@ -548,8 +548,25 @@ static void R_Upload(gltexture_t *glt, qbyte *data)
        prevbuffer = data;
 
        glt->texnum = glt->image->texnum;
-       qglBindTexture(GL_TEXTURE_2D, glt->image->texnum);
-       CHECKGLERROR
+       switch(glt->image->texturetype)
+       {
+       case GLTEXTURETYPE_1D:
+               qglBindTexture(GL_TEXTURE_1D, glt->image->texnum);
+               CHECKGLERROR
+               break;
+       case GLTEXTURETYPE_2D:
+               qglBindTexture(GL_TEXTURE_2D, glt->image->texnum);
+               CHECKGLERROR
+               break;
+       case GLTEXTURETYPE_3D:
+               qglBindTexture(GL_TEXTURE_3D, glt->image->texnum);
+               CHECKGLERROR
+               break;
+       case GLTEXTURETYPE_CUBEMAP:
+               qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, glt->image->texnum);
+               CHECKGLERROR
+               break;
+       }
        glt->flags &= ~GLTEXF_UPLOAD;
        gl_backend_rebindtextures = true;
 
@@ -580,11 +597,11 @@ static void R_Upload(gltexture_t *glt, qbyte *data)
                                CHECKGLERROR
                                break;
                        case GLTEXTURETYPE_3D:
-                               qglTexImage3DEXT(GL_TEXTURE_3D_EXT, 0, glt->image->glinternalformat, glt->image->width, glt->image->height, glt->image->depth, 0, glt->image->glformat, GL_UNSIGNED_BYTE, resizebuffer);
+                               qglTexImage3D(GL_TEXTURE_3D, 0, glt->image->glinternalformat, glt->image->width, glt->image->height, glt->image->depth, 0, glt->image->glformat, GL_UNSIGNED_BYTE, resizebuffer);
                                CHECKGLERROR
-                               qglTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MIN_FILTER, gl_filter_mag);
+                               qglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, gl_filter_mag);
                                CHECKGLERROR
-                               qglTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MAG_FILTER, gl_filter_mag);
+                               qglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, gl_filter_mag);
                                CHECKGLERROR
                                break;
                        default:
@@ -619,7 +636,7 @@ static void R_Upload(gltexture_t *glt, qbyte *data)
                        CHECKGLERROR
                        break;
                case GLTEXTURETYPE_3D:
-                       qglTexSubImage3DEXT(GL_TEXTURE_3D_EXT, 0, glt->x, glt->y, glt->z, glt->width, glt->height, glt->depth, glt->image->glformat, GL_UNSIGNED_BYTE, prevbuffer);
+                       qglTexSubImage3D(GL_TEXTURE_3D, 0, glt->x, glt->y, glt->z, glt->width, glt->height, glt->depth, glt->image->glformat, GL_UNSIGNED_BYTE, prevbuffer);
                        CHECKGLERROR
                        break;
                default:
@@ -730,7 +747,7 @@ static void R_Upload(gltexture_t *glt, qbyte *data)
                }
                break;
        case GLTEXTURETYPE_3D:
-               qglTexImage3DEXT(GL_TEXTURE_3D_EXT, mip++, internalformat, width, height, depth, 0, glt->image->glformat, GL_UNSIGNED_BYTE, prevbuffer);
+               qglTexImage3D(GL_TEXTURE_3D, mip++, internalformat, width, height, depth, 0, glt->image->glformat, GL_UNSIGNED_BYTE, prevbuffer);
                CHECKGLERROR
                if (glt->flags & TEXF_MIPMAP)
                {
@@ -738,19 +755,19 @@ static void R_Upload(gltexture_t *glt, qbyte *data)
                        {
                                Image_MipReduce(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1, glt->image->bytesperpixel);
                                prevbuffer = resizebuffer;
-                               qglTexImage3DEXT(GL_TEXTURE_3D_EXT, mip++, internalformat, width, height, depth, 0, glt->image->glformat, GL_UNSIGNED_BYTE, prevbuffer);
+                               qglTexImage3D(GL_TEXTURE_3D, mip++, internalformat, width, height, depth, 0, glt->image->glformat, GL_UNSIGNED_BYTE, prevbuffer);
                                CHECKGLERROR
                        }
-                       qglTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MIN_FILTER, gl_filter_min);
+                       qglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
                        CHECKGLERROR
-                       qglTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MAG_FILTER, gl_filter_mag);
+                       qglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, gl_filter_mag);
                        CHECKGLERROR
                }
                else
                {
-                       qglTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MIN_FILTER, gl_filter_mag);
+                       qglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, gl_filter_mag);
                        CHECKGLERROR
-                       qglTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MAG_FILTER, gl_filter_mag);
+                       qglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, gl_filter_mag);
                        CHECKGLERROR
                }
                break;
index 96a7124..48c1e60 100644 (file)
--- a/glquake.h
+++ b/glquake.h
@@ -113,6 +113,7 @@ typedef double GLclampd;
 #define GL_TEXTURE_2D                          0x0DE1
 #define GL_TEXTURE_WRAP_S                      0x2802
 #define GL_TEXTURE_WRAP_T                      0x2803
+#define GL_TEXTURE_WRAP_R                      0x8072
 #define GL_TEXTURE_MAG_FILTER                  0x2800
 #define GL_TEXTURE_MIN_FILTER                  0x2801
 #define GL_UNPACK_ALIGNMENT                    0x0CF5
@@ -288,20 +289,20 @@ extern int gl_combine_extension;
 extern cvar_t gl_combine;
 
 extern int gl_texture3d;
-#ifndef GL_TEXTURE_3D_EXT
-#define GL_PACK_SKIP_IMAGES_EXT                        0x806B
-#define GL_PACK_IMAGE_HEIGHT_EXT               0x806C
-#define GL_UNPACK_SKIP_IMAGES_EXT              0x806D
-#define GL_UNPACK_IMAGE_HEIGHT_EXT             0x806E
-#define GL_TEXTURE_3D_EXT                      0x806F
-#define GL_PROXY_TEXTURE_3D_EXT                        0x8070
-#define GL_TEXTURE_DEPTH_EXT                   0x8071
-#define GL_TEXTURE_WRAP_R_EXT                  0x8072
-#define GL_MAX_3D_TEXTURE_SIZE_EXT             0x8073
-#define GL_TEXTURE_3D_BINDING_EXT              0x806A
-extern void (GLAPIENTRY *qglTexImage3DEXT)(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
-extern void (GLAPIENTRY *qglTexSubImage3DEXT)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels);
-extern void (GLAPIENTRY *qglCopyTexSubImage3DEXT)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+#ifndef GL_TEXTURE_3D
+#define GL_PACK_SKIP_IMAGES                    0x806B
+#define GL_PACK_IMAGE_HEIGHT                   0x806C
+#define GL_UNPACK_SKIP_IMAGES                  0x806D
+#define GL_UNPACK_IMAGE_HEIGHT                 0x806E
+#define GL_TEXTURE_3D                          0x806F
+#define GL_PROXY_TEXTURE_3D                    0x8070
+#define GL_TEXTURE_DEPTH                       0x8071
+#define GL_TEXTURE_WRAP_R                      0x8072
+#define GL_MAX_3D_TEXTURE_SIZE                 0x8073
+#define GL_TEXTURE_BINDING_3D                  0x806A
+extern void (GLAPIENTRY *qglTexImage3D)(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
+extern void (GLAPIENTRY *qglTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels);
+extern void (GLAPIENTRY *qglCopyTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
 #endif
 
 extern int gl_texturecubemap;
index 24a6427..4aa7b5a 100644 (file)
@@ -12,6 +12,13 @@ qbyte *trianglefacinglight;
 rtexturepool_t *r_shadow_texturepool;
 rtexture_t *r_shadow_attenuationtexture;
 
+cvar_t r_shadow1 = {0, "r_shadow1", "16"};
+cvar_t r_shadow2 = {0, "r_shadow2", "2"};
+cvar_t r_shadow3 = {0, "r_shadow3", "65536"};
+cvar_t r_shadow4 = {0, "r_shadow4", "1"};
+cvar_t r_shadow5 = {0, "r_shadow5", "0.05"};
+cvar_t r_shadow6 = {0, "r_shadow6", "1"};
+
 void r_shadow_start(void)
 {
        // allocate vertex processing arrays
@@ -41,6 +48,12 @@ void r_shadow_newmap(void)
 
 void R_Shadow_Init(void)
 {
+       Cvar_RegisterVariable(&r_shadow1);
+       Cvar_RegisterVariable(&r_shadow2);
+       Cvar_RegisterVariable(&r_shadow3);
+       Cvar_RegisterVariable(&r_shadow4);
+       Cvar_RegisterVariable(&r_shadow5);
+       Cvar_RegisterVariable(&r_shadow6);
        R_RegisterModule("R_Shadow", r_shadow_start, r_shadow_shutdown, r_shadow_newmap);
 }
 
@@ -249,35 +262,44 @@ void R_Shadow_RenderVolume(int numverts, int numtris, int *elements, int visible
        }
 }
 
+float r_shadow_atten1, r_shadow_atten2, r_shadow_atten5;
 static void R_Shadow_MakeTextures(void)
 {
        int x, y, z, d;
        float v[3];
        qbyte data[32][32][32][4];
+       R_FreeTexturePool(&r_shadow_texturepool);
        r_shadow_texturepool = R_AllocTexturePool();
+       r_shadow_atten1 = r_shadow1.value;
+       r_shadow_atten2 = r_shadow2.value;
+       r_shadow_atten5 = r_shadow5.value;
        for (z = 0;z < 32;z++)
        {
-               v[2] = z - 16.0f;
                for (y = 0;y < 32;y++)
                {
-                       v[1] = y - 16.0f;
                        for (x = 0;x < 32;x++)
                        {
-                               v[0] = x - 16.0f;
-                               d = (int) ((1024.0f / (DotProduct(v, v)+1)) - 8.0f);
+                               v[0] = (x / 32.0f) - 0.5f;
+                               v[1] = (y / 32.0f) - 0.5f;
+                               v[2] = (z / 32.0f) - 0.5f;
+                               d = (int) (((r_shadow_atten1 / (DotProduct(v, v)+r_shadow_atten5)) - (r_shadow_atten1 * r_shadow_atten2)));
                                d = bound(0, d, 255);
                                data[z][y][x][0] = data[z][y][x][1] = data[z][y][x][2] = data[z][y][x][3] = d;
                        }
                }
        }
        r_shadow_attenuationtexture = R_LoadTexture3D(r_shadow_texturepool, "attenuation", 32, 32, 32, &data[0][0][0][0], TEXTYPE_RGBA, TEXF_PRECACHE | TEXF_ALPHA);
+       qglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+       qglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+       qglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP);
 }
 
 void R_Shadow_Stage_Depth(void)
 {
        rmeshstate_t m;
 
-       if (!r_shadow_attenuationtexture)
+       //cl.worldmodel->numlights = min(cl.worldmodel->numlights, 1);
+       if (!r_shadow_attenuationtexture || r_shadow1.value != r_shadow_atten1 || r_shadow2.value != r_shadow_atten2 || r_shadow5.value != r_shadow_atten5)
                R_Shadow_MakeTextures();
 
        memset(&m, 0, sizeof(m));
@@ -289,6 +311,9 @@ void R_Shadow_Stage_Depth(void)
 
 void R_Shadow_Stage_ShadowVolumes(void)
 {
+       rmeshstate_t m;
+       memset(&m, 0, sizeof(m));
+       R_Mesh_TextureState(&m);
        GL_Color(1, 1, 1, 1);
        qglColorMask(0, 0, 0, 0);
        qglDisable(GL_BLEND);
@@ -303,6 +328,11 @@ void R_Shadow_Stage_ShadowVolumes(void)
 
 void R_Shadow_Stage_Light(void)
 {
+       rmeshstate_t m;
+       memset(&m, 0, sizeof(m));
+       if (r_shadow6.integer)
+               m.tex3d[0] = R_GetTexture(r_shadow_attenuationtexture);
+       R_Mesh_TextureState(&m);
        qglEnable(GL_BLEND);
        qglBlendFunc(GL_ONE, GL_ONE);
        GL_Color(1, 1, 1, 1);
@@ -357,27 +387,56 @@ void R_Shadow_Stage_End(void)
        R_Mesh_State(&m);
 }
 
-void R_Shadow_VertexLight(int numverts, float *vertex, float *normals, vec3_t relativelightorigin, float lightradius2, float lightdistbias, float lightsubtract, float *lightcolor)
+void R_Shadow_Light(int numverts, float *normals, vec3_t relativelightorigin, float lightradius, float lightdistbias, float lightsubtract, float *lightcolor)
 {
-       int i;
-       float *n, *v, *c, f, dist, temp[3], light[3];
-       // calculate vertex colors
-       VectorCopy(lightcolor, light);
-
-       for (i = 0, v = vertex, c = varray_color, n = normals;i < numverts;i++, v += 4, c += 4, n += 3)
+       if (!r_shadow6.integer)
+       {
+               int i;
+               float *n, *v, *c, f, dist, temp[3], light[3], lightradius2;
+               VectorCopy(lightcolor, light);
+               lightradius2 = lightradius * lightradius;
+               for (i = 0, v = varray_vertex, c = varray_color, n = normals;i < numverts;i++, v += 4, c += 4, n += 3)
+               {
+                       VectorSubtract(relativelightorigin, v, temp);
+                       c[0] = 0;
+                       c[1] = 0;
+                       c[2] = 0;
+                       c[3] = 1;
+                       f = DotProduct(n, temp);
+                       if (f > 0)
+                       {
+                               dist = DotProduct(temp, temp);
+                               if (dist < lightradius2)
+                               {
+                                       f = ((1.0f / (dist + lightdistbias)) - lightsubtract) * (f / sqrt(dist));
+                                       c[0] = f * light[0];
+                                       c[1] = f * light[1];
+                                       c[2] = f * light[2];
+                               }
+                       }
+               }
+       }
+       else
        {
-               VectorSubtract(relativelightorigin, v, temp);
-               c[0] = 0;
-               c[1] = 0;
-               c[2] = 0;
-               c[3] = 1;
-               f = DotProduct(n, temp);
-               if (f > 0)
+               int i;
+               float *n, *v, *c, *t, f, temp[3], light[3], iradius, attentexbase[3];
+               VectorScale(lightcolor, (1.0f / r_shadow3.value), light);
+               iradius = 0.5f / lightradius;
+               attentexbase[0] = 0.5f;
+               attentexbase[1] = 0.5f;
+               attentexbase[2] = 0.5f;
+               for (i = 0, v = varray_vertex, c = varray_color, n = normals, t = varray_texcoord[0];i < numverts;i++, v += 4, c += 4, n += 3, t += 4)
                {
-                       dist = DotProduct(temp, temp);
-                       if (dist < lightradius2)
+                       VectorSubtract(v, relativelightorigin, temp);
+                       VectorMA(attentexbase, iradius, temp, t);
+                       c[0] = 0;
+                       c[1] = 0;
+                       c[2] = 0;
+                       c[3] = 1;
+                       f = DotProduct(n, temp);
+                       if (f < 0)
                        {
-                               f = ((1.0f / (dist + lightdistbias)) - lightsubtract) * (f / sqrt(dist));
+                               f /= -sqrt(DotProduct(temp, temp));
                                c[0] = f * light[0];
                                c[1] = f * light[1];
                                c[2] = f * light[2];
index cea3a9e..cbd35c6 100644 (file)
@@ -4,7 +4,7 @@
 
 void R_Shadow_Init(void);
 void R_Shadow_Volume(int numverts, int numtris, float *vertex, int *elements, int *neighbors, vec3_t relativelightorigin, float lightradius, float projectdistance, int visiblevolume);
-void R_Shadow_VertexLight(int numverts, float *vertex, float *normals, vec3_t relativelightorigin, float lightradius2, float lightdistbias, float lightsubtract, float *lightcolor);
+void R_Shadow_Light(int numverts, float *normals, vec3_t relativelightorigin, float lightradius, float lightdistbias, float lightsubtract, float *lightcolor);
 void R_Shadow_RenderLightThroughStencil(int numverts, int numtris, int *elements, vec3_t relativelightorigin, float *normals);
 void R_Shadow_ClearStencil(void);
 
index 8c05f36..7950c4e 100644 (file)
@@ -18,7 +18,7 @@ int gl_supportslockarrays = false;
 int gl_videosyncavailable = false;
 // stencil available
 int gl_stencil = false;
-// GL_EXT_texture3D
+// 3D textures available
 int gl_texture3d = false;
 // GL_ARB_texture_cubemap
 int gl_texturecubemap = false;
@@ -174,9 +174,9 @@ void (GLAPIENTRY *qglDrawRangeElementsEXT)(GLenum mode, GLuint start, GLuint end
 
 //void (GLAPIENTRY *qglColorTableEXT)(int, int, int, int, int, const void *);
 
-void (GLAPIENTRY *qglTexImage3DEXT)(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
-void (GLAPIENTRY *qglTexSubImage3DEXT)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels);
-void (GLAPIENTRY *qglCopyTexSubImage3DEXT)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+void (GLAPIENTRY *qglTexImage3D)(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
+void (GLAPIENTRY *qglTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels);
+void (GLAPIENTRY *qglCopyTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
 
 
 int GL_CheckExtension(const char *name, const gl_extensionfunctionlist_t *funcs, const char *disableparm, int silent)
@@ -333,9 +333,9 @@ static gl_extensionfunctionlist_t compiledvertexarrayfuncs[] =
 
 static gl_extensionfunctionlist_t texture3dfuncs[] =
 {
-       {"glTexImage3DEXT", (void **) &qglTexImage3DEXT},
-       {"glTexSubImage3DEXT", (void **) &qglTexSubImage3DEXT},
-       {"glCopyTexSubImage3DEXT", (void **) &qglCopyTexSubImage3DEXT},
+       {"glTexImage3D", (void **) &qglTexImage3D},
+       {"glTexSubImage3D", (void **) &qglTexSubImage3D},
+       {"glCopyTexSubImage3D", (void **) &qglCopyTexSubImage3D},
        {NULL, NULL}
 };
 
@@ -369,7 +369,7 @@ void VID_CheckExtensions(void)
                        gl_dot3arb = GL_CheckExtension("GL_ARB_texture_env_dot3", NULL, "-nodot3", false);
        }
 
-       gl_texture3d = GL_CheckExtension("GL_EXT_texture3D", texture3dfuncs, "-notexture3d", false);
+       gl_texture3d = GL_CheckExtension("glTexImage3D", texture3dfuncs, "-notexture3d", false);
        gl_texturecubemap = GL_CheckExtension("GL_ARB_texture_cube_map", NULL, "-nocubemap", false);
        gl_supportslockarrays = GL_CheckExtension("GL_EXT_compiled_vertex_array", compiledvertexarrayfuncs, "-nocva", false);
 
@@ -440,8 +440,6 @@ void IN_Mouse(usercmd_t *cmd, float mx, float my)
 
 void VID_Shared_Init(void)
 {
-       int i;
-
        Cvar_RegisterVariable(&vid_fullscreen);
        Cvar_RegisterVariable(&vid_width);
        Cvar_RegisterVariable(&vid_height);
@@ -454,22 +452,6 @@ void VID_Shared_Init(void)
        Cvar_RegisterVariable(&m_filter);
        Cmd_AddCommand("force_centerview", Force_CenterView_f);
        Cmd_AddCommand("vid_restart", VID_Restart_f);
-
-// interpret command-line parameters
-       if ((i = COM_CheckParm("-window")) != 0)
-               Cvar_SetValueQuick(&vid_fullscreen, false);
-       if ((i = COM_CheckParm("-fullscreen")) != 0)
-               Cvar_SetValueQuick(&vid_fullscreen, true);
-       if ((i = COM_CheckParm("-width")) != 0)
-               Cvar_SetQuick(&vid_width, com_argv[i+1]);
-       if ((i = COM_CheckParm("-height")) != 0)
-               Cvar_SetQuick(&vid_height, com_argv[i+1]);
-       if ((i = COM_CheckParm("-bpp")) != 0)
-               Cvar_SetQuick(&vid_bitsperpixel, com_argv[i+1]);
-       if ((i = COM_CheckParm("-nostencil")) != 0)
-               Cvar_SetValueQuick(&vid_stencil, 0);
-       if ((i = COM_CheckParm("-stencil")) != 0)
-               Cvar_SetValueQuick(&vid_stencil, 1);
 }
 
 int current_vid_fullscreen;
@@ -528,8 +510,30 @@ void VID_Restart_f(void)
        VID_OpenSystems();
 }
 
+int vid_commandlinecheck = true;
 void VID_Open(void)
 {
+       int i;
+       if (vid_commandlinecheck)
+       {
+               // interpret command-line parameters
+               vid_commandlinecheck = false;
+               if ((i = COM_CheckParm("-window")) != 0)
+                       Cvar_SetValueQuick(&vid_fullscreen, false);
+               if ((i = COM_CheckParm("-fullscreen")) != 0)
+                       Cvar_SetValueQuick(&vid_fullscreen, true);
+               if ((i = COM_CheckParm("-width")) != 0)
+                       Cvar_SetQuick(&vid_width, com_argv[i+1]);
+               if ((i = COM_CheckParm("-height")) != 0)
+                       Cvar_SetQuick(&vid_height, com_argv[i+1]);
+               if ((i = COM_CheckParm("-bpp")) != 0)
+                       Cvar_SetQuick(&vid_bitsperpixel, com_argv[i+1]);
+               if ((i = COM_CheckParm("-nostencil")) != 0)
+                       Cvar_SetValueQuick(&vid_stencil, 0);
+               if ((i = COM_CheckParm("-stencil")) != 0)
+                       Cvar_SetValueQuick(&vid_stencil, 1);
+       }
+
        Con_Printf("Starting video system\n");
        if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer))
        {