better skybox

This commit is contained in:
Nishi 2026-01-25 13:05:30 +09:00
commit c0cb0062c1
Signed by: nishi
GPG key ID: 27EF69B208EB9343
7 changed files with 29 additions and 11 deletions

View file

@ -46,7 +46,7 @@ static void render(GSEngine engine){
} }
static void after_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){ int main(int argc, char** argv){

View file

@ -18,6 +18,7 @@ GSDECL GSClient GSEngineGetClient(GSEngine engine);
GSDECL GSServer GSEngineGetServer(GSEngine engine); GSDECL GSServer GSEngineGetServer(GSEngine engine);
GSDECL GSBool GSEngineRegisterResource(GSEngine engine, const char* name, const char* path); GSDECL GSBool GSEngineRegisterResource(GSEngine engine, const char* name, const char* path);
GSDECL void GSEngineUnregisterResource(GSEngine engine, const char* name); GSDECL void GSEngineUnregisterResource(GSEngine engine, const char* name);
GSDECL GSNumber GSEngineGetTPS(GSEngine engine);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -62,6 +62,7 @@ GSDECL void GSGLEndList(GSGL gl);
GSDECL void GSGLCallList(GSGL gl, GLuint list); GSDECL void GSGLCallList(GSGL gl, GLuint list);
GSDECL void GSGLSetColor(GSGL gl, GSVector4 color); GSDECL void GSGLSetColor(GSGL gl, GSVector4 color);
GSDECL void GSGLClearDepth(GSGL gl); GSDECL void GSGLClearDepth(GSGL gl);
GSDECL void GSGLInitialTranslation(GSGL gl);
/* gl_camera.c */ /* gl_camera.c */
GSDECL void GSGLCameraPerspective(GSGL gl, GSNumber width, GSNumber height); GSDECL void GSGLCameraPerspective(GSGL gl, GSNumber width, GSNumber height);

View file

@ -33,12 +33,12 @@ GSClient GSClientCreate(GSEngine engine) {
client->engine = engine; client->engine = engine;
client->camera[0] = 0; client->camera[0] = 0;
client->camera[1] = 0; client->camera[1] = 1.5;
client->camera[2] = 5; client->camera[2] = 5;
client->look_at[0] = 0; client->look_at[0] = 0;
client->look_at[1] = 1; client->look_at[1] = 1;
client->look_at[2] = 0; client->look_at[2] = 5 - 1;
client->light0[0] = 2.5; client->light0[0] = 2.5;
client->light0[1] = 5; client->light0[1] = 5;
@ -118,9 +118,10 @@ void GSClientStep(GSClient client) {
GSGLShadowEnd(client->gl); GSGLShadowEnd(client->gl);
sprintf(buf, "%.1f FPS", client->engine->tps_sampled); sprintf(buf, "%.1f FPS", client->engine->tps_sampled);
sprintf(buf2, "%s%s", client->engine->tps_sampled < 10 ? " " : "", buf);
tw = GSGLTextWidth(client->gl, buf); tw = GSGLTextWidth(client->gl, buf2);
th = GSGLTextHeight(client->gl, buf); th = GSGLTextHeight(client->gl, buf2);
sq[0][0] = client->engine->width - tw, sq[0][1] = 0; sq[0][0] = client->engine->width - tw, sq[0][1] = 0;
sq[1][0] = client->engine->width - tw, sq[1][1] = th; sq[1][0] = client->engine->width - tw, sq[1][1] = th;
@ -134,7 +135,7 @@ void GSClientStep(GSClient client) {
GSGLSetColor(client->gl, yellow); GSGLSetColor(client->gl, yellow);
GSGLTextBold(client->gl, 1); 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); GSGLTextBold(client->gl, 0);
GSVersionGet(&ver); GSVersionGet(&ver);

View file

@ -174,3 +174,7 @@ GSClient GSEngineGetClient(GSEngine engine) {
GSServer GSEngineGetServer(GSEngine engine) { GSServer GSEngineGetServer(GSEngine engine) {
return engine->server; return engine->server;
} }
GSNumber GSEngineGetTPS(GSEngine engine) {
return engine->tps;
}

View file

@ -153,3 +153,15 @@ void GSGLCallList(GSGL gl, GLuint list) {
void GSGLSetColor(GSGL gl, GSVector4 color) { void GSGLSetColor(GSGL gl, GSVector4 color) {
glColor4f(color[0], color[1], color[2], color[3]); 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);
}

View file

@ -88,8 +88,11 @@ void GSSkyBoxDraw(GSSkyBox skybox) {
t[2][0] = 1, t[2][1] = 1; t[2][0] = 1, t[2][1] = 1;
t[3][0] = 1, t[3][1] = 0; t[3][0] = 1, t[3][1] = 0;
GSGLPushMatrix(gl);
GSGLShadowDisable(gl); GSGLShadowDisable(gl);
GSGLInitialTranslation(gl);
for(i = 0; i < 6; i++) { for(i = 0; i < 6; i++) {
GLuint tex; GLuint tex;
int j, k; int j, k;
@ -141,7 +144,6 @@ void GSSkyBoxDraw(GSSkyBox skybox) {
for(j = 0; j < 4; j++) { for(j = 0; j < 4; j++) {
for(k = 0; k < 3; k++) { for(k = 0; k < 3; k++) {
v[j][k] *= GSGLMaxDistance / 2; 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; vc[j][1] = 0.05;
for(k = 0; k < 3; k++) {
vc[j][k] += gl->engine->client->camera[k];
}
} }
GSGLTextureSet(gl, t); GSGLTextureSet(gl, t);
@ -204,6 +202,7 @@ void GSSkyBoxDraw(GSSkyBox skybox) {
GSGLClearDepth(gl); GSGLClearDepth(gl);
GSGLShadowEnable(gl); GSGLShadowEnable(gl);
GSGLPopMatrix(gl);
/* this overflows in: /* this overflows in:
* 3.402823466e+38/60/60/24/365 = 1.0790282426433283e+31 * 3.402823466e+38/60/60/24/365 = 1.0790282426433283e+31