Problem with texture coordinates

Started by
2 comments, last by Cambo_frog 18 years, 10 months ago
I'm experiencing a problem that I think is a bug in dx8, but wanted confirmation before I pull what little hair I have left out. I'm in the process of migrating to dx9, but I'm not there yet. Anyway, when I use texture coordinates 0,0 - 1,1, it looks like my texture is actually starting a pixel or two off and wrapping. If I have the very first pixel in the texture map colored red (something to stand out) I see it rendered on the opposite side. Is this possibly a known problem with dx8, something obvious in my code, and/or something fixed in the latest versions of dx9? I'm using CreateTextureFromFile Thanks
3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.
Advertisement
Most likely your code.. A bug like that would be fixed before the lib was released..
Try clamping the coords and see what happens. This is how to do it in DX9, I have forgotten what the exact call is in DX8

gD3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
gD3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP );

------------------------See my games programming site at: www.toymaker.info
If previous advice didn't help could you answer the following questions, which may help to narrow the problem down?

Have you read the section in the SDK help file entiteled "Directly mapping Texels to Pixels"?

Have you tried changing your coordinates according to "Directly mapping Texels to Pixels" (simplified, subtracting 0.5f from your screen/window coordinates)?

Does the texture you are using have dimensions (width, height) which are a power of 2 ( 2, 4, 8, 16 ... 256, 512, 1024 etc)?

If the source file for for the texture has non power of 2 dimensions, you need to load the texture in a certain way.

You say you are using "CreateTextureFromFile"
I cannot see a description of this function in the SDK C++ help.Is this a function in managed DirectX?

In the C++ help, I see the IDirect3DDevice9::CreateTexture method but not CreateTextureFromFile.

Using D3DX there are the functions D3DXCreateTextureFromFile and D3DXCreateTextureFromFileEx.

In my experience, the only way to load textures from a image file with non power of 2 dimensions (assuming the target device supports non power of 2 textures) is to use D3DXCreateTextureFromFileEx with explicit values for the "Width" and "Height" parameters for this function (not D3DX_DEFAULT).

Most of the D3DX functions for loading textures from files try to force power of 2 dimensions unless you specify explicit values for width and height.

Most modern cards support textures with non power of 2 dimensions, and some not so modern cards like mine (GEForce4 Ti4200)!

I know you are using DX8 rather than DX9 but I am sure the texel/pixel alignment and texture loading code will be very similar.

If non of my suggestions work, please post back with your texture loading code and the code that uses that texture.

HTH,
Cambo_frog

[Edited by - Cambo_frog on June 18, 2005 1:40:56 PM]
For the love of god, please tell me that you've just omitted your error checking code for brevity, and you don't really assume that all those functions succeed.

This topic is closed to new replies.

Advertisement