Jump to content
  • Advertisement
Sign in to follow this  
Skute

DirectX Game Engine Qs

This topic is 4951 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!