Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL ES 2.0 equivalent of glOrtho()?

In my iphone app, I need to project 3d scene into the 2D coordinates of the screen for some calculations. My objects go through various rotations, translations and scaling. So I figured I need to multiply the vertices with ModelView matrix first, then I need to multiply it with the Orthogonal projection matrix.

First of all am on the right track?

I have the Model View Matrix, but need the projection matrix. Is there a glOrtho() equivalent in ES 2.0?

like image 624
Sahil Sachdeva Avatar asked May 17 '10 08:05

Sahil Sachdeva


People also ask

What is glOrtho opengl?

The glOrtho subroutine describes a perspective matrix that produces a parallel projection. (Left, Bottom, -Near) and (Right, Top, -Near) specify the points on the near clipping plane that are mapped to the lower left and upper right corners of the window, respectively, assuming that the eye is located at (0, 0, 0).

What is the use of glOrtho in computer graphics?

The glOrtho function multiplies the current matrix by an orthographic matrix.


2 Answers

mat4 projectionMatrix = mat4( 2.0/768.0, 0.0, 0.0, -1.0,
                              0.0, 2.0/1024.0, 0.0, -1.0,
                              0.0, 0.0, -1.0, 0.0,
                              0.0, 0.0, 0.0, 1.0);                        

gl_Position = position;
gl_Position *= rotationMatrix;
gl_Position.x -= translateX;
gl_Position.y -= translateY;
gl_Position *= projectionMatrix;

For a fixed resolution (1024x768 in my case for iPad) I used this matrix and everything works like charm :) Here is complete description what values you need to put in your matrix: glOrtho.html

like image 58
Alexander Voloshyn Avatar answered Sep 28 '22 14:09

Alexander Voloshyn


The manual page for glOrtho() describes the equivalent operations, so as long as you have the matrix handy should be able re-implement it.

like image 25
unwind Avatar answered Sep 28 '22 15:09

unwind