Hi everyone. I have a task that I need to complete involving JOGL and since I have tried everything I thought this may be the place to go. Could any one of you seasoned Java OpenGL programmers give me some leads?
Here is the task:
Create a wrapper class for rendering that is Graphics API agnostic i.e. can be extended to wrap JOGL/LWJGL/Java2D etc…
Progress so far:
Java 2D: No help needed - Wrapping Java2D is simple because it is completely unintrusive and true to Java concept and generally well designed
LWJGL: No help needed - Wrapping LWJGL is relatively straight forward since it is unintrusive and allows calls to the OpenGL methods at any time and because it does not put restrictions on timing and threading. However it is built around the assumption that there is only one display and it has an, in my opinion, unwarranted crush on static classes (c++ fetish).
JOGL: This is where I need help - JOGL is edit difficult edit to wrap because it is built on the assumption that the renderer is the center of the universe and that I want to inject API specific code in callback method inside my game code.
Before you start sending me links about “Active rendering” let me declare which resources I have already used and why they do not work:
-
http://www.java-gaming.org/topics/active-rendering-with-jogl/17661/view.html
The instructions are outdated and do not work with the latest version of JOGL - Pro Java™ 6 3D Game Development: Java 3D™ chapter 15
The instructions are outdated and do not work with the latest version of JOGL -
http://forum.jogamp.org/Regarding-active-rendering-of-JOGL-td2989970.html
This thread lack helpful instrutions -
http://www.java-gaming.org/index.php?topic=21559.0
The instructions are outdated and do not work with the latest version of JOGL -
http://www.java-gaming.org/index.php?topic=21050.0
The instructions are outdated and do not work with the latest version of JOGL -
http://forum.jogamp.org/Rendering-without-callbacks-td2259774.html
The instructions are outdated and do not work with the latest version of JOGL -
http://stackoverflow.com/questions/7420027/jogl-how-can-i-create-my-own-opengl-context-and-bind-it-to-a-glcanvas
Does not deal with JOGL2/does not solve the issue
8.) http://www.java-gaming.org/topics/jogl-design-issues/19099/view.html
StrideColossus makes several valid point and no one seem to get it. Instead of solving the problem he seems to settle with an LWJGL implementation which is not what I am looking for.
To save some time:
Q: Why not just use an older version of JOGL?
A: Of course this is possible but then I would miss out on any bug fixes that has happened in the meantime. Reverting to an older version of JOGL is the very last option here.
Q: Why not just have a method in the wrapper interface returning the appropriate callback strategy object forwarded by the underlying API.
A: 1) It’s a matter of who is potential employer and who is the potential employee: “Don’ call us - we’ll call you”. The graphics is a peripheral that the core may want to use, not the other way around 2) It does not remove API-specific code from the game code.
Q: Why not just skip JOGL and use LWJGL instead.
A: 1) LWJGL does not allow me to render to separate windows 2) It has a large disk-space footprint (I may not need half of the files included in the library) 3) It requires me to put a license notice on my game/application 4) It is completely built around static classes. This means that no matter how cleanly I wrap it, any part of the application could still make direct calls to static classes and screw things up.
So what does the wrapper interface look like?
public interface Renderer {
public void startRendering();
// must be called before any graphics instructions are executed at the beginning of each render
// When extending Java2D this would secure the Graphics object of the image used for drawing, and for JOGL it would probably secure the graphics context
public void finnishRenderingAndRefreshDisplay();
// must be called at the end of any series of graphics instructions at the end of each render
// When extending Java2D this would release the graphics object and blit a buffered image to the display, for JOGL it would probably release the context and refresh the display
public void drawImage(int x, int y, Alignment al, ImageResource img)
// Graphics instructions 1
public void drawText(int x, int y, Alignment al, String text);
// Graphics instruction 2
// ... more graphics instructions ...
}
Simple enough?
NB! There is also a wrapper for the actual windows/GUI rectangles that owns the renderer, but this is not relevant to the problem discussed.
Thanks in advance for any replies!