Beispiel #1
0
/*glu.ScaleImage(format, widthin, heightin, pixelsArrayin, widthout, heightout) -> error, pixelsArrayout */
static int luaglu_scaleimage(lua_State *L)
{
  GLenum format;
  GLfloat *pixelsin, *pixelsout;
  int widthout, heightout, sizeout, depth, error;

  format = luagl_get_gl_enum(L, 1);
  depth = luaglu_get_depth(format);
  if (depth == 0)
    luaL_argerror(L, 1, "unknown format");

  luagl_get_arrayf(L, 4, &pixelsin);

  widthout = luaL_checkinteger(L, 5);
  heightout = luaL_checkinteger(L, 6);
  sizeout = widthout*heightout*depth;

  pixelsout = LUAGL_NEW_ARRAY(GLfloat, sizeout);

  error = gluScaleImage(format, luaL_checkinteger(L, 2), luaL_checkinteger(L, 3), GL_FLOAT, pixelsin,
                                widthout, heightout, GL_FLOAT, pixelsout);
  lua_pushnumber(L, error);

  if (error == 0)
    luagl_push_arrayf(L, pixelsout, sizeout);
  else
    lua_pushnil(L);

  LUAGL_DELETE_ARRAY(pixelsin);
  LUAGL_DELETE_ARRAY(pixelsout);

  return 2;
}
Beispiel #2
0
/* PickMatrix( x, y, deltax, deltay, viewportArray) -> none */
static int luaglu_pick_matrix(lua_State *L)
{
  GLint *vp;
  int num_args;

  if (!( lua_isnumber(L, 1) && lua_isnumber(L, 2) && lua_isnumber(L, 3)
    && lua_isnumber(L, 4)))
  {
    luaL_error(L, "incorrect argument to function 'glu.PickMatrix'");
    return 0;
  }

  if(!lua_istable(L, 5) || (num_args = luagl_get_arrayi(L, 5, &vp)) < 4)
  {
    luaL_error(L, "incorrect argument to function 'glu.PickMatrix'");
    return 0;
  }

  gluPickMatrix(
    (GLdouble)lua_tonumber(L, 1), (GLdouble)lua_tonumber(L, 2), (GLdouble)lua_tonumber(L, 3),
    (GLdouble)lua_tonumber(L, 4), vp);

  LUAGL_DELETE_ARRAY(vp);

  return 0;
}
Beispiel #3
0
/* nurb:PwlCurve (dataArray, type) -> nurb */
static int luaglu_pwl_curve(lua_State *L)
{
  LuaGLUnurb *lnurb=luaglu_checknurb(L,1);
  GLint ptsCount=0;
  GLint stride;
  GLfloat *points;
  int size=1;
  GLenum e;

  e = luaglu_get_gl_enum(L, 3);

  switch(e)
  {
  case GL_MAP1_INDEX:
  case GL_MAP2_INDEX:
  case GL_MAP1_TEXTURE_COORD_1:
  case GL_MAP2_TEXTURE_COORD_1:
    size = 1;
    break;
  case GLU_MAP1_TRIM_2:
  case GL_MAP1_TEXTURE_COORD_2:
  case GL_MAP2_TEXTURE_COORD_2:
    size = 2;
    break;
  case GLU_MAP1_TRIM_3:
  case GL_MAP1_VERTEX_3:
  case GL_MAP2_VERTEX_3:
  case GL_MAP1_NORMAL:
  case GL_MAP2_NORMAL:
  case GL_MAP1_TEXTURE_COORD_3:
  case GL_MAP2_TEXTURE_COORD_3:
    size = 3;
    break;
  case GL_MAP1_VERTEX_4:
  case GL_MAP2_VERTEX_4:
  case GL_MAP1_COLOR_4:
  case GL_MAP2_COLOR_4:
  case GL_MAP1_TEXTURE_COORD_4:
  case GL_MAP2_TEXTURE_COORD_4:
    size = 4;
    break;
  }

  ptsCount=luagl_get_arrayf(L, 2, &points);
  ptsCount/=size;
  stride=size;

  gluPwlCurve (lnurb->nurb,ptsCount,points,stride,e);

  LUAGL_DELETE_ARRAY(points);

  lua_pushvalue(L,1);
  return 1;
}
Beispiel #4
0
/* PickMatrix( x, y, deltax, deltay, viewportArray) -> none */
static int luaglu_pick_matrix(lua_State *L)
{
  GLint *vp;
  int n;

  n = luagl_get_arrayi(L, 5, &vp);
  if (n < 4)
    luaL_argerror(L, 5, "invalid number of elements in the matrix table (n<4).");

  gluPickMatrix(luaL_checknumber(L, 1), luaL_checknumber(L, 2), 
                luaL_checknumber(L, 3), luaL_checknumber(L, 4), vp);

  LUAGL_DELETE_ARRAY(vp);

  return 0;
}
Beispiel #5
0
/*or BuildMipmaps(textureData) -> error */
static int luaglu_build_2d_mipmaps(lua_State *L)
{
  if (lua_isnumber(L, 1))
  {
    lua_pushnumber(L, gluBuild2DMipmaps(GL_TEXTURE_2D, (GLint)luaL_checkinteger(L, 1), luaL_checkinteger(L, 2), luaL_checkinteger(L, 3), 
                 luagl_get_gl_enum(L, 4), luagl_get_gl_enum(L, 5), luagl_checkuserdata(L, 6)));
  }
  else
  {
    /* Old form, using only one table */
    GLenum target, format, type;
    GLubyte *pixels;
    GLint internalFormat;
    GLsizei width, height, w, h;

    h = luagl_get_array2uc(L, 1, &pixels, &w);
    if (h==-1)
      luaL_argerror(L, 1, "must be a 2D array");

    lua_getfield(L, 1, "target");  target = luagl_get_gl_enum(L, -1);  lua_remove(L, -1);
    lua_getfield(L, 1, "format");  format = luagl_get_gl_enum(L, -1);  lua_remove(L, -1);
    lua_getfield(L, 1, "type");    type   = luagl_get_gl_enum(L, -1);  lua_remove(L, -1);
    lua_getfield(L, 1, "width");   width  = (GLsizei)luaL_checkinteger(L, -1);  lua_remove(L, -1);
    lua_getfield(L, 1, "height");  height = (GLsizei)luaL_checkinteger(L, -1);  lua_remove(L, -1);
    lua_getfield(L, 1, "components");  internalFormat = (GLint)luaL_checkinteger(L, -1);  lua_remove(L, -1);

    w /= internalFormat;

    if (width > w)
      width = w;

    if (height > h)
      height = h;

    lua_pushnumber(L, gluBuild2DMipmaps(target, internalFormat, width, height, format, type, pixels));

    LUAGL_DELETE_ARRAY(pixels);
  }
  return 1;
}
Beispiel #6
0
/*Build2DMipmaps(textureData) -> error */
static int luaglu_build_2d_mipmaps(lua_State *L)
{
  GLenum target, format, type;
  GLubyte *pixels;
  GLint internalFormat;
  GLsizei width, height, w, h;
  int result;

  if(!lua_istable(L, 1))
    LUAGL_SHOWERROR("incorrect argument to function 'glu.Build2DMipmaps'");

  lua_pushstring(L, "target");  lua_gettable(L, 1);  target = luaglu_get_gl_enum(L, -1);  lua_pop(L, 1);
  lua_pushstring(L, "format");  lua_gettable(L, 1);  format = luaglu_get_gl_enum(L, -1);  lua_pop(L, 1);
  lua_pushstring(L, "type");    lua_gettable(L, 1);  type   = luaglu_get_gl_enum(L, -1);  lua_pop(L, 1);
  lua_pushstring(L, "width");   lua_gettable(L, 1);  width  = (GLsizei)lua_tonumber(L, -1);  lua_pop(L, 1);
  lua_pushstring(L, "height");  lua_gettable(L, 1);  height = (GLsizei)lua_tonumber(L, -1);  lua_pop(L, 1);
  lua_pushstring(L, "components");  lua_gettable(L, 1);  internalFormat = (GLint)lua_tonumber(L, -1);  lua_pop(L, 1);

  h = luagl_get_array2ubyte(L, 1, &pixels, &w);

  w /= internalFormat;

  if (width > w)
    width = w;

  if (height > h)
    height = h;

  result = gluBuild2DMipmaps(target, internalFormat, width,
    height, format, type, pixels);

  LUAGL_DELETE_ARRAY(pixels);

  lua_pushnumber(L, result);

  return 1;
}
Beispiel #7
0
/*BuildMipmaps(components, format, pixelsArray) -> error */
static int luaglu_build_mipmaps(lua_State *L)
{
  GLubyte *pixels;
  GLsizei width, height;
  int components;

  components = luaL_checkinteger(L, 1);
  height = luagl_get_array2uc(L, 3, &pixels, &width);

  if (height != -1)
  {
    lua_pushnumber(L, gluBuild2DMipmaps(GL_TEXTURE_2D, components, width/components, height, 
                 luagl_get_gl_enum(L, 2), GL_UNSIGNED_BYTE, pixels));
  }
  else
  {
    /* if not 2D, get 1D */
    width = luagl_get_arrayuc(L, 3, &pixels);
    lua_pushnumber(L, gluBuild1DMipmaps(GL_TEXTURE_1D, components, width/components, 
                 luagl_get_gl_enum(L, 2), GL_UNSIGNED_BYTE, pixels));
  }
  LUAGL_DELETE_ARRAY(pixels);
  return 1;
}
Beispiel #8
0
/* nurb:Surface (sKnotsArray, tKnotsArray, controlArray, type) -> nurb */
static int luaglu_nurbs_surface(lua_State *L) 
{
  LuaGLUnurb *lnurb=luaglu_checknurb(L,1);
  GLint sKnotCount=0;
  GLint tKnotCount=0;
  GLfloat *sKnots;
  GLfloat *tKnots;
  GLint sStride,tStride;
  GLint sPtsCount,tPtsCount;
  GLfloat *points;
  GLint sOrder,tOrder;
  GLenum e;
  int size=1;

  e = luaglu_get_gl_enum(L, 5);

  switch(e)
  {
  case GL_MAP1_INDEX:
  case GL_MAP2_INDEX:
  case GL_MAP1_TEXTURE_COORD_1:
  case GL_MAP2_TEXTURE_COORD_1:
    size = 1;
    break;
  case GLU_MAP1_TRIM_2:
  case GL_MAP1_TEXTURE_COORD_2:
  case GL_MAP2_TEXTURE_COORD_2:
    size = 2;
    break;
  case GLU_MAP1_TRIM_3:
  case GL_MAP1_VERTEX_3:
  case GL_MAP2_VERTEX_3:
  case GL_MAP1_NORMAL:
  case GL_MAP2_NORMAL:
  case GL_MAP1_TEXTURE_COORD_3:
  case GL_MAP2_TEXTURE_COORD_3:
    size = 3;
    break;
  case GL_MAP1_VERTEX_4:
  case GL_MAP2_VERTEX_4:
  case GL_MAP1_COLOR_4:
  case GL_MAP2_COLOR_4:
  case GL_MAP1_TEXTURE_COORD_4:
  case GL_MAP2_TEXTURE_COORD_4:
    size = 4;
    break;
  }

  sKnotCount=luagl_get_arrayf(L, 2, &sKnots);
  tKnotCount=luagl_get_arrayf(L, 3, &tKnots);
  tPtsCount = luagl_get_array2f(L, 4, &points, &sPtsCount);
  sPtsCount /= size;

  if (tPtsCount==-1)
  {
    LUAGL_DELETE_ARRAY(sKnots);
    LUAGL_DELETE_ARRAY(tKnots);
    luaL_argerror(L, 4, "must be a table of tables");
  }

  sStride=size;
  tStride=size*sPtsCount;

  sOrder=sKnotCount-sPtsCount;
  tOrder=tKnotCount-tPtsCount;
  
  if (sOrder<1 || tOrder<1)
  {
    LUAGL_DELETE_ARRAY(sKnots);
    LUAGL_DELETE_ARRAY(tKnots);
    LUAGL_DELETE_ARRAY(points);
    luaL_error(L,"incorrect order");
  }

  gluNurbsSurface (lnurb->nurb,sKnotCount,sKnots,tKnotCount,tKnots,sStride,tStride,points,sOrder,tOrder,e); 

  LUAGL_DELETE_ARRAY(sKnots);
  LUAGL_DELETE_ARRAY(tKnots);
  LUAGL_DELETE_ARRAY(points);

  lua_pushvalue(L,1);
  return 1;
}
Beispiel #9
0
/* nurb:Curve (knotsArray, controlArray, type) -> nurb */
static int luaglu_nurbs_curve(lua_State *L)
{
  LuaGLUnurb *lnurb=luaglu_checknurb(L,1);
  GLint ptsCount=0;
  GLint knotCount=0;
  GLfloat *knots;
  GLint stride;
  GLfloat *points;
  GLint order;
  int size=1;
  GLenum e;

  e = luaglu_get_gl_enum(L, 4);

  switch(e)
  {
  case GL_MAP1_INDEX:
  case GL_MAP2_INDEX:
  case GL_MAP1_TEXTURE_COORD_1:
  case GL_MAP2_TEXTURE_COORD_1:
    size = 1;
    break;
  case GLU_MAP1_TRIM_2:
  case GL_MAP1_TEXTURE_COORD_2:
  case GL_MAP2_TEXTURE_COORD_2:
    size = 2;
    break;
  case GLU_MAP1_TRIM_3:
  case GL_MAP1_VERTEX_3:
  case GL_MAP2_VERTEX_3:
  case GL_MAP1_NORMAL:
  case GL_MAP2_NORMAL:
  case GL_MAP1_TEXTURE_COORD_3:
  case GL_MAP2_TEXTURE_COORD_3:
    size = 3;
    break;
  case GL_MAP1_VERTEX_4:
  case GL_MAP2_VERTEX_4:
  case GL_MAP1_COLOR_4:
  case GL_MAP2_COLOR_4:
  case GL_MAP1_TEXTURE_COORD_4:
  case GL_MAP2_TEXTURE_COORD_4:
    size = 4;
    break;
  }

  knotCount=luagl_get_arrayf(L, 2, &knots);
  ptsCount=luagl_get_arrayf(L, 3, &points);

  ptsCount/=size;
  stride=size;

  order=knotCount-ptsCount;

  if(order<1)
  {
    LUAGL_DELETE_ARRAY(knots);
    LUAGL_DELETE_ARRAY(points);
    luaL_error(L,"incorrect order (<1)");
  }

  gluNurbsCurve (lnurb->nurb,knotCount,knots,stride,points,order,e);

  LUAGL_DELETE_ARRAY(knots);
  LUAGL_DELETE_ARRAY(points);

  lua_pushvalue(L,1);
  return 1;
}