Noob LWJGL Question

I’ve only downloaded the LWJGL dll and jar and message around with the example code a bit but I’m interested in diving into development of building a full blow 3D engine using LWJGL or one of the other java 3d libraries for the second generation of our current game project.

I wouldn’t want to start from scratch with the 3d engine though and I was wondering if the community has built and impressive terrain rendering engines (fractal or other) that are available for use.

I’d also be interested in finding out if I would have a problem creating the LWJGL’s screen buffer after I’ve already created a screen buffer by using Java bufferstrategies, and if its not a problem how would I go about getting this to work? Would I need to reset the screen buffer back to the original configuration and then recreate it with LWJGL (would lead to problems with java 1.4.1 or less since recreating your graphics config more then once often crashes your system) or is there a way I could pass my current graphics device configuration to the LWJGL’s screen device. If there was a way to pass my current graphics config to the LWJGL it would be a smooth transition between 2d and 3d rendering.

See http://chman-area.tuxfamily.org/gt/GT41.ZIP , it’s a tutorial ported from GameTutorials.com on Terrain Rendering… this may help you (no fractal anyway :frowning: )

LWJGL and AWT are completely, totally separate. If you are using LWJGL there is no need to have any part of the AWT installed provided you can be bothered to write your own GUI code. I’ve rolled my own and I’ve seen two others that are both excellent quality as well, so it’s not vastly difficult to do, and the end result is much nice than AWT.

As far as a framework for doing Stuff is concerned I’ve put some handy things together in the Shaven Puppy Game Library (http://sourceforge.net/projects/spgl) but what’s there is generally a bit buggy and in flux a lot of the time because I’m using it for my own game and it gets “developed” quite a lot.

Cas :slight_smile:

My problem is that I have a ton of code based entirely on java2D and If there was away for me to easily change my drawing mode from 2d to 3d within our game then we could make any transition over to using LWJGL much simpler in the interum, before going entirely to a 3d game with 3d overlays for the interface.

When you say write your own GUI code are your talking about creating the GUI using LWJGL opengl? For example in Jbuilder I can place a 3d opengl panel onto a form that already has a 2d screen buffer and draw 2d stuff for the interface to the 2d screen and 3d stuff inside opengl panel. I was just curious if there was or will be support for both a 2d and 3d screen buffer using LWJGL. Either by passing in my current 2d graphics config to the LWJGL (switching modes) or creating an openGL panel using LWJGL that doesn’t require me ditch my current 2d drawing buffer.

As you stated before its not that difficult to create the GUI using LWJGL but it doesn’t allow developers who have large projects already completed to easily migrate over to LWJGL without a great deal of overhead if they want to add 3d functionality to their 2d projects.

[quote]When you say write your own GUI code are your talking about creating the GUI using LWJGL opengl? For example in Jbuilder I can place a 3d opengl panel onto a form that already has a 2d screen buffer and draw 2d stuff for the interface to the 2d screen and 3d stuff inside opengl panel. I was just curious if there was or will be support for both a 2d and 3d screen buffer using LWJGL.
[/quote]
Sorry, nope. The OpenGL context created by LWJGL has nothing to do with the AWT. You can’t embed it into an AWT frame, or use AWT-based drawing routines on it in any way.

Generally, if you’re doing anything like this, LWJGL is not for you. Sorry! You’d probably do a lot better giving GL4Java a try.

…or even Java3D, which seems to be just right for this sort of thing. I mean, it’s got to be useful to someone, somewhere…

Cas :slight_smile:

Additional: I thought I should explain this a little more.

The problem you’re hitting is that LWJGL’s use of OpenGL has been designed for a very different purpose than that which Java2D was designed for. These differencies manifest themselves in a complete lack of interoperability! :wink:

However, the path between your Java2D app and GL4Java is quite easy, then when/if you’ve moved away from Java2D, the path to LWJGL becomes easy as well.

However, that’s probably some time in the future. You may not even need the features of LWJGL over GL4Java.

I will say this much, for all the pain that it causes some folks, the code path for providing it is trivially simple. The only thing LWJGL needs to do is allow something to pass it a window handle (HWND) during its construction instead of only creating it itself. Then developers have the option of providing that HWND from a standard Java component in 8 lines of code. Doesn’t break anything, doesn’t require AWT, and doesn’t cause any performance problems… and I know this because I’ve had to do this for a client who has embedded it into an application… a Swing application no less. Took a lot of work making sure that nothing overlapped the heavyweight component, but they are happy with the results.

Sending people to GL4Java or Java3D just to render in a window is totally unnecessary.

I think gl4java is the solution, if you have any questions, PM me I can give you some protips.

I’ll investigate that idea Gregory seeing as windowed mode has taken on a nasty life of its own. My debugging hack has escaped quarantine and mutated into a feature…

Cas :slight_smile:

All you need to do is split the create method into two methods Java_org_lwjgl_Display_nCreate and Java_org_lwjgl_Display_nCreateFromWindow. The only difference in Java_org_lwjgl_Display_nCreateFromWindow is that the method takes a Window handle from something else (even a C or .Net application) and when told to render, renders to that window. To get the Window handle of an AWT component or Swing component it trivially simple as well, just extract out the JAWT_DrawingSurfaceInfo and get the hWnd from it to initialize your component. From there just override paint for that component and have it call the appropriate Java_org_lwjgl_Display_nCreateFromWindow. If I wasn’t wrapped up with this GUI creation task I would do it myself. Took me a weekend to get down perfectly.

From there its up to the user to decide if they want to have an AWT capable version of the system or not. If they want to render into a Java component - they need to bind with AWT, no way around that… same thing SWT does. If they want to have no dependence on AWT they can have the library create its own component.

Piece of cake. Email me if you want to discuss - me@gregorypierce.com