glass effect
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);
You just need to put glDisable(GL_BLEND) near the end of the window render, just before glPopMatrix() would be fine.
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.
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.
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 ?
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 ?
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)
(yes, I know, I know, he should be sorting his objects according to their depth, but let's see if this works first)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement