• Advertisement

Archived

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

2D Images in a 3D environment

This topic is 4976 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 currently working on a 3D game and I want to incorporate 2D images into it for building my game interface and for some small visual effects. The way that I am current;y implementing this is br creating a primitive with transformed coordinates and then loading the image as a texture. The problem is that the textures dimensions need to be a power of 2 (2x2, 4x4, 8x8, 16x6, 64x64, etc). So the images tend to get distorted a lot when I draw render them to the primitive, since their dimensions are very irregular (200 x 400, 100 x 500, etc.) Here are my questions: 1) Is there a way to utilize the DirectDraw library and draw my 2D images using that? 2) Is there a better way to draw 2D images using the Direct3D Interface? Thanx in advance for your help. Emil Diego ediego@miami.edu

Share this post


Link to post
Share on other sites
Advertisement
1) Yes, DirectDraw is 100% 2D. That means it''s fairly easy to display textures on screen with it (actually, that''s it''s chief purpose). However, you''d be working with old, unsupported libraries (by unsupported I mean that Microsoft no long supports it - but the cards still run it, of course)

2) If you are using DX9, you can use ID3DXSprite, like J_Vitel suggested.

Any relatively new card doesn''t even have the power of 2 restriction that you are talking about. However, it''s when you start using early cards (like TnTs) that you will encounter this.


Dustin Franklin
Mircrosoft DirectX MVP

Share this post


Link to post
Share on other sites
thx for the info. I am looking at supporting older video cards, which means that I am stuck with the power of 2 restriction for my textures.

From what I understand of the sprite class, it loads images as textures. Does the sprite class have the same power of 2 limitation?


Emil Diego
ediego@miami.edu

Share this post


Link to post
Share on other sites
Yes, if you want to use ID3DXSprite, you''re still going to encounter the power of 2 limitation. This is because the IDirect3DTexture9 interface has to deal with it.

There is an easy way to deal with this, though. Simply create a power of 2 image, draw your artwork in whatever dimensions you want, and then alpha blend out all the rest. For example:

(1) Create a 256x256 image
(2) Draw your spaceship that takes up 200x150 pixels
(3) Pick a color (magenta works well), and fill in the left over space
(4) Use D3DXCreateTextureFromFileEx() to load the texture. For the ColorKey parameter, specify the RGB of magenta (or whatever filler color you picked)

Share this post


Link to post
Share on other sites
That sounds like a good workaround. I''ll have to give it a test. Since I am planning to include older video cards, I hope it wont take up too much memory and CPU processing.

thx for the help.

Emil Diego
ediego@miami.edu

Share this post


Link to post
Share on other sites
No, it won''t. All of the colorkey stuff is done at load-time, so you don''t have to worry about it slowing anything down at run-time. If you make sure you use the maximum amount of space per texture, you should be perfectly fine

Share this post


Link to post
Share on other sites

  • Advertisement