What is the modern equivalent of the OpenGL function gluOrtho2d
? clang is giving me deprecation warnings. I believe I need to write some kind of vertex shader? What should it look like?
Modern equivalent of `gluOrtho2d `
5.7k Views Asked by Neil G At
2
There are 2 best solutions below
0

Modern OpenGL is significantly different. You won't be able to just drop in a new function. Read up...
http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Chapter-1:-The-Graphics-Pipeline.html
http://www.arcsynthesis.org/gltut/index.html
http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/
I started off this answer thinking "It's not that different, you just have to...". I started writing some code to prove myself right, and ended up not really doing so. Anyway, here are the fruits of my efforts: a minimal annotated example of "modern" OpenGL.
There's a good bit of code you'll need before modern OpenGL will start to act like old-school OpenGL. I'm not going to get into the reasons why you might like to do it the new way (or not) -- there are countless other answers that give a pretty good rundown. Instead I'll post some minimal code that can get you running if you're so inclined.
You should end up with this stunning piece of art:
Basic Render Process
Part 1: Vertex buffers
Part 2: Vertex Array Object:
We need to define how the data contained in my_vertex_array is structured. This state is contained in a vertex array object (VAO). In modern OpenGL there needs to be at least one of these
Part 3: Shaders
OK, we have our source data all set up, now we can set up the shader which will transform it into pixels
Part 4: Drawing things on the screen
And That's it!
... except for the actual
Shaders
I started to get a little tired at this point, so the comments are a bit lacking. Let me know if you'd like anything clarified.
The Actual Question you asked: Orthographic Projection
As noted, the actual math is just directly from Wikipedia.