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.
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 a data flow diagram (a diagram that looks like a flow chart). It has a set of specific geometrical components like rectangles, circles, ellipses and arrows.
What I'm trying to achieve is to detect these shapes and be able to know which component is connected to which component (through the lines) and finally read the text inside each one to extract data from the diagram and do further processing. It is also notable to mention that the diagram will not be drawn by hand but computer generated so we don't have to worry about angles and ratios being inaccurate.
I'm currently working in Java and I was wondering if this is going to be possible since Java is not the best language when it comes to image processing (correct me if I'm wrong). And if it's possible I'd you guys to point out where I should start looking.
I think Java is fine, and it has many libraries to process images. ImageJ is just one example. Personally, I like to use Python, so I write scripts in this language using Java API of the DMelt platform. Look at the documentation of this projecst, wiki. Here is a link to a few examples.
Doing this in Java wasn't a great idea because mainly the lack of online resources. After a good amount of research, I found that the best and the easiest approach was the use of C# and Emgu CV which is a cross platform .Net wrapper to the OpenCV image processing library.
This example helped me to get started with detecting basic geometrical shapes like Lines, Rectangles and Triangles.
I'm working on an application which draws out a matrix - using Java 2D - which can become quite large, for example 30000 x 30000 pixels.
At this moment I've experimented a bit with BufferedImage but creating such a huge BufferedImage causes out of memory exceptions, even when enlarging the heap.
Now I was thinking splitting the image up into several images/regions, and when I'm done in a certain region write it to disk and create a new region/BufferedImage and continue drawing.
I'm interested in thoughts of other people on how they would handle this. I've been away from Java for a while so any concrete examples are welcome.
I contribute to a new/small open source project which may be quite well suited to your needs.
The project is Glimpse. Its intended to aid in construction of 2D data visualizations in Java with a focus on handling large data sets well and making it easy to provide real-time interactivity to allow easy exploration of data.
It utilizes OpenGL to take advantage of hardware features on modern GPUs like texture memory and shaders to achieve the above goals. So if you're set on using Java2D then this won't work for you. However, Glimpse panels can be placed side-by-side with other Swing components, so it's easy to drop into your existing Swing GUI. The only caveat it that you'll need a decent graphics card.
The image is an example of a large matrix of data whose coloring is being dynamically adjusted via the color scale on the right (the matrix data is stored in a GPU texture and the dynamic re-coloring is accomplished via a custom shader). The source for this example is HeatMapExample.java. There's lots of other examples like that which provide starting points for working with Glimpse's other features.
You can learn more at glimpse.metsci.com. There's an intro video on the front page, along with Java WebStart examples. The source is hosted on GitHub.
if you just want to generate the image on disk, then look at pngj - it can generate big png images with no problems because it writes lines of pixels to disk as they are available. the api is a little png-specific, but it's not too complex (it might help to read a little background on the png image format before using it).
I'm looking for a java 2d drawing framework. I'm building an application in which you load an image, and you should be able to draw on top of the image. But everything which is drawn should be selectable, modifiable, have properties etc. Actually Eclipse GEF (or Graphiti) looked really good, but that seems to be focused on drawing diagrams only. I would also need support for freehand drawing, bezier curves, lines etc.
Anybody know something like Eclipse GEF but which also supports freehand drawing and bezier curves? Or maybe it does and I didn't look quite good enough?
You can quickly write a simple editors yourself using JPanel and a custom paintComponent() method. But creating a useful editor with undo, etc. is a lot of work.
Try jfig which is shareware (free for 30 days, then $30). It has a framework with editor components plus a default editor which you can tweak.
I'm looking for a high-level java graphic library for creating artistic text, watermarks, resize, crop, image identification and manipulation.
ImageMagic is a good example of such library, but its java ports are somewhat problematic (they either run imagemagic through JNI or via commandline and are hellish to deploy to servers).
Ideally I'd like to have similar functionality to ImageMagic, but pure Java and open-source, free to use.
Has anyone seen something like that?
This is for a server-side component. A service that manipulates images of various web formats (png, jpg, gif etc).
Java has its own libraries, of course (Graphics2D) but I'm looking for something of higher level.
Here are several use cases:
Resize and crop images. If it has "smart resize" or "smart crop" that'll be cool, for example seam carving resize, or cropping by points of interest in the photo
Drawing artistic text on images. Using fonts, colors, text effects (3d text, charcoal and other effects)
Embedding watermarks.
Layering images, using images as background, masking with images etc.
Image identification such as - number of colors, stdev etc.
As mentioned, Java in its Graphics2D supports all of the above but is too low level so I'm looking for something that's nicer to work with.
Thanks!
Java Advanced Imaging ( JAI ) sounds like what you want. From the website:
The Java Advanced Imaging API provides
a set of object-oriented interfaces
that support a simple, high-level
programming model which lets you
manipulate images easily.
I found it relatively simple to work with. And the performance was better than spinning off ImageMagic processes.
Use ImageJ. In addition to being a neat program, it can be used as a library.
The Apache SVG Batik library can
be used to display some vectorial
drawing in SVG.
The eclipse project
contains a library called Graphical
Editing Framework (GEF) shipped with
a painting and layout plug-in called
Draw2D. see
http://whf.poac.ac.cn/codeopen/jiaocheng/java2s/Code/Java/SWT-JFace-Eclipse/2D.htm.
Raw Java2D makes it quite easy to do resizing and cropping (just make sure that you reduce in powers of 2, the backend doesn't handle this automatically). I only found JAI useful for my usage to do color quantization... the rest of the pipeline seemed unnecessary for basic functions.