I am trying to display some text in lwjgl in java but I dont want to use slick library, do you know if there is any other way to show some text in java using lwjgl ? If so, which external libraries I need to import ??
Unfortunately it's not possible. Either draw it pixel by pixel or use a library. You'll only need slick-util for drawing text, so it shouldn't be a problem. You can find the javadocs here.
Well, the only way I know is to create a java awt image and draw the text on it (using awt) and then pass it to opengl. So, just create a BufferedImage, get its graphics context and write on it using the methods in that. Shouldn't be too hard.
Related
I am working on a java swing application that requires rendering images in specific locations on a JPanel. Currently, I am using PNG images with the Graphics.drawImage method. The application also requires the ability to freely move and zoom the "camera", which I am accomplishing with the Graphics2D.scale and Graphics2D.translate methods.
However, a significant issue with this approach is that the images do not scale well when the application is zoomed in. I was hoping that I could get around this by using SVGs, so I downloaded the Batik library. I have been able to display an SVG using Batik's SVGCanvas, but this doesn't really solve my problem because I am unable to freely place the SVGs in the JPanel and use the SVGs alongside the java Graphics methods.
Does Batik even apply to my use case? If not, is there some other way I can freely scale and render SVGs in a JPanel just like I would with a BufferedImage? Another option would be to just use the Graphics2D methods to try to replicate the icons I want to use, but that seems unnecessarily complicated.
I have to make a Java program that gets XML files with simple snippets of code from several programming languages and draws them into a flowchart and makes it into a JPEG/PNG image, now I know it must be possible to do this but so far I haven't found anything to help me figure out how I can make Java draw an image and make it into a JPEG.
Is there any library I can use? A tutorial on this? Anything?
Suppose I have the source code of a charting library which is written in C++ and renders itself by using OpenGL. Now, I'd like to create an AWT/Swing control element that uses this charting and to embed this element into, say, a JPanel. The other elements in the JPanel should be normal JButtons, JSliders, or whatever.
Is it possible to do that? If yes, can you please provide a small code snippet demonstrating how to do that?
Any ideas and hints?
EDIT: Got it! Seems like Java Native AWT does what I want!
http://www.codeproject.com/Articles/791/Embed-OpenGL-inside-Java-AWT-Canvas
Currently, I am working on a OpenGL project and here is the screenshoot what I did
The question is, I want to add texts(degrees) to compass and want to do that with pure OpenGl methods. I found TextRenderer class however, couldn't manage to download it and use it. How to use TextRenderer class in my Java project? If there is any other way of adding text besides TextRenderer, would love to hear it.
My second and most important question is about merging swing/awt methods with OpenGL and using multiple objects. I wrote the program with only using one GL2 object and worked perfectly, is it sensible to use multiple openGL objects on the same frame? Furthermore, using swing methods and openGL methods together is a good idea?
I want to add texts(degrees) to compass and want to do that with pure OpenGl methods.
Unless you can live with not very pleasantly looking center stroke fonts, you have no choice but to use help from some other library or API.
Theoretically OpenGL can collaborate with OpenVG, but so far overall support for OpenVG is very poor, and OpenGL interoperability even worse. But say you had a proper working OpenVG – OpenGL interoperability working, then OpenVG was the way to go.
Practically you have to something different. A very fruitful approach is to use a font renderer library (like FreeType) together with some layout engine (like Pango) to produce an outline stroke list of the text to be rendered, which in turn can be either rendered directly using some extension by NVidia (http://www.opengl.org/registry/specs/NV/path_rendering.txt available only on the most recent NVidia GPUs) or manually tesselated into triangles, either on the CPU or by a combination of GPU Geometry and Tesselation Shaders. A huge drawback of drawing glyphs as tesselated filled outlines with OpenGL primitives is, that they will look very dirty (due to aliasing) if the used framebuffer doesn't have a multisample format (full screen antialiasing)
The next best thing is rendering the text to an image and copying that to the GPU and overlay that over the scene by rendering a textured quad. You should apply all text transformations already when rendering the quad, so that the font hinting system can make the proper adjustments on the transformed glyphs before rasterizing them.
Another approach is using texture mapped fonts. I implemented two TMF engines myself so far, but personally I advise against using this approach these days, as TMFs are resource hogs. A 200kiB TTF font can blow up to several megabytes of texture data. Maybe one day I or somebody else implements a TrueType or OpenType rendering engine with OpenCL, CUDA or Compute Shader, but until then rendering text with OpenGL is dirty business.
It boils down to
Crisp Look
Memory Efficient
Computationally Efficient
→ choose 2
After doing little research, I ve figured out how to install it and use it correctly.
Firstly, go to that web site and download suitable version of jogl for your os in case you dont have any library:
http://jogamp.org/deployment/autobuilds/master/jogl-b1011-2013-06-19_05-41-38/
Then, download that jar file and add it to your user library.
http://www.java2s.com/Code/Jar/j/Downloadjogl20jar.htm
That file contains the TextRenderer class.
If you dont know how to make one, use that link:
http://riccardotramma.com/2011/04/setup-eclipse-to-develop-opengl-glut-apps-in-java-cc-on-windows-mac/
Then, follow the instructions: http://download.java.net/media/jogl/jogl-2.x-docs/com/sun/opengl/util/awt/TextRenderer.html
It's very easy to use, I perfectly added numbers to my compass. However, not efficient as far as I can tell.
I wrote a Java application that uses the java.awt.Robot to take screen captures of the screen and was wondering if capturing a program using DirectX/OpenGL would be possible?
Each time I try to do this, I get a black screen
Don't know if this is really a solution but seems there's more possible ways to get the screenshot information using a "FrameGrabber" or some related class from JavaCV possibly: http://code.google.com/p/javacv/
Some of the final output shown on the screen could be calculated on a graphics card that has shaders set to act on the image data before it gets put into a display buffer for what's shown so it's possible some effects would be impossible to capture without an analog loopback (go from video out to video in on a capture card).
Related post How to take screenshots fast in Java?
OpenGL is a drawing API, not an all purpose interface to the graphics system. There were times, when taking screenshots with OpenGL was indeed possible through some dirty hacks. However recently I tried to re-implement this on modern OS to see if it still works, and no, it doesn't anymore.
Yes it is possible. But maybe only in limited circiumstances.
I've successfully captured the contents on OpenGL (jogl) windows on linux and windows using the Robot createScreenCapture.
Some specific information about the implementation that may be different for you:
The call to createScreenCapture was done from within the OpenGL
application.
The application used heavyweight GLCanvas
It used Java 6
Make sure you pass it the correct coordinates. You can get the screen coordinates to use from the GraphicsEnvironment
Uhh... a hard one ;o)
I had a try with some other screenshot utils and got a black screen, too. Looks like DirectX is passing the graphics directly to the monitor output. I am wondering if that could be accessed within a java application.