LWJGL Forum

Programming => OpenGL => Topic started by: broumbroum on September 01, 2009, 23:30:10

Title: Background fill : Frustum clip range cannot be bigger than the Window?
Post by: broumbroum on September 01, 2009, 23:30:10
hI, I'm facing an issue with clip range of the projection matrix. In the case i want to fill the whole background with one color, I've got the following solution :
rendering a quad of the size of the window at the max depth (the far clipplane of frustum). That means also that this quad appear "smaller than the window", hence I make the width and height fit the window size at depth of the far clip plane which is far/near * windowsize.
Now it seems to be clipped to the frustum specs width and height, so that it still only covers part of the background. my question is how can I change the clipplane of frustum ???
If i increase the frustum to a scaled window size then I cannot get it alright with the viewport which should not be 0,0,window.width, window.height.
I don't wan't to use glortho because of the shabby look, I do prefer frustum.
private static void _GL_reshape(AWTGLCanvas canvas) {
/* ratio is the dimension that will increase the clip volume*/
       Dimension ratio = new Dimension(Math.round((float)canvas.getWidth() * (float)_GLZRatio(_GL_FARVAL)), Math.round((float)canvas.getHeight() * (float)_GLZRatio(_GL_FARVAL)));
/* then I want to use on the near plane an area of the window size NOW this SEEMS NOT WORKING**/
       GL11.glViewport(-Math.round((float)(ratio.width - canvas.getWidth()) / 2f),
               -Math.round((float)(ratio.height - canvas.getHeight()) / 2f),
               ratio.width, ratio.height);
       /*GL11.glViewport(0, 0, canvas.getWidth(), canvas.getHeight());*/
       GL11.glMatrixMode(GL11.GL_PROJECTION);
       GL11.glLoadIdentity();
       /*GL11.glFrustum(-canvas.getWidth() / 2f, canvas.getWidth() / 2f, canvas.getHeight() / 2f, -canvas.getHeight() / 2f, _GL_NEARVAL - 1, _GL_FARVAL + 1);*/
/* frustum has clip planes clamping the ratio dimensions (not the window)*/
       GL11.glFrustum(-ratio.width / 2f, ratio.width / 2f, ratio.height / 2f, -ratio.height / 2f, _GL_NEARVAL - 1, _GL_FARVAL + 1);
       GL11.glMatrixMode(GL11.GL_MODELVIEW);
       GL11.glLoadIdentity();
/** I translate (0,0) to the upper left corner */
       GL11.glTranslatef(-canvas.getWidth() / 2f, -canvas.getHeight() / 2f, 0);
}

that sample above is what i intended to do and explained at the beginning... But It doesn't show properly.
???
Title: Re: Frustum clip range bigger than the Window?
Post by: broumbroum on September 01, 2009, 23:41:14
Dimension ratio = new Dimension(canvas.getWidth(), canvas.getHeight());
       (...)

... using window size for frustum does perform a clip volume that is "too small" for using in the far z planes because the background appers smaller...
http://sf3jswing.sourceforge.net/sf3jswing-thegame-ant-Windows%20Vista-x86.html is the applet for which I'd like to get the whole bg in white, that looks better with translucent pix. (use Ie or firefox, cause safari does not support java plugin2...)
Title: Re: Background fill : Frustum clip range cannot be bigger than the Window?
Post by: Fool Running on September 02, 2009, 12:26:59
Can you not use GL11.glClearColor() and GL11.glClear()? It seems to do what you are trying to do (unless I'm not following what you are trying to do).
Title: Re: Background fill : Frustum clip range cannot be bigger than the Window?
Post by: broumbroum on September 02, 2009, 14:02:27
oh yes, this be a way for using a white background, tk you !
what I m looking further to do is to get a texture fill ....
Title: Re: Background fill : Frustum clip range cannot be bigger than the Window?
Post by: Ciardhubh on September 02, 2009, 15:36:39
So you want a textured full screen quad as background? What do you mean by "I don't wan't to use glortho because of the shabby look"? What's shabby about glortho? What's wrong with switching to ortho, drawing the fullscreen textured quad background, switching back to perspective and drawing the rest?
Title: Re: Background fill : Frustum clip range cannot be bigger than the Window?
Post by: broumbroum on September 02, 2009, 15:41:26
I'd like to do something like "environmental mapping", that's why I think ortho is ugly... thks for your advice! ;)
Title: Re: Background fill : Frustum clip range cannot be bigger than the Window?
Post by: broumbroum on September 04, 2009, 14:18:52
http://jerome.jouvie.free.fr/OpenGl/Tutorials11-15.php
Tutorial 11 does better explain, if you wun the tutorial, you see that the brackground fills part of your screen
(not about environment mapping which is nice on the rotating objects).
Title: Re: Background fill : Proj. Frustum clip range cannot be bigger than the Window?
Post by: broumbroum on September 06, 2009, 18:55:24
Is that worth changing the projection matrix by adding a custom scale transform ?
Title: Re: Background fill : Frustum clip range cannot be bigger than the Window?
Post by: broumbroum on November 27, 2009, 00:35:09
I've just found the problem : i was running wrong values for frustum near and far.
GL11.glFrustum(-viewport.width / 2f, viewport.width / 2f, viewport.height / 2f, -viewport.height / 2f, _GL_NEARVAL - 1, _GL_FARVAL + 1);
which stored a border...
GL11.glFrustum(-viewport.width / 2f, viewport.width / 2f, viewport.height / 2f, -viewport.height / 2f, _GL_NEARVAL, _GL_FARVAL);
and z ratio computation are ok to fill a background located at -_GL_FARVAL + 1
glZratioDim =Math.abs(z / (double)_GL_NEARVAL);
:)