2026-01-12 01:54:35 +09:00
|
|
|
#include <GearSrc/GL.h>
|
2026-01-10 19:51:48 +09:00
|
|
|
|
2026-01-12 01:54:35 +09:00
|
|
|
GSGL GSGLCreate(GSClient client) {
|
2026-01-11 01:36:32 +09:00
|
|
|
GLfloat lightamb[] = {0.5, 0.5, 0.5, 1.0};
|
2026-01-10 19:51:48 +09:00
|
|
|
GLfloat lightcol[] = {1.0, 1.0, 1.0, 1.0};
|
2026-01-12 01:54:35 +09:00
|
|
|
GSGL gl;
|
2026-01-10 19:51:48 +09:00
|
|
|
|
|
|
|
|
gl = malloc(sizeof(*client->gl));
|
|
|
|
|
|
|
|
|
|
gl->engine = client->engine;
|
|
|
|
|
|
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
|
glEnable(GL_NORMALIZE);
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
glEnable(GL_COLOR_MATERIAL);
|
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
|
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_AMBIENT, lightamb);
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightcol);
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_SPECULAR, lightcol);
|
|
|
|
|
|
|
|
|
|
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
|
|
|
|
|
|
|
|
|
|
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
|
|
|
|
|
|
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
|
|
|
|
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
2026-01-12 01:54:35 +09:00
|
|
|
GSGLShadowInit(gl);
|
2026-01-10 19:51:48 +09:00
|
|
|
|
|
|
|
|
return gl;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-12 01:54:35 +09:00
|
|
|
void GSGLDestroy(GSGL gl) {
|
|
|
|
|
GSGLShadowDeinit(gl);
|
2026-01-11 01:36:32 +09:00
|
|
|
|
|
|
|
|
free(gl);
|
2026-01-10 19:51:48 +09:00
|
|
|
}
|
2026-01-11 23:10:13 +09:00
|
|
|
|
2026-01-12 01:54:35 +09:00
|
|
|
void GSGLClear(GSGL gl) {
|
2026-01-11 23:10:13 +09:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-12 01:54:35 +09:00
|
|
|
void GSGLIgnoreDepth(GSGL gl) {
|
2026-01-11 23:10:13 +09:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-12 01:54:35 +09:00
|
|
|
void GSGLCareDepth(GSGL gl) {
|
2026-01-11 23:10:13 +09:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-12 01:54:35 +09:00
|
|
|
void GSGLSetLight(GSGL gl) {
|
2026-01-11 23:10:13 +09:00
|
|
|
GLfloat f[4];
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < 4; i++) f[i] = gl->engine->client->light0[i];
|
|
|
|
|
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, f);
|
|
|
|
|
}
|
2026-01-12 01:03:18 +09:00
|
|
|
|
2026-01-12 04:36:04 +09:00
|
|
|
void GSGLPolygon(GSGL gl, int pairs, GSVector3* vert, GSVector2* tex, GSVector3 norm) {
|
2026-01-12 01:03:18 +09:00
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
glBegin(GL_POLYGON);
|
2026-01-12 04:36:04 +09:00
|
|
|
glNormal3f(norm[0], norm[1], norm[2]);
|
2026-01-12 01:03:18 +09:00
|
|
|
for(i = 0; i < pairs; i++) {
|
|
|
|
|
if(tex != NULL) glTexCoord2f(tex[i][0], tex[i][1]);
|
|
|
|
|
glVertex3f(vert[i][0], vert[i][1], vert[i][2]);
|
|
|
|
|
}
|
|
|
|
|
glEnd();
|
|
|
|
|
}
|
2026-01-12 04:36:04 +09:00
|
|
|
|
|
|
|
|
void GSGLPolygon2D(GSGL gl, int pairs, GSVector2* vert, GSVector2* tex) {
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
glBegin(GL_POLYGON);
|
|
|
|
|
for(i = 0; i < pairs; i++) {
|
|
|
|
|
if(tex != NULL) glTexCoord2f(tex[i][0], tex[i][1]);
|
|
|
|
|
glVertex2f(vert[i][0], vert[i][1]);
|
|
|
|
|
}
|
|
|
|
|
glEnd();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GSGLBegin2D(GSGL gl) {
|
|
|
|
|
GSGLIgnoreDepth(gl);
|
|
|
|
|
GSGLShadowDisable(gl);
|
|
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
glLoadIdentity();
|
|
|
|
|
glOrtho(0, gl->engine->width, gl->engine->height, 0, -1, 1);
|
|
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
glLoadIdentity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GSGLEnd2D(GSGL gl) {
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
|
|
|
|
|
GSGLShadowEnable(gl);
|
|
|
|
|
GSGLCareDepth(gl);
|
|
|
|
|
}
|