Sign in to follow this  

"How to" textures

Recommended Posts

amtri    189
Hello, I have a couple of basic texture questions that I'm hoping somebody will be able to quickly help me with. 1) I'm trying to draw a white triangle. If I comment out all texture code, I do get my white triangle. Then I add the texture, and get a shaded triangle. Then I release my texture, and remove FVF_TEX1 from my vertex list, and draw the triangle again. I get the same triangle. It's like the texture is still there. Do I need to do anything oter than texture->Release() and not have a reference to texture coordinates in my vertices in order to eliminate the references to the texture? 2) My texture is a gray scale. Any ideas why I'm getting a reddish triangle, rather than a grayscale triangle? Thanks.

Share this post

Link to post
Share on other sites
jerm007    198
Hello there.

The texture is still bound to the texture unit with the SetTexture command and still has a reference on it, so it is not actually out of memory. If you set the texture in unit 0 to NULL it will completely unbind the texture and it should go back to how it was before.

I don't have the SDK docs handy right here, so I don't know the exact setup but that should give you a good start.


Share this post

Link to post
Share on other sites
amtri    189
Setting the texture on unit 0 to NULL did remove the texture. Thanks.

Now for my color problem: my colors aren't really coming through, so I did the following:

1) Set my texture to a solid red: 0xff. Indeed, I get a solid red triangle

2) Set my texture to a solid blue: 0xff0000. I get a solid blue triangle

3) Set my texture to a solid green: 0x00ff. I get nothing! Where did my green channel go?

Thanks again.

Share this post

Link to post
Share on other sites
amtri    189
I've got the problem narrowed down to a manageable level where somebody can actually help me.

I start with dx9_texture example

Then I substituted their loadTexture function with the code below. All it does is create the texture in a BMP file format. The texture itself is a single pixel. The code shows how I try to make the pixel in the texture red, or green, or blue.

If I make it red, I see the square. If I make it either green or blue, I see nothing.

Any ideas?


void loadTexture( void )
char pixels[88];
int i,*ival;
unsigned int *uint;
short *sval;

for(i=0; i<88; ++i) pixels[i] = 0;

/* identify as BMP */
pixels[0] = 'B';
pixels[1] = 'M';

/* file size */
ival = (int*)(pixels+2);
*ival = 88;

/* beginning of pixel data */
ival = (int*)(pixels+10);
*ival = 56;

/* header size */
ival = (int*)(pixels+14);
*ival = 40;

/* texture dimensions (1x1) */
ival = (int*)(pixels+18);
*ival = 1;
ival = (int*)(pixels+22);
*ival = 1;

/* plane */
sval = (short*)(pixels+26);
*sval = 1;

/* size per pixel */
ival = (int*)(pixels+28);
*ival = 32;

uint = (unsigned int*)(pixels+56);

/* set red */
*uint = 0x000000ff;
/* set green */
*uint = 0x0000ff00;
/* set blue */
*uint = 0x00ff0000;


g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);

Share this post

Link to post
Share on other sites
amtri    189
I believe I found my answer, after some trial and error. It turns out I got things to work by storing 24 bits per pixel in the BMP file, rather than 32 bits. Don't exactly why this is the case, since if I dump my memory allocation to a file I can open the resulting 32-bit BMP file in any graphic viewer, so the BMP file in memory is ok. But changing it to 24 bits per pixel made everything work.

Share this post

Link to post
Share on other sites
jaafit    116
Which byte is supposed to be alpha in 32-bit BMP? If it's the first byte, your red/green/blue contants all had zero alpha in 32-bit, making the object invisible. If it's the last byte, then only your red color is visible (though it is black) and the other 2 colors are invisible.

Share this post

Link to post
Share on other sites
amtri    189

Not clear I get your point. My understanding is that the higher bits get the value of alpha. If that's the case, then you're right that alpha is zero everywhere. However, I do see color in some cases and not in others. I can't explain that.

Also, if I set the highest bits to 1, nothing seems to change. And, if I take a visible setup that only shows red, and add, say, green bits to it, only the red shows up.

In other words, no matter what I do, I can only see red.

Share this post

Link to post
Share on other sites

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