/* FredyGames: see glut-compat.h. */ #include "glut-compat.h" void glutIgnoreKeyRepeat(int ignore) { (void)ignore; } void glutEntryFunc(void (*func)(int state)) { (void)func; } void glutStrokeCharacter(void *font, int character) { (void)font; (void)character; } int glutStrokeWidth(void *font, int character) { (void)font; (void)character; return 0; } void glutGameModeString(const char *string) { (void)string; } int glutGameModeGet(unsigned int mode) { (void)mode; return 0; } int glutEnterGameMode(void) { return 0; } void glutLeaveGameMode(void) {} #include void glGetDoublev(GLenum pname, GLdouble *params) { GLfloat f[16]; int n = (pname == GL_MODELVIEW_MATRIX || pname == GL_PROJECTION_MATRIX) ? 16 : 4; glGetFloatv(pname, f); for (int i = 0; i < n; i++) params[i] = f[i]; } void fg_gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) { double f = 1.0 / tan(fovy * M_PI / 360.0); GLfloat m[16] = {0}; m[0] = (GLfloat)(f / aspect); m[5] = (GLfloat)f; m[10] = (GLfloat)((zFar + zNear) / (zNear - zFar)); m[11] = -1; m[14] = (GLfloat)(2.0 * zFar * zNear / (zNear - zFar)); glMultMatrixf(m); } void fg_gluLookAt(GLdouble ex, GLdouble ey, GLdouble ez, GLdouble cx, GLdouble cy, GLdouble cz, GLdouble ux, GLdouble uy, GLdouble uz) { double fx = cx - ex, fy = cy - ey, fz = cz - ez; double fl = sqrt(fx * fx + fy * fy + fz * fz); fx /= fl; fy /= fl; fz /= fl; double sx = fy * uz - fz * uy, sy = fz * ux - fx * uz, sz = fx * uy - fy * ux; double sl = sqrt(sx * sx + sy * sy + sz * sz); sx /= sl; sy /= sl; sz /= sl; double tx = sy * fz - sz * fy, ty = sz * fx - sx * fz, tz = sx * fy - sy * fx; GLfloat m[16] = {(GLfloat)sx, (GLfloat)tx, (GLfloat)-fx, 0, (GLfloat)sy, (GLfloat)ty, (GLfloat)-fy, 0, (GLfloat)sz, (GLfloat)tz, (GLfloat)-fz, 0, 0, 0, 0, 1}; glMultMatrixf(m); glTranslatef((GLfloat)-ex, (GLfloat)-ey, (GLfloat)-ez); } /* the real emulation entry points, behind the wrappers of glut-compat.h */ #undef glBegin #undef glEnd #undef glColor4f #undef glTexCoord2f #undef glVertex3f typedef struct { GLfloat x, y, z, r, g, b, a, s, t; } FgVertex; static FgVertex *fgVertices = NULL; static int fgCount = 0, fgCapacity = 0, fgTextured = 0; static GLenum fgMode = 0; static GLfloat fgR = 1, fgG = 1, fgB = 1, fgA = 1, fgS = 0, fgT = 0; void fg_Begin(GLenum mode) { fgMode = mode; fgCount = 0; fgTextured = 0; } void fg_Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a) { fgR = r; fgG = g; fgB = b; fgA = a; glColor4f(r, g, b, a); /* outside glBegin: the emulation's current color */ } void fg_TexCoord2f(GLfloat s, GLfloat t) { fgS = s; fgT = t; fgTextured = 1; } void fg_Vertex3f(GLfloat x, GLfloat y, GLfloat z) { if (fgCount == fgCapacity) { fgCapacity = fgCapacity ? fgCapacity * 2 : 256; fgVertices = (FgVertex *)realloc(fgVertices, fgCapacity * sizeof(FgVertex)); } FgVertex *v = &fgVertices[fgCount++]; v->x = x; v->y = y; v->z = z; v->r = fgR; v->g = fgG; v->b = fgB; v->a = fgA; v->s = fgS; v->t = fgT; } void fg_End(void) { glBegin(fgMode); for (int i = 0; i < fgCount; i++) { FgVertex *v = &fgVertices[i]; glColor4f(v->r, v->g, v->b, v->a); if (fgTextured) glTexCoord2f(v->s, v->t); glVertex3f(v->x, v->y, v->z); } glEnd(); }