Sagar Gupta
Sagar Gupta

Reputation: 161

How glOrtho2D Works

glViewport(0, 0, w, h);

gluOrtho2D(10, 100, 10, 100);

I am not getting any output, can you help me?

If I set it to

gluOrtho2D(-50, 50,-50, 50);

Then object created at center of window.

Upvotes: 2

Views: 9361

Answers (1)

Nico Schertler
Nico Schertler

Reputation: 32587

gluOrtho2D(left, right, top, bottom) defines a view box. That means that there is no perspective.

With

gluOrtho2D(-50,50,-50,50);

you say (assuming you have no additional model view matrix):

  • The viewport's left edge is located at world position x = -50
  • The viewport's rightedge is located at world position x = +50
  • The viewport's top edge is located at world position y = -50
  • The viewport's bottomedge is located at world position y = +50

If then your object appears at the screen's center, it is probably located at the world's origin.

If you specify

gluOrtho2D(10,100,10,100);

then you can see an x-range of 10 to 100. The origin is not within this range and therefore not visible (it is beyond the left edge of the viewport).

Note that there are apparently two different signatures of this function based on the API: gluOrtho2D(left, right, bottom, top) and gluOrtho2D(left, right, top, bottom).

Upvotes: 10

Related Questions