Showing posts with label Scene Graph. Show all posts
Showing posts with label Scene Graph. Show all posts

Sunday, February 26, 2012

I have scene graph!

I finally got my scene graph working. It looks like THIS:
Oops, wrong picture, here we go:

It's not beautiful, but now I can create different objects to my hearts content and transform them as I wish. If you want you can download the .exe(and the shader file) or the source.
Next in line I guess is adding textures, lighting and keyboard input, in whichever order is the simplest.  

The importance of Zero, and not overcomplicating things..

I haven't made any update for a while, I've been trying to split the code in initDevice that shouldn't really be in the init function if we want to create objects freely and not only once in the initialization of the game.. It would also get really cluttery and outright non-modular to create all objects we want in the initialization function.. We want to split the graphics code from the game code and instead provide tools to create objects freely from the main part of the game code.

So I've made a separate .h for the graphics, which declares a TSceneGraph class, this class will be used to handle what we see, so far it's very simple, and in fact only supports one(!!) object, only supporting one object is of course a rather useless scene graph(if it should even be called a scene graph), but let's take simple steps.

Now, the TSceneGraph class is based on the code from the DX11 SDK tutorial 5, but split into functions in the class. Most of the functions are as they where, except that the object creation code has been taken of of InitDevice() and put into CreateObject(), and the vertex data is expected to be written where the CreateObject() function is called.
I ran into some trouble doing this, which is why there hasn't been an update for a while(also, I'm on an internship, so I'm rather busy).

Anyway, the first problem:
Calling CreateBuffer() returned E_INVALIDARG and the application quit from InitDevice().
After finally making sure that the D3D11Device was created with the flag D3D11_CREATE_DEVICE_DEBUG, I found that I was my buffer description bd containd some very strange flags, apparently, this was because I had not done ZeroMemory(db). This leaves some strange random data in the fields of the buffer description that are not specifically defined.

Second problem:
I tried to create the objects as pointers to 3dObject structs containing a VertexBuffer and an IndexBuffer each.. This all got really confusing and I probably just didn't manage to access them in the correct way, leading to exceptions when trying to create the buffers. I realized that such a struct only contains pointers anyway, so there is not really any use of making them pointer variables.
So I just skipped the complicated stuff for now and made regular variables.

So after some time of trouble, I finally got it compiling again. Way!
 It's still just the same triforce, and it's not even rotating! :O
BUT, it's all just a bit more modular and uses a "scene graph".

PS, since I'm away from home for a while I have to do this on a laptop, making development really tedious due the small screen(note the lack of plural).. sigh.

Saturday, February 18, 2012

Progress Report

I have no fancy pictures of any moving textured objects yet, but there has been some progress.

I've realized that the way the code is structured in the DX11SDK tutorials simply won't do even as a starting point for a game engine, for a few different reasons..
First off, the triangles shown are defined and put into a vertex buffer in the InitDevice() function, and while we could change the triangles in some other function later, this would get rather messy, since the same kinds of things would be done at different places. Also, after Tutorial 5 we draw out two objects, but we actually only have one, we transform it and draw it at two places, but it's only one object. This is kind of a problem.

So we need to add something that manages different objects, where they're at, how large they are, what triangles they contain, how they are drawn, and so on. I *think* this is what's called a Scene Graph. We want to do these things in a separate file from the main .cpp, because in the main .cpp we will want to focus on handling events in the game.

So I'm restructuring all the code(not much code, but hey), making a class called TSceneGraph in a different .cpp file, that will do all of the above. This also means moving all the DX11 initialization to this TSceneGraph.
Inside this class I can create a variable that decides what API to use, making it possible to chose if I want it to initialize an OpenGL window or a DX11 window, while keeping track of all the objects separately from the API.
Making this new structure is kind of hard for me and requires some thought, and also, since I'm note really used to C++ anymore, lots and lots of compiling errors. To brush up I read about header file and source file standard practice here, and about class definition here. Hopefully, I'll have a rudimentary scene graph working soon.

I also found how to chose which pages to include or not in the menu, so from now on any tutorials will have their own pages, instead of posts, linked from the Tutorials page in the menu above, and from a list to the right.