Background fill : Frustum clip range cannot be bigger than the Window?

Started by broumbroum, September 01, 2009, 23:30:10

Previous topic - Next topic

broumbroum

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

broumbroum

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

Fool Running

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).
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

broumbroum

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

Ciardhubh

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?

broumbroum

I'd like to do something like "environmental mapping", that's why I think ortho is ugly... thks for your advice! ;)

broumbroum

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

broumbroum

Is that worth changing the projection matrix by adding a custom scale transform ?

broumbroum

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);

:)