Sign in to follow this  
  • entries
    455
  • comments
    639
  • views
    421678

Bonsai Clean up and additions

Sign in to follow this  
_the_phantom_

68 views

So, I sat down to do the stub application when it dawned on me I hadn't written some functionality into Bonsai I'd meant to add.

The first of these was the Window creation function. Atm it defaults to 800*600, windowed, depth testing enabled and a default clear colour. This is all well and good for testing but not in a real life situaton, so it's been changed so that you can pass a table containing a set of parameters;
- width and height; window size
- depthBuffer; enables depth testing (might rename this)
- fullscreen; enables fulscreen mode
- clearColor; a table containing the new colour to clear to

The latter 3 are optional parameters.

As part of this I found myself pulling more numbers out of tables, so decided to write a couple of aux. functions to wrap that up, making things easier; this lead me to go back and change some older functions to use the new method, cleaning them up somewhat;

// From this
lua_getfield(L,-1,"x")
float x = lua_tonumber(L,-1);
lua_pop(L,-1)
// to this
float x = getNumberFromTable(L,"x")



number, integer and boolean are supported.

Another function I found myself doing alot was pulling rgb and optionally alpha data from a table as a colour, so this got punted into it's own function as well which directly sets the glColourub().

This writing of aux functions kicked off a need for me to clean up the code; as we are treating the graphics table as an object we need to varify a certain state when we call a function, namely that the object really is a graphics object and that we have a window active to call functions on.

This code is a few lines long and looks pretty ugly at the top of each function, so once again it was punted into it's own function;

// From this
int l_deleteTexture(lua_State* L)
{
gfxEngineDetails * engine = (gfxEngineDetails*)luaL_checkudata(L,1,BONSAIGFX);
if(NOWINDOW == engine->currentwindow)
{
luaL_error(L,"Attempt to call Graphical Engine Function with no active window");
}

GLuint texid = lua_tointeger(L,-1);
deleteTexture(texid);

return 0;
}
// To this
int l_deleteTexture(lua_State* L)
{
gfxEngineDetails * engine = CheckValidGraphicsObject(L);

GLuint texid = lua_tointeger(L,-1);
deleteTexture(texid);

return 0;
}



I think that's a bit clearer.

With the introduction of a zbuffer I decide it would make sense to be able to translate on a z-axis. This would have the effect of adding a layered system to the engine. Also, as not all graphical operations need a texture I decided to add a 'setDrawColor' function.

Two more pieces of functionality need to be added, which were in the orignal Java engine; alpha blending modes and alpha testing. This will enable me to handle alpha textures properly, which the inital shoot-em-up game requires to correctly blend things together.

This should be a simple enuff add [smile]
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now