fixed protection so that the fonts doesn't get resampled

This commit is contained in:
Magnus Auvinen 2008-03-29 11:55:42 +00:00
parent 7a3874745c
commit 1f246d9dcb
10 changed files with 34 additions and 26 deletions

View file

@ -508,7 +508,7 @@ void client_disconnect()
static int client_load_data()
{
debug_font = gfx_load_texture("data/debug_font.png", IMG_AUTO);
debug_font = gfx_load_texture("data/debug_font.png", IMG_AUTO, TEXLOAD_NORESAMPLE);
return 1;
}

View file

@ -3,6 +3,7 @@
#include <stdio.h>
#include <string.h>
#include <engine/e_system.h>
#include <engine/e_client_interface.h>
#include "ec_font.h"
typedef struct
@ -87,8 +88,8 @@ int font_load(FONT *font, const char *filename)
return -1;
}
int gfx_load_texture(const char *filename, int store_format);
#define IMG_ALPHA 2
/*int gfx_load_texture(const char *filename, int store_format, int flags);
#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, ...)
{
@ -119,8 +120,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, IMG_ALPHA);
font->outline_texture = gfx_load_texture(composed_outline_texture_filename, IMG_ALPHA);
font->text_texture = gfx_load_texture(composed_text_texture_filename, IMG_ALPHA, TEXLOAD_NORESAMPLE);
font->outline_texture = gfx_load_texture(composed_outline_texture_filename, IMG_ALPHA, TEXLOAD_NORESAMPLE);
}
va_end(va);

View file

@ -242,7 +242,7 @@ int gfx_init()
inp_init();
/* create null texture, will get id=0 */
gfx_load_texture_raw(4,4,IMG_RGBA,null_texture_data,IMG_RGBA);
gfx_load_texture_raw(4,4,IMG_RGBA,null_texture_data,IMG_RGBA,TEXLOAD_NORESAMPLE);
/* set vsync as needed */
gfx_set_vsync(config.gfx_vsync);
@ -373,7 +373,7 @@ 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 store_format)
int gfx_load_texture_raw(int w, int h, int format, const void *data, int store_format, int flags)
{
int mipmap = 1;
unsigned char *texdata = (unsigned char *)data;
@ -392,7 +392,7 @@ int gfx_load_texture_raw(int w, int h, int format, const void *data, int store_f
textures[tex].next = -1;
/* resample if needed */
if(config.gfx_texture_quality==0)
if(!(flags&TEXLOAD_NORESAMPLE) && config.gfx_texture_quality==0)
{
if(w > 16 && h > 16 && format == IMG_RGBA)
{
@ -476,7 +476,7 @@ int gfx_load_texture_raw(int w, int h, int format, const void *data, int store_f
}
/* simple uncompressed RGBA loaders */
int gfx_load_texture(const char *filename, int store_format)
int gfx_load_texture(const char *filename, int store_format, int flags)
{
int l = strlen(filename);
int id;
@ -489,7 +489,7 @@ int gfx_load_texture(const char *filename, int store_format)
if (store_format == IMG_AUTO)
store_format = img.format;
id = gfx_load_texture_raw(img.width, img.height, img.format, img.data, store_format);
id = gfx_load_texture_raw(img.width, img.height, img.format, img.data, store_format, flags);
mem_free(img.data);
return id;
}

View file

@ -33,6 +33,11 @@ enum
IMG_RGBA=1,
IMG_ALPHA=2,
/* Constants: Texture Loading Flags
TEXLOAD_NORESAMPLE - Prevents the texture from any resampling
*/
TEXLOAD_NORESAMPLE=1,
/* Constants: Server Browser Sorting
BROWSESORT_NAME - Sort by name.
BROWSESORT_PING - Sort by ping.

View file

@ -337,6 +337,7 @@ int gfx_load_png(IMAGE_INFO *img, const char *filename);
Arguments:
filename - Null terminated string to the file to load.
store_format - What format to store on gfx card as.
flags - controls how the texture is uploaded
Returns:
An ID to the texture. -1 on failure.
@ -344,7 +345,7 @@ int gfx_load_png(IMAGE_INFO *img, const char *filename);
See Also:
<gfx_unload_texture, gfx_load_png>
*/
int gfx_load_texture(const char *filename, int store_format);
int gfx_load_texture(const char *filename, int store_format, int flags);
/*
Function: gfx_load_texture_raw
@ -356,6 +357,7 @@ int gfx_load_texture(const char *filename, int store_format);
data - Pointer to the pixel data.
format - Format of the pixel data.
store_format - The format to store the texture on the graphics card.
flags - controls how the texture is uploaded
Returns:
An ID to the texture. -1 on failure.
@ -367,7 +369,7 @@ int gfx_load_texture(const char *filename, int store_format);
See Also:
<gfx_unload_texture>
*/
int gfx_load_texture_raw(int w, int h, int format, const void *data, int store_format);
int gfx_load_texture_raw(int w, int h, int format, const void *data, int store_format, int flags);
/*
Function: gfx_texture_set

View file

@ -98,7 +98,7 @@ extern "C" void modc_init()
for(int i = 0; i < data->num_images; i++)
{
render_loading(load_current/load_total);
data->images[i].id = gfx_load_texture(data->images[i].filename, IMG_AUTO);
data->images[i].id = gfx_load_texture(data->images[i].filename, IMG_AUTO, 0);
load_current++;
}

View file

@ -111,12 +111,12 @@ int img_init()
char buf[256];
char *name = (char *)map_get_data(img->image_name);
str_format(buf, sizeof(buf), "data/mapres/%s.png", name);
map_textures[i] = gfx_load_texture(buf, IMG_AUTO);
map_textures[i] = gfx_load_texture(buf, IMG_AUTO, 0);
}
else
{
void *data = map_get_data(img->image_data);
map_textures[i] = gfx_load_texture_raw(img->width, img->height, IMG_RGBA, data, IMG_RGBA);
map_textures[i] = gfx_load_texture_raw(img->width, img->height, IMG_RGBA, data, IMG_RGBA, 0);
map_unload_data(img->image_data);
}
}

View file

@ -32,7 +32,7 @@ static void skinscan(const char *name, int is_dir, void *user)
return;
}
skins[num_skins].org_texture = gfx_load_texture_raw(info.width, info.height, info.format, info.data, info.format);
skins[num_skins].org_texture = gfx_load_texture_raw(info.width, info.height, info.format, info.data, info.format, 0);
int body_size = 96; // body size
unsigned char *d = (unsigned char *)info.data;
@ -105,7 +105,7 @@ static void skinscan(const char *name, int is_dir, void *user)
}
}
skins[num_skins].color_texture = gfx_load_texture_raw(info.width, info.height, info.format, info.data, info.format);
skins[num_skins].color_texture = gfx_load_texture_raw(info.width, info.height, info.format, info.data, info.format, 0);
mem_free(info.data);
// set skin data

View file

@ -1478,7 +1478,7 @@ static void replace_image(const char *filename)
gfx_unload_texture(img->tex_id);
*img = imginfo;
extract_name(filename, img->name);
img->tex_id = gfx_load_texture_raw(imginfo.width, imginfo.height, imginfo.format, imginfo.data, IMG_AUTO);
img->tex_id = gfx_load_texture_raw(imginfo.width, imginfo.height, imginfo.format, imginfo.data, IMG_AUTO, 0);
}
static void add_image(const char *filename)
@ -1489,7 +1489,7 @@ static void add_image(const char *filename)
IMAGE *img = new IMAGE;
*img = imginfo;
img->tex_id = gfx_load_texture_raw(imginfo.width, imginfo.height, imginfo.format, imginfo.data, IMG_AUTO);
img->tex_id = gfx_load_texture_raw(imginfo.width, imginfo.height, imginfo.format, imginfo.data, IMG_AUTO, 0);
img->external = 1; // external by default
extract_name(filename, img->name);
editor.map.images.add(img);
@ -2369,10 +2369,10 @@ void MAP::create_default(int entities_texture)
extern "C" void editor_init()
{
checker_texture = gfx_load_texture("data/editor/checker.png", IMG_AUTO);
background_texture = gfx_load_texture("data/editor/background.png", IMG_AUTO);
cursor_texture = gfx_load_texture("data/editor/cursor.png", IMG_AUTO);
entities_texture = gfx_load_texture("data/editor/entities.png", IMG_AUTO);
checker_texture = gfx_load_texture("data/editor/checker.png", IMG_AUTO, 0);
background_texture = gfx_load_texture("data/editor/background.png", IMG_AUTO, 0);
cursor_texture = gfx_load_texture("data/editor/cursor.png", IMG_AUTO, 0);
entities_texture = gfx_load_texture("data/editor/entities.png", IMG_AUTO, 0);
tileset_picker.make_palette();
tileset_picker.readonly = true;

View file

@ -141,7 +141,7 @@ void editor_load_old(DATAFILE *df, MAP *map)
// copy image data
img->data = mem_alloc(img->width*img->height*4, 1);
mem_copy(img->data, data, img->width*img->height*4);
img->tex_id = gfx_load_texture_raw(img->width, img->height, img->format, img->data, IMG_AUTO);
img->tex_id = gfx_load_texture_raw(img->width, img->height, img->format, img->data, IMG_AUTO, 0);
map->images.add(img);
// unload image
@ -405,7 +405,7 @@ int MAP::load(const char *filename)
if(gfx_load_png(&imginfo, buf))
{
*img = imginfo;
img->tex_id = gfx_load_texture_raw(imginfo.width, imginfo.height, imginfo.format, imginfo.data, IMG_AUTO);
img->tex_id = gfx_load_texture_raw(imginfo.width, imginfo.height, imginfo.format, imginfo.data, IMG_AUTO, 0);
img->external = 1;
}
}
@ -419,7 +419,7 @@ int MAP::load(const char *filename)
void *data = datafile_get_data(df, item->image_data);
img->data = mem_alloc(img->width*img->height*4, 1);
mem_copy(img->data, data, img->width*img->height*4);
img->tex_id = gfx_load_texture_raw(img->width, img->height, img->format, img->data, IMG_AUTO);
img->tex_id = gfx_load_texture_raw(img->width, img->height, img->format, img->data, IMG_AUTO, 0);
}
// copy image name