2026-01-09 00:40:51 +09:00
|
|
|
#include <GearBox/Client.h>
|
|
|
|
|
|
|
|
|
|
#include <GearBox/Log.h>
|
2026-01-10 19:51:48 +09:00
|
|
|
#include <GearBox/GL.h>
|
2026-01-09 00:40:51 +09:00
|
|
|
|
|
|
|
|
GBClient GBClientCreate(GBEngine engine) {
|
2026-01-09 03:38:29 +09:00
|
|
|
GBClient client = malloc(sizeof(*client));
|
|
|
|
|
|
|
|
|
|
memset(client, 0, sizeof(*client));
|
|
|
|
|
|
2026-01-09 06:12:57 +09:00
|
|
|
client->engine = engine;
|
|
|
|
|
|
2026-01-11 18:27:41 +09:00
|
|
|
client->camera[0] = 2;
|
2026-01-11 01:36:32 +09:00
|
|
|
client->camera[1] = 1.5;
|
2026-01-11 18:27:41 +09:00
|
|
|
client->camera[2] = 2;
|
2026-01-11 01:36:32 +09:00
|
|
|
|
|
|
|
|
client->look_at[0] = 0;
|
|
|
|
|
client->look_at[1] = 0;
|
|
|
|
|
client->look_at[2] = 0;
|
|
|
|
|
|
2026-01-11 17:43:03 +09:00
|
|
|
client->light0[0] = 5;
|
|
|
|
|
client->light0[1] = 5;
|
|
|
|
|
client->light0[2] = 5;
|
2026-01-11 18:27:41 +09:00
|
|
|
client->light0[3] = 1;
|
2026-01-11 01:36:32 +09:00
|
|
|
|
2026-01-10 19:51:48 +09:00
|
|
|
client->gl = GBGLCreate(client);
|
|
|
|
|
|
|
|
|
|
GBLog(GBLogInfo, "Created client");
|
2026-01-09 00:40:51 +09:00
|
|
|
|
2026-01-09 03:38:29 +09:00
|
|
|
return client;
|
2026-01-09 00:40:51 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GBClientDestroy(GBClient client) {
|
2026-01-10 19:51:48 +09:00
|
|
|
GBGLDestroy(client->gl);
|
|
|
|
|
|
2026-01-09 00:40:51 +09:00
|
|
|
free(client);
|
2026-01-10 19:51:48 +09:00
|
|
|
|
|
|
|
|
GBLog(GBLogInfo, "Destroyed client");
|
2026-01-09 00:40:51 +09:00
|
|
|
}
|
2026-01-09 03:38:29 +09:00
|
|
|
|
2026-01-11 01:36:32 +09:00
|
|
|
static void scene(void) {
|
|
|
|
|
glColor3f(1, 1, 1);
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
|
glNormal3f(0, 1, 0);
|
|
|
|
|
glVertex3f(-1, 0, -1);
|
|
|
|
|
glVertex3f(-1, 0, 1);
|
|
|
|
|
glVertex3f(1, 0, 1);
|
|
|
|
|
glVertex3f(1, 0, -1);
|
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
glColor3f(1, 0, 0);
|
|
|
|
|
for(i = 0; i < 2; i++) {
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
glRotatef(180 * i, 0, 1, 0);
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
|
glNormal3f(-1, 0, 0);
|
2026-01-11 17:43:03 +09:00
|
|
|
glVertex3f(-1, 0.5, 0.25);
|
|
|
|
|
glVertex3f(-1, 0, 0.25);
|
|
|
|
|
glVertex3f(1, 0, 0.25);
|
|
|
|
|
glVertex3f(1, 0.5, 0.25);
|
2026-01-11 01:36:32 +09:00
|
|
|
glEnd();
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
}
|
2026-01-11 17:43:03 +09:00
|
|
|
glBegin(GL_QUADS);
|
|
|
|
|
glNormal3f(0, 1, 0);
|
|
|
|
|
glVertex3f(-1, 0.5, -0.25);
|
|
|
|
|
glVertex3f(-1, 0.5, 0.25);
|
|
|
|
|
glVertex3f(1, 0.5, 0.25);
|
|
|
|
|
glVertex3f(1, 0.5, -0.25);
|
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
|
glNormal3f(0, 1, 0);
|
|
|
|
|
glVertex3f(-1, -0.5, 0.25);
|
|
|
|
|
glVertex3f(-1, -0.5, -0.25);
|
|
|
|
|
glVertex3f(1, -0.5, -0.25);
|
|
|
|
|
glVertex3f(1, -0.5, 0.25);
|
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
|
glNormal3f(-1, 0, 0);
|
|
|
|
|
glVertex3f(-1, 0.5, 0.25);
|
|
|
|
|
glVertex3f(-1, 0.5, -0.25);
|
|
|
|
|
glVertex3f(-1, 0, -0.25);
|
|
|
|
|
glVertex3f(-1, 0, 0.25);
|
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
|
glNormal3f(1, 0, 0);
|
|
|
|
|
glVertex3f(1, 0.5, -0.25);
|
|
|
|
|
glVertex3f(1, 0.5, 0.25);
|
|
|
|
|
glVertex3f(1, 0, 0.25);
|
|
|
|
|
glVertex3f(1, 0, -0.25);
|
|
|
|
|
glEnd();
|
2026-01-11 01:36:32 +09:00
|
|
|
}
|
|
|
|
|
|
2026-01-09 03:38:29 +09:00
|
|
|
void GBClientStep(GBClient client) {
|
2026-01-11 01:36:32 +09:00
|
|
|
GLfloat f[4];
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < 4; i++) f[i] = client->light0[i];
|
|
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
|
glLoadIdentity();
|
|
|
|
|
GBGLPerspective(client->gl, client->engine->width, client->engine->height);
|
|
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
glLoadIdentity();
|
|
|
|
|
GBGLSetCamera(client->gl);
|
|
|
|
|
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, f);
|
|
|
|
|
|
2026-01-11 18:27:41 +09:00
|
|
|
if(GBGLShadowBeforeMapping(client->gl)) {
|
|
|
|
|
scene();
|
|
|
|
|
GBGLShadowAfterMapping(client->gl);
|
|
|
|
|
}
|
2026-01-11 01:36:32 +09:00
|
|
|
scene();
|
|
|
|
|
GBGLShadowEnd(client->gl);
|
|
|
|
|
|
2026-01-10 19:51:48 +09:00
|
|
|
client->engine->param->gl_swapbuffer();
|
2026-01-11 01:36:32 +09:00
|
|
|
|
|
|
|
|
static double r = 0;
|
|
|
|
|
|
|
|
|
|
client->camera[0] = cos(r) * 2;
|
|
|
|
|
client->camera[2] = sin(r) * 2;
|
|
|
|
|
|
2026-01-11 18:27:41 +09:00
|
|
|
client->light0[0] = -cos(r) * 5;
|
|
|
|
|
client->light0[2] = -sin(r) * 5;
|
2026-01-11 01:36:32 +09:00
|
|
|
|
|
|
|
|
r += 0.1;
|
2026-01-09 03:38:29 +09:00
|
|
|
}
|