我目前正在使用OpenGL构建高度图地形生成器。这是一个简单的程序,可加载高度图图像,遍历图像数据并生成顶点,索引和法线。在当前状态下,它可以基于法线以单一颜色渲染高度图。
我的问题是为漫反射贴图生成正确的UV坐标。它只是错了:
这是我要加载的漫反射贴图:
这是我目前拥有的:
生成顶点,法线和指数
// Generate Vertices and texture coordinates
for (int row = 0; row <= this->imageHeight; row++)
{
for (int column = 0; column <= this->imageWidth; column++)
{
float x = (float)column / (float)this->imageWidth;
float y = (float)row / (float)this->imageHeight;
float pixel = this->imageData[this->imageWidth * row + column];
float z;
if (row == this->imageHeight || column == this->imageWidth || row == 0 || column == 0)
{
z = 0.0f;
}
else
{
z = float(pixel / …Run Code Online (Sandbox Code Playgroud)