Sign in to follow this  

Problem with textures...

This topic is 4858 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

Hello ! I have a problem with textures. Still using DX8. I'm trying to insert a texture in a rectangle: { x, y, z, D3DCOLOR_XRGB(255, 0, 0), 0.0f , 0.0f ,}, { x, y+d, z, D3DCOLOR_XRGB(255, 0, 0), 0.0f , 1.0f ,}, { x+d, y+d, z, D3DCOLOR_XRGB(255, 0, 0), 1.0f , 1.0f ,}, { x+d, y+d, z, D3DCOLOR_XRGB(255, 0, 0), 1.0f , 1.0f ,}, { x+d, y, z, D3DCOLOR_XRGB(255, 0, 0), 1.0f , 0.0f ,}, { x, y, z, D3DCOLOR_XRGB(255, 0, 0), 0.0f , 0.0f ,}, Is the mapping ok? Texture seems to be loaded correcly, and the rectangle don't appear red colour, it appears like brown color. (Solid color over all the rectangle) Some texture code: ============================================================== D3DXCreateTextureFromFile(cpy_pD3DDevice, szTextureFilePath, &cpy_pTexture); if (cpy_pTexture != NULL) { cpy_pD3DDevice->SetTexture(0, cpy_pTexture); cpy_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); } =============================================================== I'm trying to load a 128x128 bitmap found in the tutorials of andypike.com Thanks!

Share this post


Link to post
Share on other sites
Try this instead:

{ x, y, z, D3DCOLOR_XRGB(255, 0, 0), 0.0f , 1.0f ,},
{ x, y+d, z, D3DCOLOR_XRGB(255, 0, 0), 0.0f , 0.0f ,},
{ x+d, y+d, z, D3DCOLOR_XRGB(255, 0, 0), 1.0f , 0.0f ,},
{ x+d, y+d, z, D3DCOLOR_XRGB(255, 0, 0), 1.0f , 0.0f ,},
{ x+d, y, z, D3DCOLOR_XRGB(255, 0, 0), 1.0f , 1.0f ,},
{ x, y, z, D3DCOLOR_XRGB(255, 0, 0), 0.0f , 1.0f ,},

Also, make sure you are modulating the texture with the diffuse color in your texture stage state.

Chris

EDIT: The reason I changed the v texture values is because the texture coordinates are like screen coordinates. The top, left corner of the texture is 0. The further down you go (-y), the higher the v coordinate is. The further right you go (+x), the higher the u coordinate is. Of course this is only valid when you are talking about a triangle in the XY plane.

Chris

Share this post


Link to post
Share on other sites
Thanks Chris:

But unfortunately i can't load the texture. I do not understand what I'm doing bad. I've changed the textures as you said but nothing.

The rectangle appears with a solid color, like brown or something like that.

What's modulating the texture with the diffuse color in your texture stage state ?

Thanks & sorry.

Share this post


Link to post
Share on other sites
Sorry, I didn't even see the line of code:

cpy_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);

That should have clued me in that it wasn't set properly, because what that is saying is "In the first texture stage, just select the argument I specify", but you didn't specify which argument, so it's just using the one already there, which is probably DIFFUSE.

I suggest reading on texture stages. Basically, a vertex can go from one stage to the next, until it reaches the final stage that you specify. In each stage, the vertex color will be changed based on the settings for that stage. The same is true for the alpha value of the vertex. When the color and alpha values have completed their journeys through the stages, a final color and alpha value is sent off to the pixel shader, where other stuff happens, like adding fog for instance.

To set the texture stage up to render a texture, there's several ways to do it. I'll list several common ways. Each texture stage can have 2 Color operands and 2 alpha operands. Note there is ARG0 for color and alpha, but don't worry about it.

Make the vertex color the same as the texture color:
cpy_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
cpy_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);

Make the vertex color the same as the diffuse color in the vertex (or if lighting is enabled, the output from lighting):
cpy_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
cpy_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);

Make the vertex color equal the color taken from the texture multiplied (Modulated) by the vertex color:
cpy_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
cpy_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
cpy_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE);

When you've picked one, since we're only using the first texture stage stage, inform D3D that the second stage is not used.

cpy_pD3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);


Chris

[Edited by - Supernat02 on August 28, 2004 8:05:07 AM]

Share this post


Link to post
Share on other sites
Hi Chris:

Really very very appreciated your help. Still doesn't work and I'm starting to get tired :P ... (It Doesn't work in every way you have gave me :( )

My work is based on andypike.com tutorial 6 about textures. And I see the code and I can't see the difference with mine. So why? :)

I've tested that my cpy_pTexture is not NULL. It's possible to have some problem with my classes diagram or something like that?.

Cobject(Base) -> LPDIRECT3DDEVICE8 cpy_pD3DDevice;
LPDIRECT3DVERTEXBUFFER8 cpy_pVertexBuffer;
LPDIRECT3DTEXTURE8 cpy_pTexture;
CFace(Inherited)

I put my render code,

virtual bool Render(){

cpy_pD3DDevice->SetStreamSource(0, cpy_pVertexBuffer, sizeof(FACE_CUSTOMVERTEX));
cpy_pD3DDevice->SetVertexShader(FACE_D3DFVF_CUSTOMVERTEX);

if (cpy_pTexture != NULL) {
cpy_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
cpy_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
cpy_pD3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
}
else
{
cpy_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);
}

cpy_pD3DDevice->DrawPrimitive (D3DPT_TRIANGLELIST, 0, 2);
return true;
}

Share this post


Link to post
Share on other sites
Make sure you have SetRenderState(D3DRS_LIGHTING, false) somewhere. Lighting defaults to being on, and it requires that your vertex format has normals, and that you set a material. That will only affect the DIFFUSE in your texture stages, which you're ignoring for now, so that's likely not the main problem.

It shouldn't be solid color unless.... Did you set D3DRS_WRAP0 to something? It enables a weird wrapping mode that takes the shortest path between texturecoordinates. Using texcoords 0 and 1 are the same point as far as it's concerned. Set D3D_WRAP0 to 0.

Or... Did you tell D3D which texture coordinates to use? SetTextureStageState(0, D3DTSS_TEXTURECOORDINDEX, 0) will tell D3D that any texture used on stage 0 should use UV set 0 (the first one in your vertex format).

Is FACE_D3DFVF_CUSTOMVERTEX correct? Is it (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1)?

Share this post


Link to post
Share on other sites

This topic is 4858 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