about summary refs log tree commit diff
path: root/src/game/client/mapres_tilemap.cpp
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-07-24 22:53:43 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-07-24 22:53:43 +0000
commit5bd2c434f63ff4a039e854d647f02ef660c544d1 (patch)
tree3fe99b2e4a7cf5e80243bde4583e10c5650ed913 /src/game/client/mapres_tilemap.cpp
parent4b098f7711e7cb96eef6797787e3f2f2b4cbb867 (diff)
downloadzcatch-5bd2c434f63ff4a039e854d647f02ef660c544d1.tar.gz
zcatch-5bd2c434f63ff4a039e854d647f02ef660c544d1.zip
epic commit. removed tga support, removed BGR support. fixed one config for editor, server and client, optimized tilemap rendering (this needs some cleanup), added tools to fix alpha outline quirk and glitches in the tilemap reindering
Diffstat (limited to 'src/game/client/mapres_tilemap.cpp')
-rw-r--r--src/game/client/mapres_tilemap.cpp110
1 files changed, 59 insertions, 51 deletions
diff --git a/src/game/client/mapres_tilemap.cpp b/src/game/client/mapres_tilemap.cpp
index 6038e67c..197a1a8b 100644
--- a/src/game/client/mapres_tilemap.cpp
+++ b/src/game/client/mapres_tilemap.cpp
@@ -5,8 +5,12 @@
 
 #include <baselib/opengl.h>
 
+bool must_init = true;
+void *batches[32] = {0};
+
 int tilemap_init()
 {
+	must_init = true;
 	return 0;
 }
 
@@ -14,8 +18,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);
 	
@@ -23,12 +26,6 @@ void tilemap_render(float scale, int fg)
 	int start, num;
 	map_get_type(MAPRES_TILEMAP, &start, &num);
 
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-
-
 	// render tilemaps
 	int passed_main = 0;
 	for(int t = 0; t < num; t++)
@@ -42,58 +39,69 @@ void tilemap_render(float scale, int fg)
 		if((fg && passed_main) || (!fg && !passed_main))
 		{
 			gfx_texture_set(img_get(tmap->image));
-			gfx_quads_begin();
 			
-			float frac = (1.0f/1024.0f);//2.0f; //2.0f;
-			float texsize = 1024.0f;
-			float nudge = 0.5f/texsize;
+			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 			
-			int startx = (int)(screen_x0/scale) - 1;
-			int endx = (int)(screen_x1/scale) + 1;
-			int starty = (int)(screen_y0/scale) - 1;
-			int endy = (int)(screen_y1/scale) + 1;
-			for(int y = starty; y < endy; y++)
-				for(int x = startx; x < endx; x++)
-				{
-					int mx = x;
-					int my = y;
-					if(mx<0) mx = 0;
-					if(mx>=tmap->width) mx = tmap->width-1;
-					if(my<0) my = 0;
-					if(my>=tmap->height) my = tmap->height-1;
-					
-					int c = mx + my*tmap->width;
-						
-					unsigned char d = data[c*2];
-					if(d)
+			if(!batches[t])
+			{
+				gfx_quads_begin();
+				
+				float frac = (1.0f/1024.0f);//2.0f; //2.0f;
+				float texsize = 1024.0f;
+				float nudge = 0.5f/texsize;
+				float s = 1.0f;
+				
+				for(int y = 0; y < tmap->height; y++)
+					for(int x = 0; x < tmap->width; x++)
 					{
-						//gfx_quads_setsubset(
-						//	(d%16)/16.0f*s+frac,
-						//	(d/16)/16.0f*s+frac,
-						//	((d%16)/16.0f+1.0f/16.0f)*s-frac,
-						//	((d/16)/16.0f+1.0f/16.0f)*s-frac);
+						int mx = x;
+						int my = y;
+						if(mx<0) mx = 0;
+						if(mx>=tmap->width) mx = tmap->width-1;
+						if(my<0) my = 0;
+						if(my>=tmap->height) my = tmap->height-1;
+						
+						int c = mx + my*tmap->width;
 							
-						int tx = d%16;
-						int ty = d/16;
-						int px0 = tx*(1024/16);
-						int py0 = ty*(1024/16);
-						int px1 = (tx+1)*(1024/16)-1;
-						int py1 = (ty+1)*(1024/16)-1;
-						gfx_quads_setsubset(
-							nudge + px0/texsize+frac,
-							nudge + py0/texsize+frac,
-							nudge + px1/texsize-frac,
-							nudge + py1/texsize-frac);
+						unsigned char d = data[c*2];
+						if(d)
+						{
+							/*
+							gfx_quads_setsubset(
+								(d%16)/16.0f*s+frac,
+								(d/16)/16.0f*s+frac,
+								((d%16)/16.0f+1.0f/16.0f)*s-frac,
+								((d/16)/16.0f+1.0f/16.0f)*s-frac);
+								*/
+							
+							int tx = d%16;
+							int ty = d/16;
+							int px0 = tx*(1024/16);
+							int py0 = ty*(1024/16);
+							int px1 = (tx+1)*(1024/16)-1;
+							int py1 = (ty+1)*(1024/16)-1;
+							float z = -5.0f;
+
+							gfx_quads_setsubset(
+								nudge + px0/texsize+frac,
+								nudge + py0/texsize+frac,
+								nudge + px1/texsize-frac,
+								nudge + py1/texsize-frac);
 
-						gfx_quads_drawTL(x*scale, y*scale, scale, scale);
+							gfx_quads_drawTL(x*scale, y*scale, scale, scale);
+						}
 					}
-				}
+				
+				//gfx_quads_end();
+				batches[t] = gfx_quads_create_batch();
+			}
 			
-			gfx_quads_end();
+			gfx_quads_draw_batch(batches[t]);
+			//glCallList(lists_start+t);
 		}
 	}
 	
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
 	
 }