From 7cf83fbb2aa1a86604f6ac483a57f0ff98a09779 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Tue, 20 Jan 2026 14:34:13 +0900 Subject: [PATCH] some fancy things --- engine/include/GearSrc/GL.h | 5 +++ engine/include/GearSrc/TypeDefs.h | 4 +++ engine/src/client.c | 49 +++++++++++++++++++++++++++- engine/src/core.c | 4 +-- engine/src/gl.c | 4 +++ engine/src/gl_common.c | 53 +++++++++++++++++++++++++++++++ engine/src/version.c | 1 + 7 files changed, 117 insertions(+), 3 deletions(-) diff --git a/engine/include/GearSrc/GL.h b/engine/include/GearSrc/GL.h index fcc07c0..6ed009a 100644 --- a/engine/include/GearSrc/GL.h +++ b/engine/include/GearSrc/GL.h @@ -23,6 +23,10 @@ GSDECL void GSGLTextureDelete(GSGL gl, GLuint texture); /* gl_common.c */ GSDECL GSBool GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const char* filename); GSDECL GSBool GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const char* prefix); +GSDECL void GSGLTextEx(GSGL gl, double x, double y, double sx, double sy, const char* text); +GSDECL void GSGLText(GSGL gl, double x, double y, const char* text); +GSDECL double GSGLTextWidth(GSGL gl, const char* text); +GSDECL double GSGLTextHeight(GSGL gl, const char* text); /* gl_shadow.c */ GSDECL void GSGLShadowInit(GSGL gl); @@ -51,6 +55,7 @@ GSDECL void GSGLPopMatrix(GSGL gl); GSDECL GLuint GSGLBeginList(GSGL gl); GSDECL void GSGLEndList(GSGL gl); GSDECL void GSGLCallList(GSGL gl, GLuint list); +GSDECL void GSGLSetColor(GSGL gl, GSVector4 color); /* gl_camera.c */ GSDECL void GSGLCameraPerspective(GSGL gl, GSNumber width, GSNumber height); diff --git a/engine/include/GearSrc/TypeDefs.h b/engine/include/GearSrc/TypeDefs.h index 5d8a4bb..f9270b0 100644 --- a/engine/include/GearSrc/TypeDefs.h +++ b/engine/include/GearSrc/TypeDefs.h @@ -105,6 +105,9 @@ struct _GSClient { GSEngine engine; GSGL gl; + GLuint font; + int font_width; + int font_height; GSVector3 look_at; GSVector3 camera; GSVector4 light0; @@ -180,6 +183,7 @@ struct _GSResource { struct _GSVersion { char string[64]; + char copyright[256]; int majorlevel; int minorlevel; int patchlevel; diff --git a/engine/src/client.c b/engine/src/client.c index 92db5c4..311557a 100644 --- a/engine/src/client.c +++ b/engine/src/client.c @@ -5,6 +5,7 @@ #include #include #include +#include GSClient GSClientCreate(GSEngine engine) { GSClient client = malloc(sizeof(*client)); @@ -32,12 +33,20 @@ GSClient GSClientCreate(GSEngine engine) { client->skybox = GSSkyBoxTry(client, "default"); + if(GSGLTextureTry(client->gl, &client->font, &client->font_width, &client->font_height, "game:/font")){ + }else if(GSGLTextureTry(client->gl, &client->font, &client->font_width, &client->font_height, "base:/font")){ + }else{ + client->font = 0; + } + GSLog(GSLogInfo, "Created client"); return client; } void GSClientDestroy(GSClient client) { + if(client->font != 0) GSGLTextureDelete(client->gl, client->font); + GSGLDestroy(client->gl); free(client); @@ -50,7 +59,15 @@ static void scene(GSClient client) { } void GSClientStep(GSClient client) { - static double r = 0; + int tw, th; + int tw2, th2; + int sw, sh; + char buf[512]; + char buf2[512]; + GSVersion ver; + GSVector4 white = {1, 1, 1, 1}; + GSVector4 half = {0, 0, 0, 0.5}; + GSVector2 sq[4]; GSGLClear(client->gl); GSGLCameraSetup(client->gl); @@ -67,6 +84,36 @@ void GSClientStep(GSClient client) { scene(client); GSGLShadowEnd(client->gl); + + GSVersionGet(&ver); + + sprintf(buf, "GearSrc Engine %s", ver.string); + + tw = GSGLTextWidth(client->gl, buf); + th = GSGLTextHeight(client->gl, buf); + + sprintf(buf2, "%s", ver.copyright); + + tw2 = GSGLTextWidth(client->gl, buf2); + th2 = GSGLTextHeight(client->gl, buf2); + + sw = tw > tw2 ? tw : tw2; + sh = th + th2; + + sq[0][0] = client->engine->width - sw, sq[0][1] = client->engine->height - sh; + sq[1][0] = client->engine->width - sw, sq[1][1] = client->engine->height; + sq[2][0] = client->engine->width, sq[2][1] = client->engine->height; + sq[3][0] = client->engine->width, sq[3][1] = client->engine->height - sh; + + GSGLSetColor(client->gl, half); + GSGLBegin2D(client->gl); + GSGLPolygon2D(client->gl, 4, sq, NULL); + GSGLEnd2D(client->gl); + + GSGLSetColor(client->gl, white); + GSGLText(client->gl, client->engine->width - tw, client->engine->height - th * 2, buf); + GSGLText(client->gl, client->engine->width - tw2, client->engine->height - th2, buf2); + client->engine->param->gl_swapbuffer(); if(client->engine->param->after_render != NULL) client->engine->param->after_render(client->engine); diff --git a/engine/src/core.c b/engine/src/core.c index 16dfdc1..c6927a7 100644 --- a/engine/src/core.c +++ b/engine/src/core.c @@ -50,8 +50,8 @@ GSEngine GSEngineCreate(GSEngineParam* param) { engine->param = malloc(sizeof(*engine->param)); memcpy(engine->param, param, sizeof(*param)); - engine->width = 1024; - engine->height = 768; + engine->width = 800; + engine->height = 600; if(param->ready != NULL && param->client) { param->ready(engine->width, engine->height); diff --git a/engine/src/gl.c b/engine/src/gl.c index 1f46d6f..2856211 100644 --- a/engine/src/gl.c +++ b/engine/src/gl.c @@ -145,3 +145,7 @@ void GSGLEndList(GSGL gl) { void GSGLCallList(GSGL gl, GLuint list) { glCallList(list); } + +void GSGLSetColor(GSGL gl, GSVector4 color){ + glColor4f(color[0], color[1], color[2], color[3]); +} diff --git a/engine/src/gl_common.c b/engine/src/gl_common.c index 5ab06af..0095596 100644 --- a/engine/src/gl_common.c +++ b/engine/src/gl_common.c @@ -60,3 +60,56 @@ GSBool GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const c return st; } + +void GSGLTextEx(GSGL gl, double x, double y, double sx, double sy, const char* text){ + double px = x; + double py = y; + int i; + double gw = gl->engine->client->font_width / 16 * sx; + double gh = gl->engine->client->font_height / 16 * sy; + + GSGLBegin2D(gl); + GSGLTextureSet(gl, gl->engine->client->font); + + for(i = 0; text[i] != 0; i++){ + GSVector2 v[4]; + GSVector2 t[4]; + double gx = text[i] % 16; + double gy = text[i] / 16; + + gx = gx / 16; + gy = gy / 16; + + v[0][0] = px, v[0][1] = py; + + v[1][0] = px, v[1][1] = py + gh; + + v[2][0] = px + gw, v[2][1] = py + gh; + + v[3][0] = px + gw, v[3][1] = py; + + t[0][0] = gx, t[0][1] = gy; + t[1][0] = gx, t[1][1] = gy + 1.0 / 16; + t[2][0] = gx + 1.0 / 16, t[2][1] = gy + 1.0 / 16; + t[3][0] = gx + 1.0 / 16, t[3][1] = gy; + + GSGLPolygon2D(gl, 4, v, t); + + px += gw; + } + + GSGLTextureSet(gl, 0); + GSGLEnd2D(gl); +} + +void GSGLText(GSGL gl, double x, double y, const char* text){ + GSGLTextEx(gl, x, y, 1, 1, text); +} + +double GSGLTextWidth(GSGL gl, const char* text){ + return gl->engine->client->font_width / 16 * strlen(text); +} + +double GSGLTextHeight(GSGL gl, const char* text){ + return gl->engine->client->font_height / 16; +} diff --git a/engine/src/version.c b/engine/src/version.c index 9c39257..271e2c2 100644 --- a/engine/src/version.c +++ b/engine/src/version.c @@ -6,4 +6,5 @@ void GSVersionGet(GSVersion* version) { version->patchlevel = 0; sprintf(version->string, "%d.%d.%d", version->majorlevel, version->minorlevel, version->patchlevel); + strcpy(version->copyright, "Copyright (C) 2026 Pyrite development team"); }