0
votes

I m trying to implement orthographic camera. When I used DirectX, orthographic projection matrix could be determined in some way. An ordinary textured rectangle might be represented as follows:

auto l = -screenWidth / 2 + rectPosition.X;
auto r = l + rectWidth;
auto t = screenHeight / 2 - rectPosition.Y;
auto b = t - rectHeight;

float vx [] =
{
    l, t, 0, 1, 0, 0, // x y z w u v
    r, b, 0, 1, 1, 1,
    l, b, 0, 1, 0, 1,
    l, t, 0, 1, 0, 0,
    r, t, 0, 1, 1, 0,
    r, b, 0, 1, 1, 1,
};

And ortho matrix could be set this way:

ortho(screenWidth,screenHeight,0.1f,1000.f);

I could get visible image by setting camera's projection matrix as ortho matrix without changing camera's update code. So, I think this approach must work. But all I see is black screen. What's to be done?

2

2 Answers

0
votes

use glutOrtho2d. Refer the link if you have any doubts

https://www.opengl.org/sdk/docs/man2/xhtml/gluOrtho2D.xml

0
votes

An identity projection matrix puts the upper left and lower right extents of the viewport at (-1, +1) and (+1, -1) with no perspective effect, such that "by default" OpenGL gives you an orthographic projection where the top left of the screen is (-1, +1) and the lower right is (+1, -1).