about summary refs log tree commit diff
path: root/src/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/client/ec_client.c2
-rw-r--r--src/engine/client/ec_font.c20
-rw-r--r--src/engine/client/ec_font.h2
-rw-r--r--src/engine/client/ec_gfx.c58
-rw-r--r--src/engine/client/ec_inp.c3
-rw-r--r--src/engine/e_config_variables.h1
-rw-r--r--src/engine/e_interface.h7
7 files changed, 65 insertions, 28 deletions
diff --git a/src/engine/client/ec_client.c b/src/engine/client/ec_client.c
index 1b9b0120..d35121de 100644
--- a/src/engine/client/ec_client.c
+++ b/src/engine/client/ec_client.c
@@ -442,7 +442,7 @@ void client_disconnect()
 
 static int client_load_data()
 {
-	debug_font = gfx_load_texture("data/debug_font.png");
+	debug_font = gfx_load_texture("data/debug_font.png", IMG_AUTO);
 	return 1;
 }
 
diff --git a/src/engine/client/ec_font.c b/src/engine/client/ec_font.c
index 92ba3cb7..04f8b954 100644
--- a/src/engine/client/ec_font.c
+++ b/src/engine/client/ec_font.c
@@ -1,6 +1,7 @@
 /* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
 #include <stdarg.h>
 #include <stdio.h>
+#include <string.h>
 #include <engine/e_system.h>
 #include "ec_font.h"
 
@@ -86,7 +87,8 @@ int font_load(FONT *font, const char *filename)
         return -1;
 }
 
-int gfx_load_texture(const char *filename);
+int gfx_load_texture(const char *filename, int store_format);
+#define IMG_ALPHA 2
 
 int font_set_load(FONT_SET *font_set, const char *font_filename, const char *text_texture_filename, const char *outline_texture_filename, int fonts, ...)
 {
@@ -117,8 +119,8 @@ int font_set_load(FONT_SET *font_set, const char *font_filename, const char *tex
         }
 
         font->size = size;
-        font->text_texture = gfx_load_texture(composed_text_texture_filename);
-        font->outline_texture = gfx_load_texture(composed_outline_texture_filename);
+        font->text_texture = gfx_load_texture(composed_text_texture_filename, IMG_ALPHA);
+        font->outline_texture = gfx_load_texture(composed_outline_texture_filename, IMG_ALPHA);
     }
 
     va_end(va);
@@ -130,16 +132,24 @@ float font_text_width(FONT *font, const char *text, float size, int length)
     float width = 0.0f;
 
     const unsigned char *c = (unsigned char *)text;
+    int chars_left;
+    if (length == -1)
+        chars_left = strlen(text);
+    else
+        chars_left = length;
 
-    while (*c)
+    while (chars_left--)
     {
         float tex_x0, tex_y0, tex_x1, tex_y1;
         float char_width, char_height;
         float x_offset, y_offset, x_advance;
+        float advance;
 
         font_character_info(font, *c, &tex_x0, &tex_y0, &tex_x1, &tex_y1, &char_width, &char_height, &x_offset, &y_offset, &x_advance);
 
-        width += x_advance;
+        advance = x_advance + font_kerning(font, *c, *(c+1));
+
+        width += advance;
 
         c++;
     }
diff --git a/src/engine/client/ec_font.h b/src/engine/client/ec_font.h
index a68a8452..e38b11b7 100644
--- a/src/engine/client/ec_font.h
+++ b/src/engine/client/ec_font.h
@@ -28,7 +28,7 @@ typedef struct
 typedef struct
 {
     int font_count;
-    FONT fonts[8];
+    FONT fonts[14];
 } FONT_SET;
 
 int font_load(FONT *font, const char *filename);
diff --git a/src/engine/client/ec_gfx.c b/src/engine/client/ec_gfx.c
index e72fdfa7..0562a24f 100644
--- a/src/engine/client/ec_gfx.c
+++ b/src/engine/client/ec_gfx.c
@@ -208,7 +208,8 @@ int gfx_init()
 		glfwOpenWindowHint(GLFW_REFRESH_RATE, config.gfx_refresh_rate);
 	
 	/* no resizing allowed */
-	/* glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, 1); */
+	if (!config.gfx_debug_resizable)
+		glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, 1);
 		
 	/* open window */	
 	if(config.gfx_fullscreen)
@@ -281,13 +282,13 @@ int gfx_init()
 	inp_init();
 	
 	/* create null texture, will get id=0 */
-	gfx_load_texture_raw(4,4,IMG_RGBA,null_texture_data);
+	gfx_load_texture_raw(4,4,IMG_RGBA,null_texture_data,IMG_RGBA);
 
 	/* set vsync as needed */
 	gfx_set_vsync(config.gfx_vsync);
 
 	/* UGLY as hell, please remove */
-    current_font->font_texture = gfx_load_texture("data/big_font.png");
+    current_font->font_texture = gfx_load_texture("data/big_font.png", IMG_AUTO);
 
 	return 1;
 }
@@ -410,12 +411,13 @@ static unsigned char sample(int w, int h, const unsigned char *data, int u, int
 	data[((v+1)*w+u+1)*4+offset])/4;
 }
 
-int gfx_load_texture_raw(int w, int h, int format, const void *data)
+int gfx_load_texture_raw(int w, int h, int format, const void *data, int store_format)
 {
 	int mipmap = 1;
 	unsigned char *texdata = (unsigned char *)data;
 	unsigned char *tmpdata = 0;
 	int oglformat = 0;
+	int store_oglformat = 0;
 	int tex = 0;
 	
 	/* don't waste memory on texture if we are stress testing */
@@ -455,36 +457,52 @@ int gfx_load_texture_raw(int w, int h, int format, const void *data)
 	
 	if(config.debug)
 		dbg_msg("gfx", "%d = %dx%d", tex, w, h);
+
+	oglformat = GL_RGBA;
+	if(format == IMG_RGB)
+		oglformat = GL_RGB;
+	else if(format == IMG_ALPHA)
+		oglformat = GL_ALPHA;
 	
 	/* upload texture */
 	if(config.gfx_texture_compression)
 	{
-		oglformat = GL_COMPRESSED_RGBA_ARB;
-		if(format == IMG_RGB)
-			oglformat = GL_COMPRESSED_RGB_ARB;
+		store_oglformat = GL_COMPRESSED_RGBA_ARB;
+		if(store_format == IMG_RGB)
+			store_oglformat = GL_COMPRESSED_RGB_ARB;
+		else if(store_format == IMG_ALPHA)
+			store_oglformat = GL_COMPRESSED_ALPHA_ARB;
 	}
 	else
 	{
-		oglformat = GL_RGBA;
-		if(format == IMG_RGB)
-			oglformat = GL_RGB;
+		store_oglformat = GL_RGBA;
+		if(store_format == IMG_RGB)
+			store_oglformat = GL_RGB;
+		else if(store_format == IMG_ALPHA)
+			store_oglformat = GL_ALPHA;
 	}
 		
 	glGenTextures(1, &textures[tex].tex);
 	glBindTexture(GL_TEXTURE_2D, textures[tex].tex);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
-	gluBuild2DMipmaps(GL_TEXTURE_2D, oglformat, w, h, oglformat, GL_UNSIGNED_BYTE, texdata);
+	gluBuild2DMipmaps(GL_TEXTURE_2D, store_oglformat, w, h, oglformat, GL_UNSIGNED_BYTE, texdata);
 	
 	/* calculate memory usage */
-	textures[tex].memsize = w*h*4;
+	int pixel_size = 4;
+	if(store_format == IMG_RGB)
+		pixel_size = 3;
+	else if(store_format == IMG_ALPHA)
+		pixel_size = 1;
+
+	textures[tex].memsize = w*h*pixel_size;
 	if(mipmap)
 	{
 		while(w > 2 && h > 2)
 		{
 			w>>=1;
 			h>>=1;
-			textures[tex].memsize += w*h*4;
+			textures[tex].memsize += w*h*pixel_size;
 		}
 	}
 	
@@ -523,7 +541,7 @@ int gfx_load_mip_texture_raw(int w, int h, int format, const void *data)
 */
 
 /* simple uncompressed RGBA loaders */
-int gfx_load_texture(const char *filename)
+int gfx_load_texture(const char *filename, int store_format)
 {
 	int l = strlen(filename);
 	IMAGE_INFO img;
@@ -531,7 +549,10 @@ int gfx_load_texture(const char *filename)
 		return 0;
 	if(gfx_load_png(&img, filename))
 	{
-		int id = gfx_load_texture_raw(img.width, img.height, img.format, img.data);
+		if (store_format == IMG_AUTO)
+			store_format = img.format;
+
+		int id = gfx_load_texture_raw(img.width, img.height, img.format, img.data, store_format);
 		mem_free(img.data);
 		return id;
 	}
@@ -1052,8 +1073,9 @@ float gfx_pretty_text_raw(float x, float y, float size, const char *text_, int l
 
 void gfx_pretty_text(float x, float y, float size, const char *text, int max_width)
 {
-    /*gfx_text(gfx_font_set, x, y, 0.8*size, text, max_width);
-    return;*/
+    gfx_text(gfx_font_set, x, y, size, text, max_width);
+    return;
+    
 	if(max_width == -1)
 		gfx_pretty_text_raw(x, y, size, text, -1);
 	else
@@ -1078,7 +1100,7 @@ void gfx_pretty_text(float x, float y, float size, const char *text, int max_wid
 
 float gfx_pretty_text_width(float size, const char *text_, int length)
 {
-    /*return gfx_text_width(gfx_font_set, 0.8*size, text_, length);*/
+    return gfx_text_width(gfx_font_set, size, text_, length);
 
 	const float spacing = 0.05f;
 	float w = 0.0f;
diff --git a/src/engine/client/ec_inp.c b/src/engine/client/ec_inp.c
index 59b54a2f..154342f4 100644
--- a/src/engine/client/ec_inp.c
+++ b/src/engine/client/ec_inp.c
@@ -147,7 +147,8 @@ void inp_mouse_mode_absolute()
 
 void inp_mouse_mode_relative()
 {
-	glfwDisable(GLFW_MOUSE_CURSOR);
+	//if (!config.gfx_debug_resizable)
+	//glfwDisable(GLFW_MOUSE_CURSOR);
 }
 
 int inp_mouse_doubleclick()
diff --git a/src/engine/e_config_variables.h b/src/engine/e_config_variables.h
index ff6f686a..99c10c4b 100644
--- a/src/engine/e_config_variables.h
+++ b/src/engine/e_config_variables.h
@@ -36,6 +36,7 @@ MACRO_CONFIG_INT(gfx_high_detail, 1, 0, 1)
 MACRO_CONFIG_INT(gfx_texture_quality, 1, 0, 1)
 MACRO_CONFIG_INT(gfx_fsaa_samples, 0, 0, 16)
 MACRO_CONFIG_INT(gfx_refresh_rate, 0, 0, 0)
+MACRO_CONFIG_INT(gfx_debug_resizable, 0, 0, 0)
 
 MACRO_CONFIG_INT(key_screenshot, 267, 32, 512)
 MACRO_CONFIG_INT(inp_mousesens, 100, 5, 100000)
diff --git a/src/engine/e_interface.h b/src/engine/e_interface.h
index a4f3baa9..3f14745c 100644
--- a/src/engine/e_interface.h
+++ b/src/engine/e_interface.h
@@ -20,8 +20,10 @@ enum
 	SNAP_CURRENT=0,
 	SNAP_PREV=1,
 	
+	IMG_AUTO=-1,
 	IMG_RGB=0,
 	IMG_RGBA=1,
+	IMG_ALPHA=2,
 	
 	MASK_NONE=0,
 	MASK_SET,
@@ -149,6 +151,7 @@ int gfx_window_open();
 	
 	Arguments:
 		filename - Null terminated string to the file to load.
+		store_format - What format to store on gfx card as.
 	
 	Returns:
 		An ID to the texture. -1 on failure.
@@ -156,7 +159,7 @@ int gfx_window_open();
 	See Also:
 		<gfx_unload_texture>
 */
-int gfx_load_texture(const char *filename);
+int gfx_load_texture(const char *filename, int store_format);
 
 /*
 	Function: gfx_load_texture_raw
@@ -177,7 +180,7 @@ int gfx_load_texture(const char *filename);
 	See Also:
 		<gfx_unload_texture>
 */
-int gfx_load_texture_raw(int w, int h, int format, const void *data);
+int gfx_load_texture_raw(int w, int h, int format, const void *data, int store_format);
 /*int gfx_load_mip_texture_raw(int w, int h, int format, const void *data);*/
 
 /*