我正在使用Marching Cubes算法处理数据并转换为3D模型。现在我想在OpenGL中为我的3D模型使用纹理映射。我已经尝试了一个简单的示例,将一张图片映射到三角形上。
以下是我的代码:
以下是我的代码:
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Matrix
glTranslatef(1.0f,0.0f,-6.0f); // Move Into The Screen 5 Units
glRotatef(xrot,1.0f,0.0f,0.0f); // Rotate On The X Axis
glRotatef(yrot,0.0f,1.0f,0.0f); // Rotate On The Y Axis
glRotatef(zrot,0.0f,0.0f,1.0f); // Rotate On The Z Axis
glBindTexture(GL_TEXTURE_2D, texture[0]); // Select Our Texture
glBegin(GL_TRIANGLES);
glTexCoord2f(0, 0); glVertex3f( -2, 0, -2 );
glTexCoord2f(1, 0); glVertex3f( 2, 0, -2 );
glTexCoord2f(0.5, 1); glVertex3f( 0, 2, -2 );
glEnd();
xrot+=0.3f; // X Axis Rotation
yrot+=0.2f; // Y Axis Rotation
zrot+=0.4f; // Z Axis Rotation
return true; // Keep Going
}
现在的问题是图片没有完全映射到三角形内部,程序会将图片裁剪成三角形的形状,所以我失去了一部分数据。 如何将整张图片映射到三角形内呢?