assaultfish/engine/src/gl/gl.c

180 lines
3.3 KiB
C
Raw Normal View History

2026-01-12 01:54:35 +09:00
#include <GearSrc/GL.h>
2026-01-10 19:51:48 +09:00
2026-01-30 08:44:11 +09:00
#include <GearSrc/Math.h>
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-25 01:56:36 +09:00
void GSGLClearDepth(GSGL gl) {
glClear(GL_DEPTH_BUFFER_BIT);
}
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);
}
2026-01-13 04:28:36 +09:00
2026-01-19 13:53:52 +09:00
void GSGLSetPosition(GSGL gl, GSVector3 pos) {
2026-01-28 13:25:31 +09:00
glTranslatef(pos[0], pos[1], -pos[2]);
2026-01-19 13:53:52 +09:00
}
void GSGLSetRotation(GSGL gl, GSVector3 rot) {
2026-01-13 04:28:36 +09:00
glRotatef(rot[0], 1, 0, 0);
glRotatef(rot[1], 0, 1, 0);
glRotatef(rot[2], 0, 0, 1);
}
2026-01-30 08:44:11 +09:00
void GSGLSetRotation3x3(GSGL gl, GSMatrix3x3 rot) {
GSMatrix4x4 out, out2;
GLdouble mat[16];
int i;
GSMath3x3To4x4(out, rot);
GSMathRowToColumn4x4(out2, out);
for(i = 0; i < 16; i++) mat[i] = out2[i];
glMultMatrixd(mat);
}
2026-01-13 04:28:36 +09:00
void GSGLPushMatrix(GSGL gl) {
glPushMatrix();
}
void GSGLPopMatrix(GSGL gl) {
glPopMatrix();
}
GLuint GSGLBeginList(GSGL gl) {
GLuint list;
list = glGenLists(1);
glNewList(list, GL_COMPILE);
return list;
}
void GSGLEndList(GSGL gl) {
glEndList();
}
void GSGLCallList(GSGL gl, GLuint list) {
glCallList(list);
}
2026-01-20 14:34:13 +09:00
2026-01-23 15:38:08 +09:00
void GSGLSetColor(GSGL gl, GSVector4 color) {
2026-01-20 14:34:13 +09:00
glColor4f(color[0], color[1], color[2], color[3]);
}
2026-01-25 13:05:30 +09:00
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);
}