[Question] Drawing Objects outside of screenspace (glOrtho issue?)

Started by Richie551, July 14, 2012, 10:56:54

Previous topic - Next topic

Richie551

Hello everyone, I thought I should start off my first post to these forums how I start off most of my first posts on forums, with a question, naturally.  So lately when using openGL, I've found the need to create a scrolling system to allow larger worlds, rather then loading new rooms for every new area, but I've run into a problem.  For some odd reason openGL refuses to render anything outside of the screenspace I have set currently, which is at the moment 400 * 300.  I coded a basic game engine to test this principle, and it is indeed the case for me, for some reason.  I believe it to be a issue with a glortho setting I have, though I can not be sure.
Here is a image of the problem:

As you can see, it does not render anything outside of the screen 'box', of 400*300, regardless of if anything is set to draw there.
My glortho setting:
GL11.glOrtho(0, width, height, 0, -1, 1);

The reason I think it is at fault is due to the fact I set the glortho's right and bottom to 400 and 300, which would naturally change in the case of, say, the player moving around.
The problem is, though, I noticed changing my glOrtho settings threw off the entire sync of the engine, making everything draw/appear in the wrong spot, including the glViewport.
GL11.glViewport(-(player.getX() - width / 2) * 2 + (-width / 2), (player.getY() - height / 2) * 2 + (-height / 2), width * 2, height * 2);

(the *2 is for the zoom-in you see in the picture, bit messy but it will be cleaned up later)

This, is why I'm hesitant about a code overhaul in fixing these problems, if they are indeed glOrtho related.
Changing glOrtho would more than likely break a good many things.

Is there any way I can fix this issue without having to change glOrtho?

Thanks in advance to any help or advice you can offer

CodeBunny

That's a viewport issue. glOrtho (or any other setting of the projection matrix) cannot do that, only glViewport can.

glOrtho sets the projection matrix, saying: "I only want to display vertices from this in-game rectangle of space!" glViewport sets the portion of the framebuffer that you should be rendering to. Then, when you render things, the projection matrix is used to set things across the entire viewport.

It's funny - you're using glViewport in the way you need to use glOrtho, and glOrtho in the way you need to use glViewport.

Richie551

Thanks for the help CodeBunny.  By doing some tests, I got something working with glOrtho that does not have the issues glViewport had.
GL11.glOrtho(player.getX() - 20, player.getX() + 35, player.getY() + 35, player.getY() - 20, -1, 1);

This code peice is a lot easier to manage, and much more efficient than that glViewport mess I had.