grayscale and glTexImage3D

I have a beautiful picture coming out in glTexImage3D. Only problem is that the amount of data involved is huge (> 2GB). I use the GL_RGBA8 internal format and set the RGBA (4 bytes per voxel) to the same value, like so…

data[i] = value;
data[i+1] = value;
data[i+2] = value;
data[i+3] = value;

I tried to just use 1/4 of this data and set the color scheme to GL_ALPHA. It works! Only problem is that the detail and quality of picture goes way down. When I use GL_ALPHA8 or GL_LUMINANCE or GL_INTENSITY the screen just goes blank (error mode or something wrong).

My question is what is the best internalFormat and format to use when I only have grayscale values that range from 0…255 and fit in unsigned bytes?


If the format does not need to be renderable then you might be able to use some packed formats (if your data allows. can not remember the names, but there was one for 1/2 channels only). Or do some custom packing yourself (if data allows), for example using an indirection texture (just recently had to fit a huge 3D texture in memory myself - luckily, there were large regions of zeroes i was able to leave out using only one instance of thous).

I tried GL_RED but it comes out red (not grayscale) and the image looks misplaced. As for packing, without going into details, that would not be good for my application. But thanx for the suggestion.

I am interested in GL_ALPHA4, 8, 12, 16. What do those numbers mean? Is GL_ALPHA the right way to display grayscale?

Are you using shaders ?
In which case you can use any format which is a single 8-bit channel. Ie GL_RED
What version of GL are you using? Sounds like you are using fixed function to render.

I’m using glTexImage3D. I have read this on another forum: “The format you store your 3D texture is relevant only in combination with a specific pixelshader that interpretes this information”. You got me there. What’s a pixelshader and how does it interact with glTexImage3D?

Direct3D uses the term pixel shader. In OpenGL, it is called a fragment shader. They (shaders) override a part of the graphics pipeline by your own code. You get to do whatever you want (almost).

You might want to study some books or tutorials about shaders. There is the Orange Book

and many other books written about the subject.

It doesn’t interact with glTexImage3D because glTexImage3D is basically the following : please allocate some memory. please write this data to that memory allocation.

It doesn’t effect it because glTexImage3D doesn’t “render” polygons or lines or points. You need to render something for the graphics pipeline to take effect.