Index/Vertex Buffer Texturing Woes

Started by
2 comments, last by sascoo 15 years, 1 month ago
Can anyone explain to me why this is not working...? sudo code... int renderSize = 4, indexSize = 6; Vector3 vertex[renderSize*3] = { -300,300,0, 0,0,0, 0,0,1, 300,300,0, 1,0,0, 0,0,1, -300,-300,0, 0,1,0, 0,0,1, 300,-300,0, 1,1,0, 0,0,1, }; Where it is a buffer of position, texcoord, and normals. unsigned short index[indexSize] = {0,1,2,3,2,1}; LPDIRECT3DVERTEXBUFFER9 vBuffer; LPDIRECT3DINDEXBUFFER9 iBuffer; graphics->CreateVertexBuffer(renderSize*sizeof(Vector3)*3,0,0,D3DPOOL_MANAGED, &vBuffer,0); void *pVoid = NULL; vBuffer->Lock(0,0,&pVoid,0); memcpy(pVoid,vertices,renderSize*sizeof(Vector3)*3); vBuffer->Unlock(); graphics->CreateIndexBuffer(indexSize*sizeof(unsigned short),0,D3DFMT_INDEX16,D3DPOOL_MANAGED,&iBuffer,0); unsigned short *ind = NULL; iBuffer->Lock(0,0,(void**)&indices,0); memcpy(ind,indices,indexSize*sizeof(unsigned short)); iBuffer->Unlock(); And then the render code... graphics->SetStreamSource(0,vBuffer,0,sizeof(Vector3)*3); graphics->SetIndices(iBuffer); graphics->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0,0, renderSize,0,6); Right now when it textures it looks like a solid color from my texture image... Thanks, John
Advertisement
Do you have a 3D texture? You are providing 3 texture coordinates per vertex whereas two would do for 2D textures. What's your vertex declaration? Did the texture image load correctly?
------------------------------------I always enjoy being rated up by you ...
I use three coordinates because I am lazy. Here is my shader:

//External Variablesuniform extern float4x4 wvp;uniform extern texture tex;uniform extern float4 diffuse = {1,1,1,1};sampler TexS = sampler_state{	Texture = <tex>;	MinFilter = LINEAR;	MagFilter = LINEAR;	AddressU = WRAP;	AddressV = WRAP;};struct InputVS{;	float3 posL: POSITION0;	float3 tex: TEXCOORD0;	float3 norm: NORMAL0;};struct OutputVS{	float4 posH: POSITION0;	float2 tex: TEXCOORD0;};OutputVS TransformVS(InputVS inVS){	OutputVS outVS = (OutputVS)0;	outVS.posH = mul(float4(inVS.posL, 1.0f), wvp);	outVS.tex = inVS.tex;		return outVS;}float4 BasicPS(float2 tex0: TEXCOORD0):COLOR{	return tex2D(TexS, tex0) * diffuse;}technique BasicEffect{	pass P0	{		vertexShader = compile vs_2_0 TransformVS();		pixelShader = compile ps_2_0 BasicPS();	}}
Ha...I just solved it... I had my vertex format set to pos, normal, texcoord instead of pos, texcoord, normal... I just wasted three days over that mistake...

This topic is closed to new replies.

Advertisement