示例#1
0
static int l_graphics_Image_setWrap(lua_State* state) {
  l_assertType(state, 1, l_graphics_isImage);

  l_graphics_Image* img = l_graphics_toImage(state, 1);
  graphics_Wrap wrap;
  wrap.horMode = l_tools_toEnumOrError(state, 2, l_graphics_WrapMode);
  wrap.verMode = l_tools_toEnumOrError(state, 3, l_graphics_WrapMode);

  graphics_Image_setWrap(&img->image, &wrap);

  return 0;
}
示例#2
0
static int l_graphics_Font_setFilter(lua_State* state) {
  l_assertType(state, 1, l_graphics_isFont);

  graphics_Font* font = l_graphics_toFont(state, 1);
  graphics_Filter newFilter;
  graphics_Font_getFilter(font, &newFilter);
  newFilter.minMode = l_tools_toEnumOrError(state, 2, l_graphics_FilterMode);
  newFilter.magMode = l_tools_toEnumOrError(state, 3, l_graphics_FilterMode);
  newFilter.maxAnisotropy = luaL_optnumber(state, 4, 1.0f);
  graphics_Font_setFilter(font, &newFilter);

  return 0;
}
示例#3
0
static int l_graphics_Image_setFilter(lua_State* state) {
  l_assertType(state, 1, l_graphics_isImage);

  l_graphics_Image* img = l_graphics_toImage(state, 1);
  graphics_Filter newFilter;
  graphics_Image_getFilter(&img->image, &newFilter);
  newFilter.minMode = l_tools_toEnumOrError(state, 2, l_graphics_FilterMode);
  newFilter.magMode = l_tools_toEnumOrError(state, 3, l_graphics_FilterMode);
  newFilter.maxAnisotropy = luaL_optnumber(state, 4, 1.0f);
  graphics_Image_setFilter(&img->image, &newFilter);

  return 0;
}
示例#4
0
static int l_graphics_printf(lua_State* state) {
  if(!moduleData.currentFont) {
    l_graphics_loadDefaultFont();
  }

  char const* text = lua_tostring(state, 1);
  if(!text) {
    lua_pushstring(state, "string or number required");
    return lua_error(state);
  }
  int x = l_tools_toNumberOrError(state, 2);
  int y = l_tools_toNumberOrError(state, 3);
  int limit = l_tools_toNumberOrError(state, 4);
  // TODO
  graphics_TextAlign align = graphics_TextAlign_left;
  if(!lua_isnoneornil(state, 5)) {
    align = l_tools_toEnumOrError(state, 5, l_graphics_AlignMode);
  }

  float r = luaL_optnumber(state, 6, 0);
  float sx = luaL_optnumber(state, 7, 1.0f);
  float sy = luaL_optnumber(state, 8, sx);
  float ox = luaL_optnumber(state, 9, 0);
  float oy = luaL_optnumber(state, 10, 0);
  float kx = luaL_optnumber(state, 11, 0);
  float ky = luaL_optnumber(state, 12, 0);

  graphics_Font_printf(moduleData.currentFont, text, x, y, limit, align, r, sx, sy, ox, oy, kx, ky);

  return 0;
}
示例#5
0
文件: audio.c 项目: ezhangle/motor
static int l_audio_newSource(lua_State *state) {
  char const* filename = l_tools_toStringOrError(state, 1);

  audio_SourceType type = audio_SourceType_stream;
  if(!lua_isnoneornil(state, 2)) {
    type = l_tools_toEnumOrError(state, 2, l_audio_SourceType);
  }

  // TODO handle load errors
  switch(type) {
  case audio_SourceType_static:
    {
      audio_StaticSource *src = lua_newuserdata(state, sizeof(audio_StaticSource));
      audio_loadStatic(src, filename);
      lua_rawgeti(state, LUA_REGISTRYINDEX, moduleData.staticMT);
      break;
    }

  case audio_SourceType_stream:
    {
      audio_StreamSource *src = lua_newuserdata(state, sizeof(audio_StreamSource));
      audio_loadStream(src, filename);
      lua_rawgeti(state, LUA_REGISTRYINDEX, moduleData.streamMT);
      break;
    }
  }
  

  lua_setmetatable(state, -2);

  return 1;
}
示例#6
0
static int l_graphics_Mesh_setDrawMode(lua_State *state) {
  l_assertType(state, 1, l_graphics_isMesh);
  l_graphics_Mesh *mesh = l_graphics_toMesh(state, 1);
  
  graphics_MeshDrawMode mode = l_tools_toEnumOrError(state, 2, l_graphics_MeshDrawMode);

  graphics_Mesh_setDrawMode(&mesh->mesh, mode);
  return 0;
}
示例#7
0
static int l_graphics_newMesh(lua_State* state) {
  bool useVertexColor;
  size_t count = readVertices(state, &useVertexColor, 1);
  graphics_Image const* texture = l_graphics_toTextureOrError(state, 2);
  graphics_MeshDrawMode mode = l_tools_toEnumOrError(state, 3, l_graphics_MeshDrawMode);

  l_graphics_Mesh* mesh = lua_newuserdata(state, sizeof(l_graphics_Mesh));
  graphics_Mesh_new(&mesh->mesh, count, (graphics_Vertex*)moduleData.buffer, texture, mode, useVertexColor);

  lua_pushvalue(state, 2);
  mesh->textureRef = luaL_ref(state, LUA_REGISTRYINDEX);

  lua_rawgeti(state, LUA_REGISTRYINDEX, moduleData.meshMT);
  lua_setmetatable(state, -2);
  return 1;
}
示例#8
0
static int l_graphics_Image_setMipmapFilter(lua_State* state) {
  l_assertType(state, 1, l_graphics_isImage);

  l_graphics_Image* img = l_graphics_toImage(state, 1);

  graphics_Filter newFilter;
  graphics_Image_getFilter(&img->image, &newFilter);

  if(lua_isnoneornil(state, 2)) {
      newFilter.mipmapMode  = graphics_FilterMode_none;
      newFilter.mipmapLodBias = 0.0f;
    } else {
      newFilter.mipmapMode  = l_tools_toEnumOrError(state, 2, l_graphics_FilterMode);
      // param 2 is supposed to be "sharpness", which is exactly opposite to LOD,
      // therefore we use the negative value
      newFilter.mipmapLodBias = -luaL_optnumber(state, 3, 0.0f);
    }
  graphics_Image_setFilter(&img->image, &newFilter);

  return 0;
}