ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

api.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 /*
00024  * This file is based on, or a modified version of code from TinyGL (C) 1997-1998 Fabrice Bellard,
00025  * which is licensed under the zlib-license (see LICENSE).
00026  * It also has modifications by the ResidualVM-team, which are covered under the GPLv2 (or later).
00027  */
00028 
00029 #include "graphics/tinygl/zgl.h"
00030 
00031 // glVertex
00032 
00033 void tglVertex4f(float x, float y, float z, float w) {
00034     TinyGL::GLParam p[5];
00035 
00036     p[0].op = TinyGL::OP_Vertex;
00037     p[1].f = x;
00038     p[2].f = y;
00039     p[3].f = z;
00040     p[4].f = w;
00041 
00042     TinyGL::gl_add_op(p);
00043 }
00044 
00045 void tglVertex2f(float x, float y)  {
00046     tglVertex4f(x, y, 0, 1);
00047 }
00048 
00049 void tglVertex3f(float x, float y, float z)  {
00050     tglVertex4f(x, y, z, 1);
00051 }
00052 
00053 void tglVertex3fv(const float *v)  {
00054     tglVertex4f(v[0], v[1], v[2], 1);
00055 }
00056 
00057 // glNormal
00058 
00059 void tglNormal3f(float x, float y, float z) {
00060     TinyGL::GLParam p[4];
00061 
00062     p[0].op = TinyGL::OP_Normal;
00063     p[1].f = x;
00064     p[2].f = y;
00065     p[3].f = z;
00066 
00067     TinyGL::gl_add_op(p);
00068 }
00069 
00070 void tglNormal3fv(const float *v)  {
00071     tglNormal3f(v[0], v[1], v[2]);
00072 }
00073 
00074 // glColor
00075 
00076 void tglColor4f(float r, float g, float b, float a) {
00077     TinyGL::GLParam p[9];
00078 
00079     p[0].op = TinyGL::OP_Color;
00080     p[1].f = r;
00081     p[2].f = g;
00082     p[3].f = b;
00083     p[4].f = a;
00084     gl_add_op(p);
00085 }
00086 
00087 void tglColor4fv(const float *v) {
00088     tglColor4f(v[0], v[1], v[2], v[3]);
00089 }
00090 
00091 void tglColor3f(float x, float y, float z) {
00092     tglColor4f(x, y, z, 1);
00093 }
00094 
00095 void tglColor3fv(const float *v)  {
00096     tglColor4f(v[0], v[1], v[2], 1);
00097 }
00098 
00099 void tglColor3ub(unsigned char r, unsigned char g, unsigned char b) {
00100     tglColor4f(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f);
00101 }
00102 
00103 void tglColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
00104     tglColor4f(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
00105 }
00106 
00107 // TexCoord
00108 
00109 void tglTexCoord4f(float s, float t, float r, float q) {
00110     TinyGL::GLParam p[5];
00111 
00112     p[0].op = TinyGL::OP_TexCoord;
00113     p[1].f = s;
00114     p[2].f = t;
00115     p[3].f = r;
00116     p[4].f = q;
00117 
00118     TinyGL::gl_add_op(p);
00119 }
00120 
00121 void tglTexCoord2f(float s, float t) {
00122     tglTexCoord4f(s, t, 0, 1);
00123 }
00124 
00125 void tglTexCoord2fv(const float *v) {
00126     tglTexCoord4f(v[0], v[1], 0, 1);
00127 }
00128 
00129 void tglEdgeFlag(int flag) {
00130     TinyGL::GLParam p[2];
00131 
00132     p[0].op = TinyGL::OP_EdgeFlag;
00133     p[1].i = flag;
00134 
00135     gl_add_op(p);
00136 }
00137 
00138 // misc
00139 
00140 void tglShadeModel(int mode) {
00141     TinyGL::GLParam p[2];
00142 
00143     assert(mode == TGL_FLAT || mode == TGL_SMOOTH);
00144 
00145     p[0].op = TinyGL::OP_ShadeModel;
00146     p[1].i = mode;
00147 
00148     TinyGL::gl_add_op(p);
00149 }
00150 
00151 void tglCullFace(int mode) {
00152     TinyGL::GLParam p[2];
00153 
00154     assert(mode == TGL_BACK || mode == TGL_FRONT || mode == TGL_FRONT_AND_BACK);
00155 
00156     p[0].op = TinyGL::OP_CullFace;
00157     p[1].i = mode;
00158 
00159     TinyGL::gl_add_op(p);
00160 }
00161 
00162 void tglFrontFace(int mode) {
00163     TinyGL::GLParam p[2];
00164 
00165     assert(mode == TGL_CCW || mode == TGL_CW);
00166 
00167     mode = (mode != TGL_CCW);
00168 
00169     p[0].op = TinyGL::OP_FrontFace;
00170     p[1].i = mode;
00171 
00172     TinyGL::gl_add_op(p);
00173 }
00174 
00175 void tglColorMask(TGLboolean r, TGLboolean g, TGLboolean b, TGLboolean a) {
00176     TinyGL::GLParam p[2];
00177 
00178     p[0].op = TinyGL::OP_ColorMask;
00179     p[1].i = (r << 24) | (g << 16) | (b << 8) | (a << 0);
00180 
00181     TinyGL::gl_add_op(p);
00182 }
00183 
00184 void tglDepthMask(int enableWrite) {
00185     TinyGL::GLParam p[2];
00186     p[0].op = TinyGL::OP_DepthMask;
00187     p[1].i = enableWrite;
00188 
00189     TinyGL::gl_add_op(p);
00190 }
00191 
00192 void tglBlendFunc(TGLenum sfactor, TGLenum dfactor) {
00193     TinyGL::GLParam p[3];
00194 
00195     p[0].op = TinyGL::OP_BlendFunc;
00196     p[1].i = sfactor;
00197     p[2].i = dfactor;
00198 
00199     TinyGL::gl_add_op(p);
00200 }
00201 
00202 void tglAlphaFunc(TGLenum func, float ref) {
00203     TinyGL::GLParam p[3];
00204 
00205     p[0].op = TinyGL::OP_AlphaFunc;
00206     p[1].i = func;
00207     p[2].f = ref;
00208 
00209     TinyGL::gl_add_op(p);
00210 }
00211 
00212 void tglDepthFunc(TGLenum func) {
00213     TinyGL::GLParam p[2];
00214     p[0].op = TinyGL::OP_DepthFunc;
00215     p[1].i = func;
00216 
00217     TinyGL::gl_add_op(p);
00218 }
00219 
00220 void tglPolygonMode(int face, int mode) {
00221     TinyGL::GLParam p[3];
00222 
00223     assert(face == TGL_BACK || face == TGL_FRONT || face == TGL_FRONT_AND_BACK);
00224     assert(mode == TGL_POINT || mode == TGL_LINE || mode == TGL_FILL);
00225 
00226     p[0].op = TinyGL::OP_PolygonMode;
00227     p[1].i = face;
00228     p[2].i = mode;
00229 
00230     TinyGL::gl_add_op(p);
00231 }
00232 
00233 // glEnable, glDisable
00234 
00235 void tglEnable(int cap) {
00236     TinyGL::GLParam p[3];
00237 
00238     p[0].op = TinyGL::OP_EnableDisable;
00239     p[1].i = cap;
00240     p[2].i = 1;
00241 
00242     TinyGL::gl_add_op(p);
00243 }
00244 
00245 void tglDisable(int cap) {
00246     TinyGL::GLParam p[3];
00247 
00248     p[0].op = TinyGL::OP_EnableDisable;
00249     p[1].i = cap;
00250     p[2].i = 0;
00251 
00252     TinyGL::gl_add_op(p);
00253 }
00254 
00255 // glBegin, glEnd
00256 
00257 void tglBegin(int mode) {
00258     TinyGL::GLParam p[2];
00259 
00260     p[0].op = TinyGL::OP_Begin;
00261     p[1].i = mode;
00262 
00263     TinyGL::gl_add_op(p);
00264 }
00265 
00266 void tglEnd() {
00267     TinyGL::GLParam p[1];
00268 
00269     p[0].op = TinyGL::OP_End;
00270 
00271     TinyGL::gl_add_op(p);
00272 }
00273 
00274 // matrix
00275 
00276 void tglMatrixMode(int mode) {
00277     TinyGL::GLParam p[2];
00278 
00279     p[0].op = TinyGL::OP_MatrixMode;
00280     p[1].i = mode;
00281 
00282     TinyGL::gl_add_op(p);
00283 }
00284 
00285 void tglLoadMatrixf(const float *m) {
00286     TinyGL::GLParam p[17];
00287 
00288     p[0].op = TinyGL::OP_LoadMatrix;
00289     for (int i = 0; i < 16; i++)
00290         p[i + 1].f = m[i];
00291 
00292     TinyGL::gl_add_op(p);
00293 }
00294 
00295 void tglLoadIdentity() {
00296     TinyGL::GLParam p[1];
00297 
00298     p[0].op = TinyGL::OP_LoadIdentity;
00299 
00300     TinyGL::gl_add_op(p);
00301 }
00302 
00303 void tglMultMatrixf(const float *m) {
00304     TinyGL::GLParam p[17];
00305 
00306     p[0].op = TinyGL::OP_MultMatrix;
00307     for (int i = 0; i < 16; i++)
00308         p[i + 1].f = m[i];
00309 
00310     TinyGL::gl_add_op(p);
00311 }
00312 
00313 void tglPushMatrix() {
00314     TinyGL::GLParam p[1];
00315 
00316     p[0].op = TinyGL::OP_PushMatrix;
00317 
00318     TinyGL::gl_add_op(p);
00319 }
00320 
00321 void tglPopMatrix() {
00322     TinyGL::GLParam p[1];
00323 
00324     p[0].op = TinyGL::OP_PopMatrix;
00325 
00326     TinyGL::gl_add_op(p);
00327 }
00328 
00329 void tglRotatef(float angle, float x, float y, float z) {
00330     TinyGL::GLParam p[5];
00331 
00332     p[0].op = TinyGL::OP_Rotate;
00333     p[1].f = angle;
00334     p[2].f = x;
00335     p[3].f = y;
00336     p[4].f = z;
00337 
00338     TinyGL::gl_add_op(p);
00339 }
00340 
00341 void tglTranslatef(float x, float y, float z) {
00342     TinyGL::GLParam p[4];
00343 
00344     p[0].op = TinyGL::OP_Translate;
00345     p[1].f = x;
00346     p[2].f = y;
00347     p[3].f = z;
00348 
00349     TinyGL::gl_add_op(p);
00350 }
00351 
00352 void tglScalef(float x, float y, float z) {
00353     TinyGL::GLParam p[4];
00354 
00355     p[0].op = TinyGL::OP_Scale;
00356     p[1].f = x;
00357     p[2].f = y;
00358     p[3].f = z;
00359 
00360     gl_add_op(p);
00361 }
00362 
00363 void tglViewport(int x, int y, int width, int height) {
00364     TinyGL::GLParam p[5];
00365 
00366     p[0].op = TinyGL::OP_Viewport;
00367     p[1].i = x;
00368     p[2].i = y;
00369     p[3].i = width;
00370     p[4].i = height;
00371 
00372     gl_add_op(p);
00373 }
00374 
00375 void tglFrustum(double left, double right, double bottom, double top, double nearv, double farv) {
00376     TinyGL::GLParam p[7];
00377 
00378     p[0].op = TinyGL::OP_Frustum;
00379     p[1].f = (float)left;
00380     p[2].f = (float)right;
00381     p[3].f = (float)bottom;
00382     p[4].f = (float)top;
00383     p[5].f = (float)nearv;
00384     p[6].f = (float)farv;
00385 
00386     TinyGL::gl_add_op(p);
00387 }
00388 
00389 void tglOrtho(double left, double right, double bottom, double top, double zNear, double zFar) {
00390     TinyGL::GLParam p[7];
00391 
00392     p[0].op = TinyGL::OP_Ortho;
00393     p[1].f = (float)left;
00394     p[2].f = (float)right;
00395     p[3].f = (float)bottom;
00396     p[4].f = (float)top;
00397     p[5].f = (float)zNear;
00398     p[6].f = (float)zFar;
00399 
00400     TinyGL::gl_add_op(p);
00401 }
00402 
00403 // lightening
00404 
00405 void tglMaterialfv(int mode, int type, const float *v) {
00406     TinyGL::GLParam p[7];
00407     int n;
00408 
00409     assert(mode == TGL_FRONT  || mode == TGL_BACK || mode == TGL_FRONT_AND_BACK);
00410 
00411     p[0].op = TinyGL::OP_Material;
00412     p[1].i = mode;
00413     p[2].i = type;
00414     n = 4;
00415     if (type == TGL_SHININESS)
00416         n = 1;
00417     for (int i = 0; i < 4; i++)
00418         p[3 + i].f = v[i];
00419     for (int i = n; i < 4; i++)
00420         p[3 + i].f = 0;
00421 
00422     TinyGL::gl_add_op(p);
00423 }
00424 
00425 void tglMaterialf(int mode, int type, float v) {
00426     TinyGL::GLParam p[7];
00427 
00428     p[0].op = TinyGL::OP_Material;
00429     p[1].i = mode;
00430     p[2].i = type;
00431     p[3].f = v;
00432     for (int i = 0; i < 3; i++)
00433         p[4 + i].f = 0;
00434 
00435     TinyGL::gl_add_op(p);
00436 }
00437 
00438 void tglColorMaterial(int mode, int type) {
00439     TinyGL::GLParam p[3];
00440 
00441     p[0].op = TinyGL::OP_ColorMaterial;
00442     p[1].i = mode;
00443     p[2].i = type;
00444 
00445     TinyGL::gl_add_op(p);
00446 }
00447 
00448 void tglLightfv(int light, int type, const float *v) {
00449     TinyGL::GLParam p[7];
00450 
00451     p[0].op = TinyGL::OP_Light;
00452     p[1].i = light;
00453     p[2].i = type;
00454     // TODO: 3 composants
00455     for (int i = 0; i < 4; i++)
00456         p[3 + i].f = v[i];
00457 
00458     TinyGL::gl_add_op(p);
00459 }
00460 
00461 
00462 void tglLightf(int light, int type, float v) {
00463     TinyGL::GLParam p[7];
00464 
00465     p[0].op = TinyGL::OP_Light;
00466     p[1].i = light;
00467     p[2].i = type;
00468     p[3].f = v;
00469     for (int i = 0; i < 3; i++)
00470         p[4 + i].f = 0;
00471 
00472     TinyGL::gl_add_op(p);
00473 }
00474 
00475 void tglLightModeli(int pname, int param) {
00476     TinyGL::GLParam p[6];
00477 
00478     p[0].op = TinyGL::OP_LightModel;
00479     p[1].i = pname;
00480     p[2].f = (float)param;
00481     for (int i = 0; i < 3; i++)
00482         p[3 + i].f = 0;
00483 
00484     TinyGL::gl_add_op(p);
00485 }
00486 
00487 void tglLightModelfv(int pname, const float *param) {
00488     TinyGL::GLParam p[6];
00489 
00490     p[0].op = TinyGL::OP_LightModel;
00491     p[1].i = pname;
00492     for (int i = 0; i < 4; i++)
00493         p[2 + i].f = param[i];
00494 
00495     TinyGL::gl_add_op(p);
00496 }
00497 
00498 // clear
00499 
00500 void tglClear(int mask) {
00501     TinyGL::GLParam p[2];
00502 
00503     p[0].op = TinyGL::OP_Clear;
00504     p[1].i = mask;
00505 
00506     TinyGL::gl_add_op(p);
00507 }
00508 
00509 void tglClearColor(float r, float g, float b, float a) {
00510     TinyGL::GLParam p[5];
00511 
00512     p[0].op = TinyGL::OP_ClearColor;
00513     p[1].f = r;
00514     p[2].f = g;
00515     p[3].f = b;
00516     p[4].f = a;
00517 
00518     gl_add_op(p);
00519 }
00520 
00521 void tglClearDepth(double depth) {
00522     TinyGL::GLParam p[2];
00523 
00524     p[0].op = TinyGL::OP_ClearDepth;
00525     p[1].f = (float)depth;
00526 
00527     TinyGL::gl_add_op(p);
00528 }
00529 
00530 // textures
00531 
00532 void tglTexImage2D(int target, int level, int components, int width, int height, int border, int format, int type, void *pixels) {
00533     TinyGL::GLParam p[10];
00534 
00535     p[0].op = TinyGL::OP_TexImage2D;
00536     p[1].i = target;
00537     p[2].i = level;
00538     p[3].i = components;
00539     p[4].i = width;
00540     p[5].i = height;
00541     p[6].i = border;
00542     p[7].i = format;
00543     p[8].i = type;
00544     p[9].p = pixels;
00545 
00546     TinyGL::gl_add_op(p);
00547 }
00548 
00549 void tglBindTexture(int target, int texture) {
00550     TinyGL::GLParam p[3];
00551 
00552     p[0].op = TinyGL::OP_BindTexture;
00553     p[1].i = target;
00554     p[2].i = texture;
00555 
00556     TinyGL::gl_add_op(p);
00557 }
00558 
00559 void tglTexEnvi(int target, int pname, int param) {
00560     TinyGL::GLParam p[8];
00561 
00562     p[0].op = TinyGL::OP_TexEnv;
00563     p[1].i = target;
00564     p[2].i = pname;
00565     p[3].i = param;
00566     p[4].f = 0;
00567     p[5].f = 0;
00568     p[6].f = 0;
00569     p[7].f = 0;
00570 
00571     gl_add_op(p);
00572 }
00573 
00574 void tglTexParameteri(int target, int pname, int param) {
00575     TinyGL::GLParam p[8];
00576 
00577     p[0].op = TinyGL::OP_TexParameter;
00578     p[1].i = target;
00579     p[2].i = pname;
00580     p[3].i = param;
00581     p[4].f = 0;
00582     p[5].f = 0;
00583     p[6].f = 0;
00584     p[7].f = 0;
00585 
00586     TinyGL::gl_add_op(p);
00587 }
00588 
00589 void tglPixelStorei(int pname, int param) {
00590     TinyGL::GLParam p[3];
00591 
00592     p[0].op = TinyGL::OP_PixelStore;
00593     p[1].i = pname;
00594     p[2].i = param;
00595 
00596     TinyGL::gl_add_op(p);
00597 }
00598 
00599 // selection
00600 
00601 void tglInitNames() {
00602     TinyGL::GLParam p[1];
00603 
00604     p[0].op = TinyGL::OP_InitNames;
00605 
00606     TinyGL::gl_add_op(p);
00607 }
00608 
00609 void tglPushName(unsigned int name) {
00610     TinyGL::GLParam p[2];
00611 
00612     p[0].op = TinyGL::OP_PushName;
00613     p[1].i = name;
00614 
00615     TinyGL::gl_add_op(p);
00616 }
00617 
00618 void tglPopName() {
00619     TinyGL::GLParam p[1];
00620 
00621     p[0].op = TinyGL::OP_PopName;
00622 
00623     TinyGL::gl_add_op(p);
00624 }
00625 
00626 void tglLoadName(unsigned int name) {
00627     TinyGL::GLParam p[2];
00628 
00629     p[0].op = TinyGL::OP_LoadName;
00630     p[1].i = name;
00631 
00632     gl_add_op(p);
00633 }
00634 
00635 void tglPolygonOffset(TGLfloat factor, TGLfloat units) {
00636     TinyGL::GLParam p[3];
00637 
00638     p[0].op = TinyGL::OP_PolygonOffset;
00639     p[1].f = factor;
00640     p[2].f = units;
00641 
00642     TinyGL::gl_add_op(p);
00643 }
00644 
00645 // Special Functions
00646 
00647 void tglCallList(unsigned int list) {
00648     TinyGL::GLParam p[2];
00649 
00650     p[0].op = TinyGL::OP_CallList;
00651     p[1].i = list;
00652 
00653     TinyGL::gl_add_op(p);
00654 }
00655 
00656 void tglFlush() {
00657     // nothing to do
00658 }
00659 
00660 void tglHint(int target, int mode) {
00661     TinyGL::GLParam p[3];
00662 
00663     p[0].op = TinyGL::OP_Hint;
00664     p[1].i = target;
00665     p[2].i = mode;
00666 
00667     TinyGL::gl_add_op(p);
00668 }
00669 
00670 // Non standard functions
00671 
00672 void tglDebug(int mode) {
00673     TinyGL::GLContext *c = TinyGL::gl_get_context();
00674     c->print_flag = mode;
00675 }
00676 
00677 void tglSetShadowMaskBuf(unsigned char *buf) {
00678     TinyGL::GLContext *c = TinyGL::gl_get_context();
00679     c->fb->shadow_mask_buf = buf;
00680 }
00681 
00682 void tglSetShadowColor(unsigned char r, unsigned char g, unsigned char b) {
00683     TinyGL::GLContext *c = TinyGL::gl_get_context();
00684     c->fb->shadow_color_r = r << 8;
00685     c->fb->shadow_color_g = g << 8;
00686     c->fb->shadow_color_b = b << 8;
00687 }
00688 
00689 void tglEnableDirtyRects(bool enable) {
00690     TinyGL::GLContext *c = TinyGL::gl_get_context();
00691     c->_enableDirtyRectangles = enable;
00692 }


Generated on Sat Dec 7 2019 05:00:41 for ResidualVM by doxygen 1.7.1
curved edge   curved edge