C++ OpenGL从矢量创建纹理立方体

C++ OpenGL从矢量创建纹理立方体,c++,opengl,C++,Opengl,我正在尝试为球体创建一个随机噪波纹理立方体 我开发了一个生成立方体噪音的类。这个立方体只是一堆表示该像素/三像素值的floats 下面是我的代码,它的目的是生成一个GL\u纹理\u立方体\u贴图和一个采样器 glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); GLuint texture; GLuint sampler; glGenTextures(1, &texture); glGenSamplers(1,&sampler); glBindSampl

我正在尝试为球体创建一个随机噪波纹理立方体

我开发了一个生成立方体噪音的类。这个立方体只是一堆表示该像素/三像素值的
float
s

下面是我的代码,它的目的是生成一个
GL\u纹理\u立方体\u贴图
和一个采样器

glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
GLuint texture;
GLuint sampler;
glGenTextures(1, &texture);
glGenSamplers(1,&sampler);
glBindSampler(0,sampler);
glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glSamplerParameteri(sampler, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

int width = noiseMap.GetWidth();
int height = noiseMap.GetHeight();
int depth = noiseMap.GetDepth();

std::vector<float> negativeX;
std::vector<float> positiveX;
std::vector<float> negativeY;
std::vector<float> positiveY;
std::vector<float> negativeZ;
std::vector<float> positiveZ;
for(int z = 0; z < depth; ++z)
{
    for(int y = 0; y < height; ++y)
    {
        negativeX.push_back(noiseMap.GetPixel(0,y,z));
        positiveX.push_back(noiseMap.GetPixel(width-1,y,z));
    }
}
for(int z = 0; z < depth; ++z)
{
    for(int x = 0; x < width; ++x)
    {
        negativeY.push_back(noiseMap.GetPixel(x,0,z));
        positiveY.push_back(noiseMap.GetPixel(x,height-1,z));
    }
}
for(int x = 0; x < width; ++x)
{
    for(int y = 0; y < height; ++y)
    {
        negativeZ.push_back(noiseMap.GetPixel(x,y,0));
        positiveZ.push_back(noiseMap.GetPixel(x,y,depth-1));
    }
}
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_RGBA8,width,height,0,GL_RED,GL_FLOAT,positiveX.data());
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL_RGBA8,width,height,0,GL_RED,GL_FLOAT,positiveY.data());
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL_RGBA8,width,height,0,GL_RED,GL_FLOAT,positiveZ.data());
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL_RGBA8,width,height,0,GL_RED,GL_FLOAT,negativeX.data());
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,GL_RGBA8,width,height,0,GL_RED,GL_FLOAT,negativeY.data());
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL_RGBA8,width,height,0,GL_RED,GL_FLOAT,negativeZ.data());

glBindTexture(GL_TEXTURE_CUBE_MAP,0);
glEnable(GL_纹理_立方体_贴图_无缝);
胶合结构;
胶合取样器;
glGenTextures(1,&纹理);
GLGENS取样器(1个和取样器);
GLBIND采样器(0,采样器);
glBindTexture(GL_纹理_立方体_贴图,纹理);
glSamplerParameteri(采样器、GL_纹理、MAG_过滤器、GL_线性);
glSamplerParameteri(采样器、GL_纹理、最小过滤器、GL_线性);
glSamplerParameteri(采样器、GL_纹理包裹、GL_夹紧至边缘);
glSamplerParameteri(采样器、GL_纹理、GL_包裹、GL_夹紧至边缘);
glSamplerParameteri(采样器、GL_纹理、包裹、GL_夹紧至边缘);
int width=noiseMap.GetWidth();
int height=noiseMap.GetHeight();
int depth=noiseMap.GetDepth();
std::载体阴性;
std::载体阳性;
向量负性;
std::载体阳性;
std::向量负性;
std::载体阳性;
对于(int z=0;z
我的目标是将其用作漫反射纹理。当我使用从文件生成的
GL\u纹理\u立方体\u贴图
时,将其映射到球体或相关着色器不会有任何问题

所以我知道问题就在上面。我相当肯定问题在于我使用的格式,或者说内部格式,但我看不到任何问题。对noiseMap的
GetPixel
调用正在返回
float
s

我试图做的基本上是检索噪声立方体的每个“面”,并将每个面用作立方体的6种纹理之一

如果请求的像素超出范围,则
GetPixel
调用将抛出
out\u of\u range
异常


我得到的结果是一个空白纹理。不知道为什么。

宽度和高度是否有相同的值?它们有。不管怎样,我只是发现了问题。问题是我的
noiseMap
值不是从0限制到1.0,而是从0限制到255,所以看起来没有效果。