Jump to content
  • Advertisement
Sign in to follow this  
Sammie22

DirectX simple game sample with classes?

This topic is 3267 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

I am looking for a sample (or some info) on using multiple classes with directx. Particularly, I am curious about the render() call. I was planning on writing a 3D tic-tac-toe game (very basic, no sound) and wanted to build a simple class hierarchy so that the render call goes through a level class, which calls a render on each object on the level. It will use primitives and update on mouse input (not really important to a sample but just extra info on the project). The samples in the sdk are all in 1 class file (using primitives anyway), and I am trying understand what is needed to break it up into a hierarchy. For example, can I use more than 1 custom vertex definition? Can I draw primitives from different collections? Etc... If this does not make sense, please let me know any additional info needed and I will try to clarify. Thanks for any help, Brad

Share this post


Link to post
Share on other sites
Advertisement
You've got a lot of questions but I'll see what I can do.

You can certainly declare a class that contains objects to render. You may then want to declare a class for the objects themselves as each object should know how to render itself. For instance:

#include <vector>
using namespace std;

class Level {
bool Render(LPDIRECT3DDEVICE9 dev); // or whatever the device is
vector<RenderObject*> objects;
//... etc.
}

bool Level::Render(LPDIRECT3DDEVICE9 dev)
{
for(int i=0; i<(int)objects.size(); i++) {
if( !objects->Render(dev) ) return false;
}
return true;
}

bool RenderObject::Render(LPDIRECT3DDEVICE9 dev)
{
DWORD thisFVF = FVFList[thisObjectInstanceType]; // get the vertex def for this particular object
dev->SetFVF(thisFVF);
//.. etc..
HRESULT hr = dev->DrawPrim(...);
if( FAILED(hr) ) return false;
return true;
}

Is that the sort of thing you're wondering about?

Share this post


Link to post
Share on other sites
Yes that is very helpful... thanks!

Do I place the render() call between the begin/end scene:


VOID Render()
{
// Clear the backbuffer to a black color
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 0 ), 1.0f, 0 );

// Begin the scene
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{

... render() call to level here, which calls render on the objects in the level ...

g_pd3dDevice->EndScene();
}


ps not sure how to get this to post as code

Share this post


Link to post
Share on other sites
Quote:
Do I place the render() call between the begin/end scene?

Yep. Just like you have it.

You almost have the code tags. Use lower-case. [WINK]

If you want to know how someone puts things in their posts, you can click the edit button for their post and look at the source. You can't save the edit but it can be useful to see how things are done.

Share this post


Link to post
Share on other sites
Thanks again Buckeye. I was able to get the tic tac toe board drawn using a class hierarchy.

Appreciate the help,
Brad

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!