OpenGL纹理颜色映射

时间:2018-04-11 17:48:39

标签: c opengl

我想有效地执行从作为纹理对象发送到GPU的缓冲区上的整数到颜色的映射。

目前我的代码如下:

// setup the rendering pipeline and init the texture object
glBindTexture(glTEXTURE_2D, texture);

// data is an array of integers ranging from 0 to 3 of length 144 * 160 like this: [0, 1, 2, 3, 3, 2, 1, ..., 1]
glTexImage2D(glTexture_2D, 0, /* not sure what to put here */, 160, 144, glRGB, /* also not sure what to put here */, data);

我希望能够将0到3之间的数字映射到RGB值。

我觉得我应该能够在片段着色器中执行此操作,但是如何将数据传递到着色器?

我的片段着色器看起来像这样:

#version 330 core

out vec4 FragColor;

in vec2 TexCoord;

uniform sampler2D screen;

void main()
{
    /*
     * I would really like to be able to get the byte value
     * at the texture's coordinate that we are processing and 
     * use an if ... else if ... else ... block to map the texture
     */
     // FragColor = texture(screen, TexCoord);
}

0 个答案:

没有答案
相关问题