小编HP_*_*aft的帖子

从高度图计算纹理坐标

我目前正在使用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)

c++ opengl textures

5
推荐指数
1
解决办法
137
查看次数

标签 统计

c++ ×1

opengl ×1

textures ×1