【问题标题】:Creating and reading 1D textures in OpenGL 4.x在 OpenGL 4.x 中创建和读取一维纹理
【发布时间】:2014-08-28 13:42:58
【问题描述】:

我在 OpenGL 4.x 中使用 1D 纹理时遇到问题。

我以这种方式创建我的 1d 纹理(顺便说一句:我删除了错误检查以使代码更清晰和更短 - 通常在每次 gl 调用后跟随 BLUE_ASSERTEx(glGetError() == GL_NO_ERROR, "glGetError failed.");):

glGenTextures(1, &textureId_);

// bind texture
glBindTexture(GL_TEXTURE_1D, textureId_);

// tells OpenGL how the data that is going to be uploaded is aligned
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

BLUE_ASSERTEx(description.data, "Invalid data provided");

    glTexImage1D(
        GL_TEXTURE_1D,      // Specifies the target texture. Must be GL_TEXTURE_1D or GL_PROXY_TEXTURE_1D.
        0,                  // Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
        GL_RGBA32F,
        description.width,  
        0,                  // border: This value must be 0.
        GL_RGBA, 
        GL_FLOAT,
        description.data);
    BLUE_ASSERTEx(glGetError() == GL_NO_ERROR, "glGetError failed.");

// texture sampling/filtering operation.
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glBindTexture(GL_TEXTURE_1D, 0);

创建后,我尝试以这种方式读取创建纹理的像素数据: 常量 int 宽度 = width_; 常量 int 高度 = 1;

// Allocate memory for depth buffer screenshot
float* pixels = new float[width*height*sizeof(buw::vector4f)];

// bind texture
glBindTexture(GL_TEXTURE_1D, textureId_);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, width, height, GL_RGBA, GL_FLOAT, pixels);
glBindTexture(GL_TEXTURE_1D, 0);

buw::Image_4f::Ptr img(new buw::Image_4f(width, height, pixels));

buw::storeImageAsFile(filename.toCString(), img.get());

delete pixels;

但返回的像素数据与输入的像素数据不同(输入:色带,输出:黑色图像)

任何想法如何解决这个问题?也许我使用了错误的 API 调用。

【问题讨论】:

  • glReadPixels 从屏幕(或绑定的帧缓冲区)读取,而不是从纹理读取。你想要glGetTexImage。

标签: opengl textures opengl-4 texture1d


【解决方案1】:

将glReadPixels 替换为glGetTexImage 确实可以解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-05
    • 2020-11-27
    • 2014-10-22
    • 1970-01-01
    • 2014-03-12
    • 2012-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多