Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectX Game Engine Qs

Started by Skute Dec 29, 2004 at 3:49 PM 5 replies 1.3k views
Original Post
Skute
Skute
Hi, got a couple of question about the theory of a game engine. Everything is rendered in a series of triangles is it not? So does this mean that there is 1 big vertex buffer which everything gets put into, or does it mean that each individual object has its own vertex buffer? What would be the best way of rendering multiple items, say i had 4 objects of type CMyRectangleType(), how could i get those to render themselves? Does this also mean that the engine must have a list of every single object every created?
Mark Ingramhttp://www.mark-ingram.com
Moe
Moe
Quote:
Original post by Skute
Everything is rendered in a series of triangles is it not?

Yes, pretty much. At least thats the way that most people do it, and the way that video cards do things in hardware, so that is probably the best/easiest way to go.
Quote:
So does this mean that there is 1 big vertex buffer which everything gets put into, or does it mean that each individual object has its own vertex buffer?

Well, if you do a little reading, you will find that the fewer vertex buffers, the better. Some times it's just not practical using only one big vertex buffer. It is really up to the way that you decide to do things.

Quote:

What would be the best way of rendering multiple items, say i had 4 objects of type CMyRectangleType(), how could i get those to render themselves?

Well, you can do this several ways. You can create 4 seperate objects (for Rectangles) and render each in its own position, or, if they are all the same, you could simply have one object in memory and use matrices to translate it to the 4 different spots and render it at each spot.
Quote:
Does this also mean that the engine must have a list of every single object every created?
Its highly recommended that you do so. Besides, if you don't keep track of what objects you have, how can you release/delete them from memory? If you can't properly release/delete everything that you create, you end up with memory leaks, which aren't a good thing.

I hope I made sense...
Skute
Skute
thanks, thats great. some good info.

with regards to the "4 rectangles" question, i meant the physicaly rendering function, would it look like:

pRect->Render(m_pDevice);

ie, would you pass a device through to the init and rendering function?

the way im currently doing it is to have a static variable which gets set during engine initialisation. in a base class CObject, so all objects get access to it.

is there a better way?

im creating a vertex buffer for each object in their constructors. ie, CLine has a vertex buffer with 2 points in it.
Mark Ingramhttp://www.mark-ingram.com
Guimo
Guimo
Dont use a VB for each object, you should reuse them.

I.E. If you are rendering a rectangle in 4 different positions, then just use one VB for ONE rectangle. Then associate the VB with the game objects.

During render time, set the world matrix and render each object one by one. The same VB will be rendered but in different locations, rotations and scales.

That means that if you want an army of soldiers, load ONE model of a soldier. Then create 1000 3D objects all referencing the same model. Then render each soldier in a different position. Same VB that is used again and again.

Luck!
Guimo
Skute
Skute
ah ok, so hopefully it should be as simple as changing my private m_pVertexBuffer to a static variable. Then all instances of CLine will have the same buffer, and you just fill it with different values when you need to render it?
Mark Ingramhttp://www.mark-ingram.com
Moe
Moe
Pretty much. In some cases rather than refilling your vertex buffer for each object you can simply transform them to the different locations. It would save a Lock() and UnLock() call for each object.
Skute
Skute
how do you mean transfer them to different locations?
Mark Ingramhttp://www.mark-ingram.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.