Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Direct X Stuff with C++

Author
Message
Kryogenik
15
Years of Service
User Offline
Joined: 22nd Sep 2009
Location: Heidelberg, Germany
Posted: 25th Sep 2010 16:55
I decided the best place to get the seen without making people mad was here, sorry for always filling Geek Culture with questions and stuff.

I've been working on a Direct X 9 game engine. I know, it's hard and somewhat pointless, but I just want to do it. Plus, I don't want to have to deal with a commercial liscense or needing people to have visual c++ redistributables to play games I make, anyway...

I can initialize Direct 3D, render stuff, use lights, textures and non animated meshes (I haven't figured out how to use lights with stuff besides colored vertices though). I sort of understand the transformation matrices (I can rotate objects, but I don't know how to rotate and position them individually).

I can render stuff to a certain extent, but I don't know an easy, efficient and practical way to render multiple objects. DBPro uses an object number system. I don't know if I should try to do that, or how I'd do that, I need some help. I can't find any good tutorials or advice on a way to do that, do any of you guys know how to do it, or a place where I can figure it out?

Plus, nonanimated meshes aren't really an option if I want to make a decent game. I know how to make the animated meshes in a modeler (if I spelled that right), but I don't know how to display it in Direct X. There are examples for this in the Direct X SDK, but it has hundreds and hundreds of lines because it uses this DXUT thing, basically, it doesn't tell me anything.

I think there is a function called D3DXLoadMeshHierarchyFromX that I could use, but I can't find a good tutorial on it. I saw one on GameDev.net by Jason Jurecka, but I couldn't compile for some reason (something about an abstract class, so I guess I can't use his code). Anybody know anything about that function?

Thanks in advance

cout<<"I'm learning C++, and this is all I know \n"
zzz
19
Years of Service
User Offline
Joined: 13th Nov 2005
Location: Sweden
Posted: 25th Sep 2010 18:27 Edited at: 25th Sep 2010 18:33
I've worked a little with directX. What I did to render multiple objects was simply to create my own mesh/object classes containing functions and variables for rotating, positioning and scaling. I then just looped through all the instances of those classes(I think I stored them in a vector), when I wanted to update and when I wanted to render. I never did any optimisation though, you may want to have some sort of resource class also, so you don't have to load the same mesh several times.

I actually got animated meshes to work with the help of the Jurecka-tutorial. But it was a chore, and I did A LOT of copy+paste.
After that, I put the project on ice. I just got bored I guess.
Here's a video of the engine: http://www.youtube.com/watch?v=_M4ESp_JKB4

Kryogenik
15
Years of Service
User Offline
Joined: 22nd Sep 2009
Location: Heidelberg, Germany
Posted: 25th Sep 2010 20:10
That videos sweet So you make a model class and make a bunch of instances of it and loop through them? I kinda know what you mean by resource class (like using clone object in DBPro, right), but how would you do that? Do you still have the source for that engine lying around? I'm not sure how to implement the Jurecka tutorial. Thanks for the response zzz

cout<<"I'm learning C++, and this is all I know \n"
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 25th Sep 2010 21:34
Putting the objects in a linear list is fine when you want things to be small and simple, but it's not very efficient and quite illogical too. A better way to arrange them is in a tree structure. To do this, you simply make a node class, which contains a pointer to an object, and then a list (vector) of child nodes. When you call Render() on one node, it subsequently calls Render() to the object, then loops through the child nodes and calls the same Render() on those. Doing it this way allows things to have a logical structure, and, for example, by rotating one node, you can cascade the effects onto all the child nodes. So when you move a platform, anything on the platform will move with it. It also means that if a node is too far away, you simply don't call it's render method, and then it won't even look at the child nodes.

Tl;dr: look up "scene graphs"

"everyone forgets a semi-colon sometimes." - Phaelax
Kryogenik
15
Years of Service
User Offline
Joined: 22nd Sep 2009
Location: Heidelberg, Germany
Posted: 25th Sep 2010 22:08
@Zotoaster Oh yeah, you're the one who explained binary trees in this thread http://forum.thegamecreators.com/?m=forum_view&t=171740&b=22 That sounds like a good way to get optimization, thanks for the response

gpDirect3DDevice->DoSomethingAwesome(FPS_GAME)
AutoBot
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location: Everywhere
Posted: 25th Sep 2010 22:23 Edited at: 25th Sep 2010 22:25
That's a good method, Zotoaster, sounds like it could benefit from polymorphism as well. The child nodes would need to be inherited to a base class (with render as a virtual function). Then the pointer would just need to be of the base class and could trim through the vector, still successfully calling render() to the objects while each doing specialized tasks.

One use for this would be if some of the objects used a shader while others didn't, if you're using specialized terrain blocks, and all else that would need a special rendering method.

Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 25th Sep 2010 22:35
AutoBot,

Exactly correct. As long as every node class shares a common base class, with a virtual Render() method that you can override, you can get a lot of power and functionality very easily, and very quickly. No need to think about some complicated way of certain objects having certain features, etc.

"everyone forgets a semi-colon sometimes." - Phaelax
heyufool1
16
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 25th Sep 2010 23:15
I'm working on a game engine myself using OpenGL. I have my object handling setup by having a scene class that has a list of my base object class (updating is a virtual function). Then I have a couple of derived classes from the object class (Light, primitives, static meshes, etc.). So to draw the objects all I do is loop through every object in the list and call the update function. But, are you saying there's a faster way?

P.S. Sorry for being a slight thread jacker.

"So hold your head up high and know, it's not the end of the road"
Impulse Game Engine
Kryogenik
15
Years of Service
User Offline
Joined: 22nd Sep 2009
Location: Heidelberg, Germany
Posted: 25th Sep 2010 23:44
@AutoBot/Zotoaster What do virtual functions do? I know they have something to do with polymorphism and stuff, but I never understood them. The method sounds good, but how would you do it? I've done simple binary trees before, but how would you make them dynamic (items moving from one place to another corresponding with the 3d objects and stuff)?

@heyufool1
Quote: "P.S. Sorry for being a slight thread jacker."
No problem

Thanks for the posts

gpDirect3DDevice->DoSomethingAwesome(FPS_GAME)
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 26th Sep 2010 01:55
Kryo,

Basically, if you have a virtual method in a class, and then extend that class using inheritance, then you can write a new method with the same signature which does something different. If you have a base class, 'Base', with a virtual method 'Method', and then you extend those into a 'Derived' class, then, if you do this:

Base* base = new Derived;
base->Method();

Then it will call Method() in 'Derived'. However, if you did base = new Base; it will call the method in 'Base'. Basically, the appropriate method will be called depending on the type of the object. This is how polymorphism works. It's called 'dynamic dispatch' (amongst other things), you should look it up.



As for rearranging trees, I don't think that will be necessary for now, but since you ask, the answer is this. Trees are big complex structures, and moving nodes around doesn't always "mean" anything, unless you move them to nearby nodes. The most basic kind of rearranging in a tree is called 'tree rotation'. Try and imagine a node in a tree with two child nodes, and then left or right rotate it. That should give you a rough idea.

"everyone forgets a semi-colon sometimes." - Phaelax
AutoBot
15
Years of Service
User Offline
Joined: 25th Sep 2009
Location: Everywhere
Posted: 26th Sep 2010 02:00 Edited at: 26th Sep 2010 02:01
EDIT Woops, Zotoaster beat me to it

dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 27th Sep 2010 05:28
Also, simply running through your tree and rendering anything you come across will be inefficient in terms of state changes, and it won't work correctly with transparent objects. So your 'render' method would have to push the object into a list where it's first sorted into at least transparent and non-transparent objects, then sort the non-transparent ones by state(there's a good gamedev.net article on this somewhere) and sort the transparent ones by inverse distance(reverse painter's algo) and draw them. Other engines such as irrlicht have a bunch more steps in the drawing, for skyboxes and such.

Quote: "or needing people to have visual c++ redistributables to play games I make"


The only way to get around this is to statically link everything, this has nothing to do with using specific libraries vs coding a renderer yourself.

Kryogenik
15
Years of Service
User Offline
Joined: 22nd Sep 2009
Location: Heidelberg, Germany
Posted: 27th Sep 2010 08:41
@dark coder You mean for objects that use alpha or are hidden and stuff? If I can remember that, I'll put it in

Quote: "The only way to get around this is to statically link everything, this has nothing to do with using specific libraries vs coding a renderer yourself.
"


Oh, I was didn't know you could do that, I was going to code my own renderer and compile it in Dev C++ (which so far, doesn' seem to need a redist) because I figured GDK could only be coded in Visual C++ and the redists were unavoidable. All that aside, I still feel like making my own renderer [

gpDirect3DDevice->DoSomethingAwesome(FPS_GAME)
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 27th Sep 2010 09:43
I see, I was assuming you were using VC++. Anyway, you can also compile irrlicht/ogre using GCC as they both have very nice licenses, writing your own rendering engine will pretty much be a waste of time unless you have some very specific need that they don't easily cater for.

david w
19
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 27th Sep 2010 12:32
I've written a "game engine" that consists of static libraries that you would link into your project. It will do everything you need, except manage your "objects" or scene. You would have to come up with a solution for your game. If you interested of course.
Kryogenik
15
Years of Service
User Offline
Joined: 22nd Sep 2009
Location: Heidelberg, Germany
Posted: 27th Sep 2010 21:32
@dark coder I don't know, I have a feeling one day knowing pure direct x will be good for something. I guess its a waste of time, but I feel like making my own game engine for some reason

@david w Is it in direct x 9 and C++, or direct x 9 and some other language? I feel like making my own engine, but there aren't a whole lotta good tutorials out there to get me started, if you have any source I could look at that'd be cool.

Thanks for the responses, guys

gpDirect3DDevice->DoSomethingAwesome(FPS_GAME)
david w
19
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 27th Sep 2010 21:48
It's written in Direct X 9 and C++. I can't really give you the source to it, but I can help you with getting the basics of your own up and running, if thats the route you wish to go.

On a side note, if you use my libs, it does alot of the work for you and you if you want you can use direct X directly with them so you can still learn the ins and outs of the API. I have libs for basic windows, Direct X 9, Nvidia PhysX, and Xaudio2 (windows sound). These will all let work direct with their respective API's if you need.

Keep in mind writing a whole engine is a complicated and time consuming process. It took me over a year to get to this point.
marlou
16
Years of Service
User Offline
Joined: 17th Jan 2009
Location:
Posted: 29th Sep 2010 07:58
There are some advantages with compiling with GCC 4.5 at can greatly optimize your executables for speed. It's very fast compared to MVC++ and close to the commercial and expensive Intel Compiler.
You should take a look into Ogre3D and Irrlicht as they have good implementations of algorithms and such.
If time is not a concern to you, you can dig deep into other things like physics, ai and consoles.
But I think time spend on creating a rendering engine can better be placed in coding for consoles using open source homebrew SDKs as you gain experience in different platforms. On the other hand, pc games have very good graphics and is constantly increasing in capabilities.

When a person has nothing but a dream, can he dare to dream.

Login to post a reply

Server time is: 2025-05-23 06:09:17
Your offset time is: 2025-05-23 06:09:17