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][1]][1]
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.
[1]: https://i.sstatic.net/g7LMI.jpg