Render to texture using only OpenGL Context ID (Java) - 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.

Related

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

Hardware accelerate bitmap drawing in java

I want to be able to draw consecutive bitmaps (of type BufferedImage.TYPE_INT_RGB) of a video as quickly as possible in java. I want to know the best method in doing so. Does anyone have any advice where I should start? From what I've read, 2 options are:
1) Use GDI/GDI+ routines in a JNI dll working with JAWT (Im on Windows)
2) Use Java3D and apply Textures to a Box's face and rotate it to the camera
Im interesting in any advice on these topics as well as any others.
I have done a decent amount of GDI/GDI+ programming in VB when i created an ActiveX control, so using GDI should be painless, but im guessing Java3D will utilize the GPU more (I could be wrong) and give better performance. What do you think? GDI and JAWT with my previous experience, or start and new API journey with Java3D.
Thanks in advance. :)
To obtain a fluid animation (if it what you want to get), you need to use double buffering. For doing this, you will need to create a new java.awt.Image (or a subclass like BufferedImage, or if you want OpenGL accelerated processing, VolatileImage) for each frame you want to display. If you haven't already done so, call Image.getGraphics() to get a java.awt.Graphics object (can also be useful to add your content to the Image). At the end, when you hidden Image is complete, call Graphics.draw() to replace the current display smoothly.
VolatileImage is OpenGL accelerated and much faster. When VolatileImage.getGraphics() is called, it actually returns a Graphics2D, which is also part of the accelerated graphic pipeline.
It works on Windows, Linux and Solaris, but you need to have OpenGL drivers installed for your graphic card.
Some additional refs:
Accelerated graphic pipeline:
http://download.oracle.com/javase/1.5.0/docs/guide/2d/new_features.html
http://www.javalobby.org/forums/thread.jspa?threadID=16840&tstart=0
Double buffering:
http://www.java2s.com/Code/Java/2D-Graphics-GUI/Smoothmoveusingdoublebuffer.htm
http://www.heatonresearch.com/articles/23/page2.html
http://www.javacooperation.gmxhome.de/BildschirmflackernEng.html

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