How can I do off screen rendering using LWJGL? - java

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

Related

Render to texture using only OpenGL Context ID (Java)

We need to render to texture entire game window. We have only java SDK jars from our client, and we can access only OpenGL Window context ID of window they create when game runs.
My question is, is window context enough to somehow render it to texture?
We cannot alter code of our client, but we need to render Editor windows on top of their java SDK.
They are using LWJGL for rendering. Plan is to render game into separate window, similar to this:
I guess this can be only achieved via mentioned rendering to texture.
if you can use the regular openGL commands, there might be something that you could do.
the issue is that you'd need to change the openGL's state machine which might collude with what their game is doing.
One thing that could work, but again it might clash with what they are doing.
Since you want to display their final output, it's a safe bet that their are rendering to the default framebuffer. So you create your own framebuffer that has a texture color attachment, and you blit the default framebuffer into your own with glBlitFramebuffer. That way you should get the default framebuffer into a texture.
for that you need to do glBindFramebuffer(GL_READ_FRAMEBUFFER, 0) and glBindFramebuffer(GL_DRAW_FRAMEBUFFER, **your buffer**) before the blitting to set the targets of the operation.
Since I don't know if you can do code for every frame I'm not sure that would work, but it might be worth a try.

Putting a Slick2D game inside a GUI

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.

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.

Render string to texture in Android and OpenGL ES

I've googled around everywhere, but cannot find much for rendering strings to textures and then displaying that texture on a quad on the screen. Can someone provide a run-down on the process or provide good resources that describe how? Is rendering strings to textures even the best method for displaying text in an Android OpenGL ES app?
EDIT:
Okay, so LabelMaker interferes with alpha blending, the texture (created from a PNG with a transparent background) now has a solid black background, rather than a transparent background. If I comment out all the LabelMaker-related code, it works fine.
UPDATE:
Nevermind. I took a look at the code to find that LabelMaker was disabling blending after drawing the labels.
I think this is what you are looking for.
If you don't want to use GL extensions you need to create the font as a bitmap and then create a class to convert that string into quads that you can draw.
I use this method with the 2 fonts in my game. I have a class that takes a wide texture with all the letters evenly spaced, and a string that matches the image, then uses lookups on the letters to find out how far in the bitmap it should go.
Your other option is to render your text to a offscreen bitmap using android, and then bind the text as a texture. This will let you use androids built-in font processing and rendering to create texture-based fonts.
The second method I have not used yet, but I have rendered google maps to a offscreen canvas and then bound the bitmap as a GL texture, so doing it for text should be much simpler.
If you are planning to have modifying string data in a gl loop you need to really worry about StringBuilder too, because it causes GC and performance issues. I hardcode all my strings so it doesn't allocate, and all my rapidly numbers are done through a second draw function dedicated to drawing changing numbers without using string-builder.

Categories