Jump to content
  • Advertisement
Sign in to follow this  
Haytil

2D using Direct3D

This topic is 5396 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, I'm trying to learn how to do 2D graphics using Direct3D. DirectX 9 is preferable, but version 8 is fine too. I tried looking at this article: http://www.gamedev.net/reference/programming/features/2d3dquads/default.asp but found it to be fraught with errors in the code. The accompanying code files also do not compile. Anybody who could point me to an appropriate article or tutorial would be appreciated. Thanks. -Gauvir_Mucca

Share this post


Link to post
Share on other sites
Advertisement
The DirectX forum has at least a half dozen threads asking the same question.

The actual MSDN tutorials are OK at showing it, as are the DrunkenHyena tutorials. The tutorial you posted looks as though it has most of the details you need to know, but perhaps assumes too much.

I don't have nice simple example code of my own, but am currently working with a 2D project in DX9 and can answer questions and help if those or other provided links are confusing [and they are a little bit]

Share this post


Link to post
Share on other sites
2d in d3d is very easy using d3dx

// these need to be already created
IDirect3DDevice9* pDevice; // pointer to d3d device
ID3DXSprite* pSprite; // pointer to d3dx sprite

IDirect3DTexture9* pTexture; // this holds the 2d image

// load a png file
D3DXCreateTextureFromFileEx(pDevice, "image.png", D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, NULL, NULL, &pTexture);

// draw the image on the screen at 10,5
pSprite->Begin(D3DXSPRITE_ALPHABLEND);
pSprite->Draw(pTexture, NULL, &D3DXVECTOR3(0,0,0), &D3DXVECTOR3(10,5,0), D3DCOLOR_RGBA(255,255,255,255));
pSprite->End();

Share this post


Link to post
Share on other sites
I strongly recommend using the ID3DXSprite interface in DX9. It'll make your development time much shorter (more work on your game, much less work on getting your sprites to display) and is more than fast enough.

If you see people ragging on ID3DXSprite, it's mostly people still using DX8. There were some major improvements made to the interface during the 9.0b Summer Update.

Although finding a tutorial on ID3DXSprite can be tricky, you shouldn't have much of a problem figuring it out from the documentation. It's pretty simple for something that's pretty powerful.

Share this post


Link to post
Share on other sites
did you link the dx libs to the project when you typed in the code? this was the problem when i tried my first dx program... i was like "wtf, stupid tutorial wont compile... :(" then i realized that i was only too n00b and some tutorials dont mention it because they think its too obvious. but its not obvious if you are completely new to programming with directx.

if this is not the case then theres probably something else missing... i dont know. i never had much problems with tutorial codes. except for a few but i managed to fix most of them.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!