This question is very similar to my other question, however the solution provided there does not work when using OpenGL 3.1. glOrtho seems to do absolutely nothing no matter where I call it in OpenGL 3.1. Googling this didn't give me any decent results. Should I be doing something in the fragment/vertex shaders, or?

  • \$\begingroup\$ With OpenGL 3, lots of stuff got removed (Like the matrix stack you mentioned). If you want to use a matrix in OpenGL 3+, you have to supply it to your shader manually. \$\endgroup\$
    – Tara
    Dec 2, 2016 at 4:19
  • \$\begingroup\$ And how would I do that? \$\endgroup\$ Dec 2, 2016 at 5:03
  • 1
    \$\begingroup\$ You search the Internet for an OpenGL 3 tutorial, then you follow the tutorial, then once you've learned how OpenGL 3 works you go back to your game and you hopefully know how to make it work. \$\endgroup\$
    – user253751
    Dec 2, 2016 at 10:20

3 Answers 3


In modern OpenGL (> 2.0 actually) the matrix stack has been removed . The matrix stack was part of the fixed pipeline. The fixed pipeline (for example, glBegin, glEnd) is deprecated and has been replaced in favour of a programmable pipeline.

This requires you to use shaders and supply your own transform matrices. I recommend reading this for a great tutorial set on modern OpenGL. It covers everything from the basic setup of drawing a triangle to the matrices you need.

Keep in mind, comparing to older versions (with glOrtho for example) this new pipeline is much harder to learn and understand. There is not really an easy way out.

EDIT: Fixed my statement about the removed pipeline (as Dudeson pointed out). The older OpenGL code should still work on newer platforms, but you can't use both in modern OpenGL (its bad practice to use the fixed pipeline eitherway)

  • 1
    \$\begingroup\$ 1. The matrix stack is still present in OpenGL 2.1 (maybe you're confusing it with OpenGL ES 2.0). In order to still use it in OpenGL 2.1 you have to use built-in vertex shader variables like gl_ModelViewProjectionMatrix and functions like ftransform(). 2. I would argue that the new pipeline is much harder to learn and understand. In my opinion it's easier because it does less stuff behind the scenes which can be quite confusing (at least for me it was). \$\endgroup\$
    – Tara
    Dec 2, 2016 at 22:21

Yes, you should do something in the shader. A simple vertex shader would be something like:

#version 140

in vec3 position;

uniform mat4 mvp;

void main() {
    gl_Position = mvp * vec4(position, 1.0);

GLSL's versions

Where mvp is your full matrix (projection, view, model) that you pass from your code. In your case, you want your projection to be orthogonal matrix by either making one yourself or use a library like glm.


enter image description here

This is how a usual orthographic projection matrix looks like. r, l, t, b, f, and n are the positions of the right, left, top, bottom, far and near clipping planes respectively. To achieve your desired effect:

r should be the width of the display in pixels
l is 0
t is 0,
b should be the height og the display in pixels
f should be something like 1000
n should be something like -1000

The last 2 doesn't matter, but f should be bigger than n.

After you created this matrix, you need to create a shader, load in this as the projection matrix and multiply the eye-space position of the vertex with it.

  • \$\begingroup\$ If I'm reading this correctly, the first one is 2/r-l, or am I wrong? I can't read the last one one the first row either (excuse my noobiness) \$\endgroup\$ Dec 2, 2016 at 23:00
  • \$\begingroup\$ @Omega This is a matrix, those values are simple fractions. It could be translated to 2 / (r - l) \$\endgroup\$
    – Bálint
    Dec 3, 2016 at 16:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .