rendering outlines for a series of cubes
I'm trying to render the outlines of a series of cubes. in a perspective projection. I use a "quick and dirty" scheme where i first set the linewidth to 2.0 & draw a glutWireCube and then set the linewidth to 1.0 and draw a glutSolid Cube. For single cubes it works okay when cubes are adjacent the order in which you draw the cubes (left right top bottom) becomes a problem depending on the projection. Cubes rendered from left to right kind of distrort the projection of cubes on the right side of the camera which leads to weird drawings of the cube.
/----------/--------/
/ / | / |
/----------/-|------/ |
| | | | |
X | A | / B | /
| | / | /
|--------- |/--------|/
Camera looks at X.
Cube B gets drawn first correctly but then when cube A gets drawn the outline can be seen through cube B.
If you change the order e.g. A first and then B you have the exact same problem on the other side of the camera. and also the same problems occur for up and down.
Does anyone know a solution?
I could come up with an algortithm that determines whether a cube is visible and whether it has neighbours and based on that draws the outlines but it seems rather complicated.
Yea its a little confusing and your ASCII picture leads us no where. But from your text it sounds like you are not using depth testing. Unless the objects are transparent, the order of rendering should not be important. If a pixel falls behind another it should get discarded.
Are you using depth testing?
If not try adding this during your OpenGL init code.
edit: After close inspection, I think your ASCII picture is pretty good.
[Edited by - honayboyz on December 26, 2006 1:23:34 AM]
Are you using depth testing?
If not try adding this during your OpenGL init code.
glClearDepth(1.0f); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST);
edit: After close inspection, I think your ASCII picture is pretty good.
[Edited by - honayboyz on December 26, 2006 1:23:34 AM]
/----------/--------/ / /| / | /----------/-|------/ | | | | | |X | A | / B | / | | / | / |---------|/--------|/
like this?
Are your cubes transparent at all? In addition to the depth testing mentioned previously, you might need to take into account how GL blending works. Basically, it combines the color of the transparent polygon with the color that is behind it. If there's nothing behind it when it is drawn, then it blends itself with the clear color. If something then gets drawn behind it, the blending stays as it was, and does not blend with the new object behind it. Thus, you must draw from back to front in order to ensure that blending works correctly in all cases. If you have a limited view, then this may not be necessary. If, however, your users are free to manipulate the view to their hearts' desire AND having 100% correct blending is necessary, then you'll have to Z-sort your polygons yourself, which is both a pain and pretty slow in some cases.
That said, I hope enabling depth testing fixed your problems :)
-jouley
That said, I hope enabling depth testing fixed your problems :)
-jouley
Hey thanks, that did the trick. I feel so stupid since it was obviously the depth testing. But I know for sure that I tried it before with depth testing enabled but I didn't resolve it. I use SDL but when I do:
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL);
In my main application when I initialize SDL / GL etc I get a strange crash immediately.
Enabling the depth test when the blocks are actually drawn works fine.
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL);
In my main application when I initialize SDL / GL etc I get a strange crash immediately.
Enabling the depth test when the blocks are actually drawn works fine.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement