tiny mistake in an example using LWJGL on nehe.gamedev.net

Hi

I’m sorry to disturb you with this, the email address of the author of this port is no more valid. You can find the example here:
http://nehe.gamedev.net/data/lessons/lwjgl/lesson32.jar

The depth values in the select buffer are unsigned 32-bits integer and are stored into signed 32-bits integer. Of course, when the depth is greater than 2^31, the source code stores a negative value.

The actual code is:

temp = ByteBuffer.allocateDirect(2048).asIntBuffer();
GL11.glSelectBuffer(temp);                                // Tell OpenGL To Use Our Array For Selection
temp.get(buffer);
hits = GL11.glRenderMode(GL11.GL_RENDER);                               // Switch To Render Mode, Find Out How Many
// Objects Were Drawn Where The Mouse Was
if(hits > 0) {                                               // If There Were More Than 0 Hits
     int choose = buffer[3];                                 // Make Our Selection The First Object
     int depth = buffer[1];

The last line should be modified:

long depth = buffer[1] & 0xffffffffL;

Best regards.

That buffer allocation should also include an order call, like so:

temp = ByteBuffer.allocateDirect(2048).order(ByteOrder.nativeOrder()).asIntBuffer();

Anyway, I can’t see how that code could work, since it’s doing a temp.get(buffer) immediately after glSelectBuffer and before rendering anything. Or am I missing something?

the official nehe site LWJGL source code (AFAIK) has not been updated in a while.

I submitted a fix to lesson27 stencil shadows ages ago. and it never got updated.

This source code seems outdated and may contain other errors. If I had some time, I would have a deeper look at this example. I only noticed the common errors that I fixed several times somewhere else.

Maybe updating all lessons and putting the source code directly somewhere onto the official website of LWJGL would be better.

if you need a better lwjgl source code port of the nehe tutorials you can find them here. The source there is much nicer and better looking.

unfortunately I can’t start the webstart examples from the site, as the lwjgl-1.1.4-extension.jnlp doesn’t specify lwjgl natives for linux x86_64.

You’re right but there are only 25 lessons, lots of lessons are missing. Thank you for the pointer.

You’re right. It works with 32 bits linux but when I leave the application, the process is still up.