Can I use a grayscale image with the OpenGL glTexImage2D function?

前端 未结 3 1827
清酒与你
清酒与你 2020-12-06 10:14

I have a texture which has only 1 channel as it\'s a grayscale image. When I pass the pixels in to glTexImage2D, it comes out red (obviously because channel 1 is red; RGB).<

3条回答
  •  萌比男神i
    2020-12-06 11:10

    in the FragmentShader, you can write:

    uniform sampler2D A;
    vec3 result = vec3(texture(A, TexCoord).r);
    

    in the cpp file,you can write:

    glTexImage2D(
    GL_TEXTURE_2D, 0, GL_RED,
    dicomImage->GetColumns(), dicomImage->GetRows(),
    0, GL_RED, GL_UNSIGNED_BYTE, pixelArrayPtr);
    

提交回复
热议问题