00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "r_local.h"
00026 #include "r_program.h"
00027 #include "r_error.h"
00028
00029
00030 const vec2_t default_texcoords[4] = {
00031 {0.0, 0.0}, {1.0, 0.0}, {1.0, 1.0}, {0.0, 1.0}
00032 };
00033
00037 qboolean R_SelectTexture (gltexunit_t *texunit)
00038 {
00039 if (texunit == r_state.active_texunit)
00040 return qtrue;
00041
00042
00043 if (texunit->texture >= r_config.maxTextureCoords + GL_TEXTURE0_ARB)
00044 return qfalse;
00045
00046 r_state.active_texunit = texunit;
00047
00048 qglActiveTexture(texunit->texture);
00049 qglClientActiveTexture(texunit->texture);
00050 return qtrue;
00051 }
00052
00053 static void R_BindTexture_ (int texnum)
00054 {
00055 if (texnum == r_state.active_texunit->texnum)
00056 return;
00057
00058 assert(texnum > 0);
00059
00060 r_state.active_texunit->texnum = texnum;
00061
00062 glBindTexture(GL_TEXTURE_2D, texnum);
00063 R_CheckError();
00064 }
00065
00066 void R_BindTextureDebug (int texnum, const char *file, int line, const char *function)
00067 {
00068 if (texnum <= 0) {
00069 Com_Printf("Bad texnum (%d) in: %s (%d): %s\n", texnum, file, line, function);
00070 }
00071 R_BindTexture_(texnum);
00072 }
00073
00074 void R_BindTextureForTexUnit (GLuint texnum, gltexunit_t *texunit)
00075 {
00076
00077 if (texnum == texunit->texnum)
00078 return;
00079
00080 R_SelectTexture(texunit);
00081
00082 R_BindTexture(texnum);
00083
00084 R_SelectTexture(&texunit_diffuse);
00085 }
00086
00087 void R_BindLightmapTexture (GLuint texnum)
00088 {
00089 R_BindTextureForTexUnit(texnum, &texunit_lightmap);
00090 }
00091
00092 void R_BindDeluxemapTexture (GLuint texnum)
00093 {
00094 R_BindTextureForTexUnit(texnum, &texunit_deluxemap);
00095 }
00096
00097 void R_BindNormalmapTexture (GLuint texnum)
00098 {
00099 R_BindTextureForTexUnit(texnum, &texunit_normalmap);
00100 }
00101
00102 void R_BindArray (GLenum target, GLenum type, const void *array)
00103 {
00104 switch (target) {
00105 case GL_VERTEX_ARRAY:
00106 glVertexPointer(3, type, 0, array);
00107 break;
00108 case GL_TEXTURE_COORD_ARRAY:
00109 glTexCoordPointer(2, type, 0, array);
00110 break;
00111 case GL_COLOR_ARRAY:
00112 glColorPointer(4, type, 0, array);
00113 break;
00114 case GL_NORMAL_ARRAY:
00115 glNormalPointer(type, 0, array);
00116 break;
00117 case GL_TANGENT_ARRAY:
00118 R_AttributePointer("TANGENTS", 4, array);
00119 break;
00120 case GL_NEXT_VERTEX_ARRAY:
00121 R_AttributePointer("NEXT_FRAME_VERTS", 3, array);
00122 break;
00123 case GL_NEXT_NORMAL_ARRAY:
00124 R_AttributePointer("NEXT_FRAME_NORMALS", 3, array);
00125 break;
00126 case GL_NEXT_TANGENT_ARRAY:
00127 R_AttributePointer("NEXT_FRAME_TANGENTS", 4, array);
00128 break;
00129 }
00130 }
00131
00135 void R_BindDefaultArray (GLenum target)
00136 {
00137 switch (target) {
00138 case GL_VERTEX_ARRAY:
00139 R_BindArray(target, GL_FLOAT, r_state.vertex_array_3d);
00140 break;
00141 case GL_TEXTURE_COORD_ARRAY:
00142 R_BindArray(target, GL_FLOAT, r_state.active_texunit->texcoord_array);
00143 break;
00144 case GL_COLOR_ARRAY:
00145 R_BindArray(target, GL_FLOAT, r_state.color_array);
00146 break;
00147 case GL_NORMAL_ARRAY:
00148 R_BindArray(target, GL_FLOAT, r_state.normal_array);
00149 break;
00150 case GL_TANGENT_ARRAY:
00151 R_BindArray(target, GL_FLOAT, r_state.tangent_array);
00152 break;
00153 case GL_NEXT_VERTEX_ARRAY:
00154 R_BindArray(target, GL_FLOAT, r_state.next_vertex_array_3d);
00155 break;
00156 case GL_NEXT_NORMAL_ARRAY:
00157 R_BindArray(target, GL_FLOAT, r_state.next_normal_array);
00158 break;
00159 case GL_NEXT_TANGENT_ARRAY:
00160 R_BindArray(target, GL_FLOAT, r_state.next_tangent_array);
00161 break;
00162 }
00163 }
00164
00165 void R_BindBuffer (GLenum target, GLenum type, GLuint id)
00166 {
00167 if (!qglBindBuffer)
00168 return;
00169
00170 if (!r_vertexbuffers->integer)
00171 return;
00172
00173 qglBindBuffer(GL_ARRAY_BUFFER, id);
00174
00175 if (type && id)
00176 R_BindArray(target, type, NULL);
00177 }
00178
00179 void R_BlendFunc (GLenum src, GLenum dest)
00180 {
00181 if (r_state.blend_src == src && r_state.blend_dest == dest)
00182 return;
00183
00184 r_state.blend_src = src;
00185 r_state.blend_dest = dest;
00186
00187 glBlendFunc(src, dest);
00188 }
00189
00190 void R_EnableBlend (qboolean enable)
00191 {
00192 if (r_state.blend_enabled == enable)
00193 return;
00194
00195 r_state.blend_enabled = enable;
00196
00197 if (enable) {
00198 glEnable(GL_BLEND);
00199 glDepthMask(GL_FALSE);
00200 } else {
00201 glDisable(GL_BLEND);
00202 glDepthMask(GL_TRUE);
00203 }
00204 }
00205
00206 void R_EnableAlphaTest (qboolean enable)
00207 {
00208 if (r_state.alpha_test_enabled == enable)
00209 return;
00210
00211 r_state.alpha_test_enabled = enable;
00212
00213 if (enable)
00214 glEnable(GL_ALPHA_TEST);
00215 else
00216 glDisable(GL_ALPHA_TEST);
00217 }
00218
00219 void R_EnableTexture (gltexunit_t *texunit, qboolean enable)
00220 {
00221 if (enable == texunit->enabled)
00222 return;
00223
00224 texunit->enabled = enable;
00225
00226 R_SelectTexture(texunit);
00227
00228 if (enable) {
00229
00230 glEnable(GL_TEXTURE_2D);
00231
00232 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
00233
00234 if (texunit == &texunit_lightmap) {
00235 if (r_lightmap->integer)
00236 R_TexEnv(GL_REPLACE);
00237 else
00238 R_TexEnv(GL_MODULATE);
00239 }
00240 } else {
00241
00242 glDisable(GL_TEXTURE_2D);
00243 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
00244 }
00245 R_SelectTexture(&texunit_diffuse);
00246 }
00247
00248 void R_EnableColorArray (qboolean enable)
00249 {
00250 if (r_state.color_array_enabled == enable)
00251 return;
00252
00253 r_state.color_array_enabled = enable;
00254
00255 if (enable)
00256 glEnableClientState(GL_COLOR_ARRAY);
00257 else
00258 glDisableClientState(GL_COLOR_ARRAY);
00259 }
00260
00266 qboolean R_EnableLighting (r_program_t *program, qboolean enable)
00267 {
00268 if (!r_programs->integer)
00269 return r_state.lighting_enabled;
00270
00271 if (enable && (!program || !program->id))
00272 return r_state.lighting_enabled;
00273
00274 if (!r_lights->integer || (r_state.lighting_enabled == enable && r_state.active_program == program))
00275 return r_state.lighting_enabled;
00276
00277 r_state.lighting_enabled = enable;
00278
00279 if (enable) {
00280 R_UseProgram(program);
00281
00282 glEnableClientState(GL_NORMAL_ARRAY);
00283 } else {
00284 glDisableClientState(GL_NORMAL_ARRAY);
00285
00286 R_UseProgram(NULL);
00287 }
00288
00289 return r_state.lighting_enabled;
00290 }
00291
00297 void R_EnableDynamicLights (const entity_t *ent, qboolean enable)
00298 {
00299 int i, j;
00300 int maxLights = r_dynamic_lights->integer;
00301
00302 if (!enable || !r_state.lighting_enabled || r_state.numActiveLights == 0 || !ent) {
00303 if (r_state.lighting_enabled)
00304 R_ProgramParameter1i("DYNAMICLIGHTS", 0);
00305 if (!r_state.bumpmap_enabled && r_state.dynamic_lighting_enabled)
00306 R_DisableAttribute("TANGENTS");
00307 glDisable(GL_LIGHTING);
00308 for (i = 0; i < maxLights; i++) {
00309 glLightf(GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, 0.0);
00310 glDisable(GL_LIGHT0 + i);
00311 }
00312
00313 r_state.dynamic_lighting_enabled = qfalse;
00314 return;
00315 }
00316
00317 r_state.dynamic_lighting_enabled = qtrue;
00318
00319 if (r_state.glowmap_enabled)
00320 R_ProgramParameter1f("GLOWSCALE", 1.0);
00321
00322 R_EnableAttribute("TANGENTS");
00323 R_ProgramParameter1i("DYNAMICLIGHTS", 1);
00324
00325 R_ProgramParameter1f("HARDNESS", 0.1);
00326 R_ProgramParameter1f("SPECULAR", 0.25);
00327
00328 glEnable(GL_LIGHTING);
00329
00330 for (i = 0, j = 0; i < maxLights && (i + j) < ent->numLights; i++) {
00331 const r_light_t *l = ent->lights[i + j];
00332 if (!l->enabled) {
00333 j++;
00334 continue;
00335 }
00336
00337 glEnable(GL_LIGHT0 + i);
00338 glLightf(GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, l->constantAttenuation);
00339 glLightf(GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, l->linearAttenuation);
00340 glLightf(GL_LIGHT0 + i, GL_QUADRATIC_ATTENUATION, l->quadraticAttenuation);
00341
00342 glLightfv(GL_LIGHT0 + i, GL_POSITION, l->loc);
00343 glLightfv(GL_LIGHT0 + i, GL_AMBIENT, l->ambientColor);
00344 glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, l->diffuseColor);
00345 glLightfv(GL_LIGHT0 + i, GL_SPECULAR, l->specularColor);
00346 }
00347
00348
00349 while (i < maxLights) {
00350 glDisable(GL_LIGHT0 + i);
00351 glLightf(GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, 0.0);
00352 glLightf(GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, 0.0);
00353 glLightf(GL_LIGHT0 + i, GL_QUADRATIC_ATTENUATION, 0.0);
00354 i++;
00355 }
00356 }
00357
00364 void R_EnableAnimation (const mAliasMesh_t *mesh, float backlerp, qboolean enable)
00365 {
00366 if (!r_programs->integer || !r_state.lighting_enabled)
00367 return;
00368
00369 r_state.animation_enabled = enable;
00370
00371 if (enable) {
00372 R_EnableAttribute("NEXT_FRAME_VERTS");
00373 R_EnableAttribute("NEXT_FRAME_NORMALS");
00374 R_EnableAttribute("NEXT_FRAME_TANGENTS");
00375 R_ProgramParameter1i("ANIMATE", 1);
00376
00377 R_ProgramParameter1f("TIME", backlerp);
00378
00379 R_BindArray(GL_TEXTURE_COORD_ARRAY, GL_FLOAT, mesh->texcoords);
00380 R_BindArray(GL_VERTEX_ARRAY, GL_FLOAT, mesh->verts);
00381 R_BindArray(GL_NORMAL_ARRAY, GL_FLOAT, mesh->normals);
00382 R_BindArray(GL_TANGENT_ARRAY, GL_FLOAT, mesh->tangents);
00383 R_BindArray(GL_NEXT_VERTEX_ARRAY, GL_FLOAT, mesh->next_verts);
00384 R_BindArray(GL_NEXT_NORMAL_ARRAY, GL_FLOAT, mesh->next_normals);
00385 R_BindArray(GL_NEXT_TANGENT_ARRAY, GL_FLOAT, mesh->next_tangents);
00386 } else {
00387 R_DisableAttribute("NEXT_FRAME_VERTS");
00388 R_DisableAttribute("NEXT_FRAME_NORMALS");
00389 R_DisableAttribute("NEXT_FRAME_TANGENTS");
00390 R_ProgramParameter1i("ANIMATE", 0);
00391 }
00392 }
00393
00399 void R_EnableBumpmap (const image_t *normalmap, qboolean enable)
00400 {
00401 if (!r_state.lighting_enabled)
00402 return;
00403
00404 if (!r_bumpmap->value)
00405 return;
00406
00407 if (enable)
00408 R_BindNormalmapTexture(normalmap->texnum);
00409
00410 if (r_state.bumpmap_enabled == enable)
00411 return;
00412
00413 r_state.bumpmap_enabled = enable;
00414
00415 if (enable) {
00416 assert(normalmap);
00417 R_EnableAttribute("TANGENTS");
00418 R_ProgramParameter1i("BUMPMAP", 1);
00419
00420 R_ProgramParameter1f("HARDNESS", 0.1);
00421 R_ProgramParameter1f("SPECULAR", 0.25);
00422 R_ProgramParameter1f("BUMP", 1.0);
00423 R_ProgramParameter1f("PARALLAX", 0.5);
00424 } else {
00425 R_DisableAttribute("TANGENTS");
00426 R_ProgramParameter1i("BUMPMAP", 0);
00427 }
00428 }
00429
00430 void R_EnableWarp (r_program_t *program, qboolean enable)
00431 {
00432 if (!r_programs->integer)
00433 return;
00434
00435 if (enable && (!program || !program->id))
00436 return;
00437
00438 if (!r_warp->integer || r_state.warp_enabled == enable)
00439 return;
00440
00441 r_state.warp_enabled = enable;
00442
00443 R_SelectTexture(&texunit_lightmap);
00444
00445 if (enable) {
00446 glEnable(GL_TEXTURE_2D);
00447 R_BindTexture(r_warpTexture->texnum);
00448 R_UseProgram(program);
00449 } else {
00450 glDisable(GL_TEXTURE_2D);
00451 R_UseProgram(NULL);
00452 }
00453
00454 R_SelectTexture(&texunit_diffuse);
00455 }
00456
00457 void R_EnableBlur (r_program_t *program, qboolean enable, r_framebuffer_t *source, r_framebuffer_t *dest, int dir)
00458 {
00459 if (!r_programs->integer)
00460 return;
00461
00462 if (enable && (!program || !program->id))
00463 return;
00464
00465 if (!r_postprocess->integer || r_state.blur_enabled == enable)
00466 return;
00467
00468 r_state.blur_enabled = enable;
00469
00470 R_SelectTexture(&texunit_lightmap);
00471
00472 if (enable) {
00473 float userdata[] = { source->width, dir };
00474 R_UseFramebuffer(dest);
00475 program->userdata = userdata;
00476 R_UseProgram(program);
00477 } else {
00478 R_UseFramebuffer(fbo_screen);
00479 R_UseProgram(NULL);
00480 }
00481
00482 R_SelectTexture(&texunit_diffuse);
00483 }
00484
00485 void R_EnableShell (qboolean enable)
00486 {
00487 if (enable == r_state.shell_enabled)
00488 return;
00489
00490 r_state.shell_enabled = enable;
00491
00492 if (enable) {
00493 glEnable(GL_POLYGON_OFFSET_FILL);
00494 glPolygonOffset(-1.0, 1.0);
00495
00496 R_EnableDrawAsGlow(qtrue);
00497 R_EnableBlend(qtrue);
00498 R_BlendFunc(GL_SRC_ALPHA, GL_ONE);
00499
00500 if (r_state.lighting_enabled)
00501 R_ProgramParameter1f("OFFSET", refdef.time / 3.0);
00502 } else {
00503 R_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00504 R_EnableBlend(qfalse);
00505 R_EnableDrawAsGlow(qfalse);
00506
00507 glPolygonOffset(0.0, 0.0);
00508 glDisable(GL_POLYGON_OFFSET_FILL);
00509
00510 if (r_state.lighting_enabled)
00511 R_ProgramParameter1f("OFFSET", 0.0);
00512 }
00513 }
00514
00515 #define FOG_START 300.0
00516 #define FOG_END 2500.0
00517
00518 void R_EnableFog (qboolean enable)
00519 {
00520 if (!r_fog->integer || r_state.fog_enabled == enable)
00521 return;
00522
00523 r_state.fog_enabled = qfalse;
00524
00525 if (enable) {
00526 if ((refdef.weather & WEATHER_FOG) || r_fog->integer == 2) {
00527 r_state.fog_enabled = qtrue;
00528
00529 glFogfv(GL_FOG_COLOR, refdef.fogColor);
00530 glFogf(GL_FOG_DENSITY, 1.0);
00531 glEnable(GL_FOG);
00532 }
00533 } else {
00534 glFogf(GL_FOG_DENSITY, 0.0);
00535 glDisable(GL_FOG);
00536 }
00537 }
00538
00539 void R_EnableGlowMap (const image_t *image, qboolean enable)
00540 {
00541 static GLenum glowRenderTarget = GL_COLOR_ATTACHMENT1_EXT;
00542
00543 if (!r_postprocess->integer)
00544 return;
00545
00546 if (enable && image != NULL)
00547 R_BindTextureForTexUnit(image->texnum, &texunit_glowmap);
00548
00549 if (!enable && r_state.glowmap_enabled == enable)
00550 return;
00551
00552 r_state.glowmap_enabled = enable;
00553
00554 if (enable) {
00555 if (!r_state.active_program)
00556 R_UseProgram(r_state.simple_glow_program);
00557
00558 if (image == NULL)
00559 R_ProgramParameter1f("GLOWSCALE", 0.0);
00560 else
00561 R_ProgramParameter1f("GLOWSCALE", 1.0);
00562
00563 R_DrawBuffers(2);
00564 } else {
00565 if (r_state.active_program == r_state.simple_glow_program)
00566 R_UseProgram(NULL);
00567 else
00568 R_ProgramParameter1f("GLOWSCALE", 0.0);
00569
00570 if (r_state.draw_glow_enabled)
00571 R_BindColorAttachments(1, &glowRenderTarget);
00572 else
00573 R_DrawBuffers(1);
00574 }
00575 }
00576
00577 void R_EnableDrawAsGlow (qboolean enable)
00578 {
00579 static GLenum glowRenderTarget = GL_COLOR_ATTACHMENT1_EXT;
00580
00581 if (!r_postprocess->integer || r_state.draw_glow_enabled == enable)
00582 return;
00583
00584 r_state.draw_glow_enabled = enable;
00585
00586 if (enable) {
00587 R_BindColorAttachments(1, &glowRenderTarget);
00588 } else {
00589 if (r_state.glowmap_enabled) {
00590 R_DrawBuffers(2);
00591 } else {
00592 R_DrawBuffers(1);
00593 }
00594 }
00595 }
00596
00597 void R_EnableSpecularMap (const image_t *image, qboolean enable)
00598 {
00599 if (!r_state.dynamic_lighting_enabled)
00600 return;
00601
00602 if (enable && image != NULL) {
00603 R_BindTextureForTexUnit(image->texnum, &texunit_specularmap);
00604 R_ProgramParameter1i("SPECULARMAP", 1);
00605 r_state.specularmap_enabled = enable;
00606 } else {
00607 R_ProgramParameter1i("SPECULARMAP", 0);
00608 r_state.specularmap_enabled = qfalse;
00609 }
00610 }
00611
00612 void R_EnableRoughnessMap (const image_t *image, qboolean enable)
00613 {
00614 if (!r_state.dynamic_lighting_enabled)
00615 return;
00616
00617 if (enable && image != NULL) {
00618 R_BindTextureForTexUnit(image->texnum, &texunit_roughnessmap);
00619 R_ProgramParameter1i("ROUGHMAP", 1);
00620 r_state.roughnessmap_enabled = enable;
00621 } else {
00622 R_ProgramParameter1i("ROUGHMAP", 0);
00623 r_state.roughnessmap_enabled = qfalse;
00624 }
00625 }
00626
00630 static void MYgluPerspective (GLdouble zNear, GLdouble zFar)
00631 {
00632 GLdouble xmin, xmax, ymin, ymax, yaspect = (double) viddef.viewHeight / viddef.viewWidth;
00633
00634 if (r_isometric->integer) {
00635 glOrtho(-10 * refdef.fieldOfViewX, 10 * refdef.fieldOfViewX, -10 * refdef.fieldOfViewX * yaspect, 10 * refdef.fieldOfViewX * yaspect, -zFar, zFar);
00636 } else {
00637 xmax = zNear * tan(refdef.fieldOfViewX * (M_PI / 360.0));
00638 xmin = -xmax;
00639
00640 ymin = xmin * yaspect;
00641 ymax = xmax * yaspect;
00642
00643 glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
00644 }
00645 }
00646
00650 void R_Setup3D (void)
00651 {
00652 int x, x2, y2, y, w, h;
00653
00654
00655 x = floor(viddef.x * viddef.width / viddef.width);
00656 x2 = ceil((viddef.x + viddef.viewWidth) * viddef.width / viddef.width);
00657 y = floor(viddef.height - viddef.y * viddef.height / viddef.height);
00658 y2 = ceil(viddef.height - (viddef.y + viddef.viewHeight) * viddef.height / viddef.height);
00659
00660 w = x2 - x;
00661 h = y - y2;
00662
00663 glViewport(x, y2, w, h);
00664 R_CheckError();
00665
00666
00667 glMatrixMode(GL_PROJECTION);
00668 glLoadIdentity();
00669 MYgluPerspective(4.0, MAX_WORLD_WIDTH);
00670
00671 glMatrixMode(GL_MODELVIEW);
00672 glLoadIdentity();
00673
00674 glRotatef(-90.0, 1.0, 0.0, 0.0);
00675 glRotatef(90.0, 0.0, 0.0, 1.0);
00676 glRotatef(-refdef.viewAngles[2], 1.0, 0.0, 0.0);
00677 glRotatef(-refdef.viewAngles[0], 0.0, 1.0, 0.0);
00678 glRotatef(-refdef.viewAngles[1], 0.0, 0.0, 1.0);
00679 glTranslatef(-refdef.viewOrigin[0], -refdef.viewOrigin[1], -refdef.viewOrigin[2]);
00680
00681
00682 glGetFloatv(GL_MODELVIEW_MATRIX, r_locals.world_matrix);
00683
00684
00685 R_BindDefaultArray(GL_VERTEX_ARRAY);
00686
00687 glDisable(GL_BLEND);
00688
00689 glEnable(GL_DEPTH_TEST);
00690
00691
00692 R_EnableRenderbuffer(qtrue);
00693
00694 R_CheckError();
00695 }
00696
00697 extern const float SKYBOX_DEPTH;
00698
00702 void R_Setup2D (void)
00703 {
00704
00705 glViewport(0, 0, viddef.width, viddef.height);
00706
00707 glMatrixMode(GL_PROJECTION);
00708 glLoadIdentity();
00709
00710
00711
00712 glOrtho(0, viddef.width, viddef.height, 0, 9999.0f, SKYBOX_DEPTH);
00713
00714 glMatrixMode(GL_MODELVIEW);
00715 glLoadIdentity();
00716
00717
00718 R_BindDefaultArray(GL_VERTEX_ARRAY);
00719
00720 R_Color(NULL);
00721
00722 glEnable(GL_BLEND);
00723
00724 glDisable(GL_DEPTH_TEST);
00725
00726
00727 R_EnableRenderbuffer(qfalse);
00728
00729 R_CheckError();
00730 }
00731
00732
00733 static const vec4_t ambient = {
00734 0.0, 0.0, 0.0, 1.0
00735 };
00736
00737
00738 static const vec4_t material = {
00739 1.0, 1.0, 1.0, 1.0
00740 };
00741
00742 void R_SetDefaultState (void)
00743 {
00744 int i;
00745
00746 glClearColor(0, 0, 0, 0);
00747
00748 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00749
00750
00751 glEnableClientState(GL_VERTEX_ARRAY);
00752 R_BindDefaultArray(GL_VERTEX_ARRAY);
00753
00754 R_EnableColorArray(qtrue);
00755 R_BindDefaultArray(GL_COLOR_ARRAY);
00756 R_EnableColorArray(qfalse);
00757
00758 glEnableClientState(GL_NORMAL_ARRAY);
00759 R_BindDefaultArray(GL_NORMAL_ARRAY);
00760 glDisableClientState(GL_NORMAL_ARRAY);
00761
00762
00763 R_CheckError();
00764
00765
00766 for (i = 0; i < r_config.maxTextureCoords && i < MAX_GL_TEXUNITS; i++) {
00767 gltexunit_t *tex = &r_state.texunits[i];
00768 tex->texture = GL_TEXTURE0_ARB + i;
00769
00770 R_EnableTexture(tex, qtrue);
00771
00772 R_BindDefaultArray(GL_TEXTURE_COORD_ARRAY);
00773
00774 if (i > 0)
00775 R_EnableTexture(tex, qfalse);
00776
00777 R_CheckError();
00778 }
00779
00780 R_SelectTexture(&texunit_diffuse);
00781
00782 glAlphaFunc(GL_GREATER, 0.01f);
00783
00784
00785 glFogi(GL_FOG_MODE, GL_LINEAR);
00786 glFogf(GL_FOG_START, FOG_START);
00787 glFogf(GL_FOG_END, FOG_END);
00788
00789
00790 glPolygonOffset(1, 1);
00791
00792
00793 R_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00794
00795
00796 R_ClearActiveLights();
00797
00798
00799 R_CheckError();
00800 }
00801
00802 void R_TexEnv (GLenum mode)
00803 {
00804 if (mode == r_state.active_texunit->texenv)
00805 return;
00806
00807 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode);
00808 r_state.active_texunit->texenv = mode;
00809 }
00810
00811 const vec4_t color_white = {1, 1, 1, 1};
00812
00818 void R_Color (const vec4_t rgba)
00819 {
00820 const float *color;
00821 if (rgba)
00822 color = rgba;
00823 else
00824 color = color_white;
00825
00826 glColor4fv(color);
00827 R_CheckError();
00828 }