关于使用OpenGL开启Blend绘制汇报错的一个问题
源描述:https://blog.csdn.net/Strengthennn/article/details/143742022
我这里遇到的一个问题,OpenGL开启Blend后,出现了问题然后对其进行修改。绘制字体所遇到的情况,
代码如下:
1 glEnable(GL_BLEND); 2 glEnable(GL_ALPHA_TEST); 3 glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); //特殊的像素算法 4 //glDisable(GL_TEXTURE_2D); 5 6 //glEnable(GL_ALPHA); 7 int w = pCharTex->m_Width; 8 int h = pCharTex->m_Height; 9 10 int ch_x = sx + pCharTex->m_delta_x; 11 int ch_y = sy - h - pCharTex->m_delta_y; 12 13 if (maxH < h) maxH = h; 14 glBegin(GL_QUADS); // 定义一个或一组原始的顶点 15 { 16 glTexCoord2f(0.0f, 1.0f); glVertex3f(ch_x, ch_y, z); 17 glTexCoord2f(1.0f, 1.0f); glVertex3f(ch_x + w, ch_y, z); 18 glTexCoord2f(1.0f, 0.0f); glVertex3f(ch_x + w, ch_y + h, z); 19 glTexCoord2f(0.0f, 0.0f); glVertex3f(ch_x, ch_y + h, z); 20 /*glColor3f(1, 1, 1); 21 glTexCoord2f(0.0f, 1.0f); glVertex2f(ch_x, ch_y); 22 glTexCoord2f(1.0f, 1.0f); glVertex2f(ch_x + w, ch_y); 23 glTexCoord2f(1.0f, 0.0f); glVertex2f(ch_x + w, ch_y + h); 24 glTexCoord2f(0.0f, 0.0f); glVertex2f(ch_x, ch_y + h);*/ 25 } 26 glEnd(); 27 glDisable(GL_BLEND); 28 glEnable(GL_DEPTH_TEST);
解决方法:当开启Blend之前,先禁用Depth_test,然后绘制完成后,在禁用blend,开启DepthTest
也就是上面第四行代码。要加上,即可。
修改之后正确如下: