LCOV - code coverage report
Current view: top level - src - LuaGL.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.2 % 1666 3
Test Date: 2026-04-03 02:26:39 Functions: 0.7 % 153 1

            Line data    Source code
       1              : /*************************************************
       2              : *  LuaGL - an OpenGL binding for Lua
       3              : *  2003-2004(c) Fabio Guerra, Cleyde Marlyse
       4              : *  www.luagl.sourceforge.net
       5              : *-------------------------------------------------
       6              : *  Description: This file implements the OpenGL
       7              : *               binding for Lua 5.0.
       8              : *-------------------------------------------------
       9              : *  Last Update: 14/07/2004
      10              : *  Version: v1.01
      11              : *-------------------------------------------------
      12              : *  See Copyright Notice in LuaGL.h
      13              : *************************************************/
      14              : 
      15              : #include <string.h>
      16              : #include <stdlib.h>
      17              : 
      18              : extern "C" {
      19              :     #include "luajit-2.1/lauxlib.h"
      20              :     #include "LuaGL.h"
      21              : }
      22              : 
      23              : #define luaL_getn(L, i)          ((int)lua_objlen(L, i))
      24              : 
      25              : /* set field of a lua table with a number */
      26            0 : static void set_field(lua_State *L, unsigned int index, lua_Number value)
      27              : {
      28            0 :    lua_pushnumber(L, index);
      29            0 :    lua_pushnumber(L, value);
      30              : 
      31            0 :    lua_settable(L, -3);
      32            0 : }
      33              : 
      34            0 : static GLenum get_enum(const char *str, int n)
      35              : {
      36            0 :    int i = 0;
      37              : 
      38            0 :    while(gl_str[i].str != 0)
      39              :    {
      40            0 :       if(strncmp(str, gl_str[i].str, n) == 0 && gl_str[i].str[n] == 0)
      41            0 :          return gl_str[i].value;
      42              : 
      43            0 :       i++;
      44              :    }
      45            0 :    return ENUM_ERROR;
      46            0 : }
      47            0 : static GLenum get_gl_enum(lua_State *L, int index)
      48              : {
      49              :    unsigned int i;
      50            0 :    const char *str = lua_tostring(L, index);
      51            0 :    GLenum temp = 0, ret = 0;
      52              : 
      53            0 :    for(i = 0; i < strlen(str); i++)
      54              :    {
      55            0 :       if(str[i] == ',')
      56              :       {
      57            0 :          temp = get_enum(str, i);
      58            0 :          if(temp != ENUM_ERROR)
      59            0 :             ret |= temp;
      60              : 
      61            0 :          str += i+1;
      62            0 :          i = 0;
      63            0 :       }
      64            0 :    }
      65            0 :    temp = get_enum(str, strlen(str));
      66              : 
      67            0 :    if(temp == ENUM_ERROR)
      68              :    {
      69            0 :       if(ret == 0)
      70            0 :          return ENUM_ERROR;
      71            0 :       return ret;
      72              :    }
      73              : 
      74            0 :    return ret | temp;
      75            0 : }
      76              : 
      77            0 : static const char *get_str_gl_enum(GLenum num)
      78              : {
      79            0 :    unsigned int i = 0;
      80              : 
      81            0 :    while(gl_str[i].str != 0)
      82              :    {
      83            0 :       if(num == gl_str[i].value)
      84            0 :          return gl_str[i].str;
      85              : 
      86            0 :       i++;
      87              :    }
      88            0 :    return NULL;
      89            0 : }
      90              : 
      91              : /* Gets an array from a lua table, store it in 'array' and returns the no. of elems of the array
      92              :    index refers to where the table is in stack. */
      93            0 : static int get_arrayb(lua_State *L, int index, GLboolean **array)
      94              : {
      95              :    int i;
      96            0 :    int n = luaL_getn(L, index);
      97              : 
      98            0 :    *array = (GLboolean *)malloc(n * sizeof(GLboolean));
      99            0 :    for(i = 0; i < n; i++)
     100              :    {
     101            0 :       lua_rawgeti(L, index, i + 1);
     102            0 :       (*array)[i] = (GLboolean)lua_toboolean(L, -1);
     103            0 :    }
     104              : 
     105            0 :    return n; /* return the number of valid elements found.*/
     106              : }
     107            0 : static int get_arrayd(lua_State *L, int index, GLdouble **array)
     108              : {
     109              :    int i;
     110            0 :    int n = luaL_getn(L, index);
     111              : 
     112            0 :    *array = (GLdouble *)malloc(n * sizeof(GLdouble));
     113              : 
     114            0 :    for(i = 0; i < n; i++)
     115              :    {
     116            0 :       lua_rawgeti(L, index, i + 1);
     117            0 :       (*array)[i] = (GLdouble)lua_tonumber(L, -1);
     118            0 :    }
     119              : 
     120            0 :    return n; /* return the number of valid elements found.*/
     121              : }
     122            0 : static int get_arrayf(lua_State *L, int index, GLfloat **array)
     123              : {
     124              :    int i;
     125            0 :    int n = luaL_getn(L, index);
     126              : 
     127            0 :    *array = (GLfloat *)malloc(n * sizeof(GLfloat));
     128              : 
     129            0 :    for(i = 0; i < n; i++)
     130              :    {
     131            0 :       lua_rawgeti(L, index, i + 1);
     132            0 :       (*array)[i] = (GLfloat)lua_tonumber(L, -1);
     133            0 :    }
     134              : 
     135            0 :    return n; /* return the number of valid elements found.*/
     136              : }
     137            0 : static int get_arrayui(lua_State *L, int index, GLuint **array)
     138              : {
     139              :    int i;
     140            0 :    int n = luaL_getn(L, index);
     141              : 
     142            0 :    *array = (GLuint *)malloc(n * sizeof(GLint));
     143              : 
     144            0 :    for(i = 0; i < n; i++)
     145              :    {
     146            0 :       lua_rawgeti(L, index, i + 1);
     147            0 :       (*array)[i] = (GLuint)lua_tonumber(L, -1);
     148            0 :    }
     149              : 
     150            0 :    return n; /* return the number of valid elements found.*/
     151              : }
     152            0 : static int get_arrayubyte(lua_State *L, int index, GLubyte **array)
     153              : {
     154              :    int i;
     155            0 :    int n = luaL_getn(L, index);
     156              : 
     157            0 :    *array = (GLubyte *)malloc(n * sizeof(GLubyte));
     158              : 
     159            0 :    for(i = 0; i < n; i++)
     160              :    {
     161            0 :       lua_rawgeti(L, index, i + 1);
     162            0 :       (*array)[i] = (GLubyte)lua_tonumber(L, -1);
     163            0 :    }
     164              : 
     165            0 :    return n; /* return the number of valid elements found.*/
     166              : }
     167            0 : static int get_array2ubyte(lua_State *L, int index, GLubyte **array, int *size)
     168              : {
     169              :    int i, j;
     170            0 :    int n = luaL_getn(L, index);
     171              : 
     172            0 :    lua_rawgeti(L, index, 1);
     173              : 
     174            0 :    if(!lua_istable(L, -1))
     175              :    {
     176            0 :       lua_remove(L, -1);
     177            0 :       return -1;
     178              :    }
     179              : 
     180            0 :    *size = luaL_getn(L, -1);
     181              : 
     182            0 :    *array = (GLubyte *)malloc(n * (*size) * sizeof(GLubyte));
     183              : 
     184            0 :    for(i = 0; i < n; i++)
     185              :    {
     186            0 :       lua_rawgeti(L, index, i+1);
     187              : 
     188            0 :       if(!lua_istable(L, -1))
     189            0 :          return -1;
     190              : 
     191            0 :       for(j = 0; j < *size; j++)
     192              :       {
     193            0 :          lua_rawgeti(L, -1, j + 1);
     194              : 
     195            0 :          (*array)[i*(*size) + j] = (GLubyte)lua_tonumber(L, -1);
     196              : 
     197            0 :          lua_remove(L, -1);
     198            0 :       }
     199            0 :    }
     200              : 
     201            0 :    return n; /* return the number of valid elements found.*/
     202            0 : }
     203              : 
     204            0 : static int get_array2d(lua_State *L, int index, GLdouble **array, int *size)
     205              : {
     206              :    int i, j;
     207            0 :    int n = luaL_getn(L, index);
     208              : 
     209            0 :    lua_rawgeti(L, index, 1);
     210              : 
     211            0 :    if(!lua_istable(L, -1))
     212              :    {
     213            0 :       lua_remove(L, -1);
     214            0 :       return -1;
     215              :    }
     216              : 
     217            0 :    *size = luaL_getn(L, -1);
     218              : 
     219            0 :    *array = (GLdouble *)malloc(n * (*size) * sizeof(GLdouble));
     220              : 
     221            0 :    for(i = 0; i < n; i++)
     222              :    {
     223            0 :       lua_rawgeti(L, index, i+1);
     224              : 
     225            0 :       if(!lua_istable(L, -1))
     226            0 :          return -1;
     227              : 
     228            0 :       for(j = 0; j < *size; j++)
     229              :       {
     230            0 :          lua_rawgeti(L, -1, j + 1);
     231              : 
     232            0 :          (*array)[i*(*size) + j] = (GLdouble)lua_tonumber(L, -1);
     233              : 
     234            0 :          lua_remove(L, -1);
     235            0 :       }
     236            0 :    }
     237              : 
     238            0 :    return n; /* return the number of valid elements found.*/
     239            0 : }
     240            0 : static int get_array2f(lua_State *L, int index, GLfloat **array, int *size)
     241              : {
     242              :    int i, j;
     243            0 :    int n = luaL_getn(L, index);
     244              : 
     245            0 :    lua_rawgeti(L, index, 1);
     246              : 
     247            0 :    if(!lua_istable(L, -1))
     248              :    {
     249            0 :       lua_remove(L, -1);
     250            0 :       return -1;
     251              :    }
     252              : 
     253            0 :    *size = luaL_getn(L, -1);
     254              : 
     255            0 :    *array = (GLfloat *)malloc(n * (*size) * sizeof(GLfloat));
     256              : 
     257            0 :    for(i = 0; i < n; i++)
     258              :    {
     259            0 :       lua_rawgeti(L, index, i+1);
     260              : 
     261            0 :       if(!lua_istable(L, -1))
     262            0 :          return -1;
     263              : 
     264            0 :       for(j = 0; j < *size; j++)
     265              :       {
     266            0 :          lua_rawgeti(L, -1, j + 1);
     267              : 
     268            0 :          (*array)[i*(*size) + j] = (GLfloat)lua_tonumber(L, -1);
     269              : 
     270            0 :          lua_remove(L, -1);
     271            0 :       }
     272            0 :    }
     273              : 
     274            0 :    return n; /* return the number of valid elements found.*/
     275            0 : }
     276              : 
     277            0 : static int str2mask(const char *str)
     278              : {
     279              :    int i, j;
     280            0 :    int mask = 0;
     281            0 :    int size = strlen(str);
     282            0 :    for(i = 0, j = 0; j < size; i++)
     283              :    {
     284            0 :       if(str[i] == '1')
     285              :       {
     286            0 :          mask |= (1 << (size-1-j));
     287            0 :          j++;
     288            0 :       }
     289            0 :       else if(str[i] == '0')
     290            0 :          j++;
     291              : 
     292            0 :    }
     293            0 :    return mask;
     294              : }
     295            0 : static const char *mask2str(int mask)
     296              : {
     297              :    unsigned int i;
     298              :    static char str[17];
     299            0 :    for(i = 0; i < 16; i++)
     300              :    {
     301            0 :       if(mask & (1 << (15 - i)))
     302            0 :          str[i] = '1';
     303              :       else
     304            0 :          str[i] = '0';
     305            0 :    }
     306            0 :    str[i] = 0;
     307            0 :    return str;
     308              : }
     309              : 
     310              : /*Accum (op, value) -> none*/
     311            0 : static int gl_accum(lua_State *L)
     312              : {
     313              :    /* get string parameters */
     314              :    GLenum e;
     315              : 
     316              :    /* test argument */
     317            0 :    if(!lua_isstring(L, 1))
     318            0 :       luaL_error(L, "incorrect argument to function 'gl.Accum'");
     319              : 
     320            0 :    e = get_gl_enum(L, 1);
     321              : 
     322              :    /* test arguments */
     323            0 :    if(e == ENUM_ERROR)
     324            0 :       luaL_error(L, "incorrect string argument to function 'gl.Accum'");
     325              : 
     326            0 :    if(!lua_isnumber(L, 2))
     327            0 :       luaL_error(L, "incorrect argument to function 'gl.Accum'");
     328              : 
     329              :    /* call opengl function */
     330            0 :    glAccum(e, (GLfloat)lua_tonumber(L, 2));
     331              : 
     332            0 :    return 0;
     333              : }
     334              : 
     335              : /*AlphaFunc (func, ref) -> none*/
     336            0 : static int gl_alpha_func(lua_State *L)
     337              : {
     338              :    /* get string parameters */
     339              :    GLenum e;
     340              : 
     341              :    /* test argument */
     342            0 :    if(!lua_isstring(L, 1))
     343            0 :       luaL_error(L, "incorrect argument to function 'gl.AlphaFunc'");
     344              : 
     345            0 :    e = get_gl_enum(L, 1);
     346              : 
     347              :    /* test arguments */
     348            0 :    if(e == ENUM_ERROR)
     349            0 :       luaL_error(L, "incorrect string argument to function 'gl.AlphaFunc'");
     350              : 
     351            0 :    if(!lua_isnumber(L, 2))
     352            0 :       luaL_error(L, "incorrect argument to function 'gl.AlphaFunc'");
     353              : 
     354              :    /* call opengl function */
     355            0 :    glAlphaFunc(e, (GLclampf)lua_tonumber(L, 2));
     356              : 
     357            0 :    return 0;
     358              : }
     359              : 
     360              : /*AreTexturesResident (texturesArray) -> residences*/
     361            0 : static int gl_are_textures_resident(lua_State *L)
     362              : {
     363              :    GLboolean *residences;
     364              :    GLuint *textures;
     365              : 
     366              :    int i, n;
     367              : 
     368              :    /* test argument */
     369            0 :    if(!lua_istable(L, 1))
     370            0 :       luaL_error(L, "incorrect argument to function 'gl.AreTexturesResident'");
     371              : 
     372              :    /* get textures array */
     373            0 :    n = get_arrayui(L, 1, &textures);
     374              : 
     375            0 :    residences = (GLboolean *)malloc(n * sizeof(GLboolean));
     376              : 
     377              :    /* call opengl function */
     378            0 :    glAreTexturesResident(n, (GLuint *)textures, residences);
     379              : 
     380            0 :    lua_newtable(L);
     381              : 
     382              :    /* return residences values */
     383            0 :    for(i = 0; i < n; i++)
     384            0 :       set_field(L, i+1, residences[i]);
     385              : 
     386            0 :    free(textures);
     387            0 :    free(residences);
     388              : 
     389            0 :    return 1;
     390              : }
     391              : 
     392              : /*ArrayElement (i) -> none*/
     393            0 : static int gl_array_element(lua_State *L)
     394              : {
     395              :    /* test argument */
     396            0 :    if(!lua_isnumber(L, 1))
     397            0 :       luaL_error(L, "incorrect argument to function 'gl.ArrayElement'");
     398              : 
     399              :    /* call opengl function */
     400            0 :    glArrayElement((GLint)lua_tonumber(L, 1));
     401              : 
     402            0 :    return 0;
     403              : }
     404              : 
     405              : /*Begin (mode) -> none*/
     406            0 : static int gl_begin(lua_State *L)
     407              : {
     408              :    GLenum e;
     409              : 
     410              :    /* test argument */
     411            0 :    if(!lua_isstring(L, 1))
     412            0 :       luaL_error(L, "incorrect argument to function 'gl.Begin'");
     413              : 
     414            0 :    e = get_gl_enum(L, 1);
     415              : 
     416              :    /* test argument */
     417            0 :    if(e == ENUM_ERROR)
     418            0 :       luaL_error(L, "incorrect string argument to function 'gl.Begin'");
     419              : 
     420              :    /* call opengl function */
     421            0 :    glBegin(e);
     422              : 
     423            0 :    return 0;
     424              : }
     425              : 
     426              : /*BindTexture (target, texture) -> none*/
     427            0 : static int gl_bind_texture(lua_State *L)
     428              : {
     429              :    GLenum e;
     430              : 
     431              :    /* test arguments */
     432            0 :    if(!( lua_isstring(L, 1) && lua_isnumber(L, 2) ))
     433            0 :       luaL_error(L, "incorrect argument to function 'gl.BindTexture'");
     434              : 
     435              :    /* get string value */
     436            0 :    e = get_gl_enum(L, 1);
     437              : 
     438              :    /* test arguments */
     439            0 :    if(e == ENUM_ERROR)
     440            0 :       luaL_error(L, "incorrect string argument to function 'gl.BindTexture'");
     441              : 
     442              :    /* call opengl function */
     443            0 :    glBindTexture(e, (GLuint)lua_tonumber(L, 2));
     444              : 
     445            0 :    return 0;
     446              : }
     447              : 
     448              : /*Bitmap (xorig, yorig, ymove, bitmap) -> none*/
     449            0 : static int gl_bitmap(lua_State *L)
     450              : {
     451              :    int width, height;
     452              : 
     453              :    GLubyte *bitmap;
     454              : 
     455              :    /* test arguments type */
     456            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) &&
     457            0 :          lua_isnumber(L, 3) && lua_isnumber(L, 4) && lua_istable(L,5) ))
     458            0 :       luaL_error(L, "incorrect argument to function 'gl.Bitmap'");
     459              : 
     460            0 :    if((height = get_array2ubyte(L, 4, &bitmap, &width)) == -1)
     461            0 :       luaL_error(L, "incorrect argument to function 'gl.Bitmap'");
     462              : 
     463            0 :    glBitmap(width, height, (GLfloat)lua_tonumber(L, 1), (GLfloat)lua_tonumber(L, 2),
     464            0 :             (GLfloat)lua_tonumber(L, 3), (GLfloat)lua_tonumber(L, 4), bitmap);
     465            0 :    return 0;
     466              : }
     467              : 
     468              : /*BlendFunc (sfactor, dfactor) -> none*/
     469            0 : static int gl_blend_func(lua_State *L)
     470              : {
     471              :    GLenum a, b;
     472              : 
     473              :    /* test arguments */
     474            0 :    if(!(lua_isstring(L, 1) && lua_isstring(L, 2)))
     475            0 :       luaL_error(L, "incorrect argument to function 'gl.BlendFunc'");
     476              : 
     477              :    /* get values */
     478            0 :    a = (GLenum)get_gl_enum(L, 1);
     479            0 :    b = (GLenum)get_gl_enum(L, 2);
     480              : 
     481              :    /* test arguments */
     482            0 :    if((a == ENUM_ERROR) || (b == ENUM_ERROR))
     483            0 :       luaL_error(L, "incorrect string argument to function 'gl.BlendFunc'");
     484              : 
     485              :    /* call opengl function */
     486            0 :    glBlendFunc(a, b);
     487              : 
     488            0 :    return 0;
     489              : }
     490              : 
     491              : /*CallList (list) -> none*/
     492            0 : static int gl_call_list(lua_State *L)
     493              : {
     494              :    /* test argument */
     495            0 :    if(!lua_isnumber(L, 1))
     496            0 :       luaL_error(L, "incorrect argument to function 'gl.CallList'");
     497              : 
     498              :    /* call opengl function */
     499            0 :    glCallList((GLuint)lua_tonumber(L, 1));
     500              : 
     501            0 :    return 0;
     502              : }
     503              : 
     504              : /*CallLists (listArray) -> none*/
     505            0 : static int gl_call_lists(lua_State *L)
     506              : {
     507              :    GLsizei n;
     508              :    GLfloat *lists;
     509              : 
     510              :    /* test argument */
     511            0 :    if(!lua_istable(L, 1))
     512            0 :       luaL_error(L, "incorrect argument to function 'gl.CallLists'");
     513              : 
     514              :    /* get array of lists */
     515            0 :    n = get_arrayf(L, 1, &lists);
     516              : 
     517              :    /* call opengl function */
     518            0 :    glCallLists(n, GL_FLOAT, lists);
     519              : 
     520            0 :    free(lists);
     521              : 
     522            0 :    return 0;
     523              : }
     524              : 
     525              : /*Clear (mask) -> none*/
     526            0 : static int gl_clear(lua_State *L)
     527              : {
     528              :    GLenum e;
     529              : 
     530              :    /* test argument type */
     531            0 :    if(!lua_isstring(L, 1))
     532            0 :       luaL_error(L, "incorrect argument to function 'gl.Clear'");
     533              : 
     534            0 :    e = get_gl_enum(L, 1);
     535              : 
     536              :    /* test argument */
     537            0 :    if(e == ENUM_ERROR)
     538            0 :       luaL_error(L, "incorrect string argument to function 'gl.Clear'");
     539              : 
     540              :    /* call opengl function */
     541            0 :    glClear(e);
     542              : 
     543            0 :    return 0;
     544              : }
     545              : 
     546              : /*ClearAccum (red, green, blue, alpha) -> none*/
     547            0 : static int gl_clear_accum(lua_State *L)
     548              : {
     549              :    /* test arguments type */
     550            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3) && lua_isnumber(L, 4) ))
     551            0 :       luaL_error(L, "incorrect argument to function 'gl.ClearAccum'");
     552              : 
     553              :    /* call opengl function */
     554            0 :    glClearAccum((GLfloat)lua_tonumber(L, 1), (GLfloat)lua_tonumber(L, 2),
     555            0 :                 (GLfloat)lua_tonumber(L, 3), (GLfloat)lua_tonumber(L, 4));
     556              : 
     557            0 :    return 0;
     558              : }
     559              : 
     560              : /*ClearColor (red, green, blue, alpha) -> none*/
     561            0 : static int gl_clear_color(lua_State *L)
     562              : {
     563              :    /* test arguments type */
     564            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3) && lua_isnumber(L, 4) ))
     565            0 :       luaL_error(L, "incorrect argument to function 'gl.ClearColor'");
     566              : 
     567              :    /* call opengl function */
     568            0 :    glClearColor((GLclampf)lua_tonumber(L, 1), (GLclampf)lua_tonumber(L, 2),
     569            0 :                 (GLclampf)lua_tonumber(L, 3), (GLclampf)lua_tonumber(L, 4));
     570              : 
     571            0 :    return 0;
     572              : }
     573              : 
     574              : /*ClearDepth (depth) -> none*/
     575            0 : static int gl_clear_depth(lua_State *L)
     576              : {
     577              :    /* test argument type */
     578            0 :    if(!lua_isnumber(L, 1))
     579            0 :       luaL_error(L, "incorrect argument to function 'gl.ClearDepth'");
     580              : 
     581              :    /* call opengl function */
     582            0 :    glClearDepth((GLclampd)lua_tonumber(L, 1));
     583              : 
     584            0 :    return 0;
     585              : }
     586              : 
     587              : /*ClearIndex (c) -> none*/
     588            0 : static int gl_clear_index(lua_State *L)
     589              : {
     590              :    /* test argument type */
     591            0 :    if(!lua_isnumber(L, 1))
     592            0 :       luaL_error(L, "incorrect argument to function 'gl.ClearIndex'");
     593              : 
     594              :    /* call opengl function */
     595            0 :    glClearIndex((GLfloat)lua_tonumber(L, 1));
     596              : 
     597            0 :    return 0;
     598              : }
     599              : 
     600              : /*ClearStencil (s) -> none*/
     601            0 : static int gl_clear_stencil(lua_State *L)
     602              : {
     603              :    /* test argument type */
     604            0 :    if(!lua_isnumber(L, 1))
     605            0 :       luaL_error(L, "incorrect argument to function 'gl.ClearStencil'");
     606              : 
     607              :    /* call opengl function */
     608            0 :    glClearStencil((GLint)lua_tonumber(L, 1));
     609              : 
     610            0 :    return 0;
     611              : }
     612              : 
     613              : /*ClipPlane (plane, equationArray) -> none*/
     614            0 : static int gl_clip_plane(lua_State *L)
     615              : {
     616              :    GLenum plane;
     617              :    GLdouble *equation;
     618              : 
     619              :    /* test arguments */
     620            0 :    if(!lua_isstring(L, 1))
     621            0 :       luaL_error(L, "incorrect argument to function 'gl.ClipPlane'");
     622              : 
     623            0 :    if(!lua_istable(L, 2))
     624            0 :       luaL_error(L, "incorrect argument to function 'gl.ClipPlane'");
     625              : 
     626              :    /* get values */
     627            0 :    plane = get_gl_enum(L, 1);
     628              : 
     629              :    /* test argument */
     630            0 :    if(plane == ENUM_ERROR)
     631            0 :       luaL_error(L, "incorrect string argument to function 'gl.ClipPlane'");
     632              : 
     633              :    /* get array of equations */
     634            0 :    get_arrayd(L, 2, &equation);
     635              : 
     636              :    /* call opengl function */
     637            0 :    glClipPlane(plane, equation);
     638              : 
     639            0 :    free(equation);
     640              : 
     641            0 :    return 0;
     642              : }
     643              : 
     644              : /*Color (red, green, blue [, alpha]) -> none
     645              :   Color (color) -> none*/
     646            0 : static int gl_color(lua_State *L)
     647              : {
     648            0 :    GLdouble *array = 0;
     649              : 
     650              :    int index;
     651            0 :    int num_args = lua_gettop(L);
     652              : 
     653              :    /* test arguments type */
     654            0 :    if(lua_istable(L, 1))
     655              :    {
     656            0 :       num_args = get_arrayd(L, 1, &array);
     657              : 
     658              :       /* if more then 4 arguments, ignore the others */
     659            0 :       if(num_args > 4)
     660            0 :          num_args = 4;
     661              : 
     662              :       /* call openGL functions */
     663            0 :       switch(num_args)
     664              :       {
     665            0 :          case 3:  glColor3dv(array); break;
     666            0 :          case 4:  glColor4dv(array); break;
     667              :       }
     668              : 
     669            0 :       if(array)
     670            0 :          free(array);
     671              : 
     672            0 :       return 0;
     673              :    }
     674              : 
     675              :    /* if more then 4 arguments, ignore the others */
     676            0 :    if(num_args > 4)
     677            0 :       num_args = 4;
     678              : 
     679            0 :    for(index = 0; index < num_args; index++)
     680              :    {
     681            0 :       if(!lua_isnumber(L, index + 1))
     682            0 :          luaL_error(L, "incorrect argument to function 'gl.Color'");
     683            0 :    }
     684              : 
     685              :    /* call openGL functions */
     686            0 :    switch(num_args)
     687              :    {
     688            0 :       case 3:  glColor3d((GLdouble)lua_tonumber(L, 1), (GLdouble)lua_tonumber(L, 2),
     689            0 :                          (GLdouble)lua_tonumber(L, 3));
     690            0 :                break;
     691            0 :       case 4:  glColor4d((GLdouble)lua_tonumber(L, 1), (GLdouble)lua_tonumber(L, 2),
     692            0 :                          (GLdouble)lua_tonumber(L, 3), (GLdouble)lua_tonumber(L, 4));
     693            0 :                break;
     694              :    }
     695            0 :    return 0;
     696            0 : }
     697              : 
     698              : /*ColorMask (red, green, blue, alpha) -> none*/
     699            0 : static int gl_color_mask(lua_State *L)
     700              : {
     701              :    /* test arguments type */
     702            0 :    if(!( lua_isboolean(L, 1) && lua_isboolean(L, 2) && lua_isboolean(L, 3) && lua_isboolean(L, 4) ))
     703            0 :       luaL_error(L, "incorrect argument to function 'gl.ColorMask'");
     704              : 
     705            0 :    glColorMask((GLboolean)lua_toboolean(L, 1), (GLboolean)lua_toboolean(L, 2),
     706            0 :                (GLboolean)lua_toboolean(L, 3), (GLboolean)lua_toboolean(L, 4));
     707              : 
     708            0 :    return 0;
     709              : }
     710              : 
     711              : /*ColorMaterial (face, mode) -> none*/
     712            0 : static int gl_color_material(lua_State *L)
     713              : {
     714              :    GLenum e1, e2;
     715              : 
     716              :    /* test arguments */
     717            0 :    if(!( lua_isstring(L, 1) && lua_isstring(L, 2) ))
     718            0 :       luaL_error(L, "incorrect argument to function 'gl.ColorMaterial'");
     719              : 
     720              :    /* get string parameters */
     721            0 :    e1 = get_gl_enum(L, 1);
     722            0 :    e2 = get_gl_enum(L, 2);
     723              : 
     724              :    /* test strings */
     725            0 :    if(e1 == ENUM_ERROR || e2 == ENUM_ERROR)
     726            0 :       luaL_error(L, "incorrect string argument to function 'gl.ColorMaterial'");
     727              : 
     728              :    /* call opengl function */
     729            0 :    glColorMaterial(e1, e2);
     730              : 
     731            0 :    return 0;
     732              : }
     733              : 
     734              : /*ColorPointer (colorArray) -> none*/
     735            0 : static int gl_color_pointer(lua_State *L)
     736              : {
     737              :    GLint size;
     738              :    static GLdouble *array = 0;
     739            0 :    if(array)
     740            0 :       free(array);
     741              : 
     742              :    /* test arguments type */
     743            0 :    if(!lua_istable(L, 1))
     744            0 :       luaL_error(L, "incorrect argument to function 'gl.ColorPointer'");
     745              : 
     746            0 :    if(lua_isnumber(L, 2))
     747              :    {
     748            0 :       size = (GLint)lua_tonumber(L, 2);
     749            0 :       get_arrayd(L, 1, &array);
     750            0 :    }
     751            0 :    else if(get_array2d(L, 1, &array, &size) == -1)
     752              :    {
     753            0 :       luaL_error(L, "incorrect argument to function 'gl.ColorPointer'");
     754            0 :       return 0;
     755              :    }
     756              : 
     757              :    /* call opengl function */
     758            0 :    glColorPointer(size, GL_DOUBLE, 0, array);
     759              : 
     760            0 :    return 0;
     761            0 : }
     762              : 
     763              : /*CopyPixels (x, y, width, height, type) -> none*/
     764            0 : static int gl_copy_pixels(lua_State *L)
     765              : {
     766              :    GLenum e;
     767              : 
     768              :    /* test arguments type */
     769            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) &&
     770            0 :          lua_isnumber(L, 3) && lua_isnumber(L, 4) && lua_isstring(L, 5) ))
     771            0 :       luaL_error(L, "incorrect argument to function 'gl.CopyPixels'");
     772              : 
     773              :    /* get string parameter */
     774            0 :    e = get_gl_enum(L, 5);
     775              : 
     776              :    /* test argument */
     777            0 :    if(e == ENUM_ERROR)
     778            0 :       luaL_error(L, "incorrect string argument to function 'gl.CopyPixels'");
     779              : 
     780              :    /* call opengl function */
     781            0 :    glCopyPixels((GLint)  lua_tonumber(L, 1), (GLint)  lua_tonumber(L, 2),
     782            0 :                 (GLsizei)lua_tonumber(L, 3), (GLsizei)lua_tonumber(L, 4), (GLenum)e);
     783              : 
     784            0 :    return 0;
     785              : }
     786              : 
     787              : /*CopyTexImage (level, internalFormat, border, x, y, width[, height]) -> none*/
     788            0 : static int gl_copy_tex_image(lua_State *L)
     789              : {
     790              :    GLenum internalFormat;
     791              : 
     792            0 :    int num_args = lua_gettop(L);
     793              : 
     794              :    /* test arguments type */
     795            0 :    if(!(lua_isnumber(L, 1) && lua_isstring(L, 2) && lua_isnumber(L, 3) &&
     796            0 :         lua_isnumber(L, 4) && lua_isnumber(L, 5) && lua_isnumber(L, 6) ))
     797            0 :       luaL_error(L, "incorrect argument to function 'gl.CopyTexImage'");
     798              : 
     799              :    /* get string parameter */
     800            0 :    internalFormat = get_gl_enum(L, 2);
     801              : 
     802              :    /* test argument */
     803            0 :    if(internalFormat == ENUM_ERROR)
     804            0 :       luaL_error(L, "incorrect string argument to function 'gl.CopyTexImage'");
     805              : 
     806              :    /* call opengl functions */
     807            0 :    if (num_args > 6 && lua_isnumber(L, 7))
     808              :    {
     809            0 :       glCopyTexImage2D(GL_TEXTURE_2D, (GLint)lua_tonumber(L, 1), internalFormat,
     810            0 :                        (GLint)lua_tonumber(L, 4), (GLint)lua_tonumber(L, 5),
     811            0 :                        (GLsizei)lua_tonumber(L, 6), (GLsizei)lua_tonumber(L, 7),
     812            0 :                        (GLint)lua_tonumber(L, 3));
     813            0 :    }
     814              :    else
     815              :    {
     816            0 :       glCopyTexImage1D(GL_TEXTURE_1D, (GLint)lua_tonumber(L, 1), internalFormat,
     817            0 :                        (GLint)lua_tonumber(L, 4), (GLint)lua_tonumber(L, 5),
     818            0 :                        (GLsizei)lua_tonumber(L, 6), (GLint)lua_tonumber(L, 3));
     819              :    }
     820            0 :    return 0;
     821              : }
     822              : 
     823              : /*CopyTexSubImage (level, x, y, xoffset, width[, yoffset, height]) -> none*/
     824            0 : static int gl_copy_tex_sub_image(lua_State *L)
     825              : {
     826              :    int index;
     827            0 :    int num_args = lua_gettop(L);
     828              : 
     829              :    /* test arguments type */
     830            0 :    for(index = 0; index < num_args; index++)
     831              :    {
     832            0 :       if(!lua_isnumber(L, index + 1))
     833            0 :          luaL_error(L, "incorrect argument to function 'gl.CopyTexSubImage'");
     834            0 :    }
     835              : 
     836              :    /* call opengl funcitions */
     837            0 :    if(num_args >= 7)
     838              :    {
     839            0 :       glCopyTexSubImage2D(GL_TEXTURE_2D,
     840            0 :                           (GLint)lua_tonumber(L, 1), (GLint)lua_tonumber(L, 4),
     841            0 :                           (GLint)lua_tonumber(L, 6), (GLint)lua_tonumber(L, 2),
     842            0 :                           (GLint)lua_tonumber(L, 3), (GLint)lua_tonumber(L, 5),
     843            0 :                           (GLint)lua_tonumber(L, 7));
     844            0 :    }
     845              :    else
     846              :    {
     847            0 :       glCopyTexSubImage1D(GL_TEXTURE_1D,
     848            0 :                           (GLint)lua_tonumber(L, 1), (GLint)lua_tonumber(L, 4),
     849            0 :                           (GLint)lua_tonumber(L, 2), (GLint)lua_tonumber(L, 3),
     850            0 :                           (GLint)lua_tonumber(L, 5));
     851              :    }
     852            0 :    return 0;
     853              : }
     854              : 
     855              : /*CullFace (mode) -> none*/
     856            0 : static int gl_cull_face(lua_State *L)
     857              : {
     858              :    GLenum e;
     859              : 
     860              :    /* test argument type */
     861            0 :    if(!lua_isstring(L, 1))
     862            0 :       luaL_error(L, "incorrect argument to function 'gl.CullFace'");
     863              : 
     864              :    /* get string parameter */
     865            0 :    e = get_gl_enum(L, 1);
     866              : 
     867              :    /* test argument */
     868            0 :    if(e == ENUM_ERROR)
     869            0 :       luaL_error(L, "incorrect string argument to function 'gl.CullFace'");
     870              : 
     871              :    /* call opengl function */
     872            0 :    glCullFace(e);
     873              : 
     874            0 :    return 0;
     875              : }
     876              : 
     877              : /*DeleteLists (list, range) -> none*/
     878            0 : static int gl_delete_lists(lua_State *L)
     879              : {
     880              :    /* test arguments type */
     881            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) ))
     882            0 :       luaL_error(L, "incorrect argument to function 'gl.DeleteLists'");
     883              : 
     884              :    /* call opengl function */
     885            0 :    glDeleteLists((GLuint)lua_tonumber(L, 1), (GLsizei)lua_tonumber(L, 2));
     886              : 
     887            0 :    return 0;
     888              : }
     889              : 
     890              : /*DeleteTextures (texturesArray) -> none*/
     891            0 : static int gl_delete_textures(lua_State *L)
     892              : {
     893              :    int n;
     894              :    GLuint *textures;
     895              : 
     896              :    /* test argument type */
     897            0 :    if(!lua_istable(L, 1))
     898            0 :       luaL_error(L, "incorrect argument to function 'gl.DeleteTextures'");
     899              : 
     900              :    /* get textures array */
     901            0 :    n = get_arrayui(L, 1, &textures);
     902              : 
     903              :    /* call opengl function */
     904            0 :    glDeleteTextures((GLsizei)n, (GLuint *)textures);
     905              : 
     906            0 :    free(textures);
     907              : 
     908            0 :    return 0;
     909              : }
     910              : 
     911              : /*DepthFunc (func) -> none*/
     912            0 : static int gl_depth_func(lua_State *L)
     913              : {
     914              :    GLenum e;
     915              : 
     916              :    /* test argument type */
     917            0 :    if(!lua_isstring(L, 1))
     918            0 :       luaL_error(L, "incorrect argument to function 'gl.DepthFunc'");
     919              : 
     920              :    /* get string parameter */
     921            0 :    e = get_gl_enum(L, 1);
     922              : 
     923              :    /* test argument */
     924            0 :    if(e == ENUM_ERROR)
     925            0 :       luaL_error(L, "incorrect string argument to function 'gl.DepthFunc'");
     926              : 
     927              :    /* call opengl function */
     928            0 :    glDepthFunc(e);
     929              : 
     930            0 :    return 0;
     931              : }
     932              : 
     933              : /*DepthMask (flag) -> none*/
     934            0 : static int gl_depth_mask(lua_State *L)
     935              : {
     936              :    /* test argument type */
     937            0 :    if(!lua_isboolean(L, 1))
     938            0 :       luaL_error(L, "incorrect argument to function 'gl.DepthMask'");
     939              : 
     940              :    /* call opengl function */
     941            0 :    glDepthMask((GLboolean)lua_toboolean(L, 1));
     942              : 
     943            0 :    return 0;
     944              : }
     945              : 
     946              : /*DepthRange (zNear, zFar) -> none*/
     947            0 : static int gl_depth_range(lua_State *L)
     948              : {
     949              :    /* test arguments type */
     950            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) ))
     951            0 :       luaL_error(L, "incorrect argument to function 'gl.DepthRange'");
     952              : 
     953              :    /* call opengl function */
     954            0 :    glDepthRange((GLclampd)lua_tonumber(L, 1), (GLclampd)lua_tonumber(L, 2));
     955              : 
     956            0 :    return 0;
     957              : }
     958              : 
     959              : /*Disable (cap) -> none*/
     960            0 : static int gl_disable(lua_State *L)
     961              : {
     962              :    GLenum e;
     963              : 
     964              :    /* test argument type */
     965            0 :    if(!lua_isstring(L, 1))
     966            0 :       luaL_error(L, "incorrect argument to function 'gl.Disable'");
     967              : 
     968              :    /* get string parameter */
     969            0 :    e = get_gl_enum(L, 1);
     970              : 
     971              :    /* test argument */
     972            0 :    if(e == ENUM_ERROR)
     973            0 :       luaL_error(L, "incorrect string argument to function 'gl.Disable'");
     974              : 
     975              :    /* call opengl function */
     976            0 :    glDisable(e);
     977              : 
     978            0 :    return 0;
     979              : }
     980              : 
     981              : /*DisableClientState (array) -> none*/
     982            0 : static int gl_disable_client_state(lua_State *L)
     983              : {
     984              :    GLenum e;
     985              : 
     986              :    /* test argument type */
     987            0 :    if(!lua_isstring(L, 1))
     988            0 :       luaL_error(L, "incorrect argument to function 'gl.DisableClientState'");
     989              : 
     990              :    /* get string parameter */
     991            0 :    e = get_gl_enum(L, 1);
     992              : 
     993              :    /* test argument */
     994            0 :    if(e == ENUM_ERROR)
     995            0 :       luaL_error(L, "incorrect string argument to function 'gl.DisableClientState'");
     996              : 
     997              :    /* call opengl function */
     998            0 :    glDisableClientState(e);
     999              : 
    1000            0 :    return 0;
    1001              : }
    1002              : 
    1003              : /*DrawArrays (mode, first, count) -> none*/
    1004            0 : static int gl_draw_arrays(lua_State *L)
    1005              : {
    1006              :    GLenum e;
    1007              : 
    1008              :    /* test arguments type */
    1009            0 :    if(!(lua_isstring(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3) ))
    1010            0 :       luaL_error(L, "incorrect argument to function 'gl.DrawArrays'");
    1011              : 
    1012              :    /* get string parameter */
    1013            0 :    e = get_gl_enum(L, 1);
    1014              : 
    1015              :    /* test argument */
    1016            0 :    if(e == ENUM_ERROR)
    1017            0 :       luaL_error(L, "incorrect string argument to function 'gl.DrawArrays'");
    1018              : 
    1019              :    /* call opengl function */
    1020            0 :    glDrawArrays(e, (GLint)lua_tonumber(L, 2), (GLsizei)lua_tonumber(L, 3));
    1021              : 
    1022            0 :    return 0;
    1023              : }
    1024              : 
    1025              : /*DrawBuffer (mode) -> none*/
    1026            0 : static int gl_draw_buffer(lua_State *L)
    1027              : {
    1028              :    GLenum e;
    1029              : 
    1030              :    /* test argument type */
    1031            0 :    if(!lua_isstring(L, 1))
    1032            0 :       luaL_error(L, "incorrect argument to function 'gl.DrawBuffer'");
    1033              : 
    1034              :    /* get string parameter */
    1035            0 :    e = get_gl_enum(L, 1);
    1036              : 
    1037              :    /* test argument */
    1038            0 :    if(e == ENUM_ERROR)
    1039            0 :       luaL_error(L, "incorrect string argument to function 'gl.DrawBuffer'");
    1040              : 
    1041              :    /* call opengl function */
    1042            0 :    glDrawBuffer(e);
    1043              : 
    1044            0 :    return 0;
    1045              : }
    1046              : 
    1047              : /*DrawElements (mode, indicesArray) -> none*/
    1048            0 : static int gl_draw_elements(lua_State *L)
    1049              : {
    1050              :    int n;
    1051              :    GLuint *indices;
    1052              :    GLenum e;
    1053              : 
    1054              :    /* test arguments type */
    1055            0 :    if(!( lua_isstring(L, 1) && lua_istable(L, 2) ))
    1056            0 :       luaL_error(L, "incorrect argument to function 'gl.DrawElements'");
    1057              : 
    1058              :    /* get parameters */
    1059            0 :    e = get_gl_enum(L, 1);
    1060            0 :    n = get_arrayui(L, 2, &indices);
    1061              : 
    1062              :    /* test argument */
    1063            0 :    if(e == ENUM_ERROR)
    1064            0 :       luaL_error(L, "incorrect string argument to function 'gl.DrawElements'");
    1065              : 
    1066              :    /* call opengl function */
    1067            0 :    glDrawElements(e, n, GL_UNSIGNED_INT, indices);
    1068              : 
    1069            0 :    free(indices);
    1070              : 
    1071            0 :    return 0;
    1072              : }
    1073              : 
    1074              : /*DrawPixels (width, height, format, pixels) -> none*/
    1075            0 : static int gl_draw_pixels(lua_State *L)
    1076              : {
    1077              :    GLenum e;
    1078              :    GLfloat *pixels;
    1079              : 
    1080              :    /* test arguments type */
    1081            0 :    if(!(lua_isnumber(L, 1) && lua_isnumber(L, 2) &&
    1082            0 :         lua_isstring(L, 3) && lua_istable (L, 4)) )
    1083            0 :       luaL_error(L, "incorrect argument to function 'gl.DrawPixels'");
    1084              : 
    1085              :    /* get parameters */
    1086            0 :    e = get_gl_enum(L, 3);
    1087            0 :    get_arrayf(L, 4, &pixels);
    1088              : 
    1089              :    /* test argument */
    1090            0 :    if(e == ENUM_ERROR)
    1091            0 :       luaL_error(L, "incorrect string argument to function 'gl.DrawPixels'");
    1092              : 
    1093              :    /* call opengl function */
    1094            0 :    glDrawPixels((GLsizei)lua_tonumber(L, 1), (GLsizei)lua_tonumber(L, 2), e, GL_FLOAT, pixels);
    1095              : 
    1096            0 :    free(pixels);
    1097              : 
    1098            0 :    return 0;
    1099              : }
    1100              : 
    1101              : /*EdgeFlag (flag) -> none*/
    1102            0 : static int gl_edge_flag(lua_State *L)
    1103              : {
    1104              :    GLboolean *flag;
    1105              : 
    1106            0 :    if(lua_istable(L, 1))/* test argument type */
    1107              :    {
    1108              :       /* get argument */
    1109            0 :       get_arrayb(L, 1, &flag);
    1110              : 
    1111              :       /* call opengl function */
    1112            0 :       glEdgeFlagv((GLboolean *)flag);
    1113              : 
    1114            0 :       free(flag);
    1115            0 :    }
    1116            0 :    else if(lua_isboolean(L, 1))/* test argument type */
    1117              :       /* call opengl function */
    1118            0 :       glEdgeFlag((GLboolean)lua_toboolean(L, 1));
    1119              : 
    1120              :    else
    1121            0 :       luaL_error(L, "incorrect argument to function 'gl.EdgeFlag'");
    1122              : 
    1123            0 :    return 0;
    1124              : }
    1125              : 
    1126              : /*EdgeFlagPointer (flagsArray) -> none*/
    1127            0 : static int gl_edge_flag_pointer(lua_State *L)
    1128              : {
    1129              :    static GLboolean *flags = 0;
    1130            0 :    if(flags)
    1131            0 :       free(flags);
    1132              : 
    1133              :    /* test arguments type */
    1134            0 :    if(!lua_istable(L, 1))
    1135            0 :       luaL_error(L, "incorrect argument to function 'gl.EdgeFlagPointer'");
    1136              : 
    1137              :    /* get argument */
    1138            0 :    get_arrayb(L, 1, &flags);
    1139              : 
    1140              :    /* call opengl function */
    1141            0 :    glEdgeFlagPointer(0, flags);
    1142              : 
    1143            0 :    return 0;
    1144              : }
    1145              : 
    1146              : /*Enable (cap) -> none*/
    1147            0 : static int gl_enable(lua_State *L)
    1148              : {
    1149              :    GLenum e;
    1150              : 
    1151              :    /* test argument type */
    1152            0 :    if(!lua_isstring(L, 1))
    1153            0 :       luaL_error(L, "incorrect argument to function 'gl.Enable'");
    1154              : 
    1155              :    /* get string parameter */
    1156            0 :    e = get_gl_enum(L, 1);
    1157              : 
    1158              :    /* test argument */
    1159            0 :    if(e == ENUM_ERROR)
    1160            0 :       luaL_error(L, "incorrect string argument to function 'gl.Enable'");
    1161              : 
    1162              :    /* call opengl function */
    1163            0 :    glEnable(e);
    1164            0 :    return 0;
    1165              : }
    1166              : 
    1167              : /*EnableClientState (array) -> none*/
    1168            0 : static int gl_enable_client_state(lua_State *L)
    1169              : {
    1170              :    GLenum e;
    1171              : 
    1172              :    /* test argument type */
    1173            0 :    if(!lua_isstring(L, 1))
    1174            0 :       luaL_error(L, "incorrect argument to function 'gl.EnableClientState'");
    1175              : 
    1176              :    /* get string parameter */
    1177            0 :    e = get_gl_enum(L, 1);
    1178              : 
    1179              :    /* test argument */
    1180            0 :    if(e == ENUM_ERROR)
    1181            0 :       luaL_error(L, "incorrect string argument to function 'gl.EnableClientState'");
    1182              : 
    1183              :    /* call opengl function */
    1184            0 :    glEnableClientState(e);
    1185              : 
    1186            0 :    return 0;
    1187              : }
    1188              : 
    1189              : /*End () -> none*/
    1190            0 : static int gl_end(lua_State *L)
    1191              : {
    1192            0 :    glEnd();
    1193            0 :    return 0;
    1194              : }
    1195              : 
    1196              : /*EndList () -> none*/
    1197            0 : static int gl_end_list(lua_State *L)
    1198              : {
    1199            0 :    glEndList();
    1200            0 :    return 0;
    1201              : }
    1202              : 
    1203              : /*EvalCoord (u[, v]) -> none
    1204              :   EvalCoord (coordArray) -> none*/
    1205            0 : static int gl_eval_coord(lua_State *L)
    1206              : {
    1207              :    GLdouble *array;
    1208              : 
    1209              :    int index;
    1210            0 :    int num_args = lua_gettop(L);
    1211              : 
    1212              :    /* test arguments type */
    1213            0 :    if(lua_istable(L, 1))
    1214              :    {
    1215              :       /* get_array and return no of elements */
    1216            0 :       if(get_arrayd(L, 1, &array) == 1)
    1217              :       {
    1218            0 :          glEvalCoord1dv(array);
    1219            0 :          return 0;
    1220              :       }
    1221              :       else
    1222            0 :          glEvalCoord2dv(array);
    1223              : 
    1224            0 :       free(array);
    1225              : 
    1226            0 :       return 0;
    1227              :    }
    1228              : 
    1229              :    /* if more then 2 arguments, ignore the others */
    1230            0 :    if(num_args > 2)
    1231            0 :       num_args = 2;
    1232              : 
    1233              :    /* test arguments */
    1234            0 :    for(index = 0; index < num_args; index++)
    1235            0 :       if(!lua_isnumber(L, index + 1))
    1236            0 :          luaL_error(L, "incorrect argument to function 'gl.EvalCoord'");
    1237              : 
    1238              :    /* call openGL functions */
    1239            0 :    switch(num_args)
    1240              :    {
    1241            0 :       case 1:  glEvalCoord1d((GLdouble)lua_tonumber(L, 1));
    1242            0 :                break;
    1243            0 :       case 2:  glEvalCoord2d((GLdouble)lua_tonumber(L, 1), (GLdouble)lua_tonumber(L, 2));
    1244            0 :                break;
    1245              :    }
    1246            0 :    return 0;
    1247            0 : }
    1248              : 
    1249              : /*EvalMesh (mode, i1, i2[,j1, j2]) -> none*/
    1250            0 : static int gl_eval_mesh(lua_State *L)
    1251              : {
    1252              :    GLenum e;
    1253              : 
    1254              :    int index;
    1255            0 :    int num_args = lua_gettop(L);
    1256              : 
    1257              :    /* test arguments type */
    1258            0 :    if(!( lua_isstring(L, 1) && num_args > 2))
    1259            0 :       luaL_error(L, "incorrect argument to function 'gl.EvalMesh'");
    1260              : 
    1261            0 :    for(index = 2; index < num_args; index++)
    1262            0 :       if(!lua_isnumber(L, index + 1))
    1263            0 :          luaL_error(L, "incorrect argument to function 'gl.EvalMesh'");
    1264              : 
    1265              :    /* get string parameter */
    1266            0 :    e = get_gl_enum(L, 1);
    1267              : 
    1268              :    /* test argument */
    1269            0 :    if(e == ENUM_ERROR)
    1270            0 :       luaL_error(L, "incorrect string argument to function 'gl.EvalMesh'");
    1271              : 
    1272              :    /* call opengl function */
    1273            0 :    if(num_args < 5)
    1274            0 :       glEvalMesh1(e, (GLint)lua_tonumber(L, 2), (GLint)lua_tonumber(L, 3));
    1275              :    else
    1276            0 :       glEvalMesh2(e, (GLint)lua_tonumber(L, 2), (GLint)lua_tonumber(L, 3),
    1277            0 :                      (GLint)lua_tonumber(L, 4), (GLint)lua_tonumber(L, 5));
    1278              : 
    1279            0 :    return 0;
    1280              : }
    1281              : 
    1282              : /*EvalPoint (i[, j]) -> none*/
    1283            0 : static int gl_eval_point(lua_State *L)
    1284              : {
    1285              :    int index;
    1286            0 :    int num_args = lua_gettop(L);
    1287              : 
    1288              :    /* if more then 2 arguments, ignore the others */
    1289            0 :    if(num_args > 2)
    1290            0 :       num_args = 2;
    1291              : 
    1292              :    /* test arguments */
    1293            0 :    for(index = 0; index < num_args; index++)
    1294            0 :       if(!lua_isnumber(L, index + 1))
    1295            0 :          luaL_error(L, "incorrect argument to function 'gl.EvalPoint'");
    1296              : 
    1297              :    /* call openGL functions */
    1298            0 :    if(num_args == 1)
    1299            0 :       glEvalPoint1((GLint)lua_tonumber(L, 1));
    1300              :    else
    1301            0 :       glEvalPoint2((GLint)lua_tonumber(L, 1), (GLint)lua_tonumber(L, 2));
    1302              : 
    1303            0 :    return 0;
    1304              : }
    1305              : 
    1306              : /*FeedbackBuffer (size, type) -> dataArray*/
    1307            0 : static int gl_feedback_buffer(lua_State *L)
    1308              : {
    1309              :    GLfloat *array;
    1310              :    GLenum e;
    1311              :    GLsizei size;
    1312              :    int i;
    1313              : 
    1314            0 :    if(!( lua_isnumber(L, 1) && lua_isstring(L, 2) ))
    1315            0 :       luaL_error(L, "incorrect argument to function 'gl.FeedbackBuffer'");
    1316              : 
    1317              :    /* get parameters */
    1318            0 :    size = (GLsizei)lua_tonumber(L, 1);
    1319            0 :    e = get_gl_enum(L, 2);
    1320              : 
    1321            0 :    array = (GLfloat *)malloc(size * sizeof(GLfloat));
    1322              : 
    1323              :    /* test argument */
    1324            0 :    if(e == ENUM_ERROR)
    1325            0 :       luaL_error(L, "incorrect string argument to function 'gl.FeedbackBuffer'");
    1326              : 
    1327              :    /* call opengl function */
    1328            0 :    glFeedbackBuffer (size, e, array);
    1329              : 
    1330            0 :    lua_newtable(L);
    1331              : 
    1332            0 :    for(i = 0; i < size; i++)
    1333            0 :       set_field(L, i+1, array[i]);
    1334              : 
    1335            0 :    free(array);
    1336              : 
    1337            0 :    return 0;
    1338              : }
    1339              : 
    1340              : /*Finish () -> none*/
    1341            0 : static int gl_finish(lua_State *L)
    1342              : {
    1343            0 :    glFinish();
    1344            0 :    return 0;
    1345              : }
    1346              : 
    1347              : /*Flush () -> none*/
    1348            0 : static int gl_flush(lua_State *L)
    1349              : {
    1350            0 :    glFlush();
    1351            0 :    return 0;
    1352              : }
    1353              : 
    1354              : /*Fog (pname, param) -> none
    1355              :   Fog (pname, paramsArray) -> none*/
    1356            0 : static int gl_fog(lua_State *L)
    1357              : {
    1358              :    GLenum e;
    1359              :    GLfloat *param;
    1360              : 
    1361              :    /* test first argument type */
    1362            0 :    if(!lua_isstring(L, 1))
    1363            0 :       luaL_error(L, "incorrect argument to function 'gl.Fog'");
    1364              : 
    1365              :    /* get string parameter */
    1366            0 :    e = get_gl_enum(L, 1);
    1367              : 
    1368              :    /* test argument */
    1369            0 :    if(e == ENUM_ERROR)
    1370            0 :       luaL_error(L, "incorrect string argument to function 'gl.Fog'");
    1371              : 
    1372            0 :    if(lua_istable(L, 2))
    1373              :    {
    1374            0 :       get_arrayf(L, 2, &param);
    1375              : 
    1376              :       /* call opengl function */
    1377            0 :       glFogfv(e, (GLfloat*)param);
    1378              : 
    1379            0 :       free(param);
    1380              : 
    1381            0 :       return 0;
    1382              :    }
    1383              :    /* test second argument */
    1384            0 :    else if(lua_isnumber(L, 2))
    1385              :    {
    1386              :       /* call opengl function */
    1387            0 :       glFogf(e, (GLfloat)lua_tonumber(L, 2));
    1388            0 :    }
    1389            0 :    else if(lua_isstring(L, 2))
    1390              :    {
    1391              :       /* call opengl function */
    1392            0 :       glFogi(e, get_gl_enum(L, 2));
    1393            0 :    }
    1394              :    else
    1395            0 :       luaL_error(L, "incorrect argument to function 'gl.Fog'");
    1396              : 
    1397            0 :    return 0;
    1398            0 : }
    1399              : 
    1400              : /*FrontFace (mode) -> none*/
    1401            0 : static int gl_front_face(lua_State *L)
    1402              : {
    1403              :    GLenum e;
    1404              : 
    1405              :    /* test argument type */
    1406            0 :    if(!lua_isstring(L, 1))
    1407            0 :       luaL_error(L, "incorrect argument to function 'gl.FrontFace'");
    1408              : 
    1409              :    /* get string parameter */
    1410            0 :    e = get_gl_enum(L, 1);
    1411              : 
    1412              :    /* test argument */
    1413            0 :    if(e == ENUM_ERROR)
    1414            0 :       luaL_error(L, "incorrect string argument to function 'gl.FrontFace'");
    1415              : 
    1416              :    /* call opengl function */
    1417            0 :    glFrontFace(e);
    1418              : 
    1419            0 :    return 0;
    1420              : }
    1421              : 
    1422              : /*Frustum (left, right, bottom, top, zNear, zFar) -> none*/
    1423            0 : static int gl_frustum(lua_State *L)
    1424              : {
    1425              :    int index;
    1426              : 
    1427              :    /* test arguments type */
    1428            0 :    for(index = 0; index < 6; index++)
    1429            0 :       if(!lua_isnumber(L, index + 1))
    1430            0 :          luaL_error(L, "incorrect argument to function 'gl.Frustum'");
    1431              : 
    1432              :    /* call opengl function */
    1433            0 :    glFrustum((GLdouble)lua_tonumber(L, 1), (GLdouble)lua_tonumber(L, 2),
    1434            0 :              (GLdouble)lua_tonumber(L, 3), (GLdouble)lua_tonumber(L, 4),
    1435            0 :              (GLdouble)lua_tonumber(L, 5), (GLdouble)lua_tonumber(L, 6));
    1436              : 
    1437            0 :    return 0;
    1438              : }
    1439              : 
    1440              : /*GenLists (range) -> num*/
    1441            0 : static int gl_gen_lists(lua_State *L)
    1442              : {
    1443              :    /* test argument type */
    1444            0 :    if(!lua_isnumber(L, 1))
    1445            0 :       luaL_error(L, "incorrect argument to function 'gl.GenLists'");
    1446              : 
    1447              :    /* call opengl function and push the return value on the stack */
    1448            0 :    lua_pushnumber(L, glGenLists((GLsizei)lua_tonumber(L, 1)) );
    1449              : 
    1450            0 :    return 1;
    1451              : }
    1452              : 
    1453              : /*GenTextures (n) -> texturesArray*/
    1454            0 : static int gl_gen_textures(lua_State *L)
    1455              : {
    1456              :    int i;
    1457              :    GLsizei n;
    1458              :    GLuint *textures;
    1459              : 
    1460              :    /* test argument type */
    1461            0 :    if(!lua_isnumber(L, 1))
    1462            0 :       luaL_error(L, "incorrect argument to function 'gl.GenTextures'");
    1463              : 
    1464            0 :    n = (GLsizei)lua_tonumber(L, 1);
    1465            0 :    textures = (GLuint *)malloc(n * sizeof(GLuint));
    1466              : 
    1467              :    /* call opengl function */
    1468            0 :    glGenTextures(n, (GLuint *)textures);
    1469              : 
    1470            0 :    lua_newtable(L);
    1471              : 
    1472            0 :    for(i = 0; i < n; i++)
    1473            0 :       set_field(L, i+1, textures[i]);
    1474              : 
    1475            0 :    free(textures);
    1476              : 
    1477            0 :    return 1;
    1478              : }
    1479              : 
    1480              : /*Get (pname) -> params*/
    1481            0 : static int gl_get(lua_State *L)
    1482              : {
    1483            0 :    int i, size=1;
    1484              :    GLenum e;
    1485              :    GLdouble *params;
    1486              :    int mask;
    1487              : 
    1488              :    /* test argument type */
    1489            0 :    if(!lua_isstring(L, 1))
    1490            0 :       luaL_error(L, "incorrect argument to function 'gl.Get'");
    1491              : 
    1492              :    /* get string parameter */
    1493            0 :    e = get_gl_enum(L, 1);
    1494              : 
    1495            0 :    switch(e)
    1496              :    {
    1497              :       case GL_STENCIL_VALUE_MASK:
    1498              :       case GL_LINE_STIPPLE_PATTERN:
    1499              :       case GL_STENCIL_WRITEMASK:
    1500              :       case GL_INDEX_WRITEMASK:
    1501              :          /* call opengl function */
    1502            0 :          mask = 0;
    1503            0 :          glGetIntegerv(e, &mask);
    1504            0 :          lua_pushstring(L, mask2str(mask));
    1505            0 :          return 1;
    1506              : 
    1507              :       case GL_DEPTH_RANGE:
    1508              :       case GL_MAP1_GRID_DOMAIN:
    1509              :       case GL_MAP2_GRID_SEGMENTS:
    1510              :       case GL_MAX_VIEWPORT_DIMS:
    1511              :       case GL_POINT_SIZE_RANGE:
    1512              :       case GL_POLYGON_MODE:
    1513            0 :          size = 2;
    1514            0 :          break;
    1515              : 
    1516              :       case GL_CURRENT_NORMAL:
    1517            0 :          size = 3;
    1518            0 :          break;
    1519              : 
    1520              :       case GL_ACCUM_CLEAR_VALUE:
    1521              :       case GL_COLOR_CLEAR_VALUE:
    1522              :       case GL_COLOR_WRITEMASK:
    1523              :       case GL_CURRENT_COLOR:
    1524              :       case GL_CURRENT_RASTER_COLOR:
    1525              :       case GL_CURRENT_RASTER_POSITION:
    1526              :       case GL_CURRENT_RASTER_TEXTURE_COORDS:
    1527              :       case GL_CURRENT_TEXTURE_COORDS:
    1528              :       case GL_FOG_COLOR:
    1529              :       case GL_LIGHT_MODEL_AMBIENT:
    1530              :       case GL_MAP2_GRID_DOMAIN:
    1531              :       case GL_SCISSOR_BOX:
    1532              :       case GL_TEXTURE_ENV_COLOR:
    1533              :       case GL_VIEWPORT:
    1534            0 :          size = 4;
    1535            0 :          break;
    1536              : 
    1537              :       case GL_MODELVIEW_MATRIX:
    1538              :       case GL_PROJECTION_MATRIX:
    1539              :       case GL_TEXTURE_MATRIX:
    1540            0 :          size = 16;
    1541            0 :          break;
    1542              : 
    1543              :       case ENUM_ERROR:
    1544            0 :          luaL_error(L, "incorrect string argument to function 'gl.Get'");
    1545            0 :          break;
    1546              :    }
    1547            0 :    params = (GLdouble *)malloc(size * sizeof(GLdouble));
    1548              : 
    1549              :    /* call opengl function */
    1550            0 :    glGetDoublev(e, params);
    1551              : 
    1552            0 :    for(i = 0; i < size; i++)
    1553            0 :       lua_pushnumber(L, params[i]);
    1554              : 
    1555            0 :    free(params);
    1556              : 
    1557            0 :    return size;
    1558            0 : }
    1559              : 
    1560              : /*GetConst (pname) -> constant string*/
    1561            0 : static int gl_get_const(lua_State *L)
    1562              : {
    1563            0 :    int i, size=1;
    1564              :    GLenum e;
    1565              :    GLenum *params;
    1566              :    const char *str;
    1567              : 
    1568              :    /* test argument type */
    1569            0 :    if(!lua_isstring(L, 1))
    1570            0 :       luaL_error(L, "incorrect argument to function 'gl.GetConst'");
    1571              : 
    1572              :    /* get string parameter */
    1573            0 :    e = get_gl_enum(L, 1);
    1574              : 
    1575            0 :    switch(e)
    1576              :    {
    1577              :       case GL_DEPTH_RANGE:
    1578              :       case GL_MAP1_GRID_DOMAIN:
    1579              :       case GL_MAP2_GRID_SEGMENTS:
    1580              :       case GL_MAX_VIEWPORT_DIMS:
    1581              :       case GL_POINT_SIZE_RANGE:
    1582              :       case GL_POLYGON_MODE:
    1583            0 :          size = 2;
    1584            0 :          break;
    1585              : 
    1586              :       case GL_CURRENT_NORMAL:
    1587            0 :          size = 3;
    1588            0 :          break;
    1589              : 
    1590              :       case GL_ACCUM_CLEAR_VALUE:
    1591              :       case GL_COLOR_CLEAR_VALUE:
    1592              :       case GL_COLOR_WRITEMASK:
    1593              :       case GL_CURRENT_COLOR:
    1594              :       case GL_CURRENT_RASTER_COLOR:
    1595              :       case GL_CURRENT_RASTER_POSITION:
    1596              :       case GL_CURRENT_RASTER_TEXTURE_COORDS:
    1597              :       case GL_CURRENT_TEXTURE_COORDS:
    1598              :       case GL_FOG_COLOR:
    1599              :       case GL_LIGHT_MODEL_AMBIENT:
    1600              :       case GL_MAP2_GRID_DOMAIN:
    1601              :       case GL_SCISSOR_BOX:
    1602              :       case GL_TEXTURE_ENV_COLOR:
    1603              :       case GL_VIEWPORT:
    1604            0 :          size = 4;
    1605            0 :          break;
    1606              : 
    1607              :       case GL_MODELVIEW_MATRIX:
    1608              :       case GL_PROJECTION_MATRIX:
    1609              :       case GL_TEXTURE_MATRIX:
    1610            0 :          size = 16;
    1611            0 :          break;
    1612              :    }
    1613              :    /* test argument */
    1614            0 :    if(e == ENUM_ERROR)
    1615            0 :       luaL_error(L, "incorrect string argument to function 'gl.GetConst'");
    1616              : 
    1617            0 :    params = (GLenum *)malloc(size * sizeof(GLenum));
    1618              : 
    1619              :    /* call opengl function */
    1620            0 :    glGetIntegerv(e, (GLint*)params);
    1621              : 
    1622            0 :    for(i = 0; i < size; i++)
    1623              :    {
    1624            0 :       str = get_str_gl_enum(params[i]);
    1625            0 :       lua_pushstring(L, str);
    1626            0 :    }
    1627              : 
    1628            0 :    free(params);
    1629              : 
    1630            0 :    return size;
    1631              : }
    1632              : 
    1633              : /*GetArray (pname) -> paramsArray*/
    1634            0 : static int gl_get_array(lua_State *L)
    1635              : {
    1636            0 :    int i, size = 1;
    1637              :    GLenum e;
    1638              :    GLdouble *params;
    1639              : 
    1640              :    /* test argument type */
    1641            0 :    if(!lua_isstring(L, 1))
    1642            0 :       luaL_error(L, "incorrect argument to function 'gl.GetArray'");
    1643              : 
    1644              :    /* get string parameter */
    1645            0 :    e = get_gl_enum(L, 1);
    1646              : 
    1647              :    /* test argument */
    1648            0 :    if(e == ENUM_ERROR)
    1649            0 :       luaL_error(L, "incorrect string argument to function 'gl.GetArray'");
    1650              : 
    1651            0 :    switch(e)
    1652              :    {
    1653              :       case GL_DEPTH_RANGE:
    1654              :       case GL_MAP1_GRID_DOMAIN:
    1655              :       case GL_MAP2_GRID_SEGMENTS:
    1656              :       case GL_MAX_VIEWPORT_DIMS:
    1657              :       case GL_POINT_SIZE_RANGE:
    1658              :       case GL_POLYGON_MODE:
    1659            0 :          size = 2;
    1660            0 :          break;
    1661              : 
    1662              :       case GL_CURRENT_NORMAL:
    1663            0 :          size = 3;
    1664            0 :          break;
    1665              : 
    1666              :       case GL_ACCUM_CLEAR_VALUE:
    1667              :       case GL_COLOR_CLEAR_VALUE:
    1668              :       case GL_COLOR_WRITEMASK:
    1669              :       case GL_CURRENT_COLOR:
    1670              :       case GL_CURRENT_RASTER_COLOR:
    1671              :       case GL_CURRENT_RASTER_POSITION:
    1672              :       case GL_CURRENT_RASTER_TEXTURE_COORDS:
    1673              :       case GL_CURRENT_TEXTURE_COORDS:
    1674              :       case GL_FOG_COLOR:
    1675              :       case GL_LIGHT_MODEL_AMBIENT:
    1676              :       case GL_MAP2_GRID_DOMAIN:
    1677              :       case GL_SCISSOR_BOX:
    1678              :       case GL_TEXTURE_ENV_COLOR:
    1679              :       case GL_VIEWPORT:
    1680            0 :          size = 4;
    1681            0 :          break;
    1682              : 
    1683              :       case GL_MODELVIEW_MATRIX:
    1684              :       case GL_PROJECTION_MATRIX:
    1685              :       case GL_TEXTURE_MATRIX:
    1686            0 :          size = 16;
    1687            0 :          break;
    1688              :    }
    1689              : 
    1690            0 :    params = (GLdouble *)malloc(size * sizeof(GLdouble));
    1691              : 
    1692              :    /* call opengl function */
    1693            0 :    glGetDoublev(e, params);
    1694              : 
    1695            0 :    lua_newtable(L);
    1696              : 
    1697            0 :    for(i = 0; i < size; i++)
    1698            0 :       set_field(L, i+1, params[i]);
    1699              : 
    1700            0 :    free(params);
    1701              : 
    1702            0 :    return 1;
    1703              : }
    1704              : 
    1705              : /*GetClipPlane (plane) -> equationArray*/
    1706            0 : static int gl_get_clip_plane(lua_State *L)
    1707              : {
    1708              :    int i;
    1709              :    GLenum e;
    1710              :    GLdouble *equation;
    1711              : 
    1712              :    /* test argument type */
    1713            0 :    if(!lua_isstring(L, 1))
    1714            0 :       luaL_error(L, "incorrect argument to function 'gl.GetClipPlane'");
    1715              : 
    1716              :    /* get string parameter */
    1717            0 :    e = get_gl_enum(L, 1);
    1718              : 
    1719              :    /* test argument */
    1720            0 :    if(e == ENUM_ERROR)
    1721            0 :       luaL_error(L, "incorrect string argument to function 'gl.GetClipPlane'");
    1722              : 
    1723            0 :    equation = (GLdouble *)malloc(4 * sizeof(GLdouble));
    1724              : 
    1725              :    /* call opengl function */
    1726            0 :    glGetClipPlane(e, equation);
    1727              : 
    1728            0 :    lua_newtable(L);
    1729              : 
    1730            0 :    for(i = 0; i < 4; i++)
    1731            0 :       set_field(L, i+1, equation[i]);
    1732              : 
    1733            0 :    free(equation);
    1734              : 
    1735            0 :    return 1;
    1736              : }
    1737              : 
    1738              : /*GetError () -> error flag*/
    1739            0 : static int gl_get_error(lua_State *L)
    1740              : {
    1741              :    /* call glGetError function,
    1742              :       convert returned number to string,
    1743              :       and push the string on the stack. */
    1744            0 :    GLenum error = glGetError();
    1745              : 
    1746            0 :    if(error == GL_NO_ERROR)
    1747            0 :       lua_pushstring(L, "NO_ERROR");
    1748              :    else
    1749            0 :       lua_pushstring(L, get_str_gl_enum(error));
    1750              : 
    1751            0 :    return 1;
    1752              : }
    1753              : 
    1754              : /*GetLight (light, pname) -> paramsArray*/
    1755            0 : static int gl_get_light(lua_State *L)
    1756              : {
    1757            0 :    int i, size = 1;
    1758              :    GLenum e1, e2;
    1759              :    GLfloat *params;
    1760              : 
    1761              :    /* test arguments type */
    1762            0 :    if(!( lua_isstring(L, 1) && lua_isstring(L, 2) ))
    1763            0 :       luaL_error(L, "incorrect argument to function 'gl.GetLight'");
    1764              : 
    1765              :    /* get string parameters */
    1766            0 :    e1 = get_gl_enum(L, 1);
    1767            0 :    e2 = get_gl_enum(L, 2);
    1768              : 
    1769              :    /* test argument */
    1770            0 :    if(e1 == ENUM_ERROR || e2 == ENUM_ERROR)
    1771            0 :       luaL_error(L, "incorrect string argument to function 'gl.GetLight'");
    1772              : 
    1773            0 :    switch(e2)
    1774              :    {
    1775              :       case GL_AMBIENT:
    1776              :       case GL_DIFFUSE:
    1777              :       case GL_SPECULAR:
    1778              :       case GL_POSITION:
    1779            0 :          size = 4;
    1780            0 :          break;
    1781              :       case GL_SPOT_DIRECTION :
    1782            0 :          size = 3;
    1783            0 :          break;
    1784              :       case GL_SPOT_EXPONENT:
    1785              :       case GL_SPOT_CUTOFF:
    1786              :       case GL_CONSTANT_ATTENUATION:
    1787              :       case GL_LINEAR_ATTENUATION:
    1788              :       case GL_QUADRATIC_ATTENUATION:
    1789            0 :          size = 1;
    1790            0 :          break;
    1791              :    }
    1792              : 
    1793            0 :    params = (GLfloat *)malloc(size * sizeof(GLfloat));
    1794              : 
    1795              :    /* call opengl function */
    1796            0 :    glGetLightfv(e1, e2, params);
    1797              : 
    1798            0 :    lua_newtable(L);
    1799              : 
    1800            0 :    for(i = 0; i < size; i++)
    1801            0 :       set_field(L, i+1, params[i]);
    1802              : 
    1803            0 :    free(params);
    1804              : 
    1805            0 :    return 1;
    1806              : }
    1807              : 
    1808              : /*GetMap (target, query) -> vArray*/
    1809            0 : static int gl_get_map(lua_State *L)
    1810              : {
    1811            0 :    int i, size = 1;
    1812              :    GLenum e1, e2;
    1813              :    GLdouble *params;
    1814              :    GLint *order;
    1815              : 
    1816            0 :    order = (GLint *)malloc(2 * sizeof(GLint));
    1817            0 :    order[0] = order[1] = 1;
    1818              : 
    1819              :    /* test arguments type */
    1820            0 :    if( !(lua_isstring(L, 1) && lua_isstring(L, 2)) )
    1821            0 :       luaL_error(L, "incorrect argument to function 'gl.GetMap'");
    1822              : 
    1823              :    /* get string parameters */
    1824            0 :    e1 = get_gl_enum(L, 1);
    1825            0 :    e2 = get_gl_enum(L, 2);
    1826              : 
    1827              :    /* test argument */
    1828            0 :    if(e1 == ENUM_ERROR || e2 == ENUM_ERROR)
    1829            0 :       luaL_error(L, "incorrect string argument to function 'gl.GetMap'");
    1830              : 
    1831            0 :    switch(e1)
    1832              :    {
    1833              :       case GL_MAP1_INDEX:
    1834              :       case GL_MAP2_INDEX:
    1835              :       case GL_MAP1_TEXTURE_COORD_1:
    1836              :       case GL_MAP2_TEXTURE_COORD_1:
    1837            0 :          size = 1;
    1838            0 :          break;
    1839              :       case GL_MAP1_TEXTURE_COORD_2:
    1840              :       case GL_MAP2_TEXTURE_COORD_2:
    1841            0 :          size = 2;
    1842            0 :          break;
    1843              :       case GL_MAP1_VERTEX_3:
    1844              :       case GL_MAP2_VERTEX_3:
    1845              :       case GL_MAP1_NORMAL:
    1846              :       case GL_MAP2_NORMAL:
    1847              :       case GL_MAP1_TEXTURE_COORD_3:
    1848              :       case GL_MAP2_TEXTURE_COORD_3:
    1849            0 :          size = 3;
    1850            0 :          break;
    1851              :       case GL_MAP1_VERTEX_4:
    1852              :       case GL_MAP2_VERTEX_4:
    1853              :       case GL_MAP1_COLOR_4:
    1854              :       case GL_MAP2_COLOR_4:
    1855              :       case GL_MAP1_TEXTURE_COORD_4:
    1856              :       case GL_MAP2_TEXTURE_COORD_4:
    1857            0 :          size = 4;
    1858            0 :          break;
    1859              :    }
    1860              : 
    1861            0 :    glGetMapiv(e1, GL_ORDER, order);
    1862              : 
    1863            0 :    size *= order[0] * order[1];
    1864              : 
    1865            0 :    params = (GLdouble *)malloc(size * sizeof(GLdouble));
    1866              : 
    1867              :    /* call opengl function */
    1868            0 :    glGetMapdv(e1, e2, params);
    1869              : 
    1870            0 :    lua_newtable(L);
    1871              : 
    1872            0 :    for(i = 0; i < size; i++)
    1873            0 :       set_field(L, i+1, params[i]);
    1874              : 
    1875            0 :    free(params);
    1876              : 
    1877            0 :    return 1;
    1878              : }
    1879              : 
    1880              : /*GetMaterial (face, pname) -> paramsArray*/
    1881            0 : static int gl_get_material(lua_State *L)
    1882              : {
    1883            0 :    int i, size = 1;
    1884              :    GLenum e1, e2;
    1885              :    GLfloat *params;
    1886              : 
    1887              :    /* test arguments type */
    1888            0 :    if( !(lua_isstring(L, 1) && lua_isstring(L, 2)) )
    1889            0 :       luaL_error(L, "incorrect argument to function 'gl.GetMaterial'");
    1890              : 
    1891              :    /* get string parameters */
    1892            0 :    e1 = get_gl_enum(L, 1);
    1893            0 :    e2 = get_gl_enum(L, 2);
    1894              : 
    1895            0 :    switch(e2)
    1896              :    {
    1897              :       case GL_AMBIENT:
    1898              :       case GL_DIFFUSE:
    1899              :       case GL_SPECULAR:
    1900              :       case GL_EMISSION:
    1901            0 :          size = 4;
    1902            0 :          break;
    1903              :       case GL_COLOR_INDEXES:
    1904            0 :          size = 3;
    1905            0 :          break;
    1906              :       case GL_SHININESS:
    1907            0 :          size = 1;
    1908            0 :          break;
    1909              :    }
    1910              : 
    1911              :    /* test argument */
    1912            0 :    if(e1 == ENUM_ERROR || e2 == ENUM_ERROR)
    1913            0 :       luaL_error(L, "incorrect string argument to function 'gl.GetMaterial'");
    1914              : 
    1915            0 :    params = (GLfloat *)malloc(size * sizeof(GLfloat));
    1916              : 
    1917              :    /* call opengl function */
    1918            0 :    glGetMaterialfv(e1, e2, params);
    1919              : 
    1920            0 :    lua_newtable(L);
    1921              : 
    1922            0 :    for(i = 0; i < size; i++)
    1923            0 :       set_field(L, i+1, params[i]);
    1924              : 
    1925            0 :    free(params);
    1926              : 
    1927            0 :    return 1;
    1928              : }
    1929              : 
    1930              : /*GetPixelMap (map) -> valuesArray*/
    1931            0 : static int gl_get_pixel_map(lua_State *L)
    1932              : {
    1933              :    int size;
    1934            0 :    int i, s = GL_PIXEL_MAP_R_TO_R_SIZE;
    1935              :    GLenum e;
    1936              :    GLfloat *values;
    1937              : 
    1938              :    /* test argument type */
    1939            0 :    if(!lua_isstring(L, 1))
    1940            0 :       luaL_error(L, "incorrect argument to function 'gl.GetPixelMap'");
    1941              : 
    1942              :    /* get string parameter */
    1943            0 :    e = get_gl_enum(L, 1);
    1944              : 
    1945              :    /* test argument */
    1946            0 :    if(e == ENUM_ERROR)
    1947            0 :       luaL_error(L, "incorrect string argument to function 'gl.GetPixelMap'");
    1948              : 
    1949            0 :    switch(e)
    1950              :    {
    1951            0 :       case GL_PIXEL_MAP_I_TO_I: s = GL_PIXEL_MAP_I_TO_I_SIZE; break;
    1952            0 :       case GL_PIXEL_MAP_S_TO_S: s = GL_PIXEL_MAP_S_TO_S_SIZE; break;
    1953            0 :       case GL_PIXEL_MAP_I_TO_R: s = GL_PIXEL_MAP_I_TO_R_SIZE; break;
    1954            0 :       case GL_PIXEL_MAP_I_TO_G: s = GL_PIXEL_MAP_I_TO_G_SIZE; break;
    1955            0 :       case GL_PIXEL_MAP_I_TO_B: s = GL_PIXEL_MAP_I_TO_B_SIZE; break;
    1956            0 :       case GL_PIXEL_MAP_I_TO_A: s = GL_PIXEL_MAP_I_TO_A_SIZE; break;
    1957            0 :       case GL_PIXEL_MAP_R_TO_R: s = GL_PIXEL_MAP_R_TO_R_SIZE; break;
    1958            0 :       case GL_PIXEL_MAP_G_TO_G: s = GL_PIXEL_MAP_G_TO_G_SIZE; break;
    1959            0 :       case GL_PIXEL_MAP_B_TO_B: s = GL_PIXEL_MAP_B_TO_B_SIZE; break;
    1960            0 :       case GL_PIXEL_MAP_A_TO_A: s = GL_PIXEL_MAP_A_TO_A_SIZE; break;
    1961              :    }
    1962            0 :    glGetIntegerv(s, &size);
    1963              : 
    1964            0 :    values = (GLfloat *)malloc(size * sizeof(GLfloat));
    1965              : 
    1966              :    /* call opengl function */
    1967            0 :    glGetPixelMapfv(e, values);
    1968              : 
    1969            0 :    lua_newtable(L);
    1970              : 
    1971            0 :    for(i = 0; i < size; i++)
    1972            0 :       set_field(L, i+1, values[i]);
    1973              : 
    1974            0 :    free(values);
    1975              : 
    1976            0 :    return 1;
    1977              : }
    1978              : 
    1979              : /*GetPointer (pname, n) -> valuesArray*/
    1980            0 : static int gl_get_pointer(lua_State *L)
    1981              : {
    1982              :    int i, n;
    1983              :    GLenum e;
    1984              :    GLboolean *flags;
    1985              :    GLdouble *params;
    1986              : 
    1987              :    /* test argument type */
    1988            0 :    if(!( lua_isstring(L, 1) && lua_isnumber(L, 2) ))
    1989            0 :       luaL_error(L, "incorrect argument to function 'gl.GetPointer'");
    1990              : 
    1991            0 :    e = get_gl_enum(L, 1);
    1992            0 :    n = (int)lua_tonumber(L, 2);
    1993              : 
    1994              :    /* test argument */
    1995            0 :    if(e == ENUM_ERROR)
    1996            0 :       luaL_error(L, "incorrect string argument to function 'gl.GetPointer'");
    1997              : 
    1998            0 :    if(e == GL_EDGE_FLAG_ARRAY_POINTER)
    1999              :    {
    2000            0 :       flags = (GLboolean *)malloc(n * sizeof(GLboolean));
    2001              : 
    2002              :       /* call opengl function */
    2003            0 :       glGetPointerv(e, (GLvoid **)&flags);
    2004              : 
    2005            0 :       if(flags == 0)
    2006            0 :          return 0;
    2007              : 
    2008            0 :       lua_newtable(L);
    2009              : 
    2010            0 :       for(i = 0; i < n ; i++)
    2011            0 :          set_field(L, i+1, flags[i]);
    2012            0 :    }
    2013              :    else
    2014              :    {
    2015            0 :       params = (GLdouble *)malloc(n * sizeof(GLdouble));
    2016              : 
    2017              :       /* call opengl function */
    2018            0 :       glGetPointerv(e, (GLvoid **)&params);
    2019              : 
    2020            0 :       if(params == 0)
    2021            0 :          return 0;
    2022              : 
    2023            0 :       lua_newtable(L);
    2024              : 
    2025            0 :       for(i = 0; i < n ; i++)
    2026            0 :          set_field(L, i+1, params[i]);
    2027              :    }
    2028              : 
    2029            0 :    return 1;
    2030            0 : }
    2031              : 
    2032              : /*GetPolygonStipple () -> maskArray*/
    2033            0 : static int gl_get_polygon_stipple(lua_State *L)
    2034              : {
    2035              :    int index;
    2036            0 :    GLubyte *mask = (GLubyte*)malloc(32*32 * sizeof(GLubyte));
    2037              : 
    2038            0 :    glGetPolygonStipple(mask);
    2039              : 
    2040            0 :    lua_newtable(L);
    2041              : 
    2042            0 :    for(index = 0; index < 1024; index++)
    2043            0 :       set_field(L, index+1, mask[index]);
    2044              : 
    2045            0 :    return 1;
    2046              : }
    2047              : 
    2048              : /*GetString (name) -> string*/
    2049            0 : static int gl_get_string(lua_State *L)
    2050              : {
    2051              :    GLenum e;
    2052              :    const GLubyte *str;
    2053              : 
    2054              :    /* test argument type */
    2055            0 :    if(!lua_isstring(L, 1))
    2056            0 :       luaL_error(L, "incorrect argument to function 'gl.GetString'");
    2057              : 
    2058              :    /* get string parameter */
    2059            0 :    e = get_gl_enum(L, 1);
    2060              : 
    2061              :    /* test argument */
    2062            0 :    if(e == ENUM_ERROR)
    2063            0 :       luaL_error(L, "incorrect string argument to function 'gl.GetString'");
    2064              : 
    2065              :    /* call opengl function */
    2066            0 :    str = glGetString(e);
    2067              : 
    2068            0 :    lua_pushstring(L, (const char*)str);
    2069              : 
    2070            0 :    return 1;
    2071              : }
    2072              : 
    2073              : /*GetTexEnv (pname) -> paramsArray*/
    2074            0 : static int gl_get_tex_env(lua_State *L)
    2075              : {
    2076              :    int i;
    2077              :    GLenum e1;
    2078              :    GLfloat *params;
    2079              :    int e2;
    2080              : 
    2081              :    /* test arguments type */
    2082            0 :    if(!lua_isstring(L, 1))
    2083            0 :       luaL_error(L, "incorrect argument to function 'gl.GetTexEnv'");
    2084              : 
    2085              :    /* get string parameters */
    2086            0 :    e1 = get_gl_enum(L, 1);
    2087              : 
    2088              :    /* test argument */
    2089            0 :    if(e1 == ENUM_ERROR)
    2090            0 :       luaL_error(L, "incorrect string argument to function 'gl.GetTexEnv'");
    2091              : 
    2092            0 :    if(e1 == GL_TEXTURE_ENV_MODE)
    2093              :    {
    2094            0 :       glGetTexEnviv(GL_TEXTURE_ENV, e1, &e2);
    2095              : 
    2096            0 :       lua_pushstring(L, get_str_gl_enum(e2));
    2097            0 :    }
    2098            0 :    else if(e1 == GL_TEXTURE_ENV_COLOR)
    2099              :    {
    2100            0 :       params = (GLfloat *)malloc(4 * sizeof(GLfloat));
    2101              : 
    2102              :       /* call opengl function */
    2103            0 :       glGetTexEnvfv(GL_TEXTURE_ENV, e1, params);
    2104              : 
    2105            0 :       lua_newtable(L);
    2106              : 
    2107            0 :       for(i = 0; i < 4; i++)
    2108            0 :          set_field(L, i+1, params[i]);
    2109              : 
    2110            0 :       free(params);
    2111            0 :    }
    2112              :    else
    2113              :    {
    2114            0 :       luaL_error(L, "incorrect string argument to function 'gl.GetTexEnv'");
    2115              :    }
    2116            0 :    return 1;
    2117              : }
    2118              : 
    2119              : /*GetTexGen (coord, pname) -> paramsArray*/
    2120            0 : static int gl_get_tex_gen(lua_State *L)
    2121              : {
    2122              :    int i;
    2123              :    GLenum e1, e2;
    2124              :    GLdouble *params;
    2125              :    int e3;
    2126              : 
    2127              :    /* test arguments type */
    2128            0 :    if( !(lua_isstring(L, 1) && lua_isstring(L, 2)) )
    2129            0 :       luaL_error(L, "incorrect argument to function 'gl.GetTexGen'");
    2130              : 
    2131              :    /* get string parameters */
    2132            0 :    e1 = get_gl_enum(L, 1);
    2133            0 :    e2 = get_gl_enum(L, 2);
    2134              : 
    2135              :    /* test argument */
    2136            0 :    if(e1 == ENUM_ERROR || e2 == ENUM_ERROR)
    2137            0 :       luaL_error(L, "incorrect string argument to function 'gl.GetTexGen'");
    2138            0 :    if(e2 == GL_TEXTURE_GEN_MODE)
    2139              :    {
    2140              :       /* call opengl function */
    2141            0 :       glGetTexGeniv(e1, e2, &e3);
    2142              : 
    2143            0 :       lua_pushstring(L, get_str_gl_enum(e3));
    2144            0 :    }
    2145              :    else
    2146              :    {
    2147            0 :       params = (GLdouble *)malloc(4 * sizeof(GLdouble));
    2148              : 
    2149              :       /* call opengl function */
    2150            0 :       glGetTexGendv(e1, e2, params);
    2151              : 
    2152            0 :       lua_newtable(L);
    2153              : 
    2154            0 :       for(i = 0; i < 4; i++)
    2155            0 :          set_field(L, i+1, params[i]);
    2156              : 
    2157            0 :       free(params);
    2158              :    }
    2159            0 :    return 1;
    2160              : }
    2161              : 
    2162              : /*GetTexImage (target, level, format) -> pixelsArray*/
    2163            0 : static int gl_get_tex_image(lua_State *L)
    2164              : {
    2165            0 :    int i, n=1;
    2166              :    int width, height, level;
    2167              :    GLenum target, format;
    2168              :    GLfloat *pixels;
    2169              : 
    2170              :    /* test arguments type */
    2171            0 :    if( !(lua_isstring(L, 1) && lua_isnumber(L, 2) && lua_isstring(L, 3)) )
    2172            0 :       luaL_error(L, "incorrect argument to function 'gl.GetTexImage'");
    2173              : 
    2174              :    /* get string parameters */
    2175            0 :    target = get_gl_enum(L, 1);
    2176            0 :    level = (int)lua_tonumber(L, 2);
    2177            0 :    format = get_gl_enum(L, 3);
    2178              : 
    2179              :    /* get width and height of image */
    2180            0 :    glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &width);
    2181            0 :    glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &height);
    2182              : 
    2183            0 :    switch(format)
    2184              :    {
    2185              :       case GL_RED:  case GL_GREEN:  case GL_BLUE:
    2186            0 :       case GL_ALPHA: case GL_LUMINANCE: n = 1; break;
    2187            0 :       case GL_LUMINANCE_ALPHA:          n = 2; break;
    2188              :       case GL_RGB:
    2189              :       //case GL_BGR_EXT:
    2190            0 :       n = 3; break;
    2191              :       case GL_RGBA:
    2192              :       //case GL_BGRA_EXT:
    2193            0 :       n = 4; break;
    2194              :       default:
    2195            0 :          luaL_error(L, "incorrect string argument to function 'gl.GetTexImage'");
    2196            0 :    }
    2197              : 
    2198            0 :    pixels = (GLfloat *)malloc(n * width * height * sizeof(GLfloat));
    2199              : 
    2200              :    /* call opengl function */
    2201            0 :    glGetTexImage(target, level, format, GL_FLOAT, pixels);
    2202              : 
    2203            0 :    lua_newtable(L);
    2204              : 
    2205            0 :    for(i = 0; i < n * width * height; i++)
    2206            0 :       set_field(L, i+1, pixels[i]);
    2207              : 
    2208            0 :    free(pixels);
    2209              : 
    2210            0 :    return 1;
    2211              : }
    2212              : 
    2213              : /*GetTexLevelParameter (target, level, pname) -> param*/
    2214            0 : static int gl_get_tex_level_parameter(lua_State *L)
    2215              : {
    2216              :    int level;
    2217              :    GLenum target, pname;
    2218              :    GLfloat param;
    2219              : 
    2220              :    /* test arguments type */
    2221            0 :    if( !(lua_isstring(L, 1) && lua_isnumber(L, 2) && lua_isstring(L, 3)) )
    2222            0 :       luaL_error(L, "incorrect argument to function 'gl.GetTexLevelParameter'");
    2223              : 
    2224              :    /* get parameters */
    2225            0 :    target = get_gl_enum(L, 1);
    2226            0 :    level = (int)lua_tonumber(L, 2);
    2227            0 :    pname = get_gl_enum(L, 3);
    2228              : 
    2229              :    /* call opengl function */
    2230            0 :    glGetTexLevelParameterfv(target, level, pname, &param);
    2231              : 
    2232              :    /* return parameter */
    2233            0 :    lua_pushnumber(L, param);
    2234              : 
    2235            0 :    return 1;
    2236              : }
    2237              : 
    2238              : /*GetTexParameter (target, pname) -> paramsArray*/
    2239            0 : static int gl_get_tex_parameter(lua_State *L)
    2240              : {
    2241              :    int i;
    2242              :    GLenum target, pname;
    2243              :    GLfloat *params;
    2244              :    GLfloat param;
    2245              :    int e;
    2246              : 
    2247              :    /* test arguments type */
    2248            0 :    if(! (lua_isstring(L, 1) && lua_isstring(L, 2) ))
    2249            0 :       luaL_error(L, "incorrect argument to function 'gl.GetTexParameter'");
    2250              : 
    2251              :    /* get string parameters */
    2252            0 :    target = get_gl_enum(L, 1);
    2253            0 :    pname = get_gl_enum(L, 2);
    2254              : 
    2255            0 :    if(pname == GL_TEXTURE_BORDER_COLOR)
    2256              :    {
    2257            0 :       params = (GLfloat *)malloc(4 * sizeof(float));
    2258              : 
    2259              :       /* call opengl function */
    2260            0 :       glGetTexParameterfv(target, pname, params);
    2261              : 
    2262              :       /* return parameters */
    2263            0 :       lua_newtable(L);
    2264              : 
    2265            0 :       for(i = 0; i < 4; i++)
    2266            0 :          set_field(L, i+1, params[i]);
    2267            0 :    }
    2268            0 :    else if(pname == GL_TEXTURE_PRIORITY)
    2269              :    {
    2270              :       /* call opengl function */
    2271            0 :       glGetTexParameterfv(target, pname, &param);
    2272              : 
    2273            0 :       lua_pushnumber(L, param);
    2274            0 :    }
    2275              :    else
    2276              :    {
    2277              :       /* call opengl function */
    2278            0 :       glGetTexParameteriv(target, pname, &e);
    2279              : 
    2280            0 :       lua_pushstring(L, get_str_gl_enum(e));
    2281              :    }
    2282            0 :    return 1;
    2283              : }
    2284              : 
    2285              : /*Hint (target, mode) -> none*/
    2286            0 : static int gl_hint(lua_State *L)
    2287              : {
    2288              :    GLenum e1, e2;
    2289              : 
    2290              :    /* test arguments type */
    2291            0 :    if( !(lua_isstring(L, 1) && lua_isstring(L, 2)) )
    2292            0 :       luaL_error(L, "incorrect argument to function 'gl.Hint'");
    2293              : 
    2294            0 :    e1 = get_gl_enum(L, 1);
    2295            0 :    e2 = get_gl_enum(L, 2);
    2296              : 
    2297              :    /* test argument */
    2298            0 :    if(e1 == ENUM_ERROR || e2 == ENUM_ERROR)
    2299            0 :       luaL_error(L, "incorrect string argument to function 'gl.Hint'");
    2300              : 
    2301              :    /* call opengl function */
    2302            0 :    glHint(e1, e2);
    2303              : 
    2304            0 :    return 0;
    2305              : }
    2306              : 
    2307              : /*Index (c) -> none*/
    2308            0 : static int gl_index(lua_State *L)
    2309              : {
    2310              :    GLdouble *c;
    2311              : 
    2312            0 :    if(lua_istable(L, 1))/* test argument type */
    2313              :    {
    2314              :       /* get argument */
    2315            0 :       get_arrayd(L, 1, &c);
    2316              : 
    2317              :       /* call opengl function */
    2318            0 :       glIndexdv((GLdouble *)c);
    2319              : 
    2320            0 :       free(c);
    2321            0 :    }
    2322            0 :    else if(lua_isnumber(L, 1))/* test argument type */
    2323              :       /* call opengl function */
    2324            0 :       glIndexd((GLdouble)lua_tonumber(L, 1));
    2325              : 
    2326              :    else
    2327            0 :       luaL_error(L, "incorrect argument to function 'gl.Index'");
    2328              : 
    2329            0 :    return 0;
    2330              : }
    2331              : 
    2332              : /*IndexMask (mask) -> none*/
    2333            0 : static int gl_index_mask(lua_State *L)
    2334              : {
    2335            0 :    if(lua_type(L,1) == LUA_TSTRING)
    2336              :       /* call opengl function */
    2337            0 :       glIndexMask(str2mask(lua_tostring(L, 1)));
    2338              : 
    2339            0 :    else if(lua_type(L,1) == LUA_TNUMBER)
    2340              :       /* call opengl function */
    2341            0 :       glIndexMask((GLuint)lua_tonumber(L, 1));
    2342              : 
    2343              :    else
    2344            0 :       luaL_error(L, "incorrect argument to function 'gl.IndexMask'");
    2345              : 
    2346            0 :    return 0;
    2347              : }
    2348              : 
    2349              : /*IndexPointer (indexArray) -> none*/
    2350            0 : static int gl_index_pointer(lua_State *L)
    2351              : {
    2352              :    static GLdouble *array = 0;
    2353            0 :    if(array)
    2354            0 :       free(array);
    2355              : 
    2356              :    /* test arguments type */
    2357            0 :    if(!lua_istable(L, 1))
    2358            0 :       luaL_error(L, "incorrect argument to function 'gl.IndexPointer'");
    2359              : 
    2360              :    /* get argument */
    2361            0 :    get_arrayd(L, 1, &array);
    2362              : 
    2363              :    /* call opengl function */
    2364            0 :    glIndexPointer(GL_DOUBLE, 0, array);
    2365              : 
    2366            0 :    return 0;
    2367              : }
    2368              : 
    2369              : /*InitNames () -> none*/
    2370            0 : static int gl_init_names(lua_State *L)
    2371              : {
    2372            0 :    glInitNames();
    2373            0 :    return 0;
    2374              : }
    2375              : 
    2376              : /*IsEnabled (cap) -> true/false*/
    2377            0 : static int gl_is_enabled(lua_State *L)
    2378              : {
    2379              :    GLenum e;
    2380              : 
    2381              :    /* test argument type */
    2382            0 :    if(!lua_isstring(L, 1))
    2383            0 :       luaL_error(L, "incorrect argument to function 'gl.IsEnabled'");
    2384              : 
    2385              :    /* get string parameter */
    2386            0 :    e = get_gl_enum(L, 1);
    2387              : 
    2388              :    /* test argument */
    2389            0 :    if(e == ENUM_ERROR)
    2390            0 :       luaL_error(L, "incorrect string argument to function 'gl.IsEnabled'");
    2391              : 
    2392              :    /* call opengl function */
    2393            0 :    lua_pushboolean(L, glIsEnabled(e));
    2394              : 
    2395            0 :    return 1;
    2396              : }
    2397              : 
    2398              : /*IsList (list) -> true/false*/
    2399            0 : static int gl_is_list(lua_State *L)
    2400              : {
    2401              :    /* test argument type */
    2402            0 :    if(!lua_isnumber(L, 1))
    2403            0 :       luaL_error(L, "incorrect argument to function 'gl.IsList'");
    2404              : 
    2405              :    /* call opengl function and push return value in the lua stack */
    2406            0 :    lua_pushboolean(L, glIsList((GLuint)lua_tonumber(L, 1)));
    2407              : 
    2408            0 :    return 1;
    2409              : }
    2410              : 
    2411              : /*IsTexture (texture) -> true/false*/
    2412            0 : static int gl_is_texture(lua_State *L)
    2413              : {
    2414              :    /* test argument type */
    2415            0 :    if(!lua_isnumber(L, 1))
    2416            0 :       luaL_error(L, "incorrect argument to function 'gl.IsTexture'");
    2417              : 
    2418              :    /* call opengl function and push return value in the lua stack */
    2419            0 :    lua_pushboolean(L, glIsTexture((GLuint)lua_tonumber(L, 1)));
    2420              : 
    2421            0 :    return 1;
    2422              : }
    2423              : 
    2424              : /*Light (light, pname, param) -> none
    2425              :   Light (light, pname, paramsArray) -> none*/
    2426            0 : static int gl_light(lua_State *L)
    2427              : {
    2428              :    GLenum e1, e2;
    2429              :    GLfloat *params;
    2430              : 
    2431              :    /* test arguments type */
    2432            0 :    if(!( lua_isstring(L, 1) && lua_isstring(L, 2) ))
    2433            0 :       luaL_error(L, "incorrect argument to function 'gl.Light'");
    2434              : 
    2435              :    /* get string parameters */
    2436            0 :    e1 = get_gl_enum(L, 1);
    2437            0 :    e2 = get_gl_enum(L, 2);
    2438              : 
    2439              :    /* test argument */
    2440            0 :    if(e1 == ENUM_ERROR || e2 == ENUM_ERROR)
    2441            0 :       luaL_error(L, "incorrect string argument to function 'gl.Light'");
    2442              : 
    2443              :    /* test argument type */
    2444            0 :    if(lua_istable(L, 3))
    2445              :    {
    2446              :       /* get argument */
    2447            0 :       get_arrayf(L, 3, &params);
    2448              : 
    2449              :       /* call opengl function */
    2450            0 :       glLightfv(e1, e2, (GLfloat *)params);
    2451              : 
    2452            0 :       free(params);
    2453            0 :    }
    2454              :    /* test argument type */
    2455            0 :    else if(lua_isnumber(L, 3))
    2456              :    {
    2457              :       /* call opengl function */
    2458            0 :       glLightf(e1, e2, (GLfloat)lua_tonumber(L, 3));
    2459            0 :    }
    2460              :    else
    2461            0 :       luaL_error(L, "incorrect argument to function 'gl.Light'");
    2462              : 
    2463            0 :    return 0;
    2464              : }
    2465              : 
    2466              : /*LightModel (pname, param) -> none
    2467              :   LightModel (pname, paramsArray) -> none*/
    2468            0 : static int gl_light_model(lua_State *L)
    2469              : {
    2470              :    GLenum e;
    2471              :    GLfloat *params;
    2472              : 
    2473              :    /* test argument type */
    2474            0 :    if(!lua_isstring(L, 1))
    2475            0 :       luaL_error(L, "incorrect argument to function 'gl.LightModel'");
    2476              : 
    2477              :    /* get string parameter */
    2478            0 :    e = get_gl_enum(L, 1);
    2479              : 
    2480              :    /* test argument */
    2481            0 :    if(e == ENUM_ERROR)
    2482            0 :       luaL_error(L, "incorrect string argument to function 'gl.LightModel'");
    2483              : 
    2484              :    /* test argument type */
    2485            0 :    if(lua_istable(L, 2))
    2486              :    {
    2487              :       /* get argument */
    2488            0 :       get_arrayf(L, 2, &params);
    2489              : 
    2490              :       /* call opengl function */
    2491            0 :       glLightModelfv(e, (GLfloat *)params);
    2492              : 
    2493            0 :       free(params);
    2494            0 :    }
    2495              :    /* test argument type */
    2496            0 :    else if(lua_isnumber(L, 2))
    2497              :       /* call opengl function */
    2498            0 :       glLightModelf(e, (GLfloat)lua_tonumber(L, 2));
    2499              : 
    2500              :    else
    2501            0 :       luaL_error(L, "incorrect argument to function 'gl.LightModel'");
    2502              : 
    2503            0 :    return 0;
    2504              : }
    2505              : 
    2506              : /*LineStipple (factor, pattern) -> none*/
    2507            0 : static int gl_line_stipple(lua_State *L)
    2508              : {
    2509              :    /* test arguments type */
    2510            0 :    if(!lua_isnumber(L, 1))
    2511            0 :       luaL_error(L, "incorrect argument to function 'gl.LineStipple'");
    2512              : 
    2513            0 :    if(lua_type(L,2) == LUA_TSTRING)
    2514              :       /* call opengl function */
    2515            0 :       glLineStipple((GLint)lua_tonumber(L, 1), (GLushort)str2mask(lua_tostring(L, 2)));
    2516              : 
    2517            0 :    else if(lua_type(L,2) == LUA_TNUMBER)
    2518              :       /* call opengl function */
    2519            0 :       glLineStipple((GLint)lua_tonumber(L, 1), (GLushort)lua_tonumber(L, 2));
    2520              : 
    2521              :    else
    2522            0 :       luaL_error(L, "incorrect argument to function 'gl.LineStipple'");
    2523              : 
    2524            0 :    return 0;
    2525              : }
    2526              : 
    2527              : /*LineWidth (width) -> none*/
    2528            0 : static int gl_line_width(lua_State *L)
    2529              : {
    2530              :    /* test argument type */
    2531            0 :    if(!lua_isnumber(L, 1))
    2532            0 :       luaL_error(L, "incorrect argument to function 'gl.LineWidth'");
    2533              : 
    2534              :    /* call opengl function */
    2535            0 :    glLineWidth((GLfloat)lua_tonumber(L, 1));
    2536              : 
    2537            0 :    return 0;
    2538              : }
    2539              : 
    2540              : /*ListBase (base) -> none*/
    2541            0 : static int gl_list_base(lua_State *L)
    2542              : {
    2543              :    /* test argument type */
    2544            0 :    if(!lua_isnumber(L, 1))
    2545            0 :       luaL_error(L, "incorrect argument to function 'gl.ListBase'");
    2546              : 
    2547              :    /* call opengl function */
    2548            0 :    glListBase((GLuint)lua_tonumber(L, 1));
    2549              : 
    2550            0 :    return 0;
    2551              : }
    2552              : 
    2553              : /*LoadIdentity () -> none*/
    2554            0 : static int gl_load_identity(lua_State *L)
    2555              : {
    2556            0 :    glLoadIdentity();
    2557            0 :    return 0;
    2558              : }
    2559              : 
    2560              : /*LoadMatrix (mArray) -> none*/
    2561            0 : static int gl_load_matrix(lua_State *L)
    2562              : {
    2563              :    GLdouble *m;
    2564              : 
    2565              :    /* test argument type and the number of arguments in the array, must be 16 values */
    2566            0 :    if(!lua_istable(L, 1) || luaL_getn(L, 1) < 16)
    2567            0 :       luaL_error(L, "incorrect argument to function 'gl.LoadMatrix'");
    2568              : 
    2569              :    /* get argument */
    2570            0 :    get_arrayd(L, 1, &m);
    2571              : 
    2572              :    /* call opengl function */
    2573            0 :    glLoadMatrixd(m);
    2574              : 
    2575            0 :    free(m);
    2576              : 
    2577            0 :    return 0;
    2578              : }
    2579              : 
    2580              : /*LoadName (name) -> none*/
    2581            0 : static int gl_load_name(lua_State *L)
    2582              : {
    2583              :    /* test argument type */
    2584            0 :    if(!lua_isnumber(L, 1))
    2585            0 :       luaL_error(L, "incorrect argument to function 'gl.LoadName'");
    2586              : 
    2587              :    /* call opengl function */
    2588            0 :    glLoadName((GLuint)lua_tonumber(L, 1));
    2589              : 
    2590            0 :    return 0;
    2591              : }
    2592              : 
    2593              : /*LogicOp (opcode) -> none*/
    2594            0 : static int gl_logic_op(lua_State *L)
    2595              : {
    2596              :    GLenum opcode;
    2597              : 
    2598              :    /* test argument type */
    2599            0 :    if(!lua_isstring(L, 1))
    2600            0 :       luaL_error(L, "incorrect argument to function 'gl.LogicOp'");
    2601              : 
    2602              :    /* get string parameter */
    2603            0 :    opcode = get_gl_enum(L, 1);
    2604              : 
    2605              :    /* test argument */
    2606            0 :    if(opcode == ENUM_ERROR)
    2607            0 :       luaL_error(L, "incorrect string argument to function 'gl.LogicOp'");
    2608              : 
    2609              :    /* call opengl function */
    2610            0 :    glLogicOp(opcode);
    2611              : 
    2612            0 :    return 0;
    2613              : }
    2614              : 
    2615              : /*Map (target, u1, u2, ustride, pointsArray) -> none
    2616              :   Map (target, u1, u2, ustride, v1, v2, vstride, pointsArray) -> none*/
    2617            0 : static int gl_map(lua_State *L)
    2618              : {
    2619            0 :    int size=1;
    2620              :    GLenum target;
    2621              :    GLdouble *points;
    2622              :    GLint uorder, vorder;
    2623              : 
    2624              :    /* test argument */
    2625            0 :    if(!( lua_isstring(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3) ))
    2626            0 :       luaL_error(L, "incorrect argument to function 'gl.Map'");
    2627              : 
    2628            0 :    target = get_gl_enum(L, 1);
    2629              : 
    2630            0 :    switch(target)
    2631              :    {
    2632              :       case GL_MAP1_INDEX:
    2633              :       case GL_MAP2_INDEX:
    2634              :       case GL_MAP1_TEXTURE_COORD_1:
    2635              :       case GL_MAP2_TEXTURE_COORD_1:
    2636            0 :          size = 1;
    2637            0 :          break;
    2638              :       case GL_MAP1_TEXTURE_COORD_2:
    2639              :       case GL_MAP2_TEXTURE_COORD_2:
    2640            0 :          size = 2;
    2641            0 :          break;
    2642              :       case GL_MAP1_VERTEX_3:
    2643              :       case GL_MAP2_VERTEX_3:
    2644              :       case GL_MAP1_NORMAL:
    2645              :       case GL_MAP2_NORMAL:
    2646              :       case GL_MAP1_TEXTURE_COORD_3:
    2647              :       case GL_MAP2_TEXTURE_COORD_3:
    2648            0 :          size = 3;
    2649            0 :          break;
    2650              :       case GL_MAP1_VERTEX_4:
    2651              :       case GL_MAP2_VERTEX_4:
    2652              :       case GL_MAP1_COLOR_4:
    2653              :       case GL_MAP2_COLOR_4:
    2654              :       case GL_MAP1_TEXTURE_COORD_4:
    2655              :       case GL_MAP2_TEXTURE_COORD_4:
    2656            0 :          size = 4;
    2657            0 :          break;
    2658              :    }
    2659              : 
    2660              :    /* test argument */
    2661            0 :    if(target == ENUM_ERROR)
    2662            0 :       luaL_error(L, "incorrect string argument to function 'gl.Map'");
    2663              : 
    2664              :    /* test number of argument in the array */
    2665            0 :    if(lua_gettop(L) < 6)
    2666              :    {
    2667            0 :       if(!lua_istable(L, 4))
    2668            0 :          luaL_error(L, "incorrect argument to function 'gl.Map'");
    2669              : 
    2670              :       /* get argument */
    2671            0 :       uorder = get_arrayd(L, 4, &points) / size;
    2672              : 
    2673              :       /* call opengl function */
    2674            0 :       glMap1d(target, (GLdouble)lua_tonumber(L, 2),
    2675            0 :                       (GLdouble)lua_tonumber(L, 3),
    2676            0 :                       size, uorder, points);
    2677              : 
    2678            0 :       free(points);
    2679            0 :    }
    2680              :    else
    2681              :    {
    2682            0 :       if(!( lua_isnumber(L, 4) && lua_isnumber(L, 5) && lua_istable(L, 6) ))
    2683            0 :          luaL_error(L, "incorrect argument to function 'gl.Map'");
    2684              : 
    2685              :       /* get argument */
    2686            0 :       vorder = get_array2d(L, 6, &points, &uorder);
    2687            0 :       uorder /= size;
    2688              : 
    2689              :       /* call opengl function */
    2690            0 :       glMap2d(target, (GLdouble)lua_tonumber(L, 2),
    2691            0 :                       (GLdouble)lua_tonumber(L, 3),
    2692            0 :                       size, uorder,
    2693            0 :                       (GLdouble)lua_tonumber(L, 4),
    2694            0 :                       (GLdouble)lua_tonumber(L, 5),
    2695            0 :                       size * uorder, vorder,
    2696            0 :                       points);
    2697              : 
    2698            0 :       free(points);
    2699              :    }
    2700            0 :    return 0;
    2701              : }
    2702              : 
    2703              : /*MapGrid (un, u1, u2[, vn, v1, v2]) -> none*/
    2704            0 : static int gl_map_grid(lua_State *L)
    2705              : {
    2706              :    /* test arguments */
    2707            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3) ))
    2708            0 :       luaL_error(L, "incorrect argument to function 'gl.MapGrid'");
    2709              : 
    2710              :    /* test number of arguments */
    2711            0 :    if(lua_gettop(L) < 6)
    2712              :    {
    2713              :       /* call opengl function */
    2714            0 :       glMapGrid1d((GLint)lua_tonumber(L, 1),
    2715            0 :                   (GLdouble)lua_tonumber(L, 2),
    2716            0 :                   (GLdouble)lua_tonumber(L, 3));
    2717            0 :    }
    2718              :    else
    2719              :    {
    2720              :       /* test arguments type */
    2721            0 :       if(!( lua_isnumber(L, 4) && lua_isnumber(L, 5) && lua_isnumber(L, 6) ))
    2722            0 :          luaL_error(L, "incorrect argument to function 'gl.MapGrid'");
    2723              : 
    2724              :       /* call opengl function */
    2725            0 :       glMapGrid2d((GLint)lua_tonumber(L, 1),
    2726            0 :                   (GLdouble)lua_tonumber(L, 2),
    2727            0 :                   (GLdouble)lua_tonumber(L, 3),
    2728            0 :                   (GLint)lua_tonumber(L, 4),
    2729            0 :                   (GLdouble)lua_tonumber(L, 5),
    2730            0 :                   (GLdouble)lua_tonumber(L, 6));
    2731              :    }
    2732            0 :    return 0;
    2733              : }
    2734              : 
    2735              : /*Material (face, pname, param) -> none*/
    2736            0 : static int gl_material(lua_State *L)
    2737              : {
    2738              :    GLenum e1, e2;
    2739              :    GLfloat *params;
    2740              : 
    2741              :    /* test arguments type */
    2742            0 :    if( !(lua_isstring(L, 1) && lua_isstring(L, 2)) )
    2743            0 :       luaL_error(L, "incorrect argument to function 'gl.Material'");
    2744              : 
    2745              :    /* get string parameters */
    2746            0 :    e1 = get_gl_enum(L, 1);
    2747            0 :    e2 = get_gl_enum(L, 2);
    2748              : 
    2749              :    /* test argument */
    2750            0 :    if(e1 == ENUM_ERROR || e2 == ENUM_ERROR)
    2751            0 :       luaL_error(L, "incorrect string argument to function 'gl.Material'");
    2752              : 
    2753              :    /* test argument type */
    2754            0 :    if(lua_istable(L, 3))
    2755              :    {
    2756              :       /* get argument */
    2757            0 :       get_arrayf(L, 3, &params);
    2758              : 
    2759              :       /* call opengl function */
    2760            0 :       glMaterialfv(e1, e2, (GLfloat *)params);
    2761              : 
    2762            0 :       free(params);
    2763            0 :    }
    2764              :    /* test argument type */
    2765            0 :    else if(lua_isnumber(L, 3))
    2766              :    {
    2767              :       /* call opengl function */
    2768            0 :       glMaterialf(e1, e2, (GLfloat)lua_tonumber(L, 3));
    2769            0 :    }
    2770              :    else
    2771            0 :       luaL_error(L, "incorrect argument to function 'gl.Material'");
    2772              : 
    2773            0 :    return 0;
    2774              : }
    2775              : 
    2776              : /*MatrixMode (mode) -> none*/
    2777            0 : static int gl_matrix_mode(lua_State *L)
    2778              : {
    2779              :    GLenum mode;
    2780              : 
    2781              :    /* test argument type */
    2782            0 :    if(!lua_isstring(L, 1))
    2783            0 :       luaL_error(L, "incorrect argument to function 'gl.MatrixMode'");
    2784              : 
    2785              :    /* get string parameter */
    2786            0 :    mode = get_gl_enum(L, 1);
    2787              : 
    2788              :    /* test argument */
    2789            0 :    if(mode == ENUM_ERROR)
    2790            0 :       luaL_error(L, "incorrect string argument to function 'gl.MatrixMode'");
    2791              : 
    2792              :    /* call opengl function */
    2793            0 :    glMatrixMode(mode);
    2794              : 
    2795            0 :    return 0;
    2796              : }
    2797              : 
    2798              : /*MultMatrix (mArray) -> none*/
    2799            0 : static int gl_mult_matrix(lua_State *L)
    2800              : {
    2801              :    GLdouble *m;
    2802              : 
    2803              :    /* test argument type and the number of arguments in the array, must be 16 values */
    2804            0 :    if(!lua_istable(L, 1) || luaL_getn(L, 1) < 16)
    2805            0 :       luaL_error(L, "incorrect argument to function 'gl.MultMatrix'");
    2806              : 
    2807              :    /* get argument */
    2808            0 :    get_arrayd(L, 1, &m);
    2809              : 
    2810              :    /* call opengl function */
    2811            0 :    glMultMatrixd((GLdouble *)m);
    2812              : 
    2813            0 :    free(m);
    2814              : 
    2815            0 :    return 0;
    2816              : }
    2817              : 
    2818              : /*NewList (list, mode) -> none*/
    2819            0 : static int gl_new_list(lua_State *L)
    2820              : {
    2821              :    GLenum e;
    2822              : 
    2823              :    /* test arguments type */
    2824            0 :    if(!( lua_isnumber(L, 1) && lua_isstring(L, 2) ))
    2825            0 :       luaL_error(L, "incorrect argument to function 'gl.NewList'");
    2826              : 
    2827              :    /* get string parameter */
    2828            0 :    e = get_gl_enum(L, 2);
    2829              : 
    2830              :    /* test argument */
    2831            0 :    if(e == ENUM_ERROR)
    2832            0 :       luaL_error(L, "incorrect string argument to function 'gl.NewList'");
    2833              : 
    2834              :    /* call opengl function */
    2835            0 :    glNewList((GLint)lua_tonumber(L, 1), e);
    2836              : 
    2837            0 :    return 0;
    2838              : }
    2839              : 
    2840              : /*Normal (nx, ny, nz) -> none
    2841              :   Normal (nArray) -> none*/
    2842            0 : static int gl_normal(lua_State *L)
    2843              : {
    2844              :    GLdouble *array;
    2845              : 
    2846              :    int num_args;
    2847              : 
    2848              :    /* test arguments type */
    2849            0 :    if(lua_istable(L, 1))
    2850              :    {
    2851            0 :       num_args = get_arrayd(L, 1, &array);
    2852              : 
    2853            0 :       if(num_args < 3)
    2854            0 :          luaL_error(L, "incorrect argument to function 'gl.Normal'");
    2855              : 
    2856              :       /* call openGL function */
    2857            0 :       glNormal3dv(array);
    2858              : 
    2859            0 :       free(array);
    2860              : 
    2861            0 :       return 0;
    2862              :    }
    2863              : 
    2864              :    /* test arguments */
    2865            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3) ))
    2866            0 :       luaL_error(L, "incorrect argument to function 'gl.Normal'");
    2867              : 
    2868              :    /* call openGL functions */
    2869            0 :    glNormal3d((GLdouble)lua_tonumber(L, 1), (GLdouble)lua_tonumber(L, 2),
    2870            0 :               (GLdouble)lua_tonumber(L, 3));
    2871              : 
    2872            0 :    return 0;
    2873            0 : }
    2874              : 
    2875              : /*NormalPointer (normalArray) -> none*/
    2876            0 : static int gl_normal_pointer(lua_State *L)
    2877              : {
    2878              :    GLint size;
    2879              : 
    2880              :    static GLdouble *array = 0;
    2881              : 
    2882            0 :    if(array)
    2883            0 :       free(array);
    2884              : 
    2885              :    /* test arguments type */
    2886            0 :    if(!lua_istable(L, 1))
    2887            0 :       luaL_error(L, "incorrect argument to function 'gl.NormalPointer'");
    2888              :    /* get argument */
    2889            0 :    if(get_array2d(L, 1, &array, &size) == -1)
    2890            0 :       size = get_arrayd(L, 1, &array) / 3;
    2891              : 
    2892              :    /* call opengl function */
    2893            0 :    glNormalPointer(GL_DOUBLE, 0, array);
    2894              : 
    2895            0 :    return 0;
    2896              : }
    2897              : 
    2898              : /*Ortho (left, right, bottom, top, zNear, zFar) -> none*/
    2899            0 : static int gl_ortho(lua_State *L)
    2900              : {
    2901              :    /* test arguments type */
    2902            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3) &&
    2903            0 :          lua_isnumber(L, 4) && lua_isnumber(L, 5) && lua_isnumber(L, 6)))
    2904            0 :       luaL_error(L, "incorrect string argument to function 'gl.Ortho'");
    2905              : 
    2906              :    /* call opengl function */
    2907            0 :    glOrtho((GLdouble)lua_tonumber(L, 1), (GLdouble)lua_tonumber(L, 2),
    2908            0 :            (GLdouble)lua_tonumber(L, 3), (GLdouble)lua_tonumber(L, 4),
    2909            0 :            (GLdouble)lua_tonumber(L, 5), (GLdouble)lua_tonumber(L, 6));
    2910              : 
    2911            0 :    return 0;
    2912              : }
    2913              : 
    2914              : /*PassThrough (token) -> none*/
    2915            0 : static int gl_pass_through(lua_State *L)
    2916              : {
    2917              :    /* test argument type */
    2918            0 :    if(!lua_isnumber(L, 1))
    2919            0 :       luaL_error(L, "incorrect string argument to function 'gl.PassThrough'");
    2920              : 
    2921              :    /* call opengl function */
    2922            0 :    glPassThrough((GLfloat)lua_tonumber(L, 1));
    2923              : 
    2924            0 :    return 0;
    2925              : }
    2926              : 
    2927              : /*PixelMap (map, valuesArray) -> none*/
    2928            0 : static int gl_pixel_map(lua_State *L)
    2929              : {
    2930              :    GLenum map;
    2931              :    GLfloat *values;
    2932              :    int mapsize;
    2933              : 
    2934              :    /* test arguments */
    2935            0 :    if(!( lua_isstring(L, 1) && lua_istable(L, 2) ))
    2936            0 :       luaL_error(L, "incorrect argument to function 'gl.PixelMap'");
    2937              : 
    2938              :    /* get values */
    2939            0 :    map = get_gl_enum(L, 1);
    2940              : 
    2941              :    /* test argument */
    2942            0 :    if(map == ENUM_ERROR)
    2943            0 :       luaL_error(L, "incorrect string argument to function 'gl.PixelMap'");
    2944              : 
    2945              :    /* get array of equations */
    2946            0 :    mapsize = get_arrayf(L, 2, &values);
    2947              : 
    2948              :    /* call opengl function */
    2949            0 :    glPixelMapfv(map, mapsize, values);
    2950              : 
    2951            0 :    free(values);
    2952              : 
    2953            0 :    return 0;
    2954              : }
    2955              : 
    2956              : /*PixelStore (pname, param) -> none*/
    2957            0 : static int gl_pixel_store(lua_State *L)
    2958              : {
    2959              :    /* get string parameters */
    2960              :    GLenum e;
    2961              : 
    2962              :    /* test argument */
    2963            0 :    if(!lua_isstring(L, 1))
    2964            0 :       luaL_error(L, "incorrect argument to function 'gl.PixelStore'");
    2965              : 
    2966            0 :    e = get_gl_enum(L, 1);
    2967              : 
    2968              :    /* test arguments */
    2969            0 :    if(e == ENUM_ERROR)
    2970            0 :       luaL_error(L, "incorrect string argument to function 'gl.PixelStore'");
    2971              : 
    2972            0 :    if(lua_isnumber(L, 2))
    2973              :       /* call opengl function */
    2974            0 :       glPixelStoref(e, (GLfloat)lua_tonumber(L, 2));
    2975              : 
    2976            0 :    else if(lua_isboolean(L,2))
    2977              :       /* call opengl function */
    2978            0 :       glPixelStoref(e, (GLfloat)lua_toboolean(L, 2));
    2979              : 
    2980              :    else
    2981            0 :       luaL_error(L, "incorrect argument to function 'gl.PixelStore'");
    2982              : 
    2983            0 :    return 0;
    2984              : }
    2985              : 
    2986              : /*PixelTransfer (pname, param) -> none*/
    2987            0 : static int gl_pixel_transfer(lua_State *L)
    2988              : {
    2989              :    /* get string parameters */
    2990              :    GLenum e;
    2991              : 
    2992              :    /* test argument */
    2993            0 :    if(!lua_isstring(L, 1))
    2994            0 :       luaL_error(L, "incorrect argument to function 'gl.PixelTransfer'");
    2995              : 
    2996            0 :    e = get_gl_enum(L, 1);
    2997              : 
    2998              :    /* test arguments */
    2999            0 :    if(e == ENUM_ERROR)
    3000            0 :       luaL_error(L, "incorrect string argument to function 'gl.PixelTransfer'");
    3001              : 
    3002            0 :    if(lua_isnumber(L, 2))
    3003              :       /* call opengl function */
    3004            0 :       glPixelTransferf(e, (GLfloat)lua_tonumber(L, 2));
    3005              : 
    3006            0 :    else if(lua_isboolean(L,2))
    3007              :       /* call opengl function */
    3008            0 :       glPixelTransferf(e, (GLfloat)lua_toboolean(L, 2));
    3009              : 
    3010              :    else
    3011            0 :       luaL_error(L, "incorrect argument to function 'gl.PixelTransfer'");
    3012              : 
    3013            0 :    return 0;
    3014              : }
    3015              : 
    3016              : /*PixelZoom (xfactor, yfactor) -> none*/
    3017            0 : static int gl_pixel_zoom(lua_State *L)
    3018              : {
    3019              :    /* test arguments type */
    3020            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) ))
    3021            0 :       luaL_error(L, "incorrect string argument to function 'gl.PixelZoom'");
    3022              : 
    3023              :    /* call opengl function */
    3024            0 :    glPixelZoom((GLfloat)lua_tonumber(L, 1), (GLfloat)lua_tonumber(L, 2));
    3025              : 
    3026            0 :    return 0;
    3027              : }
    3028              : 
    3029              : /*PointSize (size) -> none*/
    3030            0 : static int gl_point_size(lua_State *L)
    3031              : {
    3032              :    /* test arguments type */
    3033            0 :    if(!lua_isnumber(L, 1))
    3034            0 :       luaL_error(L, "incorrect string argument to function 'gl.PointSize'");
    3035              : 
    3036              :    /* call opengl function */
    3037            0 :    glPointSize((GLfloat)lua_tonumber(L, 1));
    3038              : 
    3039            0 :    return 0;
    3040              : }
    3041              : 
    3042              : /*PolygonMode (face, mode) -> none*/
    3043            0 : static int gl_polygon_mode(lua_State *L)
    3044              : {
    3045              :    GLenum e1, e2;
    3046              : 
    3047              :    /* test arguments type */
    3048            0 :    if( !(lua_isstring(L, 1) && lua_isstring(L, 2)) )
    3049            0 :       luaL_error(L, "incorrect argument to function 'gl.PolygonMode'");
    3050              : 
    3051              :    /* get string parameters */
    3052            0 :    e1 = get_gl_enum(L, 1);
    3053            0 :    e2 = get_gl_enum(L, 2);
    3054              : 
    3055              :    /* test argument */
    3056            0 :    if(e1 == ENUM_ERROR || e2 == ENUM_ERROR)
    3057            0 :       luaL_error(L, "incorrect string argument to function 'gl.PolygonMode'");
    3058              : 
    3059              :    /* call opengl function */
    3060            0 :    glPolygonMode(e1, e2);
    3061              : 
    3062            0 :    return 0;
    3063              : }
    3064              : 
    3065              : /*PolygonOffset (factor, units) -> none*/
    3066            0 : static int gl_polygon_offset(lua_State *L)
    3067              : {
    3068              :    /* test arguments type */
    3069            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) ))
    3070            0 :       luaL_error(L, "incorrect string argument to function 'gl.PolygonOffset'");
    3071              : 
    3072              :    /* call opengl function */
    3073            0 :    glPolygonOffset((GLfloat)lua_tonumber(L, 1), (GLfloat)lua_tonumber(L, 2));
    3074              : 
    3075            0 :    return 0;
    3076              : }
    3077              : 
    3078              : /*PolygonStipple (maskArray) -> none*/
    3079            0 : static int gl_polygon_stipple(lua_State *L)
    3080              : {
    3081              :    GLubyte *array;
    3082            0 :    int width, height = 32;
    3083              : 
    3084              :    /* test arguments type */
    3085            0 :    if(!lua_istable(L, 1))
    3086            0 :       luaL_error(L, "incorrect argument to function 'gl.PolygonStipple'");
    3087              : 
    3088            0 :    if((height = get_array2ubyte(L, 1, &array, &width)) == -1)
    3089            0 :       width = get_arrayubyte(L, 4, &array);
    3090              : 
    3091            0 :    if(width != 32 && height != 32)
    3092              :    {
    3093            0 :       free(array);
    3094            0 :       luaL_error(L, "incorrect argument to function 'gl.PolygonStipple'");
    3095            0 :    }
    3096              : 
    3097              :    /* call opengl function */
    3098            0 :    glPolygonStipple(array);
    3099              : 
    3100            0 :    return 0;
    3101              : }
    3102              : 
    3103              : /*PopAttrib () -> none*/
    3104            0 : static int gl_pop_attrib(lua_State *L)
    3105              : {
    3106            0 :    glPopAttrib();
    3107            0 :    return 0;
    3108              : }
    3109              : 
    3110              : /*PopClientAttrib () -> none*/
    3111            0 : static int gl_pop_client_attrib(lua_State *L)
    3112              : {
    3113            0 :    glPopClientAttrib();
    3114            0 :    return 0;
    3115              : }
    3116              : 
    3117              : /*PopMatrix () -> none*/
    3118            0 : static int gl_pop_matrix(lua_State *L)
    3119              : {
    3120            0 :    glPopMatrix();
    3121            0 :    return 0;
    3122              : }
    3123              : 
    3124              : /*PopName () -> none*/
    3125            0 : static int gl_pop_name(lua_State *L)
    3126              : {
    3127            0 :    glPopName();
    3128            0 :    return 0;
    3129              : }
    3130              : 
    3131              : /*PrioritizeTextures (texturesArray, prioritiesArray) -> none*/
    3132            0 : static int gl_prioritize_textures(lua_State *L)
    3133              : {
    3134              :    GLsizei n1, n2;
    3135              :    GLuint *array1;
    3136              :    GLclampf *array2;
    3137              : 
    3138              :    /* test arguments type */
    3139            0 :    if(!( lua_istable(L, 1) && lua_istable(L, 2) ))
    3140            0 :       luaL_error(L, "incorrect argument to function 'gl.PrioritizeTextures'");
    3141              : 
    3142              :    /* get arguments */
    3143            0 :    n1 = get_arrayui(L, 1, &array1);
    3144            0 :    n2 = get_arrayf(L, 2, &array2);
    3145              : 
    3146              :    /* call opengl function */
    3147            0 :    if(n1 > n2) n1 =  n2;
    3148              : 
    3149            0 :    glPrioritizeTextures(n1, array1, array2);
    3150              : 
    3151            0 :    free(array1);
    3152            0 :    free(array2);
    3153              : 
    3154            0 :    return 0;
    3155              : }
    3156              : 
    3157              : /*PushAttrib (mask) -> none*/
    3158            0 : static int gl_push_attrib(lua_State *L)
    3159              : {
    3160              :    GLbitfield e;
    3161              : 
    3162              :    /* test arguments type */
    3163            0 :    if(!lua_isstring(L, 1))
    3164            0 :       luaL_error(L, "incorrect argument to function 'gl.PushAttrib'");
    3165              : 
    3166            0 :    e = get_gl_enum(L, 1);
    3167              : 
    3168              :    /* test arguments */
    3169            0 :    if(e == ENUM_ERROR)
    3170            0 :       luaL_error(L, "incorrect string argument to function 'gl.PushAttrib'");
    3171              : 
    3172              :    /* call opengl function */
    3173            0 :    glPushAttrib(e);
    3174              : 
    3175            0 :    return 0;
    3176              : }
    3177              : 
    3178              : /*PushClientAttrib (mask) -> none*/
    3179            0 : static int gl_push_client_attrib(lua_State *L)
    3180              : {
    3181              :    GLbitfield e;
    3182              : 
    3183              :    /* test arguments type */
    3184            0 :    if(!lua_isstring(L, 1))
    3185            0 :       luaL_error(L, "incorrect argument to function 'gl.PushClientAttrib'");
    3186              : 
    3187            0 :    e = get_gl_enum(L, 1);
    3188              : 
    3189              :    /* test arguments */
    3190            0 :    if(e == ENUM_ERROR)
    3191            0 :       luaL_error(L, "incorrect string argument to function 'gl.PushClientAttrib'");
    3192              : 
    3193              :    /* call opengl function */
    3194            0 :    glPushClientAttrib(e);
    3195              : 
    3196            0 :    return 0;
    3197              : }
    3198              : 
    3199              : /*PushMatrix () -> none*/
    3200            0 : static int gl_push_matrix(lua_State *L)
    3201              : {
    3202            0 :    glPushMatrix();
    3203            0 :    return 0;
    3204              : }
    3205              : 
    3206              : /*PushName (GLuint name) -> none*/
    3207            0 : static int gl_push_name(lua_State *L)
    3208              : {
    3209              :    /* test arguments type */
    3210            0 :    if(!lua_isnumber(L, 1))
    3211            0 :       luaL_error(L, "incorrect argument to function 'gl.PushName'");
    3212              : 
    3213              :    /* call opengl function */
    3214            0 :    glPushName((GLuint)lua_tonumber(L, 1));
    3215              : 
    3216            0 :    return 0;
    3217              : }
    3218              : 
    3219              : /*RasterPos (x, y[, z, w]) -> none
    3220              :   RasterPos (vArray) -> none*/
    3221            0 : static int gl_raster_pos(lua_State *L)
    3222              : {
    3223              :    GLdouble *array;
    3224              : 
    3225              :    int index;
    3226            0 :    int num_args = lua_gettop(L);
    3227              : 
    3228              :    /* test arguments type */
    3229            0 :    if(lua_istable(L, 1))
    3230              :    {
    3231            0 :       num_args = get_arrayd(L, 1, &array);
    3232              : 
    3233              :       /* if more then 4 arguments, ignore the others */
    3234            0 :       if(num_args > 4)
    3235            0 :          num_args = 4;
    3236              : 
    3237              :       /* call openGL functions */
    3238            0 :       switch(num_args)
    3239              :       {
    3240            0 :          case 2:  glRasterPos2dv(array); break;
    3241            0 :          case 3:  glRasterPos3dv(array); break;
    3242            0 :          case 4:  glRasterPos4dv(array); break;
    3243              :       }
    3244              : 
    3245            0 :       free(array);
    3246              : 
    3247            0 :       return 0;
    3248              :    }
    3249              : 
    3250              :    /* if more then 4 arguments, ignore the others */
    3251            0 :    if(num_args > 4)
    3252            0 :       num_args = 4;
    3253              : 
    3254            0 :    for(index = 0; index < num_args; index++)
    3255              :    {
    3256            0 :       if(!lua_isnumber(L, index + 1))
    3257            0 :          luaL_error(L, "incorrect argument to function 'gl.RasterPos'");
    3258            0 :    }
    3259              : 
    3260              :    /* call openGL functions */
    3261            0 :    switch(num_args)
    3262              :    {
    3263            0 :       case 2:  glRasterPos2d((GLdouble)lua_tonumber(L, 1), (GLdouble)lua_tonumber(L, 2));
    3264            0 :                break;
    3265            0 :       case 3:  glRasterPos3d((GLdouble)lua_tonumber(L, 1), (GLdouble)lua_tonumber(L, 2),
    3266            0 :                              (GLdouble)lua_tonumber(L, 3));
    3267            0 :                break;
    3268            0 :       case 4:  glRasterPos4d((GLdouble)lua_tonumber(L, 1), (GLdouble)lua_tonumber(L, 2),
    3269            0 :                              (GLdouble)lua_tonumber(L, 3), (GLdouble)lua_tonumber(L, 4));
    3270            0 :                break;
    3271              :    }
    3272            0 :    return 0;
    3273            0 : }
    3274              : 
    3275              : /*ReadBuffer (mode) -> none*/
    3276            0 : static int gl_read_buffer(lua_State *L)
    3277              : {
    3278              :    GLenum mode;
    3279              : 
    3280              :    /* test argument type */
    3281            0 :    if(!lua_isstring(L, 1))
    3282            0 :       luaL_error(L, "incorrect argument to function 'gl.ReadBuffer'");
    3283              : 
    3284              :    /* get string parameter */
    3285            0 :    mode = get_gl_enum(L, 1);
    3286              : 
    3287              :    /* test argument */
    3288            0 :    if(mode == ENUM_ERROR)
    3289            0 :       luaL_error(L, "incorrect string argument to function 'gl.ReadBuffer'");
    3290              : 
    3291              :    /* call opengl function */
    3292            0 :    glReadBuffer(mode);
    3293              : 
    3294            0 :    return 0;
    3295              : }
    3296              : 
    3297              : /*ReadPixels (x, y, width, height, format, pixelsArray) -> none*/
    3298            0 : static int gl_read_pixels(lua_State *L)
    3299              : {
    3300              :    GLenum e;
    3301              :    GLfloat *pixels;
    3302              : 
    3303              :    /* test arguments type */
    3304            0 :    if(!(lua_isnumber(L, 1) && lua_isnumber(L, 2) &&
    3305            0 :         lua_isnumber(L, 3) && lua_isnumber(L, 4) &&
    3306            0 :         lua_isstring(L, 5) && lua_istable (L, 6)) )
    3307            0 :       luaL_error(L, "incorrect argument to function 'gl.ReadPixels'");
    3308              : 
    3309              :    /* get parameters */
    3310            0 :    e = get_gl_enum(L, 5);
    3311            0 :    get_arrayf(L, 6, &pixels);
    3312              : 
    3313              :    /* test argument */
    3314            0 :    if(e == ENUM_ERROR)
    3315            0 :       luaL_error(L, "incorrect string argument to function 'gl.ReadPixels'");
    3316              : 
    3317              :    /* call opengl function */
    3318            0 :    glReadPixels((GLint)lua_tonumber(L, 1), (GLint)lua_tonumber(L, 2),
    3319            0 :                 (GLsizei)lua_tonumber(L, 3), (GLsizei)lua_tonumber(L, 4),
    3320            0 :                 e, GL_FLOAT, pixels);
    3321              : 
    3322            0 :    free(pixels);
    3323              : 
    3324            0 :    return 0;
    3325              : }
    3326              : 
    3327              : /*Rect (x1, y1, x2, y2) -> none
    3328              :   Rect (v1, v2) -> none*/
    3329            0 : static int gl_rect(lua_State *L)
    3330              : {
    3331              :    GLdouble *v1, *v2;
    3332              : 
    3333              :    /* test argument type */
    3334            0 :    if(lua_istable(L, 1) && lua_istable(L, 2))
    3335              :    {
    3336              :       /* get parameters */
    3337            0 :       get_arrayd(L, 1, &v1);
    3338            0 :       get_arrayd(L, 2, &v2);
    3339              : 
    3340              :       /* call opengl function */
    3341            0 :       glRectdv(v1, v2);
    3342              : 
    3343            0 :       free(v1);
    3344            0 :       free(v2);
    3345            0 :    }
    3346              :    /* test argument type */
    3347            0 :    else if(lua_isnumber(L, 1) && lua_isnumber(L, 2) &&
    3348            0 :            lua_isnumber(L, 3) && lua_isnumber(L, 4))
    3349              :       /* call openGL functions */
    3350            0 :       glRectd((GLdouble)lua_tonumber(L, 1), (GLdouble)lua_tonumber(L, 2),
    3351            0 :               (GLdouble)lua_tonumber(L, 3), (GLdouble)lua_tonumber(L, 4));
    3352              : 
    3353              :    else
    3354            0 :       luaL_error(L, "incorrect argument to function 'gl.Rect'");
    3355              : 
    3356            0 :    return 0;
    3357              : }
    3358              : 
    3359              : /*RenderMode (mode) -> none*/
    3360            0 : static int gl_render_mode(lua_State *L)
    3361              : {
    3362              :    GLenum mode;
    3363              : 
    3364              :    /* test argument type */
    3365            0 :    if(!lua_isstring(L, 1))
    3366            0 :       luaL_error(L, "incorrect argument to function 'gl.RenderMode'");
    3367              : 
    3368              :    /* get string parameter */
    3369            0 :    mode = get_gl_enum(L, 1);
    3370              : 
    3371              :    /* test argument */
    3372            0 :    if(mode == ENUM_ERROR)
    3373            0 :       luaL_error(L, "incorrect string argument to function 'gl.RenderMode'");
    3374              : 
    3375              :    /* call opengl function */
    3376            0 :    glRenderMode(mode);
    3377              : 
    3378            0 :    return 0;
    3379              : }
    3380              : 
    3381              : /*Rotate (angle, x, y, z) -> none*/
    3382            0 : static int gl_rotate(lua_State *L)
    3383              : {
    3384              :    /* test argument type */
    3385            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) &&
    3386            0 :          lua_isnumber(L, 3) && lua_isnumber(L, 4) ))
    3387            0 :       luaL_error(L, "incorrect argument to function 'gl.Rotate'");
    3388              : 
    3389              :    /* call opengl function */
    3390            0 :    glRotated((GLdouble)lua_tonumber(L, 1), (GLdouble)lua_tonumber(L, 2),
    3391            0 :              (GLdouble)lua_tonumber(L, 3), (GLdouble)lua_tonumber(L, 4));
    3392              : 
    3393            0 :    return 0;
    3394              : }
    3395              : 
    3396              : /*Scale (x, y, z) -> none*/
    3397            0 : static int gl_scale(lua_State *L)
    3398              : {
    3399              :    /* test argument type */
    3400            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3) ))
    3401            0 :       luaL_error(L, "incorrect argument to function 'gl.Scale'");
    3402              : 
    3403              :    /* call opengl function */
    3404            0 :    glScaled((GLdouble)lua_tonumber(L, 1), (GLdouble)lua_tonumber(L, 2),
    3405            0 :             (GLdouble)lua_tonumber(L, 3));
    3406              : 
    3407            0 :    return 0;
    3408              : }
    3409              : 
    3410              : /*Scissor (x, y, width, height) -> none*/
    3411            0 : static int gl_scissor(lua_State *L)
    3412              : {
    3413              :    /* test argument type */
    3414            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3) && lua_isnumber(L, 4) ))
    3415            0 :       luaL_error(L, "incorrect argument to function 'gl.Scissor'");
    3416              : 
    3417              :    /* call opengl function */
    3418            0 :    glScissor((GLint)lua_tonumber(L, 1), (GLint)lua_tonumber(L, 2),
    3419            0 :              (GLsizei)lua_tonumber(L, 3), (GLsizei)lua_tonumber(L, 4));
    3420              : 
    3421            0 :    return 0;
    3422              : }
    3423              : 
    3424              : /*SelectBuffer (size) -> SelectArray*/
    3425            0 : static int gl_select_buffer(lua_State *L)
    3426              : {
    3427              :    int size, i;
    3428              :    GLuint *buffer;
    3429              : 
    3430              :    /* test arguments type */
    3431            0 :    if(!lua_isnumber(L, 1))
    3432            0 :       luaL_error(L, "incorrect argument to function 'gl.SelectBuffer'");
    3433              : 
    3434            0 :    size = (int)lua_tonumber(L, 1);
    3435              : 
    3436            0 :    buffer = (GLuint *)malloc(size * sizeof(GLuint));
    3437              : 
    3438              :    /* call opengl function */
    3439            0 :    glSelectBuffer (size, buffer);
    3440              : 
    3441              :    /* return parameters */
    3442            0 :    lua_newtable(L);
    3443              : 
    3444            0 :    for(i = 0; i < size; i++)
    3445            0 :       set_field(L, i+1, buffer[i]);
    3446              : 
    3447            0 :    free(buffer);
    3448              : 
    3449            0 :    return 1;
    3450              : }
    3451              : 
    3452              : /*ShadeModel (mode) -> none*/
    3453            0 : static int gl_shade_model(lua_State *L)
    3454              : {
    3455              :    GLenum mode;
    3456              : 
    3457              :    /* test argument type */
    3458            0 :    if(!lua_isstring(L, 1))
    3459            0 :       luaL_error(L, "incorrect argument to function 'gl.ShadeModel'");
    3460              : 
    3461              :    /* get string parameter */
    3462            0 :    mode = get_gl_enum(L, 1);
    3463              : 
    3464              :    /* test argument */
    3465            0 :    if(mode == ENUM_ERROR)
    3466            0 :       luaL_error(L, "incorrect string argument to function 'gl.ShadeModel'");
    3467              : 
    3468              :    /* call opengl function */
    3469            0 :    glShadeModel(mode);
    3470              : 
    3471            0 :    return 0;
    3472              : }
    3473              : 
    3474              : /*StencilFunc (func, ref, mask) -> none*/
    3475            0 : static int gl_stencil_func(lua_State *L)
    3476              : {
    3477              :    GLenum func;
    3478              : 
    3479              :    /* test arguments type */
    3480            0 :    if(!( lua_isstring(L, 1) && lua_isnumber(L, 2) ))
    3481            0 :       luaL_error(L, "incorrect argument to function 'gl.StencilFunc'");
    3482              : 
    3483              :    /* get string parameter */
    3484            0 :    func = get_gl_enum(L, 1);
    3485              : 
    3486              :    /* test argument */
    3487            0 :    if(func == ENUM_ERROR)
    3488            0 :       luaL_error(L, "incorrect string argument to function 'gl.StencilFunc'");
    3489              : 
    3490            0 :    if(lua_type(L,3) == LUA_TSTRING)
    3491              :       /* call opengl function */
    3492            0 :       glStencilFunc(func, (GLint)lua_tonumber(L, 2), str2mask(lua_tostring(L, 3)));
    3493              : 
    3494            0 :    else if(lua_type(L,3) == LUA_TNUMBER)
    3495              :       /* call opengl function */
    3496            0 :       glStencilFunc(func, (GLint)lua_tonumber(L, 2), (GLuint)lua_tonumber(L, 3));
    3497              : 
    3498              :    else
    3499            0 :       luaL_error(L, "incorrect argument to function 'gl.StencilFunc'");
    3500              : 
    3501            0 :    return 0;
    3502              : }
    3503              : 
    3504              : /*StencilMask (mask) -> none*/
    3505            0 : static int gl_stencil_mask(lua_State *L)
    3506              : {
    3507            0 :    if(lua_type(L,1) == LUA_TSTRING)
    3508              :       /* call opengl function */
    3509            0 :       glStencilMask(str2mask(lua_tostring(L, 1)));
    3510              : 
    3511            0 :    else if(lua_type(L,1) == LUA_TNUMBER)
    3512              :       /* call opengl function */
    3513            0 :       glStencilMask((GLuint)lua_tonumber(L, 1));
    3514              : 
    3515              :    else
    3516            0 :       luaL_error(L, "incorrect argument to function 'gl.StencilMask'");
    3517              : 
    3518            0 :    return 0;
    3519              : }
    3520              : 
    3521              : /*StencilOp (fail, zfail, zpass) -> none*/
    3522            0 : static int gl_stencil_op(lua_State *L)
    3523              : {
    3524              :    GLenum e1, e2, e3;
    3525              : 
    3526              :    /* test arguments type */
    3527            0 :    if( !(lua_isstring(L, 1) && lua_isstring(L, 2) && lua_isstring(L, 3) ))
    3528            0 :       luaL_error(L, "incorrect argument to function 'gl.StencilOp'");
    3529              : 
    3530            0 :    e1 = get_gl_enum(L, 1);
    3531            0 :    e2 = get_gl_enum(L, 2);
    3532            0 :    e3 = get_gl_enum(L, 3);
    3533              : 
    3534              :    /* test argument */
    3535            0 :    if(e1 == ENUM_ERROR || e2 == ENUM_ERROR || e3 == ENUM_ERROR)
    3536            0 :       luaL_error(L, "incorrect string argument to function 'gl.StencilOp'");
    3537              : 
    3538              :    /* call opengl function */
    3539            0 :    glStencilOp(e1, e2, e3);
    3540              : 
    3541            0 :    return 0;
    3542              : }
    3543              : 
    3544              : /*TexCoord (s[, t, r, q]) -> none
    3545              :   TexCoord (vArray) -> none*/
    3546            0 : static int gl_tex_coord(lua_State *L)
    3547              : {
    3548              :    int index;
    3549            0 :    int num_args = lua_gettop(L);
    3550              : 
    3551            0 :    GLdouble *v = 0;
    3552              : 
    3553              :    /* if more then 4 arguments, ignore the others */
    3554            0 :    if(num_args > 4)
    3555            0 :       num_args = 4;
    3556              : 
    3557              :    /* if have there's no arguments show an error message */
    3558            0 :    if(num_args == 0)
    3559            0 :       luaL_error(L, "incorrect argument to function 'gl.TexCoord'");
    3560              : 
    3561              :    /* test argument type */
    3562            0 :    if(lua_istable(L, 1))
    3563            0 :       num_args = get_arrayd(L, 1, &v);
    3564              : 
    3565              :    else
    3566              :    {
    3567            0 :       v = (GLdouble *)malloc(num_args * sizeof(GLdouble));
    3568              : 
    3569              :       /* get arguments */
    3570            0 :       for(index = 0; index < num_args; index++)
    3571              :       {
    3572              :          /* test arguments type */
    3573            0 :          if(!lua_isnumber(L, index + 1))
    3574            0 :             luaL_error(L, "incorrect argument to function 'gl.TexCoord'");
    3575              : 
    3576              :          /* get argument */
    3577            0 :          v[index] = lua_tonumber(L, index + 1);
    3578            0 :       }
    3579              :    }
    3580              : 
    3581              :    /* call openGL functions */
    3582            0 :    switch(num_args)
    3583              :    {
    3584            0 :       case 1:  glTexCoord1dv((GLdouble *)v);  break;
    3585            0 :       case 2:  glTexCoord2dv((GLdouble *)v);  break;
    3586            0 :       case 3:  glTexCoord3dv((GLdouble *)v);  break;
    3587            0 :       case 4:  glTexCoord4dv((GLdouble *)v);  break;
    3588            0 :       default: break;
    3589              :    }
    3590              : 
    3591            0 :    free(v);
    3592              : 
    3593            0 :    return 0;
    3594              : }
    3595              : 
    3596              : /*TexCoordPointer(vArray) -> none*/
    3597            0 : static int gl_tex_coord_pointer(lua_State *L)
    3598              : {
    3599              :    GLint size;
    3600              :    static GLdouble *array = 0;
    3601              : 
    3602            0 :    if(array)
    3603            0 :       free(array);
    3604              : 
    3605              :    /* test arguments type */
    3606            0 :    if(!lua_istable(L, 1))
    3607            0 :       luaL_error(L, "incorrect argument to function 'gl.TexCoordPointer'");
    3608              : 
    3609            0 :    if(lua_isnumber(L, 2))
    3610              :    {
    3611            0 :       size = (GLint)lua_tonumber(L, 2);
    3612            0 :       get_arrayd(L, 1, &array);
    3613            0 :    }
    3614            0 :    else if(get_array2d(L, 1, &array, &size) == -1)
    3615            0 :       luaL_error(L, "incorrect argument to function 'gl.TexCoordPointer'");
    3616              : 
    3617              :    /* call opengl function */
    3618            0 :    glTexCoordPointer(size, GL_DOUBLE, 0, array);
    3619              : 
    3620            0 :    return 0;
    3621              : }
    3622              : 
    3623              : /*TexEnv (pname, param) -> none
    3624              :   TexEnv (pname, paramsArray) -> none*/
    3625            0 : int static gl_tex_env(lua_State *L)
    3626              : {
    3627              :    GLfloat *param;
    3628              :    GLenum e;
    3629              : 
    3630              :    /* test arguments type */
    3631            0 :    if(!lua_isstring(L, 1))
    3632            0 :       luaL_error(L, "incorrect argument to function 'gl.TexEnv'");
    3633              : 
    3634              :    /* get string parameters */
    3635            0 :    e = get_gl_enum(L, 1);
    3636              : 
    3637              :    /* test argument */
    3638            0 :    if(e == ENUM_ERROR)
    3639            0 :       luaL_error(L, "incorrect string argument to function 'gl.TexEnv'");
    3640              : 
    3641            0 :    if(lua_istable(L, 2))
    3642              :    {
    3643            0 :       get_arrayf(L, 2, &param);
    3644              : 
    3645              :       /* call opengl function */
    3646            0 :       glTexEnvfv(GL_TEXTURE_ENV, e, (GLfloat *)param);
    3647              : 
    3648            0 :       free(param);
    3649            0 :    }
    3650            0 :    else if(lua_isnumber(L, 2))
    3651              :       /* call opengl function */
    3652            0 :       glTexEnvf(GL_TEXTURE_ENV, e, (GLfloat)lua_tonumber(L, 2));
    3653              : 
    3654            0 :    else if(lua_isstring(L, 2))
    3655              :       /* call opengl function */
    3656            0 :       glTexEnvi(GL_TEXTURE_ENV, e, get_gl_enum(L, 2));
    3657              : 
    3658              :    else
    3659            0 :       luaL_error(L, "incorrect argument to function 'gl.TexEnv'");
    3660              : 
    3661            0 :    return 0;
    3662              : }
    3663              : 
    3664              : /*TexGen (coord, pname, param) -> none
    3665              :   TexGen (coord, pname, paramsArray) -> none*/
    3666            0 : int static gl_tex_gen(lua_State *L)
    3667              : {
    3668              :    GLenum e1, e2;
    3669              :    GLdouble *param;
    3670              : 
    3671              :    /* test arguments type */
    3672            0 :    if(!( lua_isstring(L, 1) && lua_isstring(L, 2) ))
    3673            0 :       luaL_error(L, "incorrect argument to function 'gl.TexGen'");
    3674              : 
    3675              :    /* get string parameters */
    3676            0 :    e1 = get_gl_enum(L, 1);
    3677            0 :    e2 = get_gl_enum(L, 2);
    3678              : 
    3679              :    /* test argument */
    3680            0 :    if(e1 == ENUM_ERROR || e2 == ENUM_ERROR)
    3681            0 :       luaL_error(L, "incorrect string argument to function 'gl.TexGen'");
    3682              : 
    3683            0 :    if(lua_istable(L, 3))
    3684              :    {
    3685            0 :       get_arrayd(L, 3, &param);
    3686              : 
    3687              :       /* call opengl function */
    3688            0 :       glTexGendv(e1, e2, (GLdouble *)param);
    3689              : 
    3690            0 :       free(param);
    3691            0 :    }
    3692            0 :    else if(lua_isstring(L, 3))
    3693              :       /* call opengl function */
    3694            0 :       glTexGeni(e1, e2, get_gl_enum(L, 3));
    3695              : 
    3696              :    else
    3697            0 :       luaL_error(L, "incorrect argument to function 'gl.TexGen'");
    3698            0 :    return 0;
    3699              : }
    3700              : 
    3701              : /*TexImage(level, internalformat, format, pixels) -> none*/
    3702            0 : static int gl_tex_image(lua_State *L)
    3703              : {
    3704              :    GLenum e;
    3705              :    GLfloat *pixels;
    3706              :    GLsizei width, height;
    3707              :    int iformat;
    3708              : 
    3709              :    /* test arguments type */
    3710            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) &&
    3711            0 :          lua_isstring(L, 3) && lua_istable(L, 4) ))
    3712            0 :       luaL_error(L, "incorrect argument to function 'gl.TexImage'");
    3713              : 
    3714            0 :    e = get_gl_enum(L, 3);
    3715              : 
    3716              :    /* test argument */
    3717            0 :    if(e == ENUM_ERROR)
    3718            0 :       luaL_error(L, "incorrect string argument to function 'gl.TexImage'");
    3719              : 
    3720            0 :    iformat = (int)lua_tonumber(L, 2);
    3721              : 
    3722            0 :    if((height = get_array2f(L, 4, &pixels, &width)) != -1)
    3723              :    {
    3724            0 :       glTexImage2D(GL_TEXTURE_2D, (GLint)lua_tonumber(L, 1),
    3725            0 :                    iformat, width/iformat, height, 0, e, GL_FLOAT, pixels);
    3726            0 :       return 0;
    3727              :    }
    3728              :    else
    3729              :    {
    3730            0 :       width = get_arrayf(L, 4, &pixels);
    3731            0 :       glTexImage1D(GL_TEXTURE_1D, (GLint)lua_tonumber(L, 1),
    3732            0 :                    iformat, width/iformat, 0, e, GL_FLOAT, pixels);
    3733            0 :       return 0;
    3734              :    }
    3735            0 : }
    3736              : 
    3737              : /*TexSubImage (level, format, pixels, xoffset) -> none
    3738              :   TexSubImage (level, format, pixels, xoffset, yoffset) -> none*/
    3739            0 : static int gl_tex_sub_image(lua_State *L)
    3740              : {
    3741              :    GLenum format;
    3742              :    GLfloat *pixels;
    3743              :    GLsizei width, height;
    3744            0 :    int size = 1;
    3745              : 
    3746              :    /* test arguments type */
    3747            0 :    if(!( lua_isnumber(L, 1) && lua_isstring(L, 2) &&
    3748            0 :          lua_istable(L, 3) && lua_isnumber(L, 4) ))
    3749            0 :       luaL_error(L, "incorrect argument to function 'gl.TexSubImage'");
    3750              : 
    3751            0 :    format = get_gl_enum(L, 2);
    3752            0 :    switch(format)
    3753              :    {
    3754              :       case GL_COLOR_INDEX:
    3755              :       case GL_RED:
    3756              :       case GL_GREEN:
    3757              :       case GL_BLUE:
    3758              :       case GL_ALPHA:
    3759              :       case GL_LUMINANCE:
    3760            0 :          size = 1;
    3761            0 :          break;
    3762              : 
    3763              :       case GL_LUMINANCE_ALPHA:
    3764            0 :          size = 2;
    3765            0 :          break;
    3766              : 
    3767              :       case GL_RGB:
    3768              :       //case GL_BGR_EXT:
    3769            0 :          size = 3;
    3770            0 :          break;
    3771              : 
    3772              :       case GL_RGBA:
    3773              :       //case GL_BGRA_EXT:
    3774            0 :          size = 4;
    3775            0 :          break;
    3776              :    }
    3777              : 
    3778              :    /* test argument */
    3779            0 :    if(format == ENUM_ERROR)
    3780            0 :       luaL_error(L, "incorrect string argument to function 'gl.TexSubImage'");
    3781              : 
    3782            0 :    if((height = get_array2f(L, 3, &pixels, &width)) != -1)
    3783              :    {
    3784            0 :       glTexSubImage2D(GL_TEXTURE_2D, (GLint)lua_tonumber(L, 1), (GLint)lua_tonumber(L, 4),
    3785            0 :                       (GLint)lua_tonumber(L, 5), width/size, height, format, GL_FLOAT, pixels);
    3786            0 :       return 0;
    3787              :    }
    3788              :    else
    3789              :    {
    3790            0 :       width = get_arrayf(L, 3, &pixels);
    3791            0 :       glTexSubImage1D(GL_TEXTURE_1D, (GLint)lua_tonumber(L, 1), (GLint)lua_tonumber(L, 4),
    3792            0 :                       width/size, format, GL_FLOAT, pixels);
    3793            0 :       return 0;
    3794              :    }
    3795            0 : }
    3796              : 
    3797              : /*TexParameter (target, pname, param) -> none
    3798              :   TexParameter (target, pname, paramsArray) -> none*/
    3799            0 : static int gl_tex_parameter(lua_State *L)
    3800              : {
    3801              :    GLenum e1, e2;
    3802              :    GLfloat *param;
    3803              : 
    3804              :    /* test arguments type */
    3805            0 :    if(! (lua_isstring(L, 1) && lua_isstring(L, 2) ))
    3806            0 :       luaL_error(L, "incorrect argument to function 'gl.TexParameter'");
    3807              : 
    3808              :    /* get string parameters */
    3809            0 :    e1 = get_gl_enum(L, 1);
    3810            0 :    e2 = get_gl_enum(L, 2);
    3811              : 
    3812              :    /* test argument */
    3813            0 :    if(e1 == ENUM_ERROR || e2 == ENUM_ERROR)
    3814            0 :       luaL_error(L, "incorrect string argument to function 'gl.TexParameter'");
    3815              : 
    3816            0 :    if(lua_istable(L, 3))
    3817              :    {
    3818            0 :       get_arrayf(L, 3, &param);
    3819              : 
    3820              :       /* call opengl function */
    3821            0 :       glTexParameterfv(e1, e2, (GLfloat *)param);
    3822              : 
    3823            0 :       free(param);
    3824            0 :    }
    3825            0 :    else if(lua_isnumber(L, 3))
    3826              :    {
    3827              :       /* call opengl function */
    3828            0 :       glTexParameterf(e1, e2, (GLfloat)lua_tonumber(L, 3));
    3829            0 :    }
    3830            0 :    else if(lua_isstring(L, 3))
    3831              :    {
    3832              :       /* call opengl function */
    3833            0 :       glTexParameteri(e1, e2, get_gl_enum(L, 3));
    3834            0 :    }
    3835              :    else
    3836            0 :       luaL_error(L, "incorrect argument to function 'gl.TexParameter'");
    3837              : 
    3838            0 :    return 0;
    3839              : }
    3840              : 
    3841              : /*Translate (x, y, z) -> none*/
    3842            0 : static int gl_translate(lua_State *L)
    3843              : {
    3844              :    /* test arguments type */
    3845            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3) ))
    3846            0 :       luaL_error(L, "incorrect argument to function 'gl.Translate'");
    3847              : 
    3848              :    /* call opengl function */
    3849            0 :    glTranslated((GLdouble)lua_tonumber(L, 1), (GLdouble)lua_tonumber(L, 2),
    3850            0 :                 (GLdouble)lua_tonumber(L, 3));
    3851              : 
    3852            0 :    return 0;
    3853              : }
    3854              : 
    3855              : /*Vertex (x, y, [z, w]) -> none
    3856              :   Vertex (v) -> none*/
    3857            0 : static int gl_vertex(lua_State *L)
    3858              : {
    3859              :    int index;
    3860            0 :    int num_args = lua_gettop(L);
    3861              : 
    3862              :    GLdouble *v;
    3863              : 
    3864              :    /* if have there's no arguments show an error message */
    3865            0 :    if(num_args == 0)
    3866            0 :       luaL_error(L, "incorrect argument to function 'gl.Vertex'");
    3867              : 
    3868              :    /* test argument type */
    3869            0 :    if(lua_istable(L, 1))
    3870            0 :       num_args = get_arrayd(L, 1, &v);
    3871              : 
    3872              :    else
    3873              :    {
    3874              :       /* test number of arguments */
    3875            0 :       if(num_args < 2)
    3876            0 :          luaL_error(L, "incorrect argument to function 'gl.Vertex'");
    3877              : 
    3878            0 :       v = (GLdouble *)malloc(num_args * sizeof(GLdouble));
    3879              : 
    3880              :       /* get arguments */
    3881            0 :       for(index = 0; index < num_args; index++)
    3882              :       {
    3883              :          /* test arguments type */
    3884            0 :          if(!lua_isnumber(L, index + 1))
    3885            0 :             luaL_error(L, "incorrect argument to function 'gl.Vertex'");
    3886              : 
    3887              :          /* get argument */
    3888            0 :          v[index] = (GLdouble)lua_tonumber(L, index + 1);
    3889            0 :       }
    3890              :    }
    3891              : 
    3892              :    /* if more then 4 arguments, ignore the others */
    3893            0 :    if(num_args > 4)
    3894            0 :       num_args = 4;
    3895              : 
    3896              :    /* call openGL functions */
    3897            0 :    switch(num_args)
    3898              :    {
    3899            0 :       case 2:  glVertex2dv((GLdouble *)v);  break;
    3900            0 :       case 3:  glVertex3dv((GLdouble *)v);  break;
    3901            0 :       case 4:  glVertex4dv((GLdouble *)v);  break;
    3902              :    }
    3903              : 
    3904            0 :    free(v);
    3905              : 
    3906            0 :    return 0;
    3907              : }
    3908              : 
    3909              : /*VertexPointer (vertexArray) -> none*/
    3910            0 : static int gl_vertex_pointer(lua_State *L)
    3911              : {
    3912              :    GLint size;
    3913              :    static GLdouble *array = 0;
    3914              : 
    3915            0 :    if(array)
    3916            0 :       free(array);
    3917              : 
    3918              :    /* test arguments type */
    3919            0 :    if(!lua_istable(L, 1))
    3920            0 :       luaL_error(L, "incorrect argument to function 'gl.VertexPointer'");
    3921              : 
    3922            0 :    if(lua_isnumber(L, 2))
    3923              :    {
    3924            0 :       size = (GLint)lua_tonumber(L, 2);
    3925            0 :       get_arrayd(L, 1, &array);
    3926            0 :    }
    3927            0 :    else if(get_array2d(L, 1, &array, &size) == -1)
    3928              :    {
    3929            0 :       luaL_error(L, "incorrect argument to function 'gl.VertexPointer'");
    3930            0 :       return 0;
    3931              :    }
    3932              : 
    3933              :    /* call opengl function */
    3934            0 :    glVertexPointer(size, GL_DOUBLE, 0, array);
    3935              : 
    3936            0 :    return 0;
    3937            0 : }
    3938              : 
    3939              : /*Viewport (x, y, width, height) -> none*/
    3940            0 : static int gl_viewport(lua_State *L)
    3941              : {
    3942              :    /* test arguments type */
    3943            0 :    if(!( lua_isnumber(L, 1) && lua_isnumber(L, 2) &&
    3944            0 :          lua_isnumber(L, 3) && lua_isnumber(L, 4) ))
    3945            0 :       luaL_error(L, "incorrect argument to function 'gl.Viewport'");
    3946              : 
    3947              :    /* call openGL function */
    3948            0 :    glViewport((GLint)lua_tonumber(L, 1), (GLint)lua_tonumber(L, 2),
    3949            0 :               (GLsizei)lua_tonumber(L, 3), (GLsizei)lua_tonumber(L, 4));
    3950              : 
    3951            0 :    return 0;
    3952              : }
    3953              : 
    3954              : static const luaL_Reg gllib[] = {
    3955              :   {"Accum", gl_accum},
    3956              :   {"AlphaFunc", gl_alpha_func},
    3957              :   {"AreTexturesResident", gl_are_textures_resident},
    3958              :   {"ArrayElement", gl_array_element},
    3959              :   {"Begin", gl_begin},
    3960              :   {"BindTexture", gl_bind_texture},
    3961              :   {"Bitmap", gl_bitmap},
    3962              :   {"BlendFunc", gl_blend_func},
    3963              :   {"CallList", gl_call_list},
    3964              :   {"CallLists", gl_call_lists},
    3965              :   {"Clear", gl_clear},
    3966              :   {"ClearAccum", gl_clear_accum},
    3967              :   {"ClearColor", gl_clear_color},
    3968              :   {"ClearDepth", gl_clear_depth},
    3969              :   {"ClearIndex", gl_clear_index},
    3970              :   {"ClearStencil", gl_clear_stencil},
    3971              :   {"ClipPlane", gl_clip_plane},
    3972              :   {"Color", gl_color},
    3973              :   {"ColorMask", gl_color_mask},
    3974              :   {"ColorMaterial", gl_color_material},
    3975              :   {"ColorPointer", gl_color_pointer},
    3976              :   {"CopyPixels", gl_copy_pixels},
    3977              :   {"CopyTexImage", gl_copy_tex_image},
    3978              :   {"CopyTexSubImage", gl_copy_tex_sub_image},
    3979              :   {"CullFace",gl_cull_face},
    3980              :   {"DeleteLists",gl_delete_lists},
    3981              :   {"DeleteTextures",gl_delete_textures},
    3982              :   {"DepthFunc",gl_depth_func},
    3983              :   {"DepthMask",gl_depth_mask},
    3984              :   {"DepthRange",gl_depth_range},
    3985              :   {"Disable",gl_disable},
    3986              :   {"DisableClientState",gl_disable_client_state},
    3987              :   {"DrawArrays",gl_draw_arrays},
    3988              :   {"DrawBuffer",gl_draw_buffer},
    3989              :   {"DrawElements", gl_draw_elements},
    3990              :   {"DrawPixels", gl_draw_pixels},
    3991              :   {"EdgeFlag", gl_edge_flag},
    3992              :   {"EdgeFlagPointer", gl_edge_flag_pointer},
    3993              :   {"Enable", gl_enable},
    3994              :   {"EnableClientState", gl_enable_client_state},
    3995              :   {"End", gl_end},
    3996              :   {"EndList", gl_end_list},
    3997              :   {"EvalCoord", gl_eval_coord},
    3998              :   {"EvalMesh", gl_eval_mesh},
    3999              :   {"EvalPoint", gl_eval_point},
    4000              :   {"FeedbackBuffer", gl_feedback_buffer},
    4001              :   {"Finish", gl_finish},
    4002              :   {"Flush", gl_flush},
    4003              :   {"Fog", gl_fog},
    4004              :   {"FrontFace", gl_front_face},
    4005              :   {"Frustum", gl_frustum},
    4006              :   {"GenLists", gl_gen_lists},
    4007              :   {"GenTextures", gl_gen_textures},
    4008              :   {"Get", gl_get},
    4009              :   {"GetArray", gl_get_array},
    4010              :   {"GetConst", gl_get_const},
    4011              :   {"GetClipPlane", gl_get_clip_plane},
    4012              :   {"GetError", gl_get_error},
    4013              :   {"GetLight", gl_get_light},
    4014              :   {"GetMap", gl_get_map},
    4015              :   {"GetMaterial", gl_get_material},
    4016              :   {"GetPixelMap", gl_get_pixel_map},
    4017              :   {"GetPointer", gl_get_pointer},
    4018              :   {"GetPolygonStipple", gl_get_polygon_stipple},
    4019              :   {"GetString", gl_get_string},
    4020              :   {"GetTexEnv", gl_get_tex_env},
    4021              :   {"GetTexGen", gl_get_tex_gen},
    4022              :   {"GetTexImage", gl_get_tex_image},
    4023              :   {"GetTexLevelParameter", gl_get_tex_level_parameter},
    4024              :   {"GetTexParameter", gl_get_tex_parameter},
    4025              :   {"Hint", gl_hint},
    4026              :   {"Index", gl_index},
    4027              :   {"IndexMask", gl_index_mask},
    4028              :   {"IndexPointer", gl_index_pointer},
    4029              :   {"InitNames", gl_init_names},
    4030              :   {"IsEnabled", gl_is_enabled},
    4031              :   {"IsList", gl_is_list},
    4032              :   {"IsTexture", gl_is_texture},
    4033              :   {"Light", gl_light},
    4034              :   {"LightModel", gl_light_model},
    4035              :   {"LineStipple", gl_line_stipple},
    4036              :   {"LineWidth", gl_line_width},
    4037              :   {"ListBase", gl_list_base},
    4038              :   {"LoadIdentity", gl_load_identity},
    4039              :   {"LoadMatrix", gl_load_matrix},
    4040              :   {"LoadName", gl_load_name},
    4041              :   {"LogicOp", gl_logic_op},
    4042              :   {"Map", gl_map},
    4043              :   {"MapGrid", gl_map_grid},
    4044              :   {"Material", gl_material},
    4045              :   {"MatrixMode", gl_matrix_mode},
    4046              :   {"MultMatrix", gl_mult_matrix},
    4047              :   {"NewList", gl_new_list},
    4048              :   {"Normal", gl_normal},
    4049              :   {"NormalPointer", gl_normal_pointer},
    4050              :   {"Ortho", gl_ortho},
    4051              :   {"PassThrough", gl_pass_through},
    4052              :   {"PixelMap", gl_pixel_map},
    4053              :   {"PixelStore", gl_pixel_store},
    4054              :   {"PixelTransfer", gl_pixel_transfer},
    4055              :   {"PixelZoom", gl_pixel_zoom},
    4056              :   {"PointSize", gl_point_size},
    4057              :   {"PolygonMode", gl_polygon_mode},
    4058              :   {"PolygonOffset", gl_polygon_offset},
    4059              :   {"PolygonStipple", gl_polygon_stipple},
    4060              :   {"PopAttrib", gl_pop_attrib},
    4061              :   {"PopClientAttrib", gl_pop_client_attrib},
    4062              :   {"PopMatrix", gl_pop_matrix},
    4063              :   {"PopName", gl_pop_name},
    4064              :   {"PrioritizeTextures", gl_prioritize_textures},
    4065              :   {"PushAttrib", gl_push_attrib},
    4066              :   {"PushClientAttrib", gl_push_client_attrib},
    4067              :   {"PushMatrix", gl_push_matrix},
    4068              :   {"PushName", gl_push_name},
    4069              :   {"RasterPos", gl_raster_pos},
    4070              :   {"ReadBuffer", gl_read_buffer},
    4071              :   {"ReadPixels", gl_read_pixels},
    4072              :   {"Rect", gl_rect},
    4073              :   {"RenderMode", gl_render_mode},
    4074              :   {"Rotate", gl_rotate},
    4075              :   {"Scale", gl_scale},
    4076              :   {"Scissor", gl_scissor},
    4077              :   {"SelectBuffer", gl_select_buffer},
    4078              :   {"ShadeModel", gl_shade_model},
    4079              :   {"StencilFunc", gl_stencil_func},
    4080              :   {"StencilMask", gl_stencil_mask},
    4081              :   {"StencilOp", gl_stencil_op},
    4082              :   {"TexCoord", gl_tex_coord},
    4083              :   {"TexCoordPointer", gl_tex_coord_pointer},
    4084              :   {"TexEnv", gl_tex_env},
    4085              :   {"TexGen", gl_tex_gen},
    4086              :   {"TexImage", gl_tex_image},
    4087              :   {"TexSubImage", gl_tex_sub_image},
    4088              :   {"TexParameter", gl_tex_parameter},
    4089              :   {"Translate", gl_translate},
    4090              :   {"Vertex", gl_vertex},
    4091              :   {"VertexPointer", gl_vertex_pointer},
    4092              :   {"Viewport", gl_viewport},
    4093              :   {NULL, NULL}
    4094              : };
    4095              : 
    4096            9 : int luaopen_opengl (lua_State *L) {
    4097            9 :   luaL_openlib(L, "gl", gllib, 0);
    4098            9 :   return 1;
    4099              : }
        

Generated by: LCOV version 2.4-0