# screen coordinate not working with pixel values

I have a very simple effect file shown below. I am using this to draw 2D lines, however it is not behaving how I expected and I can't seem to get my head round why.

If I draw a line that goes from 0,0 to 100, 100 for example, I would expect it to draw a line from one corner of the screen to a little way in. I would expect it to treat these numbers as screen coordinates. Instead, the line is huge! A line of about 2 long fills the whole screen. Why is this? How can I modify my shader to 'think' in screen coordinates?

// a struct for the vertex shader return value
struct VSOut
{
float4 Col : COLOR;    // vertex color
float4 Pos : SV_POSITION;    // vertex screen coordinates
};

VSOut VS(float4 Col : COLOR, float4 Pos : POSITION)
{
VSOut Output;
Output.Pos = Pos;    // set the vertex position to the input's position
Output.Col = Col;    // set the vertex color to the input's color

return Output;    // send the modified vertex data to the Rasterizer Stage
}

float4 PS(float4 Col : COLOR) : SV_TARGET
{
return Col;    // set the pixel color to the color passed in by the Rasterizer Stage
}

// the primary technique
technique10 Technique_0
{
// the primary pass
pass Pass_0
{
}
}

• I'm pretty sure that texture coordinates work on a scale of 0-1 so if you divide the coordinates by the size of the screen (in each axis) you can get a number from 0-1 (and even if it's 0-2 you can just multiply by 2 to get the correct range) Jan 11, 2012 at 0:17
• probably worth mentioning that if I put in 0,0 as the coords, that point draws dead centre. This puzzles me. @annonymously I tried, it didn't work unfortunately. Jan 11, 2012 at 0:24
• Do you mean that the line draws from the center of the screen? Jan 11, 2012 at 0:28
• yes. well one end of it does anyway. Jan 11, 2012 at 0:28
• Oh I just realised that the coordinates are [-1 - 1]: riemers.net/eng/Tutorials/XNA/Csharp/Series1/World_space.php Jan 11, 2012 at 0:30

x = (x / screenWidthInPixels) * 2.0 - 1.0