MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / Material

Method Material

src/lua/LuaOpenGL.cpp:1272–1333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1270
1271
1272int LuaOpenGL::Material(lua_State* L) {
1273 CheckDrawingEnabled(L, __FUNCTION__);
1274
1275 const int args = lua_gettop(L);
1276 if ((args != 1) || !lua_istable(L, 1)) {
1277 luaL_error(L, "Incorrect arguments to gl.Material(table)");
1278 }
1279
1280 fvec4 color;
1281
1282 const int table = lua_gettop(L);
1283 for (lua_pushnil(L); lua_next(L, table) != 0; lua_pop(L, 1)) {
1284 if (!lua_israwstring(L, -2)) { // the key
1285 LuaLog(1, "gl.Material: bad state type");
1286 return 0;
1287 }
1288 const std::string key = lua_tostring(L, -2);
1289
1290 if (key == "shininess") {
1291 if (lua_israwnumber(L, -1)) {
1292 const GLfloat specExp = (GLfloat)lua_tonumber(L, -1);
1293 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, specExp);
1294 }
1295 continue;
1296 }
1297
1298 const int count = ParseFloatArray(L, color, 4);
1299 if (count == 3) {
1300 color[3] = 1.0f;
1301 }
1302
1303 if (key == "ambidiff") {
1304 if (count >= 3) {
1305 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
1306 }
1307 }
1308 else if (key == "ambient") {
1309 if (count >= 3) {
1310 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
1311 }
1312 }
1313 else if (key == "diffuse") {
1314 if (count >= 3) {
1315 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
1316 }
1317 }
1318 else if (key == "specular") {
1319 if (count >= 3) {
1320 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
1321 }
1322 }
1323 else if (key == "emission") {
1324 if (count >= 3) {
1325 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color);
1326 }
1327 }
1328 else {
1329 LuaLog(1, "gl.Material: unknown material type: %s", key.c_str());

Callers

nothing calls this directly

Calls 10

lua_israwstringFunction · 0.85
LuaLogFunction · 0.85
lua_israwnumberFunction · 0.85
lua_tonumberFunction · 0.85
c_strMethod · 0.80
ParseFloatArrayFunction · 0.70
lua_gettopFunction · 0.50
luaL_errorFunction · 0.50
lua_pushnilFunction · 0.50
lua_nextFunction · 0.50

Tested by

no test coverage detected