Jump to content
  • Advertisement
Sign in to follow this  
Yura

Can not set texture coordinate

This topic is 2162 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,

Sorry for so silly question,

I can't set texture coordinates in my shader. They are always equal 0.

 

So, here is declarations in shader:

Texture ColorTexture;

sampler ColorTextureSampler = 
sampler_state 
{ 
texture = <ColorTexture> ; 
magfilter = NONE; 
minfilter = NONE; 
mipfilter = NONE; 
AddressU = wrap; 
AddressV = wrap; 
};

struct VertexShaderInput
{
    float4 Position : POSITION;
    float2 texCoord : TEXCOORD0;
};

struct VertexShaderOutput 
{
    float4 Position : POSITION;
    float2 texCoord : TEXCOORD0;

};

 

 

and program code:

 

List<Vertex> points = new List<Vertex>();
for (int j = 0; j < list.Count; j++)
{
points.Add(new Vertex()
{
Coord = new Vector2(SomeTextureCoordinate, 0),
Position = new Vector3(list[j].X, list[j].Y, list[j].Z)
});
}

VertexFormat myVertexFormat = VertexFormat.Position | VertexFormat.Texture0;

vertices = new VertexBuffer(d3dDevice, sizeOfVertex * totalPointsCount, Usage.WriteOnly,
myVertexFormat, Pool.Managed);

var vertexElems = new[] {
                new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                new VertexElement(0, 12, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
                VertexElement.VertexDeclarationEnd
            };
            vertexDecl = new VertexDeclaration(d3dDevice, vertexElems);

            d3dDevice.VertexFormat = myVertexFormat;
            d3dDevice.VertexDeclaration = vertexDecl;

 

 

Position set well, but texCoord in shader is always 0. 

I did all declarations in VertexBuffer, device and shader, so, where is the problem?

Share this post


Link to post
Share on other sites
Advertisement

I found mistake, now it works

VertexFormat myVertexFormat = VertexFormat.Position | VertexFormat.Texture0;

need to be

VertexFormat myVertexFormat = VertexFormat.Position | VertexFormat.Texture1;

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!