Re: [PyOpenGL-Users] opaque polygons
Brought to you by:
mcfletch
From: Astan C. <st...@al...> - 2008-04-08 08:13:07
|
Hi, Thanks for these tips. It worked. I didnt know I had to do a blend. Thanks again. Cheers Astan Gary Herron wrote: > Astan Chee wrote: >> Hi, >> Im trying to make this: >> >> green = (( 0.0, 1.0, 0.0, 1 )) >> glColor4f( 0, 1, 0, .1 ) >> glBegin( GL_POLYGON ) >> glMaterialfv( GL_FRONT, GL_EMISSION, green ) >> rad = 0.5 >> for i in xrange(0,360,5): >> glVertex3f(x1+math.sin(i*math.pi/180.0)*rad , >> y1+math.cos(i*math.pi/180.0)*rad,z1) glEnd( ) >> >> to be opaque. I read that the last part of glColor4f() allows alpha >> channels for transparency levels. I changed it and it still remains >> solid. What am I doing wrong? >> Thanks again for any help. >> Cheers >> Astan >> >> > Several things wrong there: > > First, you must enable blending with > glEnable(GL_BLEND) > before the glBegin and you should disable it with > glDisable(GL_BLEND) > after the glEnd. > > Second, you are mixing two ways of specifying color. Choose one of > these: > > Choice 1: Using glColor > Choose this method with glDisable(GL_LIGHTING) > Specify color per vertex with any of the glColorXX routines. > > Choice 2: Using Phong lighting > Choose this method with glEnable(GL_LIGHTING) > For lighting to work, you must also specify the light's position/color > and other properties with glLight, > as well as the surface properties (diffuse/specula/shininess/ ...) per > vertex with glMaterial. > > (There is a third method where values specified with glColor affect > lighting values normally specified via glMaterial. It uses the > glColorMaterial calls. Call this mode advance, and ignore it for now.) > > Either method of specifying color can specify RGBA > (red,green,blue,alpha) values. If the alpha value is not equal to 1 > and GL_BLEND is enabled, you will get blending. In order for that > blending to look like transparency, you must make sure to draw the > background first, without blending enabled, then draw the transparent > object with blending enabled. > > The last piece of the puzzle is to specify how you want the > transparent color to be combined the the existing background color. > This is done with > glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) > when you enable blending (or earlier). > > Gary Herron > > > > -- "Formulations of number theory: Complete, Consistent, Non-trivial. Choose two." Animal Logic http://www.animallogic.com Please think of the environment before printing this email. This email and any attachments may be confidential and/or privileged. If you are not the intended recipient of this email, you must not disclose or use the information contained in it. Please notify the sender immediately and delete this document if you have received it in error. We do not guarantee this email is error or virus free. |