How to do 3d in a Java applet? - java

I'd like to render a very simple 3D scene in a java applet. I could do all the math myself and render that to a bitmap, but as I'm sure I'm not the first person in history to have to draw a few cubes to the screen, I was wondering how this is usually done.
Every place I've read has said either Java3D or LWJGL, but as I understand it these rely on platform-dependent code and need to be installed separately from Java, making them both unsuitable for graphics.
So how is this usually done?

This old page lists the demos/apps/libraries of 3D Java applets with no hardware dependencies. Unfortunately very few are open-source, others are not even downloadable.
Personally I recommend you to experiment with Java 1.1 3D renderer by Ken Perlin, which has source code available and free to use for academic purposes.
EDIT: jGL is another Java 3D library with no hardware dependencies. It mimics OpenGL 1.* API. It is licensed under GNU Lesser General Public License (LGPL).

In a plug-in 2 JRE (1.6.0_10+), you can use JWS extensions for embedded applets. This is important because JWS makes it much easier to ensure the correct binaries are on the run-time class path. AFAIU JOGL and Java 3D both offer JWS extensions for their APIs.
Should you choose to go that way, please make the applet has the draggable parameter added, so the end user might choose if they want a (mostly useless) browser window wrapped around a 3D animation.

I ran into similar problems when I needed to do some 3d rendering in an applet. My solution was to simply implement from scratch a 3d rendering library in Java. The fear was that it would be a poor performer but on an I5 processor, this proved to not be the case. The added advantage is that I was able to write the library in the way I always wanted graphics to be done. The real advantage,, though, is that it will run regardless of any need to have some graphics library installed on the client and without regard to any graphics card dependencies.
I will gladly share a subset of this code to anyone who wants to look at it.

Could you use JOGL?
http://download.java.net/media/jogl/demos/www/applettest-jnlp.html

I'm not a Java guy, but 2/3 years ago when I was at univeristy I had the same problem :)
I've tried jogl... and for noob in Java like myself I found it too complicated to configure and write something using it.
I used Java3d and it worked like a charm, the only problem I had back then, was that Java3d did not worked with all graphic cards. But fortunatelly it worked with computers at my univeristy :)

Related

Java 3D Object Rendering with Yaw/Pitch/Roll

Im looking for a way of displaying a 3D Rectangle, which could be moved by the values a gyrosensor delivers from my arduino.
I just don't know where to start with the Implementation of the 3D Space, the communication works fine.
I did not find any useful information online, however, I just need a Window (Don't know, is JFrame enough for this) with a model that I can set x/y/z and yaw/pitch/roll etc.
Are there libraries or code-examples?
I did see one integration with JavaFX which I have never used yet, or the implementations were in other languages.
Unity worked out for this, even though i was getting buggy behaviour.
Therefore i tried out Processing, which turned out to work fine. There are some snippets online where you can pass in the values of your arduino and it just works out.
I cannot provide more details since the project was abandoned.

Adding Text to Screen with OpenGL

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.

PlayN java desktop version slower than web version?

so i've been playing with google PlayN, and i built a small sprite sheet loader for explosions.
what is weird thought is that the desktop java version (that uses the same core code) runs way slower than my web version.
for instance my web version: sapropwns.appspot.com (click with left mouse button and drag the pointer), as you can see its pretty smooth. on the other hand the java desktop version lags every like 2 secs and doesnt draw as much as this web version (the trail doesnt have as much drawing even though both use the same mouse callback for drawing at the same speed).
is there a limitation on the PlayN library that im missing?
thanks in advance.
It's been a while since I looked at PlayN (I was poking at it for a little while for fun). But performance for desktop apps may not be great for certain applications since they are using straight-up Java2D for their rendering. I'm also guessing it's not all that optimized at this point.
There is some discussion on the PlayN group about improving performance by switching from Java2D to LWJGL (Lightweight Java Game Library). This would improve performance greatly for desktop apps (Minecraft uses LWJGL).

High level API for creating 2D Shapes in Java

I am seeking an API or program which I can use to create Shapes graphically in Java (specifically closed shapes). A tool simalar to paint in windows, but without the colors and such. After the shapes are created, I will be using them as part of a simulation program, so I need to get access to the actual java Shape objects.
I could create my own tool using Java2D, but I am sure I would be wasting my time as there must be some useful tools out there. However, after a long time scowering google, I had no luck. Any tips would be much appreciated.
Here's an article describing how to do it accompanied with source code that you might be able to use.

Guidelines to implement a minimal shape drawing tool desktop application using Java

We need to implement a Java desktop application that allows us (initially) to create / edit / resize / polygons on (initially) images. Then these polygons would be mapped to objects in our domain model.
So we basically need a toolbar with the options describe above and the possibility for the example to create a polygon on the an image and then scale it, or resize it, just that.
Do you know some library that could facilitate our work?
We've analyzed GEF, Picollo, NetBeans Visual API, Plain Swing or SWT/JFace, but none of them seems to help us to achieve our goal, which is, implement a really basic image editing tool.
I would like to mention that I'm not saying that what I want to do is not possible with the analyzed libraries, of course it can be done, but I'd like to learn from your experiences which is the correct path to take for this problem.
Any suggestion will be welcomed.
You could try to use GEF and the eclipse plataform.
this article could help you.
saluti
You might look at GraphPanel, a simple object drawing program. The control components are arranged in a JPanel, but JToolBar is a more flexible alternative.
Have you looked at imagine.dev.java.net? It is a NetBeans Platform application, which, though unfinished, might provide you with an interesting starting point.

Categories

Resources