我正在加载具有 32 位和一些透明区域的 png 纹理。我在初始化函数中设置了这段代码:
// OpenGL
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glEnable( GL_ALPHA_TEST );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glClearColor( 0.0, 0.0, 0.0, 0.0 );
这就是我加载纹理的方式:
// Load textures
glGenTextures( 1, &this->texture );
int width, height;
unsigned char* image;
glActiveTexture( GL_TEXTURE0 );
glBindTexture( GL_TEXTURE_2D, this->texture );
std::string path = "../assets/textures/" + name;
image = SOIL_load_image( path.c_str(), &width, &height, 0, SOIL_LOAD_RGBA );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image );
SOIL_free_image_data( image );
glUniform1i( glGetUniformLocation( shader->shader, "materialTex" ), 0 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
这是我得到的效果:
我正在尝试使草背景从黑色变为透明。
你能帮助我吗?