So I was referred to Microsofts Expression Blend 3 by my friend who works with silverlight. Expression Blend is a nice editor like tool used to design fancy shmancy gui’s in WPF and Silverlight.
The learning curve for it is slightly high (for the non designer, developer type like myself that at the moment is still new to WPF), but given a couple weeks and with my backend in need of a more robust frontend, i think the time invested will have a nice payoff. The problem is i need to take some time to learn the thing. anyways, here is a picture of the interface.
I have been working on my editor as of late in hopes of being able to use it to make my simple demo I have been talking about. I found a lot of doubt on the internet about the ability to interop OpenGL with the WPF rendering stack.
Well, we got it to work and it is very similar to the setup I had used to get it working in WinForms. Here is how we did it. First of all, you need a 3D Engine with the ability to take an HWND and use that for rendering. A complete tutorial on how to do this can be found in a gamedev article here.
Once you get this far, its only a matter of creating some xaml.
And your C# for this xaml would look something like:
publicpartialclass MainWindow : Window
{private GravWrap gravWrap =new GravWrap();//an instance of the engine
ILua LuaPortal;public MainWindow(){
InitializeComponent();System.Windows.Forms.Panel panel =newSystem.Windows.Forms.Panel();this.OpenGlPanel.Child= panel;//add the winform panel as a child to the winformhost
IntPtr LuaState =this.gravWrap.Initialize(panel.Handle.ToInt32());//pass the panels hwnd.
We created a Panel within the WinformsHost and that was it.
So, you have integrated Lua into your game engine, you are able to write scripts that define game objects and program some game logic. But what happens when you want to stop your engine? Can you reproduce a game state 20 minutes in? Well, this is where saving/loading lua tables comes in handy. If your Lua environment is anything like mine, tables store everything. And being able to save tables to a file and then re-load them completely intact can achieve this result.
You have 1 and a half options. why the half? Because I soon found out that 1 option provided half the result (really nothing since it mangled tables). Those options? Lua Pickle and Table.save . These little Lua scripts provide the functionality described above.
Lua Pickle is the half, not coming with the file writing functionality but it was easy to put in. The problem with Lua Pickle was that if you saved and loaded and saved again, certain values would come back mangled when loaded, which doesn’t do us any good! The script is 10 years old though so it’s alright, it made a good run. Lastly, it does not store functions, which is not surprising if you do not think of them as first class variables. If your tables are very simple and do not have sub tables and complex self references, this is a decent option.
Table.save is what I use, however there is a catch. The test that runs it causes it to fail. They claim that using a tmpfile() in io is fast for huge tables you want to save, but the stdio tmpfile function was deprecated on the msdn site, so i had to avoid that “extra feature”. the cool thing about table save is it also can save functions, which, as long as you use some sort of encapsulation (meaning the functions only refer to variables that exist in the table) then you are good to go!
I moved the lighting objects to lua, and more so removed some of the legacy lua code (no more sandbox). I’m running lua the way its intended to be run with the engine, initializing lua objects and relying on events for all of their updating.
I started converting my editor to wpf, which actually is not all that bad.
I added another framebuffer at the tail-end of the rendering pipe, this is where I do the culling of the lighting volumes for Deferred Shading. This is also the beginnings of any future post-processing work I do (HDR/Tonemapping/ambient occlusion).
I feel like the lighting is done enough to move into Lua.
My next project is to make a realtime editing of light values in the editor I have (the purpose of its early existance).
Here is an example of where i hope to get with my editor eventually, but for now im just going to do lights =). I by no means have an Uber-Shader yet, but I’m working towards that.
I added point lights over the weekend. Aside from getting the proper light volume shape (a sphere geometry) and proper values for my attenuation, its almost there. Here’s a pic.
So my Deferred Shading shaders were messed up, and after some clarification on theory and math I am starting to see some real working results. here is a picture of a light moving from right to left right behind the camera.
directional light
Next is point lights and a bunch of lights moving around the screen.
Cheers!
PS. Once this is working and im comfy with it i will be sure to talk about it =)
Here is a link to someone who has given me some critiquing on my deferred renderer. We have similar goals with different tools and different things we are currently working on. Another great source for engine stuff.