Swift - Friday Pie
Swift - Friday Pie

Reputation: 14688

what are actual formulas for glOrtho

Working with legacy project that used OpenGL and adapting it to OpenGL ES I stumbled upon this problem. I have to implement matrix stack use on my own and create some state machine and own implementation of glOrtho and glPerspective, but some documentation are different, depending on which source I look.

Documentation on Kronos website is mangled and unusable. Documentation on Microsoft site

https://learn.microsoft.com/ru-ru/windows/win32/opengl/glortho?redirectedfrom=MSDN

Another version, which matches also formulas in man pages and some books:

https://lmb.informatik.uni-freiburg.de/people/reisert/opengl/doc/glOrtho.html

Experimentation with glGelFloatv() had shown that on Windows glOrtho() uses first version. Is it possible that other platforms use another? There were plenty problems with projection matrix in this code base and trying swapping out implementation aggravated either one or another, to the point that I get impression that sign actually changes under some conditions. Which variant I should to follow? Does glOrtho contain some additional logic aside from multiplying existing matrix on new one?

Upvotes: 1

Views: 201

Answers (1)

Rabbid76
Rabbid76

Reputation: 211230

The only truth is the specification. From OpenGL 2.1 API specification - 2.11.2 Matrices:

void Ortho( double l, double r, double b, double t, double n, double f );

describes a matrix that produces parallel projection. (l b − n)T and (r t − n)T specify the points on the near clipping plane that are mapped to the lower left and upper right corners of the window, respectively. f gives the distance from the eye to the far clipping plane. If l is equal to r, b is equal to t, or n is equal to f, the error INVALID VALUE results. The corresponding matrix is

enter image description here

(The most recent OpenGL 4.6 API Compatibility Profile Specification - 12.1 Fixed-Function Vertex Transformations says the same)

Upvotes: 2

Related Questions