Advertisement Jump to content
Sign in to follow this  

Problem with texture coordinates

This topic is 4963 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'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

Share this post

Link to post
Share on other sites
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 );

Share this post

Link to post
Share on other sites
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.


[Edited by - Cambo_frog on June 18, 2005 1:40:56 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!