LWJGL
May 22, 2013, 05:28:58 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL is now using GitHub
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: [Question] Rendering multiple layers with different glOrtho settings  (Read 1286 times)
Richie551
Newbie
*
Posts: 10


« on: July 15, 2012, 20:11:47 »

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:
GL11.glOrtho(0, width * 2, height * 2, 0, -2, -1);
And the other 'layer' looks like this:

Made using this glOrtho code:
Code:
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.
Logged
CodeBunny
Nerdus Imperius
*****
Posts: 561



WWW
« Reply #1 on: July 16, 2012, 05:00:32 »

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.
Logged
Richie551
Newbie
*
Posts: 10


« Reply #2 on: July 16, 2012, 05:33:03 »

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:
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?
Logged
Fool Running
Nerdus Imperius
*****
Posts: 742


« Reply #3 on: July 16, 2012, 06:30:01 »

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.
Logged

Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option Grin
Richie551
Newbie
*
Posts: 10


« Reply #4 on: July 16, 2012, 06:40:24 »

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.
Logged
CodeBunny
Nerdus Imperius
*****
Posts: 561



WWW
« Reply #5 on: July 16, 2012, 10:37:43 »

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?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!