Skip to main content
added more information
Source Link

thisThe main reason behind the above attempt is to draw a quad/triangle using screen co-ordinates so that i can place exactly where i want without the need to calculate the vertices all the time when ever i wish to place my quad/triangle.

This issue has left me baffled for last couple days. Any help or suggestion would be really helpful.

this issue has left me baffled for last couple days. Any help or suggestion would be really helpful.

The main reason behind the above attempt is to draw a quad/triangle using screen co-ordinates so that i can place exactly where i want without the need to calculate the vertices all the time when ever i wish to place my quad/triangle.

This issue has left me baffled for last couple days. Any help or suggestion would be really helpful.

edited body
Source Link

this issue has left me bafflesbaffled for last couple days. Any help or suggestion would be really helpful.

this issue has left me baffles for last couple days. Any help or suggestion would be really helpful.

this issue has left me baffled for last couple days. Any help or suggestion would be really helpful.

Tweeted twitter.com/StackGameDev/status/714150552830144512
Source Link

Why is quad rendered at the center (0,0) instead of top left when using orthographic projection

I have been trying to render a quad(containg a texture) using orthographic camera so that the quad can be rendered using the screen coordinates directly.

I started of by rendering just a triangle with a image. The triangle is rendered but it seems teh center of the screen is 0,0 but using the code below it should have been at top left of the screen.

Ortho camera matrix code:

// Set the camera position var cameraPosition = new Vector3(0.0f, 0.0f, 0.0f); var cameraTarget = new Vector3(0f, 0.0f, 1.0f); // Looking at the origin 0,0,0 var cameraUp = new Vector3(0.0f, 1.0f, 0.0f); // Y+ is Up // Prepare matrices // Create the view matrix from our camera position, look target and up direction // direct X uses left hand co-ordinate system m_viewMatrix = Matrix.LookAtLH(cameraPosition, cameraTarget, cameraUp); // Initialize the world matrix m_worldMatrix = Matrix.Identity; var scalingMatrix = Matrix.Scaling(720, 576, 1); var translationMatrix = Matrix.Translation(new Vector3(0, 0, 0)); var rotationMatrix = Matrix.RotationZ(0); m_worldMatrix = translationMatrix * scalingMatrix * rotationMatrix; m_worldMatrix = translationMatrix * scalingMatrix * rotationMatrix; var worlViewMatrix = Matrix.Multiply(m_worldMatrix, m_viewMatrix); m_projectionMatrix = Matrix.OrthoOffCenterLH(0, 720, 576, 0, 1f, 1000.0f); m_perObject.WorldViewProjection = Matrix.Multiply(worlViewMatrix, m_projectionMatrix); 

Vertices code:

stream.WriteRange(new[] { new VertexPositionTexture( new Vector4(720, 576, 0.5f, 1.0f), // position bottom-right new Vector2(1024,576) ), new VertexPositionTexture( new Vector4(0, 0, 0.5f, 1.0f), // position top-left new Vector2(0, 0) ), new VertexPositionTexture( new Vector4(720, 0, 0.5f, 1.0f), // position top-right new Vector2(1024, 0) ), }); 

Shader code:

float4x4 WorldViewProj; struct VertexShaderInput { float4 Position : SV_Position; float2 TextureUV : TEXCOORD0; }; VertexShaderOutput VSMain(VertexShaderInput input) { VertexShaderOutput output = (VertexShaderOutput)0; //output.Position = input.Position; output.Position = mul(input.Position, WorldViewProj); output.TextureUV = input.TextureUV; return output; } 

Screenshot of image rendered: enter image description here

Now I can't seem to figure out why the center of the screen is 0,0 and not top left ? Also as a part of this if I do not use a scaling matrix the triangle is not rendered.

this issue has left me baffles for last couple days. Any help or suggestion would be really helpful.

Note: I am using Directx11 with sharpdx and still learning directx learner.