我正在尝试渲染草叶。简单的方法是在中间绘制两条平行的四边形,如此
问题是要渲染的第一个四边形对于下一个要绘制的草叶是不透明的。如果我绘制A然后绘制B,B将不会显示在A
之后
这就是我渲染的方式
void drawHighGrass(){
glDisable(GL_LIGHTING);
glClearColor(1.0, 1.0, 1.0, 1.0);
glColor4f(1.0, 1.0, 1.0, 0.95);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texturas[HIGH_GRASS]);
glCullFace(GL_FRONT);
glPushMatrix();
//glTranslatef(1000, 0, 1000);
glScalef(1, 1.5, 1);
glPushMatrix();
glTranslatef(-100 / 2, -10, 0);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0, 0, 0);
glTexCoord2f(1.0f, 0.0f); glVertex3f(100, 0, 0);
glTexCoord2f(1.0f, 1.0f); glVertex3f(100, 40, 0);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0, 40, 0);
glEnd();
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(100, 0, 0);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0, 0, 0);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0, 40, 0);
glTexCoord2f(0.0f, 1.0f); glVertex3f(100, 40, 0);
glEnd();
glPopMatrix();
glPushMatrix();
//glTranslatef(1000, 0, 1000);
glTranslatef(0, -10, -100 / 2);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0, 0, 0);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0, 0, 100);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0, 40, 100);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0, 40, 0);
glEnd();
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0, 0, 100);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0, 0, 0);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0, 40, 0);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0, 40, 100);
glEnd();
glPopMatrix();
glPopMatrix();
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glEnable(GL_LIGHTING);
glCullFace(GL_BACK);
}
答案 0 :(得分:0)
我找到了解决方案:
glAlphaFunc(GL_GREATER, 0.5);
glEnable(GL_ALPHA_TEST);