我正在尝试使用我找到并调整大小的木质位图对木桌模型进行纹理处理,但是我遇到的问题是,当应用纹理时,构成桌子表面的每个四边形都清晰可见。如何让它看起来像一个光滑的纹理?
void Table::DrawTableTop()
{
glPushMatrix();
//draw tabletop
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texid);
glBegin(GL_QUADS);
glMaterialfv(GL_FRONT, GL_SPECULAR, static_cast<GLfloat*>(specular));
glMaterialf(GL_FRONT, GL_SHININESS, static_cast<GLfloat>(shininess));
float unitx = 1.0f / (float)(xsize * 2 + 1);
float unity = 1.0f / (float)(zsize * 2 + 1);
for (int i = -xsize; i <= xsize; i++)
{
for (int j = -zsize; j <= zsize; j++)
{
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, static_cast<GLfloat*>(wDiffuse));
//top
glNormal3f(0.0f, 1.0f, 0.0f);
if (tex) glTexCoord2f(unitx * static_cast<float>(i + 20 + 1), unity * static_cast<float>(j + 10));
glVertex3f(scale[0] * static_cast<float>(i) + scale[0], 0, scale[2] * static_cast<float>(j) + scale[2]);
if (tex) glTexCoord2f(unitx * static_cast<float>(i + 20 + 1), unity * static_cast<float>(j + 10 + 1));
glVertex3f(scale[0] * static_cast<float>(i) + scale[0], 0, scale[2] * static_cast<float>(j));
if (tex) glTexCoord2f(unitx * static_cast<float>(i + 20), unity * static_cast<float>(j + 10 + 1));
glVertex3f(scale[0] * static_cast<float>(i), 0, scale[2] * static_cast<float>(j));
if (tex) glTexCoord2f(unitx * static_cast<float>(i + 20 ), unity * static_cast<float>(j + 10));
glVertex3f(scale[0] * static_cast<float>(i), 0, scale[2] * static_cast<float>(j) + scale[2]);
}
}
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
xsize 和 zsize 的值分别为 20 和 10
我希望纹理看起来好像加载到一个大四边形上,但显然使用多个四边形来改善照明等。
这是纹理图像的样子: