#### Archived

This topic is now archived and is closed to further replies.

# How to make a directx wrapper?

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

## Recommended Posts

Hi, I want to create a directx wrapper, but with all the code in one header file. I want it so i only declare what i want to use. For example. I am using Direct3D, so automatically i''d use the d3ddevice and d3d etc. And use only fonts for drawing text. which i would declare d3dfont And say I also want to use Direct Input so i declare didevice. But only want to use the keyboard so i also only declare dikeyboard How would i do this? Like have a class for Direct3D, DirectInput etc. Then have a class For things like keyboard, mouse, text, meshes. That are stored in the allocated spot. Like keyboard, mouse classes are in the directInput class, and the others in direct3d class. My main problem is having to declare a d3dDevice for every d3dfont, d3dMesh, d3detc. And then make all those d3dDevices equal the one in the direct3D after i have initialised it. Anyone had experience with making these wrappers? Like any ideas on how to do it the way i described in the first 2 paragraphs or any other way of doing it. Thanks.

##### Share on other sites
I have a DX 9 wrapper, just 2 files, one header and one source. I downloaded it from some website, I think it was called PCS Soft. But I don''t remember the link. Search for it on google and go to that website. It''s just a 46 KB download. Or give me your mail address and I''ll mail it to you.

##### Share on other sites
What would be the point of such a wrapper?

How appropriate. You fight like a cow.

##### Share on other sites
quote:
Original post by Sneftel
What would be the point of such a wrapper?

How appropriate. You fight like a cow.

If you have to ask, you do not deserve to know.

##### Share on other sites
What you're asking is a very basic design issue, and has nothing to do with DirectX. You've got the right idea about the classes, but you're missing the point on how to access/share class data. I'm not going to explain that here, but I will recommend that you spend more time reading about classes in C++.

For a more immediate answer to your problem, you would not initialize a seperate d3ddevice for each object. You could use the constructor to point the d3device member to the one in your debvice class. Or, you could initialize it to NULL in the constructor and create a setDevice() method. There are other approaches you could take as well, that would not require each class to have a d3ddevice member.

Again, this has nothing to do with DirectX and everything to do with programming fundamentals. I suggest that if you can't figure out what to do via a C++ book (Thinking in C++ by Bruce Eckle is excellent and available online for free), then you should look for help in either the General Programming or For Beginnner's forums.

[edited by - aldacron on September 3, 2003 1:48:15 AM]

[edited by - aldacron on September 3, 2003 1:49:06 AM]

##### Share on other sites
quote:
Original post by Remnex
If you have to ask, you do not deserve to know.

Remmex: Your expert knowledge of condescension shames me, to the point where I cry into my pillow. I am a hollow, ruined shell of a man. And my knee itches.

Other people: again, what''s the point? This seems to be an effort to graft a Facade pattern onto DX... but I''m not quite seeing what functionality the OP wants to leave out. What wrapper things have other people done to DX?

How appropriate. You fight like a cow.

##### Share on other sites
Sneftel the reason i want to make my own one instead of someone elses is that i can choose what the methods are and whats in them etc. I don't want have to learn someone elses wrapper, the way they did it.

poly ill have a look and see how they've done it.

ok aldacron ill have a look at that. Its just that I have actually read alot up on classes etc, and learned alot about them, but i still dont see how i have it so i don't have to declare a device in each method.

As I don't want to declare something that i might not use, like have it outside the class.

Would you have an idea on how i would have only one device declared?

(My device class isn't to be declared everytime, so thats why i don't just refer to it. As sometimes i might not use d3d)

Thanks

...thanks for the support remnex

[edited by - johnnyBravo on September 3, 2003 6:11:35 AM]

##### Share on other sites
quote:
Original post by Sneftel
quote:
Original post by Remnex
If you have to ask, you do not deserve to know.

Remmex: Your expert knowledge of condescension shames me, to the point where I cry into my pillow. I am a hollow, ruined shell of a man. And my knee itches.

Other people: again, what''s the point? This seems to be an effort to graft a Facade pattern onto DX... but I''m not quite seeing what functionality the OP wants to leave out. What wrapper things have other people done to DX?

How appropriate. You fight like a cow.

Sneftel: It''s ok, man. Dry your eyes my good sir. What I meant by my original post is that any programmer worth anything has a collection of code that contains often used code that has been debugged and proven to be efficent. With this the dev process hastened as one does not have to constantly rewrite the same stuff over and over.

For example, I include two headers and size lines of code later I can have a WIN32 window up completely DirectDraw, DirectSound, DirectMusic and DirectInput started and ready to go.

But, everyone has their thing...

As per the original post, I suggest you seperate each component into a single class and make each class a singleton. This will give you the ability to keep everything in a class and helper functions within to allow you to do things that pertain to that Direct3D component your are placing in a class.

This way you can just include the header and a library and will have global access to all your objects, but moreover, you can only have one instance so you do not need to worry about certain things. This is the way I designed my DirectX 2D library; it worked great.

Ex:

// Declare the singletonsCDirectDraw *pDirectDraw = CDirectDraw::Instance();CPrimarySurface *pPrimSurf = CPrimarySurface::Instance();// Create directdraw - 640x480x32bit color - Fullscreen modepDirectDraw->Initialize( 640, 480, FULLSCREEN, 32 );// Create the primary surfacepPrimSurface->PreCreate( FULLSCREEN, NO_MENU );pPrimSurface->Create( 640, 480 );

BAM! That is all the code I need for a 640x480 @ 32bit color application!

CPrimarySurface and CSurface inherit functions from CGenericSurface that allows surface manipulation (read: pPrimSurface->Text(...)) so that I can change/add one function in CGenericSurface and it filters down.

Coal, eh?