Few questions regarding setBitsPerPixel and setDepthBits

Hello, I am fairly new to JME and I must say that I love this engine :smiley: - so thanks!

The questions I have are in regard to setBitsPerPixel and setDepthBits in AppSettings.

Firstly, I am kind of confused as to what the difference between the two are.

When trying this code everything seems fine and the application starts normally
[java]
AppSettings settings = new AppSettings(true);
GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode mode = device.getDisplayMode();
settings.setBitsPerPixel(mode.getBitDepth());
setSettings(settings);
// start application
[/java]

But then using this code results in the following error: org.lwjgl.LWJGLException: Insufficient depth buffer precision
[java]
AppSettings settings = new AppSettings(true);
GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode mode = device.getDisplayMode();
settings.setDepthBits(mode.getBitDepth());
setSettings(settings);
// start application
[/java]

Obviously I assume that they must not be the same, otherwise they would produce the same results when running, so what’s the difference?

Furthermore, another question I had was in regard to this page: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:intermediate:appsettings

On that page it says this:

setBitsPerPixel(32) Set the color depth. 1 bpp = black and white, 2 bpp = gray, 4 bpp = 16 colors, 8 bpp = 256 colors, 24 or 32 bpp = "truecolor".

However, I tried setting setBitsPerPixel(1) in my application (just for fun to see if it would be in black and white) and nothing happens - does this only work if supported by the display?

So, to recap, my questions are:
1) What’s the difference between setBitsPerPixel and setDepthBits?
2) (related to #1) Why does my code setDepthBits(mode.getBitDepth()) throw an exception?
3) Why does setBitsPerPixel(1) not make my application black and white (is it because it only works if supported by display?)

Thanks!

(1) One controls the bits per pixel and the other controls the bits per element in the depth buffer.
(2) Because your graphics card does not support the same depth bits as your current color bit depth. Since these are two completely separate and completely unrelated things, it kind of makes sense.
(3) Probably because it is ignored in window mode or is not supported by your display.

P.S.: I kind of have to feel like the javadoc was pretty clear on this… but maybe you can tell what was confusing:
http://hub.jmonkeyengine.org/javadoc/com/jme3/system/AppSettings.html#setDepthBits(int)

1 Like
<cite>@pspeed said:</cite> P.S.: I kind of have to feel like the javadoc was pretty clear on this... but maybe you can tell what was confusing: http://hub.jmonkeyengine.org/javadoc/com/jme3/system/AppSettings.html#setDepthBits(int)

The javadoc of java.awt.DisplayMode.getBitDepth() mentioned both bit depth and bits per pixel so the naming threw me off a bit.
I’ll be sure to check the javadoc more thoroughly next time. Thanks for answering my questions :slight_smile:

edit: regarding question #2
on this page Google Code Archive - Long-term storage for Google Code Project Hosting. I found this bit of code which is why I was originally attempting to use it.
[java]settings.setDepthBits(modes[0].getBitDepth());[/java]

That code seems erroneous to me. Might as well be passing any old arbitrary and completely unrelated value.

@Clifton said: The javadoc of java.awt.DisplayMode.getBitDepth() mentioned both bit depth and bits per pixel so the naming threw me off a bit.

Note: “bit depth” and “depth bits” are not the same thing. Bit depth is roughly the same as bits per pixel… like time is roughly the same as milliseconds.

Packt just contacted me about this, it seems you, @clifton are trying to get an errata in the jME3 ebook.

The code in particular (page 43) is fine. I just tried it and it doesn’t give any error.

If it is causing an error, you’re doing it wrong.

[java]
GraphicsDevice dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode[] modes = dev.getDisplayModes();
settings.setDepthBits(modes[0].getBitDepth());
[/java]

@madjack said: Packt just contacted me about this, it seems you, @clifton are trying to get an errata in the jME3 ebook.

The code in particular (page 43) is fine. I just tried it and it doesn’t give any error.

If it is causing an error, you’re doing it wrong.

[java]
GraphicsDevice dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode modes = dev.getDisplayModes();
settings.setDepthBits(modes[0].getBitDepth());
[/java]

Are you sure? Because if I understand what pspeed says in the comment right above yours Depth bits and bit depth are unrelated. So even if you are lucky and your machine can set 32 depth bits just because your color bit depth happen to be 32 doesn’t make the code right.

1 Like
@jmaasing said: Are you sure? Because if I understand what pspeed says in the comment right above yours Depth bits and bit depth are unrelated. So even if you are lucky and your machine can set 32 depth bits just because your color bit depth happen to be 32 doesn't make the code right.

This is correct. They are two different things that happen to use the word “depth”.

In fact, Java provides no way of getting the “depth buffer depth” so there is no way to safely setDepthBits() with anything but a guess.

appSettings.setBitsPerPixel(mores[i].getBitDepth()) is the two values that go together with AppSettings and DisplayMode.

appSettings().setDepthBits() has something to do with the zbuffer i think and is unrelated, you probably dont want to change this value.

http://hub.jmonkeyengine.org/forum/topic/bitdepth-depthbits-bitsperpixels-confusion-somewhere/

(the correct usage is now clarified in the wiki)

theyre just two settings that unfortunately have similar names.

My bad people, my bad.

It is indeed wrong. I mixed up the methods. I saw DepthBits and thought BitsDepth. I’ll notify Packt.