Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

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

Do I change GL_RGBA? If so, what to?

like image 538
Nick Bolton Avatar asked Mar 25 '09 03:03

Nick Bolton


1 Answers

Change it to GL_LUMINANCE. See https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexImage2D.xhtml

like image 131
ypnos Avatar answered Oct 06 '22 07:10

ypnos