# Why is this orthographic projection matrix not showing my textured quad?

I've been following tutorials, mainly this one, and I am still not quite sure why my textured quad is not showing inside the frustum that I've rendered before. I can see it if and only if I don't multiply gl_Position with OrthoProjMatrix * vertexmodelspace, and instead, multiply gl_position with vertexmodelspace.

Here is some of my code; my Main.CPP is also available via PasteBin.

Orthographic Projection Matrix Setup Code:

void OpenGL_Engine::OrthoProjectionSetup(GLuint program)
{
GLfloat Right = 100.0;
GLfloat Left = 50.0;
GLfloat Top = 100.0;
GLfloat Bottom = 50.0;
GLfloat zFar = 1.0;
GLfloat zNear = -1.0;

GLfloat LeftAndRight = 2.0f / (Right - Left);
GLfloat TopAndBottom = 2.0f / (Top - Bottom);
GLfloat ZFarAndZNear = - 2.0f / (zFar - zNear);

GLfloat orthographicprojmatrix[] = {
//XX XY XZ XW
LeftAndRight,
0.0, 0.0,
- (Right + Left) / (Right - Left),

//YX YY YZ YW
0.0,
TopAndBottom,
0.0 ,
- (Top + Bottom) / (Top - Bottom),

//ZX ZY ZZ ZW
0.0,
0.0 ,
ZFarAndZNear,

//WX WY WZ WW
- (zFar + zNear ) / (zFar - zNear),
0.0,
1.0
};

GLint orthographicmatrixloc = glGetUniformLocation(program, "OrthoProjMatrix");
glUniformMatrix4fv(orthographicmatrixloc, 1, GL_TRUE,
&orthographicprojmatrix[0]);
}


Vertex Shader Code :

#version 330 core

layout(location = 0) in vec4 vertexposition_modelspace;
layout(location = 1) in vec2 vertexUV;
out vec2 UV;
uniform mat4 OrthoProjMatrix;

void main()
{
gl_Position =  OrthoProjMatrix * vertexposition_modelspace;
UV = vertexUV;
}


I'm having problems with the orthographic projection matrix; either it is not being done correctly, not setup correctly, my shader is not setup correctly or it's the textured quad that is not in view. Please note that I do not want to use a library for this. What am I doing wrong?

• Try changing GL_TRUE to GL_FALSE – Bálint Oct 7 '16 at 8:57
• Punctuation is your friend. I got out of breath reading the first paragraph. – 3Dave Dec 14 '16 at 18:14
• Also, WHERE is your quad located? If Z = 0, it'll get culled. – 3Dave Dec 14 '16 at 18:15

## 1 Answer

In your code orthographicprojmatrix does not define a 4x4 orthographic projection matrix, you list an array of 14 floats, not 16, in your last two rows you missed some elements, it should be:

GLfloat orthographicprojmatrix[] = {
//XX XY XZ XW
LeftAndRight,
0.0,
0.0,
-(Right + Left) / (Right - Left),

//YX YY YZ YW
0.0,
TopAndBottom,
0.0,
-(Top + Bottom) / (Top - Bottom),

//ZX ZY ZZ ZW
0.0,
0.0,
ZFarAndZNear,
-(zFar + zNear ) / (zFar - zNear),

//WX WY WZ WW
0.0,
0.0,
0.0,
1.0
};

• Okay I made the changes thanks for pointing that out, however still no textured quad their hmmm... – Dominic Hughes Aug 1 '16 at 7:16
• Texturing a quad requires a fragment shader and associated texture initialization code, none of which I see in your question, if you'd like help with those additional issues please attach the fragment shader and relevant texture code. – user5665 Aug 1 '16 at 7:20
• I have that already setup , I am talking about why their is no anything showing on the rasterizer when clearly I've done my matrix correctly?. It works if I don't multiply by the matrix.\ – Dominic Hughes Aug 1 '16 at 7:24
• You've verified your texture code with another (perspective) projection or the sort and know there are no issues with your fragment shader? Then are you sure your textured quad is contained within your projection? The values you use for your projection don't match those in the tutorial you linked to, it makes me think that you don't fully understand those values and might have made a change to them without understanding how they affect your projection. – user5665 Aug 1 '16 at 7:35
• @DominicHughes if your current code is different from the question, please fix the question first. – sam hocevar Sep 2 '16 at 11:26