Hello Guest

[Question] Rendering multiple layers with different glOrtho settings

  • 5 Replies
  • 10105 Views
Hello once again, and in this post I have yet another question.  You don't learn anything if you don't ask questions, after all.  So my new issue is, I've coded a font engine using openGL, but the issue is, I do not want to have to adjust it based on the players position, but have it constantly displaying on a seperate 'layer' with seperate glOrtho settings.
Basically, here is how one 'layer' currently looks:

This layer was created using the following glOrtho code:
Code: [Select]
GL11.glOrtho(0, width * 2, height * 2, 0, -2, -1);
And the other 'layer' looks like this:

Made using this glOrtho code:
Code: [Select]
GL11.glOrtho(player.getX() - 25, player.getX() + 40, player.getY() + 40, player.getY() - 25, -1, 1);
The issue with this is, when I combine both sets of glOrtho code, I don't get those 2 layers merged as you would expect, but I get a totally black box, with nothing within it.

Am I doing something wrong?
Can I not manage seperate 'layers' using glOrtho, is there another thing I'm supposed to be doing to manage seperate layers?
Any help would be appriciated, thanks.

Post your render code in full. I have a couple of ideas, but I'm not 100% sure from your description why it's all black.

Post your render code in full. I have a couple of ideas, but I'm not 100% sure from your description why it's all black.
What do you mean by my render code in full?  Do you mean the code that handles rendering textures, and such, or the code containing my glOrthos?
I'm going to guess you are meaning my code containing my glOrthos, and in that case, this is that particular code:
Code: [Select]
while(!Display.isCloseRequested())
{
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();

GL11.glOrtho(player.getX() - 25, player.getX() + 40, player.getY() + 40, player.getY() - 25, -1, 1);

GL11.glOrtho(0, width * 2, height * 2, 0, -2, -1);

frameLoop();

Display.update();
}
Shouldn't glOrtho techincally only apply to the near and far it is set to, and not other near/far settings as well?

Try calling GL11.glLoadIdentity() before the second glOrtho() call. glOrtho() changes the current matrix by multiplying the matrix created with the call with the current matrix. In other words, you're messing up the modelview matrix by calling glOrtho() twice without resetting your current matrix in between. See http://www.talisman.org/opengl-1.1/Reference/glOrtho.html.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Thanks, Fool Running, that did indeed fix the issue, I never even thought calling glOrtho twise could mess with the matrix.  I was starting to think what I was trying to do was not possible.

glOrtho is a matrix transformation - it doesn't set the matrix to the given values, but multiplies what's already there.

Also, do you render anything between the two calls?