Sign in to follow this  
justinxnitsuj

glass effect

Recommended Posts

hi! i'm trying to make a window for my house. i put the glass texture and i enable gl_blend for the window. but then all the things are affected. how can i prevent it ? or have i to do it in another way ? here is the code : void DrawWindow (float x,float y,float z){ glPushMatrix(); glEnable(GL_BLEND); glTranslatef(x,y,z); glBindTexture(GL_TEXTURE_2D, texture[9]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-5.0f, -5.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 5.0f, -5.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 5.0f, 5.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-5.0f, 5.0f, 0.0f); glEnd(); glPopMatrix(); } ............... DrawWindow (-16.0f,0.0f,30.0f);

Share this post


Link to post
Share on other sites
You just need to put glDisable(GL_BLEND) near the end of the window render, just before glPopMatrix() would be fine.

Share this post


Link to post
Share on other sites
glEnable(...) and other functions change the state of the OpenGL state machine permanently, so unless you glDisable(...) blending after using it, all objects drawn after the window will be blended (this means all objects in the following frames if you don't ever disable blending).

Just call glDisable(GL_BLEND) after drawing the window for a simple solution.

Better: group the objects that need blending, enable it once, draw all the objects, disable blending one. This way you reduce state changes in OpenGL which can be very expensive in terms of performance. Keep in mind that other states may be more expensive so optimize your rendering order to reduce the most expensive state changes first.

Share this post


Link to post
Share on other sites
thanks for the help :)
but there is a problem. from inside the effect is good, but from outside the effect looks terrible (i guess from the texture inside) can i configure the intensity of the effect ?

Share this post


Link to post
Share on other sites
try adding glDisable(GL_DEPTH_TEST); when rendering your window

(yes, I know, I know, he should be sorting his objects according to their depth, but let's see if this works first)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this