Sign in to follow this  

Texture Pixels

This topic is 4692 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 trying to create a texture and map it to a quad. The problem I'm having is that there seems to be way more pixels in the texture than what I created the texture with. For example, if I make a 10x10 texture in a paint program and draw a one pixel red border around the texture, it maps onto the quad just fine. The quad has a red border around it. The smaller I make the texture, the more texels it maps to so the fatter the border is on the quad. Now, if I use D3DXCreateTexture to create a blank texture of 10x10 pixels, lock the texture and set the bits for the red border, it doesn't look right when it is mapped on to the quad. I would assume that there are 100 pixels and the first is at 0 and the last at 99 in the bit array. If I try setting bits 0, 9, 90 and 99 to red and leave the rest black, then it should render on the quad with a red dot in each corner, but it doesn't there seems to be no corrolation to this and the red dots are just all over the place. In addtion they are far smaller than when I use a texture of the same size from a pint program. I just don't understand how this works. I can set bit 200 to red and it puts a red dot near the bottom corner of the quad. But how can there even be a bit 200 when I only made a 10x10 texture. I'm thinking that a pixel is made up of multiple bits, is this correct?

Share this post


Link to post
Share on other sites
Each row in a texture also has a pitch: some extra data that doesnt contribute to the image. The pitch is typically 1/4 of the width of your texture. So, if you have a 40x40 texture, 40 / 4 = 10 pixels of pitch per row. So the size of a 40x40 texture is actually 50x40 in memory.

Also, are you writting to the 200th byte or the 200th pixel? Because in a 32 bit texture 1 pixel = 4 bytes.

Share this post


Link to post
Share on other sites
I knew there was something strange going on. How do I know if I'm writing to the 200th byte or the 200th pixel. I want to write to pixels. I thought that in a 10x10 texture I could do the following:

texture->LockRect(0, &Rc, 0, 0 );
DWORD* P = (DWORD*)Rc.pBits;
P[0] = D3DCOLOR_COLORVALUE( 1.0f, 0.0f, 0.0f, 0.0f);
P[9] = D3DCOLOR_COLORVALUE( 0.0f, 1.0f, 0.0f, 0.0f);
P[90] = D3DCOLOR_COLORVALUE( 0.0f, 0.0f, 1.0f, 0.0f);
P[99] = D3DCOLOR_COLORVALUE( 1.0f, 1.0f, 1.0f, 0.0f);
texture->UnlockRect(0);


I thought this would write a red pixel in the top left corner, a green pixel in the top right corner, a blue pixel in the bottom left corner and a white pixel in the bottom right corner of the texture. I guess was wrong.

Can you show me what is wrong with this code?

How can I set it up in a couple of loops for the x,y coordinate, taking the pitch into account?

Share this post


Link to post
Share on other sites

This topic is 4692 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this