texture makes triangle darker instead of textured

Started by
12 comments, last by Tonni 17 years, 10 months ago
hi, i'm new to DirectX. first of all, don't be scared when you read my code :) i know there are free engines out there that are much better than mine will ever get, but nevertheless i develop my own. this is because i love to learn the very basics and build up my own solution upon it, so i understand every single line. i don't like to use engines/libraries or whatever that others have written and therefore i don't know what exactly is going on. this is my first c++ project and i'm sure there are much noobie-errors in my code. please forgive me ;) so, here is what drives me crazy: i tried to render a rotating triangle. that works fine. the next step was to extend my vertex format, load a texture and use it to render my triangle. well, loading works, assigning works, rendering works - but the triangle is not textured. instead, the triangle just gets darker, but not black. the first 150 frames are rendered without the texture, the next 150 with it, so you can compare the effect. the following link is a "short summary" of what i think may contain the error. http://pastebin.com/725403 this is the whole project, in case the "summary" above is not enough code. unfortunately i haven't built a config tool yet, so you have to work your way through the DirectX settings yourselves. sorry for that :/ http://www.myupload.biz/f/2fs/30811/texture_error.zip and last, the binary for windows, if some of you don't want to compile it himself. just place a texture called "Texture.bmp" in the same directory as the binary. http://www.myupload.biz/f/1tx/30812/deleteme.exe i am sure there will be much more to ask for me, so, is there any IRC channel you could recommend to me? sometimes it is more useful to ask something small in a chat and get the answer a minute later than to create a new thread here :) thanks, Tonni
Advertisement
How did you create the UV texture coords for the 3 vertices of the triangle? If you don't do them right, the texture could get end up looking flat, because you may have mapped too small of a part of the texture to the triangle and it ends up tiling it (it is shrunk down to the point that it loses its detail).
--------------------------Most of what I know came from Frank D. Luna's DirectX books
the texture coordinates are hard-coded
the top vertex of the riangle has the texture coordinates 0.5|0, the lower-left vertex 0|1, the lower-right one 1|1

should be well that way, shouldn't it?
Hi there!
After a quick look at your code (the pastebin one) it seems that your UV-coordinates are actually wrong, like DXnut guessed.
These lines should change:
Vertex t=Vertex(Vector3(0, 1, 0), Color(1, 0, 0), Vector2(0.5, 1)); tl.push_back(t);t=Vertex(Vector3(1, -1, 0), Color(0, 1, 0), Vector2(1, 0));tl.push_back(t);t=Vertex(Vector3(-1, -1, 0), Color(0, 0, 1), Vector2(0, 0)); // <---- changetl.push_back(t);

You might want to swap the uv-coordinates of the second and third vertex.
If you´re not sure how UV-coordinates are interpreted, look for "Texture coordinates" in the DX SDK docs, but just as a quick overview:
A UV-coordinate of (0,0) refers to the top-left corner of a texture, (1,0) is top-right, (0,1) bottom-left and (1,1) is bottom-right of it.
Your UV-coordinates could cause that effect you described, but that would depend on the texture you use, so I´m not too sure if that will solve your problem.

Good luck!
well, that change didn't cause anything to happen :/

some more ideas?
I see absolutely nothing wrong with those texture coordinates he originally had.
Though it could still be a problem with the texture itself, or with the texture stage state.
.
i get the same effect with every texture i load
the texture stage states are default, what should i try to set them to?
directly from the DX SDK docs:
    // Setup texture. Using textures introduces the texture stage states, which    //   govern how textures get blended together (in the case of multiple    //   textures) and lighting information. In this case, you are modulating    //   (blending) your texture with the diffuse color of the vertices.    g_pd3dDevice->SetTexture( 0, g_pTexture );    g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );    g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );    g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );    g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );


That should result in your texture being multiplied with the vertex colors, though as far as the docs state, this should be the behaviour of the default values of these states, too, except the default value for D3DTSS_ALPHAOP is different. Default values for texture stage 0 are:
D3DTSS_COLOROP => D3DTOP_MODULATE
D3DTSS_COLORARG1 => D3DTA_TEXTURE
D3DTSS_COLORARG2 => D3DTA_CURRENT, which is equivalent to D3DTA_DIFFUSE on stage 0
D3DTSS_ALPHAOP => D3DTOP_SELECTARG

So, it should be enough to disable alpha blending by setting D3DTSS_ALPHAOP to D3DTOP_DISABLE.
Perhaps it helps ;)
just be aware:
D3DTOP_DISABLE
Disables output from this texture stage and all stages with a higher index. To disable texture mapping, set this as the color operation for the first texture stage (stage 0). Alpha operations cannot be disabled when color operations are enabled. Setting the alpha operation to D3DTOP_DISABLE when color blending is enabled causes undefined behavior.
I cant seem to get to the pastebin... what size is a color struct, if you are using FFP then the diffuse component should be an int.

Try turning off all lighting.
Insufficent Information: we need more infromationhttp://staff.samods.org/aiursrage2k/

This topic is closed to new replies.

Advertisement