Putting a Slick2D game inside a GUI - java

What I am trying to do is to create a GUI using SWING and then have a container that will display the actual Slick game inside as seen below.
The problem is that the AppGameContainer is the only available container (that I know of) but that creates the whole window (which includes the title bar and stuff) so I can't really embed that inside the GUI, could I? I'm open to other solutions as well so let me know if there is a better way to achieve this.
I am not very experienced with Slick2D so sorry if it's obvious but I tried Googling it and didn't come up with anything.

I would recommend using an OpenGL Frame Buffer Object (FBO) to render your scene to. An FBO acts like a 2D texture object in OpenGL, so you could then read the pixel data from the FBO and use it to render to a Buffered Image, and use that to render to your java swing canvas. This
is a pretty good tutorial on how to use FBOs if you choose to implement this strategy.

Related

Libgdx Batch without ApplicationListener

Hi i'm looking for a way to display a Libgdx sprite batch, or something like this, without using any Application Listener, Adapter or the Game class.It should be possible to call a constructor of some gameobject and then it's texture should be displayed to a batch or some window.
The reason is, that i want to use a desktop-application-project in class with students to start programming lessons and therefore we use BlueJ. But features like the object inspector aren't working, if there's an active application thread and things like Gdx.files ends in a nullpointer exception.
In later lessons there will be an application but in the beginning that goes too far.
All my attempts with the Game class or self written ApplicationListeners weren't succesfull. I hope somebody out there has a idea.
A SpriteBacth draws to a Screen. Application Listener/Adapter and Game is needed to manage the screens. The SpriteBach assumes you have a Screen, a LibGDX Screen, not just any Screen, and does not magically know what you want it to draw on.
You cannot just instantiate an object from one library and expect it to magically work in a different library.
I fail to see the point of it even if it were to work. Either use LibGDX or don't.
You would be much better off using something like JavaFX. It is built into java and is easy to draw images and sprites to a window. You can use JavaFX to make games AND desktop applications.

Java, LibGDX, and JBox2d: Resizing a window while maintaining the aspect ratio of the objects being drawn

I am conducting a learning experiment with Java. I am attempting to create a simple "Megaman" style game using Java and the 3rd party API "LibGDX". I have obtained a rather solid understanding of the relationship between the OrthographicCamera object from LibGDX and the World object from LibGDX's implementation of "JBox2d".
However, when I resize the window the objects inside World stretch. I have made use of the resize(int width, int height) method of the Screen interface. Inside of which i reset the OrthographicCamera's width and height. This does not seem to have any effect of the way the images looks or behaves in the physics simulation.
So my question is this: How do i properly resize a LibGDX/JBox2d application's window without distorting the objects being simulated?
here is the code (in the form of a git repo because i find GitHub faster, easier, and kinder to the SO server...)
EXTERNAL LINK
https://gist.github.com/konnerdroid/8113302
EXTERNAL LINK
AHA!!!! i wasnt updating my camera...
For any changes made to the camera to be visible and their effect to be felt you need to call camera.update() either in your loop or after any changes are made
well... at least i learned how to use github =)

Creating a hidden Canvas with LWJGL

I'm beginning to write a special use graphing program and I'm leaning towards using OpenGL to generate the graphics. The ultimate goal is an architecture that accommodates both 2D and 3D graphs with the basic framework.
Exporting the generated graphs as images is a critical feature, and eventually I'm going to write the code to generate vector images of the graphs' 2D projections. However, in the mean time, I want to be able to export the graphs as high resolution images--images significantly larger than the application window.
I'm writing this application in Java and using the LWJGL OpenGL wrapper. I've figured out how to take screenshots of the display window, but I haven't been successful creating larger images. I've tried to make invisible Canvases, but I can't make it work.
The documentation says here that the Canvas's isDisplayable() method must return true, and to that end I've overridden the isDisplayable() method to always return true, so that it shouldn't care whether or not it's in a Frame, but this doesn't work. Instead, it throws the following error:
java.lang.RuntimeException: No OpenGL context found in the current thread.
at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
at org.lwjgl.opengl.GL20.glDeleteProgram(GL20.java:311)
The problem seems to be that it also needs some properties from the top-level window, but even when I make a dummy Frame class I get the same error as before, until I call setVisible(true) on the frame.
Does anyone know how to fake these graphics properties into thinking it has a visible top-level window? Does anyone know an easier way?
As an alternative, you could use a framebuffer object (FBO) to render into a texture.
Have a look at this render to texture example.

lwjgl - Editor Viewport

I'm working on a project with lwjgl and I've gone pretty far in what concerns progress. Now I need to create an editor so my mapper can start making maps and to make my debugging life easier.
To do a decent editor I need a user interface and at least one viewport.
If you search for Unreal Editor (tm) in google, you'll know what I'm talking about. The problem is I have no idea of how to achieve something like that.
Edit: It's a top down 3d game. The only thing I need to know is how to make opengl (lwjgl) render to a specific region of the window instead of using the whole window.
So ye, I only need to know how to tell OpenGL to render to a specific region of the window, I know how to do the rest.
Try glScissor you can find it in org.lwjgl.opengl.GL11 it will allow you to render content in a specified area and anything outside it will be cut off, it's great for scrolling areas!
You also need to enable GL_SCISSOR_TEST before using it and then disable after using glEnable(GL_SCISSOR_TEST) and glDisable(GL_SCISSOR_TEST)

How can I do off screen rendering using LWJGL?

I'm trying to find a way to do rendering off screen with LWJGL. What I want to do is render something and keep it in memory as a texture, then at a later point use that to texture a shape I'm drawing in the main window. I'm pretty sure this should be done using a Frame Buffer Object, but I haven't been able to find any useful documentation online. I'm fairly new to Open GL and LWJGL so I'm sure there is some fundamental concept I'm missing.
Could someone possibly provide a simple example that renders something(I don't really care what) off screen to a texture? Ideally I would like to end up with a slick-util Texture object.
Create a frame buffer object and bind it as the primary render target. Here is a tutorial:
http://www.gamedev.net/page/resources/_/technical/opengl/opengl-frame-buffer-object-101-r2331

Categories