Question about OpenGL

Posted 27 December 2013 - 10:36 AM

Hi,

I am a Java programmer interested in 3D graphics. I have never used OpenGL before, but I have experience in C++.

My question is: is Java's AWT/Swing API at the same layer as OpenCL? In other words, is C++ to OpenGL what Java is to AWT/Swing? Are the OpenGL APIs for Java (such as LWJGL) meant to replace Java's SE graphics APIs?

Replies To: Question about OpenGL

Re: Question about OpenGL

Posted 27 December 2013 - 11:06 AM

Hey.

The AWT and Swing APIs are meant to provide easy to use window GUI widgets for Java programs, whereas OpenGL is an API meant to expose the full rendering capabilities of the graphics hardware to programmers.

I don't know exactly how much graphics rendering capabilities Swing or AWT provide these days, but unless it's drastically improved in the last few years, it's no more than basic 2D rendering. More like the Windows GDI+.

If you want to do 3D development, it's OpenGL you want. (Or possibly Direct3D, for Windows-only development.)

Re: Question about OpenGL

My question wasn't which is better (obviously OpenGL is), but whether they are in the same category or not; i.e. do they sit at the same layer between software and hardware?

I have written a 3D engine in Java using AWT and I was thinking of moving on to OpenGL (I guess using LWJGL). However, since this is for learning purposes, I want to keep my project as "from scratch" as possible (I do all the rendering and math myself).

Re: Question about OpenGL

Posted 27 December 2013 - 11:45 AM

I see. I don't see how they could be though. Whatever Java API you'd use would always be built on top of either OpenGL or Direct3D, depending on platform. They are the lowest level APIs you will find, and pretty much every graphics library out there is built on top of them.

I must admit I'm not exactly up to date on what AWT is capable of, but I never knew it to be capable of 3D rendering on it's own. It does allow other graphics libraries to write on top of it's canvas, that much I do know, and that there are Java APIs that abstract the lower-level, platform-specific APIs (OpenGL and Direct3D) into platform-independent Java classes.

Re: Question about OpenGL

Posted 27 December 2013 - 12:11 PM

Atli, on 27 December 2013 - 11:45 AM, said:

I see. I don't see how they could be though. Whatever Java API you'd use would always be built on top of either OpenGL or Direct3D, depending on platform. They are the lowest level APIs you will find, and pretty much every graphics library out there is built on top of them.

Do you mean like WebGL is Javascript on top of OpenGL? The equivalent to that would be Java with LWJGL?

Atli, on 27 December 2013 - 11:45 AM, said:

I must admit I'm not exactly up to date on what AWT is capable of, but I never knew it to be capable of 3D rendering on it's own. It does allow other graphics libraries to write on top of it's canvas, that much I do know, and that there are Java APIs that abstract the lower-level, platform-specific APIs (OpenGL and Direct3D) into platform-independent Java classes.

AWT is not capable of doing any 3D. I use java.awt.Graphics to draw my 3D objects after transforming, clipping, culling, etc, then finally perspective transforming it into 2D. I guess this is what you meant by "other graphics libraries".

Re: Question about OpenGL

Awt and swing are built upon opengl.
But they are definetly not equivalent.

OpenGL is more low level.

C++ is to OpenGL, what Java is to LWJGL (kind of)
In awt you do 1 call to render a texture.

In C++ you need to:
decode the image (unless using an external library)
load in the texture
bind all textures and buffers
have a shader to render them

I know this is an oversimplification of both awt and openGL.
Java made alot of packages (like awt and swing) to have something more "all in one"

C++ doesn't really have this. Yes, it has the standard template library.
But it isn't as expanded.

To do anything usefull, you need to use external libraries.
OpenGL is an external library.

OpenGL is just a wrapper around your drivers and it's written in C.
To be able to use OpenGL in other languages, there needs to be a wrapper around OpenGL.

This is what LWJGL is. It just binds Java functions to OpenGL.
But it gives you pure OpenGL. However it also providers audio, window, image loading.

OpenGL is just graphics.
Obviously you need a window to draw in.
In C++ you would either:
write it from scratch using win32 and such (this code will be different from linux, to windows, to mac)
or use a library like GLFW

If you want to draw real time 3D graphics, you don't use awt or swing.
Most Java games are written using LWJGL.
Awt and swing aren't made for this purpose (and they are quite bulky)

I'm not saying it's impossible to use them for this purpose.
But you will notice the difference.

Re: Question about OpenGL

Posted 28 December 2013 - 05:08 PM

axel1994, on 28 December 2013 - 04:02 AM, said:

[clip]

Thank you so much. This is exactly what I needed to know. />

What is the difference between OpenCL and OpenGL? (Other than the former is for computation and the latter for graphics.) I need to learn OpenCL for a completely unrelated project and it would be great if I could learn both in parallel without getting too distracted.