From 022c49035fe765d67bf58ed27b95b74d31225b45 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 5 Dec 2022 13:35:44 +0900 Subject: [PATCH] [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. --- include/QF/GL/qf_textures.h | 2 ++ libs/video/renderer/gl/gl_draw.c | 12 ++++++-- libs/video/renderer/gl/gl_textures.c | 42 ++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/include/QF/GL/qf_textures.h b/include/QF/GL/qf_textures.h index ea5a8c9ac..d5b832850 100644 --- a/include/QF/GL/qf_textures.h +++ b/include/QF/GL/qf_textures.h @@ -41,10 +41,12 @@ extern int gl_filter_max; extern qboolean gl_Anisotropy; extern float gl_aniso; 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_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_LoadTex (const char *identifier, int mips, struct tex_s *tex); int GL_FindTexture (const char *identifier); void GL_TextureMode_f (void); diff --git a/libs/video/renderer/gl/gl_draw.c b/libs/video/renderer/gl/gl_draw.c index fbe3d28e3..c8e311b75 100644 --- a/libs/video/renderer/gl/gl_draw.c +++ b/libs/video/renderer/gl/gl_draw.c @@ -1066,8 +1066,14 @@ gl_Draw_AddFont (struct rfont_s *rfont) glfont_t *font = &gl_fonts.a[fontid]; font->font = rfont; - font->texid = GL_LoadTexture ("", rfont->scrap.width, rfont->scrap.height, - rfont->scrap_bitmap, 0, 1, 1); + tex_t tex = { + .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; } @@ -1090,6 +1096,7 @@ gl_render_glyph (uint32_t glyphid, int x, int y, void *_rgctx) float v = rect->y; float s = 1.0 / rfont->scrap.width; float t = 1.0 / rfont->scrap.height; + qfglColor4ubv (rgctx->color); qfglTexCoord2f (u * s, v * t); qfglVertex2f (x, y); 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); qfglEnd (); + qfglColor4ubv (color_white); } diff --git a/libs/video/renderer/gl/gl_textures.c b/libs/video/renderer/gl/gl_textures.c index 68af61db2..80313dcd5 100644 --- a/libs/video/renderer/gl/gl_textures.c +++ b/libs/video/renderer/gl/gl_textures.c @@ -42,6 +42,7 @@ #include "QF/crc.h" #include "QF/cvar.h" #include "QF/draw.h" +#include "QF/image.h" #include "QF/mathlib.h" #include "QF/sys.h" #include "QF/GL/defines.h" @@ -641,6 +642,47 @@ SetupTexture: 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 GL_ReleaseTexture (int tex) {