我链接,包含并完成了使用SOIL及其功能所需的一切。
我在init()中加载了这样的纹理:
void initRendering() {
std::string vertexInputString="exampleVS.txt";
std::string fragmentInputString="exampleFS.txt";
//create new shader
InitializeProgram(shaderOne, readFiletoString(vertexInputString), readFiletoString(fragmentInputString));
//enables/disables
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnable (GL_BLEND);
//glEnable(GL_LIGHTING);
//glEnable(GL_LIGHT0);
//states
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
//load textures
image = SOIL_load_OGL_texture(
"resources/wood.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_INVERT_Y
);
if( 0 == image ){printf( "SOIL loading error: '%s'\n", SOIL_last_result());}
//start shader
glUseProgram(shaderOne);
}
为简单起见,wood.png是一个256x256 png纹理并加载没有错误信息。
这是我绘制纹理四边形的地方:
glPushMatrix();
glColor4f(0.0, 0.0, 0.0,1.0f);
glBindTexture(GL_TEXTURE_2D, image);
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_DECAL);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_DECAL);
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); // when texture area is small, bilinear filter the closest mipmap
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // when texture area is large, bilinear filter the first mipmap
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // texture should tile
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glNormal3f(0.0, 1.0f, 0.0f);
glTexCoord2f(0.0f,0.0f); glVertex3f(-50.0f, 10.0f, 50.0f);
glTexCoord2f(0.0f,1.0f); glVertex3f(-50.0f, 10.0f, -50.0f);
glTexCoord2f(1.0f,1.0f); glVertex3f(50.0f, 10.0f, -50.0f);
glTexCoord2f(1.0f,0.0f); glVertex3f(50.0f, 10.0f, 50.0f);
glEnd();
glPopMatrix();
结果只是一个全黑的纹理而不是木质纹理: