Why are LWJGL3 windows longs?

Hello JGO:

I have a question. In my recent test with LWJGL3, I’ve noticed something that strikes me as odd. Prior to LWJGL3, windows were Display objects, which seemed perfectly normal to me. But now, in LWJGL3, windows are suddenly [icode]long[/icode]s, which is a primitive. What’s with that? How does the code make a window out of a primitive type? Since longs can only hold numbers, what does the long look like post-window initialization? I’ve just been wondering this, and thought maybe someone could shine some light on this.

Thanks,
-DarkCart

Instead of passing objects around* you LWJGL3 passes around a number for a specific object, like if you’ve ever been to a supermarket or restaurant where instead of standing in line (passing yourself around) you grab a ticket and they call ticket numbers up to the counter to order.

It’s an API choice, the ‘pointers’ could easily be encapsulated as fields of an object (which is almost certainly what the Display object was), perhaps Spasi could shine more light there. It’s at least less indirection.

  • Actually this is how it’s always done even in java, ‘passing objects around’ is actually passing pointers (numbers) to objects around. Java merely hides this from you, in C, etc. (which LWJGL binds to) pointers are explicit.

From the point of a client of LWJGL (your game/app) it can be considered as an opaque data type, assigned by GLFW (which manages the windows) when creating the window. So whenever you invoke any LWJGL method operating on a window, you just need to use that long as an argument. So it is irrelevant to your application, what that window’s structure actually is, since its interface is not defined by a data structure but rather by a set of operations you can invoke on it.
In detail, this long is the address of a native GLFWwindow struct, which is managed by the GLFW library internally.

Yeah so it’s as if LWJGL holds an internal array of objects, and you just keep track of the index into that array for your specific object.
[sub](RAM is equivalent to an array)[/sub]

there are no objects, just pointers (longs) to memory.