Now I initialize my OpenGL view by this code:
glLoadIdentity();
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glOrtho(0.0, w, 0.0, h, -1.0, 10.0);
And I it looks like it should look.
But its Othological view. And I want Perspective view. So I try to initialize that with:
glLoadIdentity();
glViewport(0, 0, w, h);
glMatrixMode(GL_MODELVIEW);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
gluPerspective(60, w/h, 0.1, 100);
glTranslatef(0.0,0.0,-5.0);
Your first misconception is thinking in terms of “initialization”. OpenGL is a state machine and you’re expected to set the state as required throughout your program. Those calls you call “initializing” actually belong into the drawing code.
Second: The projection matrix is sort of the “lens” of OpenGL, hence all sorts of projection belong there, and only there, which also applies to
gluPerspective(which is not part of OpenGL but GLU, a third party library, that eventually callsglFrustum).In your original code you set the ortho limits to the viewport size, i.e. you’re going to see the world space coordinate rate (0,0) to (width,height). Everything in that worldspace volume will fill the view. In the case of perspective you got a viewing volume symmetrically centered around the Z axis and depending on the near and far planes will usually cover something like about (-near*aspect, -near) to (+near*aspect, near) at the near clipping plane. In your case that would be something like -0.1,-0.1 to 0.1,0.1, which is a very small volume and will just largely magnify your image.
How to fix this?
Now in your case I strongly doubt you actually want perspective for that “Drop your image here” backdrop, but only for whatever is drawn on top of this. Remember that I told you OpenGL is a state machine? Well, here’s why: Because you should switch projections between those two drawing stages: