Friday, June 16, 2017

java - How do I ensure my skybox is always in the background, with OpenGL?


I created a skybox in OpenGL (through LWJGL), but the only way I found to render it behind all objects was to make it very big. This leads to ugly edges between the 6 skybox planes.


Optimally, I would draw a small skybox and disable DepthTesting on all other objects, but since I want those to display in the right depth order, that isn't possible.


How can I do this?



Answer




glDepthRange (1, 1);

Job's a good 'un, done.




How this works:


glDepthRange() remaps depth values for the purpose of interacting with the z-buffer. Setting glDepthRange(1,1); makes every fragment, regardless of how close or far it actually is from the camera, be treated as if it was exactly at the far plane.


Remember to return it to its default glDepthRange(0,1)-setting before drawing other objects. Further details in this StackOverflow question.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...