Jump to content
  • Advertisement
Sign in to follow this  
f_shaukat

OpenGL tranparency issue

This topic is 4148 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am new to opengl programming and i have a simple question to ask. I want to draw two consecutive walls that should appear as one wall. Additionally, i want to make the wall transparent. I am achieving this by drawing two consecutive cubes. The problem is that when i rotate these two consecutive walls then the edge where these two walls meet (i.e. the back side of the first cube and the front side of the adjacent cube) is highlighted and it seems that these are two different walls and not the one. I am using the following command for the color glcolor3f(1.0,1.0,1.0,0.7). As you can see from the 4th parameter that the walls are drawn transparently. Is there any method by which the two walls seem like one wall i.e on rotation the edge is not highlighted but still the wall remains transparent? I am not using any lightning in the application! Sorry for the excessive words in the description! Thanks, Faisal.

Share this post


Link to post
Share on other sites
Advertisement
glcolor3f(1.0,1.0,1.0,0.7)
will never work and suprized you haven't gotten an error.

You need
glColor4f(1.0f, 1.0f, 1.0f, .7f);

and you need to turn on blending
glEnable(GL_BLEND);
glBlendFunc(/*use various parameters to meet your needs*/);

Share this post


Link to post
Share on other sites
Also...

1º render all opaque objects
2º render all transparent object in one of these ways:
2.1 order transparent polygon, then render them from back to front.
2.2 OR deactivate deph writing. Render transparent polygons between glDepthMask(false); and glDepthMask(true);


Bye bye.

Share this post


Link to post
Share on other sites
Hi,
Thank you for your reply. I am actually using glColor4f.

I am using the following commands as well.

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA);

I can achieve the desired effect if i replace the above command by

glBlendFunc(GL_ONE,GL_ZERO).

But it creates an other problem. Consider the following situation.

A single wall consists of two adjacent cubes. The two adjacent cubes should look like a single wall. But there could be more than one walls. One one such wall intersects or overlaps another then this should be visible through the walls.

How to achieve this effect. With the above mentioned command, the two walls does not remain transparent any more.

My code roughly looks like the following:
;; the following code is in lips
(defun draw-a-cube ( )

;; using push and pop matrix.
(with-matrix
;(glTranslated -0.5d0 -0.5d0 0d0)
(with-mode GL_QUADS
;; FIXME: Front is actually bottom?
;; Front -- bottom
(glNormal3d 0d0 0d0 -1d0)
(glVertex3d 0d0 0d0 0d0)
(glVertex3d 0d0 1d0 0d0)
(glVertex3d 1d0 1d0 0d0)
(glVertex3d 1d0 0d0 0d0)
;; Top -- left
(glNormal3d 0d0 1d0 0d0)
(glVertex3d 0d0 1d0 0d0)
(glVertex3d 0d0 1d0 1d0)
(glVertex3d 1d0 1d0 1d0)
(glVertex3d 1d0 1d0 0d0)
;; Right -- back

(glNormal3d 1d0 0d0 0d0)
(glVertex3d 1d0 1d0 0d0)
(glVertex3d 1d0 1d0 1d0)
(glVertex3d 1d0 0d0 1d0)
(glVertex3d 1d0 0d0 0d0)
;; Left -- front
(glNormal3d -1d0 0d0 0d0)
(glVertex3d 0d0 0d0 0d0)
(glVertex3d 0d0 0d0 1d0)
(glVertex3d 0d0 1d0 1d0)
(glVertex3d 0d0 1d0 0d0)

;; Bottom
(glNormal3d 0d0 -1d0 0d0)
(glVertex3d 0d0 0d0 0d0)
(glVertex3d 1d0 0d0 0d0)
(glVertex3d 1d0 0d0 1d0)
(glVertex3d 0d0 0d0 1d0)
;; Back
(glNormal3d 0d0 0d0 1d0)
(glVertex3d 0d0 0d0 1d0)
(glVertex3d 1d0 0d0 1d0)
(glVertex3d 1d0 1d0 1d0)
(glVertex3d 0d0 1d0 1d0)
)))
Now a single wall

(defun draw-a-wall
(draw-a-cube )
(draw-a-cube )
)

Now the general program

(defun main ()
(loop
;; randomly draw walls
(draw-a-wall )))

Now in this setting, how can i achieve the desired effect.

One way is to either use another blending function, or use the alpha value of 1.0 while drawing a single wall (i.e. two cubes) but this then has the effect that this wall is no longer transparent for other walls. :(

Any reply would be highly appreciated.

Thanks,
Faisal.

Share this post


Link to post
Share on other sites
im guessing some depth stuff is involved try
glEnable( GL_DEPTH_TEST );

with glDepthMask(0); + if that doesnt work use glDepthMask(1);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!