...
vertexList = new VertexPositionTexture
vertexList[0] = new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 0), new Vector2(0.0f, 0.0f)); // Color.Red
vertexList[1] = new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 0), new Vector2(0.0f, 1.0f)); // Color.Yellow
vertexList[2] = new VertexPositionTexture(new Vector3(1.0f, 1.0f, 0), new Vector2(1.0f, 0.0f)); // Color.Green
vertexList[3] = new VertexPositionTexture(new Vector3(1.0f, 1.0f, 0), new Vector2(1.0f, 0.0f)); // Color.Green
vertexList[4] = new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 0), new Vector2(0.0f, 1.0f)); // Color.Yellow
vertexList[5] = new VertexPositionTexture(new Vector3(1.0f, -1.0f, 0), new Vector2(1.0f, 1.0f)); // Color.Red
vertexDeclaration = new VertexDeclaration(graphics.GraphicsDevice, VertexPositionTexture.VertexElements);
...
Only with vertex colors everything is fine, but when try to use textures everything is messed up. So how I should define texture coordinates with XNA
EDIT: Whole point is to generate screen aligned quad..

Texture coordinates?!
kperson
At first glance it looks as though the texture is not loaded correctly. Can you show us the shader you are using
Jim Wooley
http://img133.imageshack.us/img133/146/jokubugaahy7.jpg <-- something strange with texture coords..
BrianMcCashin
I defined vertex shader it's still not working. Now it will just throw an exeception (InvalidCallException, ErrorCode=-2147467259) when DrawUserPrimitives is called. Is there any sample/tutorial how simple texture screen aligned should be done with XNA
EDIT: My mistake BeginScene() was commented out
Kevin Hoffman
If you aren't specifically setting a vertex shader, this rendering will just be inheriting whatever was previously set. My guess would be the previous vertex shader isn't passing through texture coordinates.
BJ Custard
Shader code:
// GLOBALS
//
uniform float waveFreq = 0.0;
uniform float waveAmp = 0.0;
uniform float time = 0.0;
texture SCENE
<
string name = "SCENE";
>;
uniform sampler2D tex0;
// STRUCTRS
//
struct PS_IN
{
float4 t0 : TEXCOORD0;
};
struct PS_OUT
{
float4 c0 : COLOR;
};
// PS ENTRY POINT
//
PS_OUT main(PS_IN ps_in)
{
float PI = 3.14159;
// point
float4 point = ps_in.t0 - float4(0.5, 0.5, 0.0, 0.1);
// radius
float radius = sqrt(point.x * point.x + point.y * point.y);
// angles
float cosAngle = point.x / radius;
float sinAngle = point.y / radius;
// calculate wave angle
float waveAngle = (radius - time) * waveFreq;
waveAngle = fmod(waveAngle, 2 * PI);
// calculate offset
float offset = 1 - cos(waveAngle - PI);
offset *= waveAmp;
// new radius
float newRadius = radius + offset;
// new point
float4 newPoint = float4(newRadius * cosAngle + 0.5, newRadius * sinAngle + 0.5, 0.0, 0.1);
PS_OUT ps_out;
ps_out.c0 = tex2D(tex0, newPoint);
ps_out.c0 += float4(time, 0.0, 0.0, 0.0);
return ps_out;
}
// PASSES
//
technique ripple
{
pass
{
Sampler[0] = sampler_state
{
Texture = (SCENE);
};
CullMode = None;
MultiSampleAntiAlias = TRUE;
AlphaBlendEnable = TRUE;
PixelShader = compile ps_2_0 main();
}
}
Irfon Subhan
Are you using BasicEffect for this, or a custom shader
What exactly is the problem with your output A bit more detail about how the image is looking wrong would be useful to help diagnose this.