From c0cb0062c14d4d70665276317fdefb3a40637845 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Sun, 25 Jan 2026 13:05:30 +0900 Subject: [PATCH] better skybox --- client/main.c | 2 +- engine/include/GearSrc/Core.h | 1 + engine/include/GearSrc/GL.h | 1 + engine/src/client.c | 11 ++++++----- engine/src/core.c | 4 ++++ engine/src/gl.c | 12 ++++++++++++ engine/src/skybox.c | 9 ++++----- 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/client/main.c b/client/main.c index 13f8d12..476295f 100644 --- a/client/main.c +++ b/client/main.c @@ -46,7 +46,7 @@ static void render(GSEngine engine){ } static void after_render(GSEngine engine){ - rot[0] = rot[1] = rot[2]++; + rot[0] = rot[1] = rot[2] += (1.0 / GSEngineGetTPS(engine)) * 90; } int main(int argc, char** argv){ diff --git a/engine/include/GearSrc/Core.h b/engine/include/GearSrc/Core.h index 0901ab8..81eec06 100644 --- a/engine/include/GearSrc/Core.h +++ b/engine/include/GearSrc/Core.h @@ -18,6 +18,7 @@ GSDECL GSClient GSEngineGetClient(GSEngine engine); GSDECL GSServer GSEngineGetServer(GSEngine engine); GSDECL GSBool GSEngineRegisterResource(GSEngine engine, const char* name, const char* path); GSDECL void GSEngineUnregisterResource(GSEngine engine, const char* name); +GSDECL GSNumber GSEngineGetTPS(GSEngine engine); #ifdef __cplusplus } diff --git a/engine/include/GearSrc/GL.h b/engine/include/GearSrc/GL.h index 040770b..53bd12d 100644 --- a/engine/include/GearSrc/GL.h +++ b/engine/include/GearSrc/GL.h @@ -62,6 +62,7 @@ GSDECL void GSGLEndList(GSGL gl); GSDECL void GSGLCallList(GSGL gl, GLuint list); GSDECL void GSGLSetColor(GSGL gl, GSVector4 color); GSDECL void GSGLClearDepth(GSGL gl); +GSDECL void GSGLInitialTranslation(GSGL gl); /* gl_camera.c */ GSDECL void GSGLCameraPerspective(GSGL gl, GSNumber width, GSNumber height); diff --git a/engine/src/client.c b/engine/src/client.c index 2277a72..7955b00 100644 --- a/engine/src/client.c +++ b/engine/src/client.c @@ -33,12 +33,12 @@ GSClient GSClientCreate(GSEngine engine) { client->engine = engine; client->camera[0] = 0; - client->camera[1] = 0; + client->camera[1] = 1.5; client->camera[2] = 5; client->look_at[0] = 0; client->look_at[1] = 1; - client->look_at[2] = 0; + client->look_at[2] = 5 - 1; client->light0[0] = 2.5; client->light0[1] = 5; @@ -118,9 +118,10 @@ void GSClientStep(GSClient client) { GSGLShadowEnd(client->gl); sprintf(buf, "%.1f FPS", client->engine->tps_sampled); + sprintf(buf2, "%s%s", client->engine->tps_sampled < 10 ? " " : "", buf); - tw = GSGLTextWidth(client->gl, buf); - th = GSGLTextHeight(client->gl, buf); + tw = GSGLTextWidth(client->gl, buf2); + th = GSGLTextHeight(client->gl, buf2); sq[0][0] = client->engine->width - tw, sq[0][1] = 0; sq[1][0] = client->engine->width - tw, sq[1][1] = th; @@ -134,7 +135,7 @@ void GSClientStep(GSClient client) { GSGLSetColor(client->gl, yellow); GSGLTextBold(client->gl, 1); - GSGLText(client->gl, client->engine->width - tw, 0, buf); + GSGLText(client->gl, client->engine->width - tw, 0, buf2); GSGLTextBold(client->gl, 0); GSVersionGet(&ver); diff --git a/engine/src/core.c b/engine/src/core.c index 198af5e..6138657 100644 --- a/engine/src/core.c +++ b/engine/src/core.c @@ -174,3 +174,7 @@ GSClient GSEngineGetClient(GSEngine engine) { GSServer GSEngineGetServer(GSEngine engine) { return engine->server; } + +GSNumber GSEngineGetTPS(GSEngine engine) { + return engine->tps; +} diff --git a/engine/src/gl.c b/engine/src/gl.c index 2f81c30..14e6e73 100644 --- a/engine/src/gl.c +++ b/engine/src/gl.c @@ -153,3 +153,15 @@ void GSGLCallList(GSGL gl, GLuint list) { void GSGLSetColor(GSGL gl, GSVector4 color) { glColor4f(color[0], color[1], color[2], color[3]); } + +void GSGLInitialTranslation(GSGL gl) { + GLdouble matrix[16]; + + glGetDoublev(GL_MODELVIEW_MATRIX, matrix); + + matrix[4 * 3 + 0] = 0; + matrix[4 * 3 + 1] = 0; + matrix[4 * 3 + 2] = 0; + + glLoadMatrixd(matrix); +} diff --git a/engine/src/skybox.c b/engine/src/skybox.c index 74ad5a7..587b10f 100644 --- a/engine/src/skybox.c +++ b/engine/src/skybox.c @@ -88,8 +88,11 @@ void GSSkyBoxDraw(GSSkyBox skybox) { t[2][0] = 1, t[2][1] = 1; t[3][0] = 1, t[3][1] = 0; + GSGLPushMatrix(gl); GSGLShadowDisable(gl); + GSGLInitialTranslation(gl); + for(i = 0; i < 6; i++) { GLuint tex; int j, k; @@ -141,7 +144,6 @@ void GSSkyBoxDraw(GSSkyBox skybox) { for(j = 0; j < 4; j++) { for(k = 0; k < 3; k++) { v[j][k] *= GSGLMaxDistance / 2; - v[j][k] += gl->engine->client->camera[k]; } } @@ -188,10 +190,6 @@ void GSSkyBoxDraw(GSSkyBox skybox) { } vc[j][1] = 0.05; - - for(k = 0; k < 3; k++) { - vc[j][k] += gl->engine->client->camera[k]; - } } GSGLTextureSet(gl, t); @@ -204,6 +202,7 @@ void GSSkyBoxDraw(GSSkyBox skybox) { GSGLClearDepth(gl); GSGLShadowEnable(gl); + GSGLPopMatrix(gl); /* this overflows in: * 3.402823466e+38/60/60/24/365 = 1.0790282426433283e+31