Skip to main content
GameDev.net gamedev.net
🔒 Locked

My 2d in Direct3d model

Started by Muzlack Apr 9, 2005 at 7:19 PM 2 replies 1.2k views
Original Post
Muzlack
Muzlack
I've concocted a model to port my Directdraw engine to direct3d. I thought I'd run the idea by some of the gurus here. Basically, the entire game is in 2d. Everything already revolves around an image class that I wrote. Essentially how it'd work is when you load the image, you would specify if it needs color keying, rotation, flipping, or alpha blending. If it doesn't, it would load it into an IDirect3DSurface9. If it does, it would figure out the maximum texture size for the client machine. It would divide the image into multiple textures spanning across the maximum texture size. Meaning, in the simplest example, if it loaded a 512x512 image, and the maximum texture size for the graphics card is 256x256, it would load 4 256x256 textures. Now, I don't make my images in powers of two. So if it was something like 520x512, it would load the 2x2 256x256 textures like before, but it would also figure out the smallest power of two above it, so that it could match. Meaning, in this example, the textures would turn out to look something like this: [256x256][256x256][4x256] [256x256][256x256][4x256] This way, it could load any size image up. It would also generate the quads automatically. I could keep all of the functionality necessary from my directdraw engine, and use this. Would it work? are there any pressing flaws that I don't notice?
--Muzlack
Evil Steve
Evil Steve
That looks fine to me. If you're using D3DX to load the images (Actually, if you're doing it yourself this applies too), then you need to make sure you have your texture coordinates set up correctly, so if you load a 4x256 texture, you only actually use the first 4 pixels (so your v texture coordinate would be 4/256 = 0.015625).
You may also want to check if the graphics card supports non-square textures (a lot do now), so a 5x256 image could become 8x256, or a 300x200 texture could become:
[256x128][64x128]
[256x128][64x128]
But that could confuse things a fair bit...

I wouldn't bother going as far as checking for non-power-of-2 support, since a) it's not widely supported and b) a lot of cards just treat it as a larger power of 2 texture (so 100x100 would become 128x128 on the card, and it'd hide that information from you to pretend to be really 100x100).

Good luck [smile]
Holy Fuzz
Holy Fuzz
Why do you load images that don't require color keying, flipping, and alpha blending into surfaces as oppposed to textures.
Muzlack
Muzlack
Well if they don't need any 3d features, why bother?

A perfect example is a full screen background. There's no sense at all in drawing those as textured quads.
--Muzlack

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.