GLCapabilities always reports 8Bit per ColorChannel

hello, at the beginning of my game i do this:

GLCapabilities caps = new GLCapabilities();
caps.setDoubleBuffered(true);
caps.setHardwareAccelerated(true);
System.out.println(caps.toString());

now this always outputs:
GLCapabilities [DoubleBuffered: true, Stereo: false, HardwareAccelerated: true, DepthBits: 24, StencilBits: 0, Red: 8, Green: 8, Blue: 8, Alpha: 0, Red Accum: 0, Green Accum: 0, Blue Accum: 0, Alpha Accum: 0, Multisample: false ]

when i set my colordepth from true color(32 Bit) to high color (16Bit) or even (8Bit) this still gives me 8 Bits per color channel, although with high color i would expect something like:
Red: 5, Green: 6, Blue: 5

how can i reliably get the available colordepth? (Bits per channel)

Pixelformat settings are always treated as the minimum acceptable in GL, so if you request 16bit it’s perfectly reasonable to return 32bit if the implementation feels like it. This is probably due to:

  1. The user has forced all apps to be 32 bit colour via the control panel
  2. You’re running in a window and the desktop is set to 32bit colour.

The GLCapabilities object reports what you’re requesting from the card, not the available set of pixel formats. If you want to enumerate those you need to implement the GLCapabilitiesChooser interface. See for example the source code for the demos.multisample.Multisample demo in the jogl-demos workspace, which implements a custom GLCapabilitiesChooser.

thanks.
is there maybe another way to detect the color depth?
maybe using GraphicsEnvironment?

i just need to know if it’s truecolor, hicolor or even something below that.

Not as far as I know. The way we’re doing this in the JOGL backend for Java 3D is to create a small on-screen window and use the GLCapabilitiesChooser interface to figure out what the parameters of the chosen pixel format would be, then destroy this temporary window and create the real one. You can check out the source code to j3d-core and look in the JoglPipeline class (src/classes/jogl/javax/media/j3d/JoglPipeline.java) to see how this works.

thanks Ken, i’ll have a look into that.