Sign in to follow this  

Index/Vertex Buffer Texturing Woes

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

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

Share this post


Link to post
Share on other sites
I use three coordinates because I am lazy. Here is my shader:


//External Variables
uniform 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();
}
}

Share this post


Link to post
Share on other sites

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