Jump to content
  • Advertisement
Sign in to follow this  
Reegan

Learning DirectX

This topic is 3634 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, ive been trying to learn directx and so far im a little confused as to what is what! Ive been looking at various tutorials on the internet trying to find a good starting point for me to learn directx i did find one website which was pretty decent and i actually managed to compile and semi-understand what was going on in my code (Link: http://www.directxtutorial.com/). Thing is, that website jumps straight into direct3d which is a kinda hard for me to understand right now as ive never done any 3d programming. I would like to start by using the directx API to draw simple 2d primitive shapes like rectangles, ellipses and so on... Then maybe try loading some bitmaps into video memory and displaying them in my window. Anyway, what im trying to say is, what would you recommend to someone trying to get into DirectX?? What i want to learn: How to create a simple directX application complete with sound and 2d graphics? What i can do: I have created two simple games (using the GDI for graphics), Retro Pong and Retro Breakout from scratch. What im confused about - Direct3D functions that have to be created can become quite long and confusing even for a simple application and i dont think i can remember all of it. Do i really have to remember it all or is there some kinda trick to this? - What are the main compnents of DirectX, for example DirectAudio, DirectMusic and DirectSound? whats going on here?! - Are some of the directX components not supported by microsoft anymore? because the SDK i downloaded does not come with tutorials on most components (example; DirectSound, DirectDraw, etc...). Im so confused here.... Please someone, help a poor sod out. Thanks. ~Reegan

Share this post


Link to post
Share on other sites
Advertisement
DirectX no longer contains DirectDraw, or any 2D graphics API for that matter. If you're just looking to draw ellipses, rectangles, and blit images to the screen, Microsoft's official API for that would be GDI+ (I'm not recommending you use it, just pointing out that it's there). If you want to learn graphics with DirectX, you're going to have to use D3D. However D3D9 does have some 2D functionality that was taken from DirectDraw. Notably there's the ID3DXSprite helper class: you can simply create one of these, load a texture, and tell the sprite class to draw that texture anywhere on the screen.

As for audio...things are a bit confusing on that end. DirectSound still exists, as a low-level audio library. DirectMusic is gone. However there is now also XAudio2 and also XACT. XAudio2 is a new cross-platform (PC and 360) library that's "supposed" to replace DirectSound. XACT has two parts: a GUI tool for sound designers, and a library/SDK used to play the sounds designed in the tool. Unfortunately I can't explain much better than that, I'm not really experienced with these tools myself. You may want to read through the docs.

Share this post


Link to post
Share on other sites
Quote:
Direct3D functions that have to be created can become quite long and confusing even for a simple application and i dont think i can remember all of it. Do i really have to remember it all or is there some kinda trick to this?

First: I have sympathy for you, Reegan. Learning a new api can be very frustrating.

Second: You don't have to remember it all but, unfortunately, there's no trick to use, either. I've been programming for years and I still lookup most of the functions in the index, copy and paste the definitions from the help page to my code and edit it.

I also cut and paste from the SDK examples a lot!

Another technique for "remembering" how to do something is to keep and refer to old projects. Unfortunately, at this point, you don't have any old Dx projects but that day will come.

Third: There is some good information to be found if you click the link "View Forum FAQ" in the top left area of this screen.

Fourth: This forum has a lot of people willing to help you learn. Have a question? Post it!

Share this post


Link to post
Share on other sites
Ok, thanks, thats cleared up a few things ^^

@MJP:
I can only get the GDI to work properly with my native C++ win32, how does GDI+ differ from GDI, or should i just look it up on the net? :P
Eventually i want to get into the games industry (hopeful) so which components of DirectX are most useful and will better my chances of getting into the industry? (graphics, sound, others?)

@Buckeye:
Thanks for your sympathy ^^
I guess ill just have to keep practicing then! :)
I will use the forums only when im truly stuck, i dont want to annoy anyone >.<
but thanks for letting me know im welcome ^^

~Reegan

PS: any advice people can give me regarding DirectX graphics, sound, others.. will be helpful and very much appreciated! also what has hpppend to DirectPlay? is that still around?

Share this post


Link to post
Share on other sites
Quote:
Original post by Reegan
I can only get the GDI to work properly with my native C++ win32, how does GDI+ differ from GDI, or should i just look it up on the net? :P
Eventually i want to get into the games industry (hopeful) so which components of DirectX are most useful and will better my chances of getting into the industry? (graphics, sound, others?)
Generally speaking, most companies will use their own engines, so you won't have to touch the low level stuff. It's useful to have an overview of how various APIs work though. I'd recommend having at least a reading knowledge of all DirectX components (I.e. so you can look at some code and understand what it does).
For doing a portfolio or something, I'd recommend having a good grasp of Direct3D, since that's the most challenging part. You can use other libraries like FMod for sound, or you can teach yourself that too.

Quote:
Original post by Reegan
PS: any advice people can give me regarding DirectX graphics, sound, others.. will be helpful and very much appreciated! also what has hpppend to DirectPlay? is that still around?
DirectPlay is dead, for networking it's recommended that you use Winsock, which is lower level but still reasonably easy to get a grasp of.

Share this post


Link to post
Share on other sites
GDI+ is a C++ interface for accessing drivers directly (GDI doesn't do that). GDI+ is supported for Windows XP and later.

Lookup GDI+ or GDIPlusStartup in your Studio index. (Eventually) you can find some GDI+ examples for straight windows applications.

Share this post


Link to post
Share on other sites
@Evil steve:
Thanks for the info :D
If i was to create my own engine for games would it cut the more complex parts of setting up a game like initializing the API's (specifically direcx) so then i could use it in any game i create? For example if i had a direct3d engine setup would it just mean punching out different functions to load models and set coordinates things like that instead of having to initialize the whole thing before any real action took place?
Winsock eh? well when i get to online mulitplayer games ill be sure to look that up Thanks! ^^

@Buckeye:
Already managed to setup GDI+ and loving it, i prefer the way it handles drawing and gives me easier access for things like fonts, size and color for text. Much easier than regular GDI!

Im having a blast with this and im never going to give it up!
Happy coding! ^^

Thanks!
~Reegan

EDIT: one question, can GDI+ work along side direct3d? in otherwordds can i use GDI+ to draw my 2d stuff and then direct3d for my 3d stuff in the same window? how would this work?

Share this post


Link to post
Share on other sites
You can do 2D stuff with Direct3D.

There should have been some tutorials on this page, of DirectXtutorial.com, which, is a fairly decent explanation. You aren't merely limited to doing Direct3D, just showing you that it is possible.

Share this post


Link to post
Share on other sites
Quote:
Original post by Reegan
If i was to create my own engine for games would it cut the more complex parts of setting up a game like initializing the API's (specifically direcx) so then i could use it in any game i create? For example if i had a direct3d engine setup would it just mean punching out different functions to load models and set coordinates things like that instead of having to initialize the whole thing before any real action took place?
Yes. For example, some code from my engine:

bool GGame::Init(const wchar_t* szCmdLine)
{
// Load a sprite
ESprite::SP pSprite;
pSprite = ESprite::Load(11, L"Test3.bmp");
pSprite->SetPos(EVector2(0, 0));
ESceneMgr::Get().Add(pSprite);

// Add some text
EFont::SP pFont = EGrahpics::Get().GetFont(L"Ariel", 24, EFont::Bold);
pFont->PreloadGlyphs(L" 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz()+-");
m_pText = new EText(pFont, L"?? FPS", FloatRect(0, 0, (float)s_nWidth, (float)s_nHeight));
m_pText->SetColour(EColour(255, 0, 128, 0));
ESceneMgr::Get().Add(m_pText);

return true;
}

void GGame::Tick()
{
EInput& input = EInput::Get();

// Enter = toggle fullscreen
if(input.WasKeyTapped(EInput::KEY_Return))
{
EGraphics::Get().SetFullscreen(!EGraphics::Get().IsFullscreen());
}

// Update FPS
static float s_fElapsed = 0.0f;
static float s_fTotalTime = 0.0f;
s_fTotalTime += ETimer::Get().GetFrameTime();
s_fElapsed += ETimer::Get().GetFrameTime();
if(s_fElapsed > 250.0f)
{
std::wstringstream str;
str << (int)(1000.0f/ETimer::Get().GetFrameTime()) << " FPS\n";
str << EGraphics::Get().GetFrameStats().c_str();
m_pText->SetText(str.str());
s_fElapsed = 0;
}
}


Everything else is handled by the engine code. And before anyone says it; I know, I know - singletons are bad, I'm working at getting rid of them [smile]

Quote:
Original post by Reegan
EDIT: one question, can GDI+ work along side direct3d? in otherwordds can i use GDI+ to draw my 2d stuff and then direct3d for my 3d stuff in the same window? how would this work?
It's possible, but not usually a good idea. You can use the GetDC() function of a IDirect3DSurface9, if the surface is in a reasonable format (See the docs for restrictions). You can use that to pass the HDC to GDI+ for rendering, and render 2D onto a texture.
Generally speaking though, mixing D3D and GDI (or GDI+) is just going to cause you headaches and is best avoided where possible.

Share this post


Link to post
Share on other sites
Quote:
Generally speaking though, mixing D3D and GDI (or GDI+) is just going to cause you headaches and is best avoided where possible.

I second that. I used to use GDI(+) to "quickly" draw grid lines and reticules, trying to avoid the use of another DirectX buffer for lines, etc. However, there were occasional problems (particularly in fullscreen mode) that disappeared when I stopped using GDI with Dx.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!