mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-13 08:27:39 +00:00
[gl] Add a function to load a tex_t image
In theory, it supports all the non-palette formats, but only luminance and alpha (tex_l and tex_a) have been tested. Fixes the rather broken glyph rendering.
This commit is contained in:
parent
b987414c1d
commit
022c49035f
3 changed files with 54 additions and 2 deletions
|
@ -41,10 +41,12 @@ extern int gl_filter_max;
|
||||||
extern qboolean gl_Anisotropy;
|
extern qboolean gl_Anisotropy;
|
||||||
extern float gl_aniso;
|
extern float gl_aniso;
|
||||||
extern GLuint gl_part_tex;
|
extern GLuint gl_part_tex;
|
||||||
|
struct tex_s;
|
||||||
|
|
||||||
void GL_Upload8 (const byte *data, int width, int height, qboolean mipmap, qboolean alpha);
|
void GL_Upload8 (const byte *data, int width, int height, qboolean mipmap, qboolean alpha);
|
||||||
void GL_Upload8_EXT (const byte *data, int width, int height, qboolean mipmap, qboolean alpha);
|
void GL_Upload8_EXT (const byte *data, int width, int height, qboolean mipmap, qboolean alpha);
|
||||||
int GL_LoadTexture (const char *identifier, int width, int height, const byte *data, qboolean mipmap, qboolean alpha, int bytesperpixel);
|
int GL_LoadTexture (const char *identifier, int width, int height, const byte *data, qboolean mipmap, qboolean alpha, int bytesperpixel);
|
||||||
|
int GL_LoadTex (const char *identifier, int mips, struct tex_s *tex);
|
||||||
int GL_FindTexture (const char *identifier);
|
int GL_FindTexture (const char *identifier);
|
||||||
|
|
||||||
void GL_TextureMode_f (void);
|
void GL_TextureMode_f (void);
|
||||||
|
|
|
@ -1066,8 +1066,14 @@ gl_Draw_AddFont (struct rfont_s *rfont)
|
||||||
glfont_t *font = &gl_fonts.a[fontid];
|
glfont_t *font = &gl_fonts.a[fontid];
|
||||||
|
|
||||||
font->font = rfont;
|
font->font = rfont;
|
||||||
font->texid = GL_LoadTexture ("", rfont->scrap.width, rfont->scrap.height,
|
tex_t tex = {
|
||||||
rfont->scrap_bitmap, 0, 1, 1);
|
.width = rfont->scrap.width,
|
||||||
|
.height = rfont->scrap.height,
|
||||||
|
.format = tex_a,
|
||||||
|
.loaded = 1,
|
||||||
|
.data = rfont->scrap_bitmap,
|
||||||
|
};
|
||||||
|
font->texid = GL_LoadTex ("", 0, &tex);
|
||||||
return fontid;
|
return fontid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1090,6 +1096,7 @@ gl_render_glyph (uint32_t glyphid, int x, int y, void *_rgctx)
|
||||||
float v = rect->y;
|
float v = rect->y;
|
||||||
float s = 1.0 / rfont->scrap.width;
|
float s = 1.0 / rfont->scrap.width;
|
||||||
float t = 1.0 / rfont->scrap.height;
|
float t = 1.0 / rfont->scrap.height;
|
||||||
|
qfglColor4ubv (rgctx->color);
|
||||||
qfglTexCoord2f (u * s, v * t);
|
qfglTexCoord2f (u * s, v * t);
|
||||||
qfglVertex2f (x, y);
|
qfglVertex2f (x, y);
|
||||||
qfglTexCoord2f ((u + w) * s, v * t);
|
qfglTexCoord2f ((u + w) * s, v * t);
|
||||||
|
@ -1126,4 +1133,5 @@ gl_Draw_FontString (int x, int y, int fontid, const char *str)
|
||||||
RText_DeleteShaper (shaper);
|
RText_DeleteShaper (shaper);
|
||||||
|
|
||||||
qfglEnd ();
|
qfglEnd ();
|
||||||
|
qfglColor4ubv (color_white);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include "QF/crc.h"
|
#include "QF/crc.h"
|
||||||
#include "QF/cvar.h"
|
#include "QF/cvar.h"
|
||||||
#include "QF/draw.h"
|
#include "QF/draw.h"
|
||||||
|
#include "QF/image.h"
|
||||||
#include "QF/mathlib.h"
|
#include "QF/mathlib.h"
|
||||||
#include "QF/sys.h"
|
#include "QF/sys.h"
|
||||||
#include "QF/GL/defines.h"
|
#include "QF/GL/defines.h"
|
||||||
|
@ -641,6 +642,47 @@ SetupTexture:
|
||||||
return glt->texnum;
|
return glt->texnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
GL_LoadTex (const char *identifier, int mips, tex_t *tex)
|
||||||
|
{
|
||||||
|
GLuint tnum;
|
||||||
|
qfglGenTextures (1, &tnum);
|
||||||
|
int format = GL_RGB;
|
||||||
|
|
||||||
|
switch (tex->format) {
|
||||||
|
case tex_l:
|
||||||
|
case tex_a:
|
||||||
|
format = tex->format;
|
||||||
|
break;
|
||||||
|
case tex_la:
|
||||||
|
format = GL_LUMINANCE_ALPHA;
|
||||||
|
break;
|
||||||
|
case tex_rgb:
|
||||||
|
format = GL_RGB;
|
||||||
|
break;
|
||||||
|
case tex_rgba:
|
||||||
|
format = GL_RGBA;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Sys_Error ("GL_CreateScrap: Invalid texture format");
|
||||||
|
}
|
||||||
|
|
||||||
|
qfglBindTexture (GL_TEXTURE_2D, tnum);
|
||||||
|
qfglTexImage2D (GL_TEXTURE_2D, 0, format, tex->width, tex->height,
|
||||||
|
0, format, GL_UNSIGNED_BYTE, tex->data);
|
||||||
|
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
if (mips) {
|
||||||
|
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
qfglGenerateMipmap (GL_TEXTURE_2D);
|
||||||
|
} else {
|
||||||
|
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
}
|
||||||
|
return tnum;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
GL_ReleaseTexture (int tex)
|
GL_ReleaseTexture (int tex)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue