Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Drawing in 2D with DirectX 9 - Sprites?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 beefsteak   Members   -  Reputation: 150

Like
1Likes
Like

Posted 03 October 2012 - 02:44 PM

I would like to develop a 2D game client in c++ and windows, with DirectX 9.

Most of the graphics are stored in png format, hence I found textures to be very useful (easy to load png files with "D3DXCreateTextureFromFile").

In order to be able to draw the textures on the screen in 2D, I used one sprite (LPD3DXSPRITE). This seemed like a simple solution and works perfectly fine for textures.

Now I would like to additionally draw some colored rectangles in between the drawing of images. Surprisingly for me, sprites in DirectX don't support any kind of primitive drawing. There is only one "Draw" method that will render a texture to the display device.


So far I've been pondering about the following solutions:

1. Create textures that contain a certain area of solid color. Then draw any kind of rectangle by aligning the small single-colored textures next to each other. I guess it will work but seems really cumbersome, as I will need to write lots of code to manage the color textures and do the drawing.

2. Find a better way to draw my images to the display device, so that i can mix the image-drawing with primitive drawing operations. So far I couldn't figure out how to do it. I suspect I will need some kind of intermediate "surface" object to draw my texture on.

3. Mix sprite drawing operations with device drawing operations. This would require to split up my drawing code to use many different sprites for different purposes. I will need to call sprite.Begin/End very often. On the whole I don't like this idea because it seems "messy".


Thank you for any kind of feedback that will point me in the right direction! Posted Image

Sponsor:

#2 yewbie   Members   -  Reputation: 665

Like
0Likes
Like

Posted 04 October 2012 - 09:05 AM

Are you strictly limiting yourself to 2d?
I ended up just drawing everything 2d as primitives in my engine I did and subverted LPD3DXSPRITE all together.

Using a custom vertex format like:

//Custom vertex format
const DWORD D3DFVF_TLVERTEX = D3DFVF_XYZRHW| D3DFVF_DIFFUSE | D3DFVF_TEX1;
//Custom vertex
struct TLVERTEX
{
    float x;
    float y;
    float z;
float rhw;
    D3DCOLOR colour;
    float u;
    float v;
};


#3 mhagain   Crossbones+   -  Reputation: 8281

Like
3Likes
Like

Posted 04 October 2012 - 09:18 AM

ID3DXSprite::Draw has a D3DCOLOR parameter and the default texture stage states are set for modulation, so you could use a 1x1 white texture and set this color appropriately for untextured drawing.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#4 beefsteak   Members   -  Reputation: 150

Like
1Likes
Like

Posted 04 October 2012 - 12:42 PM

Are you strictly limiting yourself to 2d?
I ended up just drawing everything 2d as primitives in my engine I did and subverted LPD3DXSPRITE all together.


The graphics of my game are 2D, which means everything is drawn flat and there is no depth. I wouldn't mind using 3D functions for programming however, if they are suitable for my needs.

The problem I currenty have with 3D functions is that I couldn't find a way to render images. How did you handle that in your engine? Image I have an image of a red dragon, stored in a png file on disk - how can I print that to the screen?

#5 beefsteak   Members   -  Reputation: 150

Like
1Likes
Like

Posted 04 October 2012 - 12:50 PM

ID3DXSprite::Draw has a D3DCOLOR parameter and the default texture stage states are set for modulation, so you could use a 1x1 white texture and set this color appropriately for untextured drawing.


Thank you for this hint - I didn't realize I can do that.
Starting with a white texture is really a cool trick.

Now I'm using a white "blueprint" texture for primitive drawing, then add color via the "sprite.Draw" method. This makes life a lot easier indeed, because I don't need to create and manage multiple textures for the purpose of primitive drawing.

If anyone else has other / better ideas, I would be glad to read about it.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS