Jump to content
  • Advertisement
Sign in to follow this  

texture problem (always not resolved : see last post)

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

Hi, my program just displays one triangle with color instead of a quad (composed of two triangles) textured. This is what i do : my four vertices and my texture loading in the constructor :
[source cpp]
vertexData[0].x=0.0f ;
	vertexData[0].y=10.0f ;
	vertexData[0].z=0.9f ;
	vertexData[0].w=1.0f ;
	vertexData[0].color=D3DCOLOR_ARGB(0, 255, 0, 0) ;
	vertexData[0].u = 0.0f ;
	vertexData[0].v = 0.0f ;

	vertexData[1].x=10.0f ;
	vertexData[1].y=0.0f ;
	vertexData[1].z=0.9f ;
	vertexData[1].w=1.0f ;
	vertexData[1].color=D3DCOLOR_ARGB(0, 0, 255, 0) ;
	vertexData[1].u = 1.0f ;
	vertexData[1].v = 1.0f ;

	vertexData[2].x=0.0f ;
	vertexData[2].y=0.0f ;
	vertexData[2].z=0.9f ;
	vertexData[2].w=1.0f ;
	vertexData[2].color=D3DCOLOR_ARGB(0, 0, 0, 255) ;
	vertexData[2].u = 0.0f ;
	vertexData[2].v = 1.0f ;

	vertexData[3].x=0.0f ;
	vertexData[3].y=0.0f ;
	vertexData[3].z=0.9f ;
	vertexData[3].w=1.0f ;
	vertexData[3].color=D3DCOLOR_ARGB(0, 0, 0, 255) ;
	vertexData[3].u = 1.0f ;
	vertexData[3].v = 0.0f ;

	HRESULT hr=D3DXCreateTextureFromFile(myIDirect3DDevice9, "veg004.jpg", firstTexture);

i use vertex and indice buffers, so i define indices with this : long int tabIndices[]={0, 1, 2, 0, 3, 2};// here the first triangle is displayed and not the second, but i don't find in what order i have to put the three last vertices, if it is the problem. in the rendering function, i do :
[source cpp]
	myIDirect3DDevice9->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);   //Ignored
	myIDirect3DDevice9->SetTexture(0, (IDirect3DBaseTexture9 *)firstTexture);

finally i do this : myIDirect3DDevice9->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2); [Edited by - blueShadow on August 4, 2007 6:37:21 AM]

Share this post

Link to post
Share on other sites
I had the same problem I think it has something to do with the
fact that you didn't set a material, I could be wrong. And if you are
using Flexibel Vertex Format stuff you must make sure you put everything in
the right order inside your vertex structure. In the directx sdk documentation
there is a tabel of the oder in wich you need to put them into the structure.


Share this post

Link to post
Share on other sites
This is how I create my textured quads, in MDX.

// Create the quad vertices....
CustomVertex.PositionNormalTextured[] verts =
new CustomVertex.PositionNormalTextured(new Vector3(-1, 1, 1), new Vector3(0.0f, 0.0f, -1.0f), 0.0f, 0.0f), // upper right
new CustomVertex.PositionNormalTextured(new Vector3(-1, -1, 1), new Vector3(0.0f, 0.0f, -1.0f), 0.0f, 1.0f), // lower right
new CustomVertex.PositionNormalTextured(new Vector3( 1, 1, 1), new Vector3(0.0f, 0.0f, -1.0f), 1.0f, 0.0f), // upper left
new CustomVertex.PositionNormalTextured(new Vector3( 1, -1, 1), new Vector3(0.0f, 0.0f, -1.0f), 1.0f, 1.0f), // lower left

// ...and indices.
short[] inds = { 0, 1, 2, 2, 1, 3 };

Share this post

Link to post
Share on other sites
Do you know if your texture is actually created? Are you getting a return error from the 'D3DXCreateTextureFromFile'? Another thing would be to comment out your texture stage states and just set the texture.

Share this post

Link to post
Share on other sites
i do :

HRESULT hr=D3DXCreateTextureFromFile(myIDirect3DDevice9, "veg004.jpg", firstTexture);


and nothing appends, so i think that it's good.

Share this post

Link to post
Share on other sites
Are you saying you don't get an error or you do?
What about the texture states?
If you are seeing a black quad then you need to turn off lighting, because you are using a texture.

Share this post

Link to post
Share on other sites
It may have to do with your FVF structure and how you define it.

struct QuadVertex
FLOAT x, y, z;
D3DCOLOR color;
FLOAT tu, tv;


Setup quad vertices...

g_d3dDevice->SetStreamSource(0, quadVertexbuffer, 0, sizeof(QuadVertex));
g_d3dDevice->SetTexture(0, (IDirect3DBaseTexture9 *)quadTexture);
g_d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2);

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net 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!