6 Replies - 365 Views - Last Post: 28 December 2013 - 05:08 PM Rate Topic: -----

#1 carnivroar  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 382
  • Joined: 18-September 11

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?

Thanks.
Is This A Good Question/Topic? 0
  • +

Replies To: Question about OpenGL

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

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.)
Was This Post Helpful? 0
  • +
  • -

#3 carnivroar  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 382
  • Joined: 18-September 11

Re: Question about OpenGL

Posted 27 December 2013 - 11:22 AM

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).

This post has been edited by carnivroar: 27 December 2013 - 11:23 AM

Was This Post Helpful? 1
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

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.
Was This Post Helpful? 1
  • +
  • -

#5 carnivroar  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 382
  • Joined: 18-September 11

Re: Question about OpenGL

Posted 27 December 2013 - 12:11 PM

View PostAtli, 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?

View PostAtli, 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".

This post has been edited by carnivroar: 27 December 2013 - 12:13 PM

Was This Post Helpful? 0
  • +
  • -

#6 axel1994  Icon User is offline

  • D.I.C Head

Reputation: 83
  • View blog
  • Posts: 167
  • Joined: 27-May 13

Re: Question about OpenGL

Posted 28 December 2013 - 04:02 AM

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.

This post has been edited by axel1994: 28 December 2013 - 04:12 AM

Was This Post Helpful? 1
  • +
  • -

#7 carnivroar  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 382
  • Joined: 18-September 11

Re: Question about OpenGL

Posted 28 December 2013 - 05:08 PM

View Postaxel1994, 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.

This post has been edited by carnivroar: 28 December 2013 - 05:13 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1