lal7777
Posts
if all.knowledge = orange then: seed = mankind.knowledge: grow(seed,time): endif
Posts: 88
|
Post by lal7777 on May 28, 2011 16:08:04 GMT -5
As many (or maybe not so many) of you know I've been working on a .obj loader for some time now. The reason that I've posted here is because there may a problem with the .obj loader's depth sensing ability. The scene provided with this file should look like this: 3 cubes of varying colors rotating around a torus made of 2 colors, with a rook (chess piece) rotation on the outside edge of everything. There are 2 objects in the scene that are transparent. One of the first is a green cube, and the second is the rook. instructions to view problem: When the program is started press "c" to enable color, then "d" to enable the color the be dissolved for objects to become "see-through". Press "s" to enter a script and type "clear rotation". then press the right and left arrow keys to rotate the object. (*optional: press"l" to view lighting, then "s" and type "autoaddlight" to automatically add a light) Now for the problem:When the transparent green cube is in front of everything you naturally see the other objects through it, because it's see-through. The problem occurs when the green cube rotates behind everything, and ends up looking like it's in front of the torus. This shouldn't happen. Instead the green cube should appear to be in back of other objects when it' s behind them. My question is: How do i make the depth of objects that are transparent correct?Please answer. Attachments:
|
|
|
Post by matthew on May 28, 2011 18:24:06 GMT -5
I've just taken a quick look at your code & you seem to be disabling GL_DEPTH_TEST several times but you don't seem to be enabling it anywhere.
|
|
lal7777
Posts
if all.knowledge = orange then: seed = mankind.knowledge: grow(seed,time): endif
Posts: 88
|
Post by lal7777 on May 28, 2011 18:56:46 GMT -5
k, then on line 554 get rid of the stuff that will be read by the program, and allow it to read the rem'd out words. (i.e. replace line 554 with glenable (GL_DEPTH_TEST) ) However that still doesn't solve my problem. While the transparency of objects is visible, you can still see them through objects that are in front of them. Do i constantly have to keep switching it on/off every time there's a material switch? Is there any way to have transparent objects and nontransparent objects in the same scene; acting just as they normally would?
|
|
|
Post by matthew on May 28, 2011 19:17:32 GMT -5
The order in which the objects are placed on the screen is important. Take a look at the OpenGL FAQ regarding Transparency, Translucency, and Blending. Specifically 15.020 How can I achieve a transparent effect? It will tell you the problems that you may encounter using the Depth Buffer.
|
|
lal7777
Posts
if all.knowledge = orange then: seed = mankind.knowledge: grow(seed,time): endif
Posts: 88
|
Post by lal7777 on May 28, 2011 20:13:43 GMT -5
The webpage you provided suggests using the glPolygonStipple() function. However I don't understand what's supposed to be passed to it in order for it to work. www.opengl.org/sdk/docs/man/xhtml/glPolygonStipple.xmlInforms me that it needs to receive a pointer to a 32*32 stipple pattern. What does this mean?
|
|
|
Post by matthew on May 28, 2011 20:38:01 GMT -5
Don't worry about glPolygonStipple it's irrelevant & doesn't help solve the problem. Instead read this question on Stack Overflow, someone was having the same problem as you & got it solved. It would appear that the glDepthMask command should be used.
|
|
lal7777
Posts
if all.knowledge = orange then: seed = mankind.knowledge: grow(seed,time): endif
Posts: 88
|
Post by lal7777 on May 28, 2011 21:35:42 GMT -5
Thanks, very informative link. From what it's saying all non-transparent objects need to be drawn. Then it's saying that I need to somehow draw the faces that are furthest away first when drawing the transparent objects. Sorting all the triangles from furthest away to closest may be time consuming. (especially for high poly models)It almost seems like a finding vertex normals.(i.e. looking for all the vertices connected to one in order to find an average.) My new question is: How do i always know which triangle is closest to the camera with all the rotations and translations going on?
|
|
|
Post by matthew on May 29, 2011 5:35:36 GMT -5
Just set glDepthMask(GL_TRUE) then draw all of your non-transparent objects first & see if that works.
|
|
lal7777
Posts
if all.knowledge = orange then: seed = mankind.knowledge: grow(seed,time): endif
Posts: 88
|
Post by lal7777 on Jun 2, 2011 23:58:30 GMT -5
Sorry I haven't replied for so long. Just had graduation not that long ago, and been busy. I'm not going to use the depth mask yet, because earlier this week I learned about data structures. When I look at the program now it looks really sloppy. Going to fix it up a bit before working more with it.
|
|
|
Post by matthew on Jun 4, 2011 17:02:21 GMT -5
I've been thinking that you don't actually need to mess about with the depth mask either. You could just turn blending on for the transparent objects & turn it off when you display the non-transparent objects.
|
|
|
Post by DJLinux on Jun 4, 2011 20:09:26 GMT -5
first draw all solid or textured objects second enable BLENDING and draw your transparent objects it playes no rule if a transparent object is in front or behind a solid object (the depht buffers need not to know what are transparent or what are solid)
happy codding
|
|