diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2007-07-29 15:21:25 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2007-07-29 15:21:25 +0000 |
| commit | f8d037ee4877810ea113505fd5cf618677ebfa12 (patch) | |
| tree | caac9fb4a1004e13cd286b9015d12c8df3a807df | |
| parent | e6c4db94d81306fda59b8fb32ae07fb3f0c8bf08 (diff) | |
| download | zcatch-f8d037ee4877810ea113505fd5cf618677ebfa12.tar.gz zcatch-f8d037ee4877810ea113505fd5cf618677ebfa12.zip | |
added options for crappy gfxcards
| -rw-r--r-- | src/engine/client/gfx.cpp | 69 | ||||
| -rw-r--r-- | src/engine/config_variables.h | 5 | ||||
| -rw-r--r-- | src/game/client/game_client.cpp | 47 | ||||
| -rw-r--r-- | src/game/client/mapres_tilemap.cpp | 22 |
4 files changed, 104 insertions, 39 deletions
diff --git a/src/engine/client/gfx.cpp b/src/engine/client/gfx.cpp index 76326487..f5983598 100644 --- a/src/engine/client/gfx.cpp +++ b/src/engine/client/gfx.cpp @@ -23,9 +23,11 @@ struct custom_vertex vec4 color; }; -const int vertex_buffer_size = 2048*64; +const int vertex_buffer_size = 32*1024; //static custom_vertex vertices[4]; static custom_vertex *vertices = 0; +//static index_buffer ib; +static unsigned short indecies[vertex_buffer_size*6]; static int num_vertices = 0; static vec4 color[4]; static vec2 texture[4]; @@ -82,7 +84,9 @@ static void draw_quad(bool _bflush = false) opengl::stream_color(&vertex_buffer, 4, GL_FLOAT, sizeof(custom_vertex), sizeof(vec3)+sizeof(vec2)); - opengl::draw_arrays(GL_QUADS, 0, num_vertices); + + glDrawElements(GL_TRIANGLES, num_vertices, GL_UNSIGNED_SHORT, indecies); + //opengl::draw_arrays(GL_QUADS, 0, num_vertices); } else { @@ -220,7 +224,19 @@ bool gfx_init() textures[i].next = i+1; textures[MAX_TEXTURES-1].next = -1; - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + // init indecies + for(int i = 0; i < vertex_buffer_size; i++) + { + indecies[i*6 + 0] = i+0; + indecies[i*6 + 1] = i+1; + indecies[i*6 + 2] = i+2; + + indecies[i*6 + 3] = i+1; + indecies[i*6 + 4] = i+3; + indecies[i*6 + 5] = i+2; + } + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // create null texture, will get id=0 gfx_load_texture_raw(4,4,IMG_RGBA,null_texture_data); @@ -297,15 +313,50 @@ int gfx_load_texture_raw(int w, int h, int format, const void *data) first_free_texture = textures[tex].next; textures[tex].next = -1; - // set data and return - // TODO: should be RGBA, not BGRA + // resample if needed + unsigned char *texdata = (unsigned char *)data; + unsigned char *tmpdata = 0; + if(config.gfx_texture_quality==0) + { + if(w > 16 && h > 16 && format == IMG_RGBA) + { + int amount = 2; + int pitch = w*4; + w/=amount; + h/=amount; + unsigned char *tmpdata = (unsigned char *)mem_alloc(w*h*4, 1); + int c = 0; + for(int y = 0; y < h; y++) + for(int x = 0; x < w; x++, c++) + { + tmpdata[c*4] = texdata[(y*amount*pitch+x*amount*4)]; + tmpdata[c*4+1] = texdata[(y*amount*pitch+x*amount*4)+1]; + tmpdata[c*4+2] = texdata[(y*amount*pitch+x*amount*4)+2]; + tmpdata[c*4+3] = texdata[(y*amount*pitch+x*amount*4)+3]; + } + texdata = tmpdata; + } + } + dbg_msg("gfx", "%d = %dx%d", tex, w, h); - if(format == IMG_RGB) - textures[tex].tex.data2d(w, h, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, data); - else if(format == IMG_RGBA) + + // set data and return + if(config.gfx_texture_compression && GLEW_ARB_texture_compression) { - textures[tex].tex.data2d(w, h, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, data); + if(format == IMG_RGB) + textures[tex].tex.data2d(w, h, GL_COMPRESSED_RGB_ARB, GL_RGB, GL_UNSIGNED_BYTE, texdata); + else if(format == IMG_RGBA) + textures[tex].tex.data2d(w, h, GL_COMPRESSED_RGBA_ARB, GL_RGBA, GL_UNSIGNED_BYTE, texdata); } + else + { + if(format == IMG_RGB) + textures[tex].tex.data2d(w, h, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, texdata); + else if(format == IMG_RGBA) + textures[tex].tex.data2d(w, h, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, texdata); + } + + mem_free(tmpdata); return tex; } diff --git a/src/engine/config_variables.h b/src/engine/config_variables.h index fb894139..8dcc7365 100644 --- a/src/engine/config_variables.h +++ b/src/engine/config_variables.h @@ -13,6 +13,11 @@ MACRO_CONFIG_STR(player_name, 32, "nameless tee") MACRO_CONFIG_STR(clan_name, 32, "") MACRO_CONFIG_STR(password, 32, "") +MACRO_CONFIG_INT(gfx_texture_compression, 1, 0, 1) +MACRO_CONFIG_INT(gfx_high_detail, 1, 0, 1) +MACRO_CONFIG_INT(gfx_texture_quality, 1, 0, 1) + + MACRO_CONFIG_STR(masterserver, 128, "master.teewars.com") diff --git a/src/game/client/game_client.cpp b/src/game/client/game_client.cpp index 365205a4..ff212006 100644 --- a/src/game/client/game_client.cpp +++ b/src/game/client/game_client.cpp @@ -1373,33 +1373,34 @@ void modc_render() // draw background gfx_clear(0.65f,0.78f,0.9f); - // draw the sun - render_sun(20+screen_x*0.6f, 20+screen_y*0.6f); - - - static vec2 cloud_pos[6] = {vec2(-500,0),vec2(-500,200),vec2(-500,400)}; - static float cloud_speed[6] = {30, 20, 10}; - static int cloud_images[6] = {IMAGE_CLOUD_1, IMAGE_CLOUD_2, IMAGE_CLOUD_3}; - - for(int i = 0; i < 3; i++) + // draw the sun + if(config.gfx_high_detail) { - float parallax_amount = 0.55f; - gfx_texture_set(data->images[cloud_images[i]].id); + render_sun(20+screen_x*0.6f, 20+screen_y*0.6f); + + static vec2 cloud_pos[6] = {vec2(-500,0),vec2(-500,200),vec2(-500,400)}; + static float cloud_speed[6] = {30, 20, 10}; + static int cloud_images[6] = {IMAGE_CLOUD_1, IMAGE_CLOUD_2, IMAGE_CLOUD_3}; + + for(int i = 0; i < 3; i++) + { + float parallax_amount = 0.55f; + gfx_texture_set(data->images[cloud_images[i]].id); + gfx_quads_begin(); + gfx_quads_drawTL((cloud_pos[i].x+fmod(client_localtime()*cloud_speed[i]+i*100.0f, 1700.0f))+screen_x*parallax_amount, + cloud_pos[i].y+screen_y*parallax_amount, 300, 300); + gfx_quads_end(); + } + + + // draw backdrop + gfx_texture_set(data->images[IMAGE_BACKDROP].id); gfx_quads_begin(); - gfx_quads_drawTL((cloud_pos[i].x+fmod(client_localtime()*cloud_speed[i]+i*100.0f, 1700.0f))+screen_x*parallax_amount, - cloud_pos[i].y+screen_y*parallax_amount, 300, 300); + float parallax_amount = 0.25f; + for(int x = -1; x < 3; x++) + gfx_quads_drawTL(1024*x+screen_x*parallax_amount, (screen_y)*parallax_amount+150, 1024, 1024); gfx_quads_end(); } - - - // draw backdrop - gfx_texture_set(data->images[IMAGE_BACKDROP].id); - gfx_quads_begin(); - float parallax_amount = 0.25f; - for(int x = -1; x < 3; x++) - gfx_quads_drawTL(1024*x+screen_x*parallax_amount, (screen_y)*parallax_amount+150, 1024, 1024); - gfx_quads_end(); - // render map tilemap_render(32.0f, 0); diff --git a/src/game/client/mapres_tilemap.cpp b/src/game/client/mapres_tilemap.cpp index 3b2a5006..6f61e656 100644 --- a/src/game/client/mapres_tilemap.cpp +++ b/src/game/client/mapres_tilemap.cpp @@ -2,6 +2,7 @@ #include "mapres_tilemap.h" #include "mapres_image.h" #include "../mapres.h" +#include "../../engine/config.h" #include <baselib/opengl.h> @@ -22,7 +23,7 @@ void tilemap_render(float scale, int fg) { if(!map_is_loaded()) return; - + float screen_x0, screen_y0, screen_x1, screen_y1; gfx_getscreen(&screen_x0, &screen_y0, &screen_x1, &screen_y1); @@ -39,21 +40,28 @@ void tilemap_render(float scale, int fg) if(tmap->main) passed_main = 1; - + if((fg && passed_main) || (!fg && !passed_main)) { + if(!config.gfx_high_detail && !tmap->main) + continue; gfx_texture_set(img_get(tmap->image)); if(!batches[t]) { gfx_quads_begin(); + int starty = (int)(screen_y0/scale)-1; + int startx = (int)(screen_x0/scale)-1; + int endy = (int)(screen_y1/scale)+1; + int endx = (int)(screen_x1/scale)+1; + float frac = (1.0f/1024.0f);//2.0f; //2.0f; float texsize = 1024.0f; float nudge = 0.5f/texsize; int border = 24; - for(int y = -border; y < tmap->height+border; y++) - for(int x = -border; x < tmap->width+border; x++) + for(int y = starty; y < endy; y++) + for(int x = startx; x < endx; x++) { int mx = x; int my = y; @@ -92,11 +100,11 @@ void tilemap_render(float scale, int fg) } } - //gfx_quads_end(); - batches[t] = gfx_quads_create_batch(); + gfx_quads_end(); + //batches[t] = gfx_quads_create_batch(); } - gfx_quads_draw_batch(batches[t]); + //gfx_quads_draw_batch(batches[t]); //glCallList(lists_start+t); } } |