add clouds

This commit is contained in:
Nishi 2026-01-25 01:56:36 +09:00
commit c1a236ffe2
Signed by: nishi
GPG key ID: 27EF69B208EB9343
14 changed files with 109 additions and 34 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 306 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 231 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 249 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

After

Width:  |  Height:  |  Size: 54 KiB

Before After
Before After

View file

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

View file

@ -130,6 +130,11 @@ struct _GSSkyBox {
GLuint back;
GLuint up;
GLuint down;
GLuint cloud0;
GLuint cloud1;
GSNumber tick;
};
struct _GSModelFace {
@ -173,6 +178,7 @@ struct _GSEngine {
GSResourceKV* resource;
int width;
int height;
GSNumber tps;
};
struct _GSFile {

View file

@ -19,13 +19,13 @@ GSClient GSClientCreate(GSEngine engine) {
client->camera[2] = 5;
client->look_at[0] = 0;
client->look_at[1] = 0;
client->look_at[1] = 1;
client->look_at[2] = 0;
client->light0[0] = 2.5;
client->light0[1] = 5;
client->light0[2] = 5;
client->light0[3] = 1;
client->light0[3] = 0;
client->skybox_enabled = GSFalse;
@ -116,6 +116,10 @@ void GSClientStep(GSClient client) {
client->engine->param->gl_swapbuffer();
if(client->engine->param->after_render != NULL) client->engine->param->after_render(client->engine);
static double r = 0;
r += 0.1;
}
GSGL GSClientGetGL(GSClient client) {

View file

@ -113,9 +113,10 @@ void GSEngineParamInit(GSEngineParam* param) {
}
void GSEngineLoop(GSEngine engine) {
long t = 0;
int wait_actually = 0;
long wait = 1000 / 50.0;
long t = 0;
int wait_actually = 0;
GSNumber tps = 50;
long wait = 1000 / tps;
if(engine->param->sleep == NULL || engine->param->get_tick == NULL) {
GSLog(GSLogWarn, "sleep and/or get_tick parameter are missing!");
@ -126,17 +127,23 @@ void GSEngineLoop(GSEngine engine) {
wait_actually = 1;
}
engine->tps = tps;
while(1) {
if(engine->client != NULL) GSClientStep(engine->client);
if(engine->server != NULL) GSServerStep(engine->server);
if(engine->param->tick != NULL) engine->param->tick();
if(wait_actually && !engine->param->client) {
int diff = (engine->param->get_tick() - t);
if(wait_actually) {
if(!engine->param->client) {
int diff = (engine->param->get_tick() - t);
if(wait > diff)
engine->param->sleep(wait - diff);
if(wait > diff)
engine->param->sleep(wait - diff);
}
engine->tps = 1000.0 / (engine->param->get_tick() - t);
t = engine->param->get_tick();
}

View file

@ -52,6 +52,10 @@ void GSGLCareDepth(GSGL gl) {
glEnable(GL_DEPTH_TEST);
}
void GSGLClearDepth(GSGL gl) {
glClear(GL_DEPTH_BUFFER_BIT);
}
void GSGLSetLight(GSGL gl) {
GLfloat f[4];
int i;

View file

@ -14,32 +14,23 @@ GSSkyBox GSSkyBoxOpen(GSClient client, const char* base) {
skybox->engine = client->engine;
ptr[0] = &skybox->left;
ptr[1] = "/left.";
ptr[1] = "/left";
ptr[2] = &skybox->right;
ptr[3] = "/right.";
ptr[3] = "/right";
ptr[4] = &skybox->front;
ptr[5] = "/front.";
ptr[5] = "/front";
ptr[6] = &skybox->back;
ptr[7] = "/back.";
ptr[7] = "/back";
ptr[8] = &skybox->up;
ptr[9] = "/up.";
ptr[9] = "/up";
ptr[10] = &skybox->down;
ptr[11] = "/down.";
ptr[11] = "/down";
for(i = 0; i < 12; i += 2) {
char* b = GSStringConcat(base, ptr[i + 1]);
int j;
const char* fmt[] = {"png", "bmp", "jpg", "jpeg"};
char* b = GSStringConcat(base, ptr[i + 1]);
for(j = 0; j < 4; j++) {
p = GSStringConcat(b, fmt[j]);
if(GSGLTextureLoadFile(client->gl, ptr[i], NULL, NULL, p)) {
free(p);
break;
}
free(p);
}
if(j == 4) {
if(!GSGLTextureTry(client->gl, ptr[i], NULL, NULL, b)) {
free(b);
GSSkyBoxClose(skybox);
return NULL;
}
@ -47,6 +38,16 @@ GSSkyBox GSSkyBoxOpen(GSClient client, const char* base) {
free(b);
}
p = GSStringConcat(base, "/cloud0");
GSGLTextureTry(client->gl, &skybox->cloud0, NULL, NULL, p);
free(p);
p = GSStringConcat(base, "/cloud1");
GSGLTextureTry(client->gl, &skybox->cloud1, NULL, NULL, p);
free(p);
skybox->tick = 0;
return skybox;
}
@ -75,18 +76,18 @@ void GSSkyBoxDraw(GSSkyBox skybox) {
int i;
GSVector3 v[4];
GSVector2 t[4];
GSVector3 n = {0, 0, 0};
GSNumber s = 0.001;
GSVector3 n = {0, 0, 0};
GSNumber s = GSGLMaxDistance / 2 / 10000;
GSVector2 scroll[2] = {
{-0.002, 0.0005}, /**/
{0.006, 0.005} /**/
};
t[0][0] = 0, t[0][1] = 0;
t[1][0] = 0, t[1][1] = 1;
t[2][0] = 1, t[2][1] = 1;
t[3][0] = 1, t[3][1] = 0;
GSGLIgnoreDepth(gl);
GSGLShadowDisable(gl);
for(i = 0; i < 6; i++) {
@ -149,10 +150,62 @@ void GSSkyBoxDraw(GSSkyBox skybox) {
GSGLPolygon(gl, 4, v, t, n);
}
GSGLIgnoreDepth(gl);
for(i = 0; i < 2; i++) {
GLuint t = (i == 0) ? skybox->cloud0 : skybox->cloud1;
if(t != 0) {
GSVector3 vc[4];
GSVector2 tc[4];
GSVector3 n;
int j, k;
n[0] = 0;
n[1] = -1;
n[2] = 0;
vc[0][0] = -1 - s, vc[0][1] = 1, vc[0][2] = 1 - s;
vc[1][0] = -1 - s, vc[1][1] = 1, vc[1][2] = -1 + s;
vc[2][0] = 1 - s, vc[2][1] = 1, vc[2][2] = -1 + s;
vc[3][0] = 1 - s, vc[3][1] = 1, vc[3][2] = 1 - s;
tc[0][0] = -1, tc[0][1] = -1;
tc[1][0] = -1, tc[1][1] = 1;
tc[2][0] = 1, tc[2][1] = 1;
tc[3][0] = 1, tc[3][1] = -1;
for(j = 0; j < 4; j++) {
for(k = 0; k < 2; k++) {
tc[j][k] *= GSGLMaxDistance;
}
for(k = 0; k < 2; k++) {
tc[j][k] += scroll[i][k] * skybox->tick;
}
}
for(j = 0; j < 4; j++) {
for(k = 0; k < 3; k++) {
vc[j][k] *= GSGLMaxDistance / 2;
}
vc[j][1] = 0.05;
for(k = 0; k < 3; k++) {
vc[j][k] += gl->engine->client->camera[k];
}
}
GSGLTextureSet(gl, t);
GSGLPolygon(gl, 4, vc, tc, n);
}
}
GSGLCareDepth(gl);
GSGLTextureSet(gl, 0);
GSGLClearDepth(gl);
GSGLShadowEnable(gl);
GSGLCareDepth(gl);
skybox->tick += 1 / skybox->engine->tps;
}
void GSSkyBoxClose(GSSkyBox skybox) {