[java] Magician or Gl4java

Started by
13 comments, last by alert 23 years, 6 months ago
Hello im learning java at the moment but i wanna start learning opengl aswell. should i use gl4java or magician ? i can''t seem to find any information relating to these specificly. Does anyone know of some tutorials for implementing them ? i wanted to start working through NEHE''S opengl tutorials as a start.
Advertisement
I don''t have an answer for you, but I can tell you a couple of things to consider.

SGI has recommended to the ARB that Magician be adopted as the OpenGL standard for java bindings, so that is one mark in its favor.

You mentioned that you were interested in working through the Nehe tutorials. The Nehe tutorials have been ported to Java by Hodglimm (linked below), but he used the GL4Java API. I would imagine this is a mark in favor of using GL4Java. I am not aware of Nehe ports that use Magician.

The Nehe tutorials and the Java port are linked from the FAQ. There is also an article with information on Magician but its somewhat outdated (from back when Magician was to be cancelled).

http://games.cpbinc.com/faq/ogl.asp

I am not as familiar with GL4Java, so I can''t give you a personal impression. Magician has worked well for me. The performance is good and overall its very stable (though I did have some problems with Magician and earlier versions of my video card drivers). Magician does a really good job of leveraging Java''s OO capabilities while not straying too far from the standard OpenGL approach (as least in my opinion).

Thx jarry for the responce, one thing that is holding me back from learning opengl is how magician is supposed to work with java. What i mean is the docs that accompany magician provide code examples of how magician+opengl+java work together, yet i don''t know opengl. The docs atleast in my opinion don''t explain magician from a beginners point of view one that doesn''t know opengl. How am i supposed to learn opengl using java if magician does''t have any docs assuming no prior opengl knowledge ?
Here is what you do to use Magician:
1 - Aquire OpenGL Red Book
2 - Find a demo that came with Magician such as openGL/logo.java
3 - Erase all code that is applet only ( init(), start()... )
4 - Erase all code that makes the letters
5 - Erase all the comments at the top because they annoy me
6 - Keep the rest

Basically what is left is what you would have if you were using GLUT with C/C++. You will have to erase a bunch of code, like the lighting and material stuff int the initialize() method, that the old app used but you should be able to see the basics of opengl especially if you follow step one. The book will make it alot easier. I am seriously thinking about setting up a small site for Magician demos, maybe some NeHe ports but I might not have a place for it next semester and I know little html. If you wait a week I MAY have some more help for you. I looked to see if I have some of the early Magician stuff I did but I wrote over them and they are a little messy to be useful. I will probably clean the stuff up and put up the first NeHe tut or one from the red book tomorrow. At the very least I will post the frame work for the basic Magician app.

I wanrned you! Didn't I warn you?! That colored chalk was forged by Lucifer himself!
"... we should have such an empire for liberty as she has never surveyed since the creation ..."Thomas Jefferson
Well, looks like GKW beat me to the answer...

Magician''s implementation of OpenGL is not substantially different from standard OpenGL. In a couple of cases there are some minor variations, such as Magician using overloaded methods to handle various data type lengths rather than multiple methods with slightly different names. Any reference on OpenGL should do fine for you. The OpenGL SuperBible is another great starting place.

It is going to be more difficult to learn OpenGL in Java than it would be to do so with C++. I am not aware of any books that teach OpenGL in Java - and I have looked for several months now. Its kind of depressing in a a way. I know of several resources for learning OpenGL in Delphi or Visual Basic, but few for Java.
Thx GKW and Jarry for the responces
i really appreciate them, GKW if you could tell me when you have any magician related material that would be great.
I put together a little application that draws a triangle and a quad like one of the nehe tutorials I hope it looks alright in the forum. I am going to try an set up a site and post it there. But this is it for tonight. Vikes suck.

Jerry - Have you ever tried to do a JApplet with Magician? I get a can''t find GLEventListener class. AWT applets work fine. Not a big deal but I would like to know why it does not work.

/*

MagicianTemplate.java



This app just draws a triangle and a rectangle but

you can erase the drawing code and put your

own in and you should have a working application.

This application uses Swing so get JRE 1.3.



Magician uses AWT canvas which is incompatable

with the lightweight Swing components but

work arounds exist. I hope this will be fixed

in JRE 1.4



GKW

*/





import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import com.hermetica.magician.*;



public class MagicianTemplate extends JFrame implements GLEventListener, WindowListener {



// Components of the Magician OpenGL state machine

GL gl = null;

CoreGL coregl = new CoreGL();

GLU glu = null;

CoreGLU coreglu = new CoreGLU();



// The GLComponent is the canvas where the graphics will be rendered

GLComponent glc = null;



// Creates new form MagicianTemplate

public MagicianTemplate() {

// Sets up the the OpenGL state machine

gl = coregl;

glu = coreglu;

setTitle( "Magician Template" );

}



public static void main (String args[]) {

MagicianTemplate mt = new MagicianTemplate();

// Initializes the GLComponent for drawing

mt.setupGL();

}



// Called once when the GLComponent is initialized

public void initialize(final com.hermetica.magician.GLDrawable p1) {

/* Sets the color that the color buffer is filled with

during the glClear call in display() */



gl.glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );



/* Depth buffer is now enabled

It is not needed in this application but it gives

you an idea of what can be put in initialize() */



gl.glEnable( GL.GL_DEPTH_TEST );

}



// Handles the drawing

public void display(final com.hermetica.magician.GLDrawable p1) {

/* Clears the color buffer and the depth buffer. If you don''t

clear them then the values from the last time display() was

called will still be there and cause unintended results. */



gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );



/* Loads the identity matrix onto the stack. In this case

it is the MODELVIEW matrix which was set in reshape(). */



gl.glLoadIdentity();



/* Moves all geometry after this call 2.0 units into the

screen.*/



gl.glTranslated( 0.0d, 0.0d, -2.0d );



/* Saves the current matrix onto the stack to isolate the

translation for the triangle from the quad. I did push

the last translation onto the stack because I want both

the triangle and the rectangle to be moved away from the

viewer. */



gl.glPushMatrix();



/* Moves the origin -2.5 units along the x-axis */



gl.glTranslated( -2.5d, 0.0d, 0.0d );



/* Draws a triangle. Don''t forget the glEnd() or things

will get funky. */



gl.glBegin( GL.GL_TRIANGLES );

gl.glVertex3d( 0.0d, 1.0d, 0.0d );

gl.glVertex3d( -1.0d, 0.0d, 0.0d );

gl.glVertex3d( 1.0d, 0.0d, 0.0d );

gl.glEnd();



/* Destroys the current matrix and replaces it with the

last matrix pushed onto the stack. The origin is now

restored to the earlier matrix when the origin was at

( 0.0, 0.0, -2.0 ). */



gl.glPopMatrix();



/* Since this application is so simple I don''t really

need to save the current matrix again but I am. */



gl.glPushMatrix();



/* Move the origin 2.5 along the x-axis */



gl.glTranslated( 2.5d, 0.0d, 0.0d );



/* Draws a rectangle */



gl.glBegin( GL.GL_QUADS );

gl.glVertex3d( -1.0d, 1.0d, 0.0d );

gl.glVertex3d( -1.0d, 0.0d, 0.0d );

gl.glVertex3d( 1.0d, 0.0d, 0.0d );

gl.glVertex3d( 1.0d, 1.0d, 0.0d );

gl.glEnd();



/* Don''t really need this either for this application */

gl.glPopMatrix();



/* Kicks the machine into gear if it isn''t already. */

gl.glFlush();

}



/* Called at the creation of the rendering canvas and when

ever the canvas is resized in the GUI. */



public void reshape( GLDrawable component, int x, int y, int width, int height ) {



/* Sets up the viewport */

gl.glViewport( component, x, y, width, height );



/* Makes the prjection matrix the current matrix */

gl.glMatrixMode( GL.GL_PROJECTION );



/* Load the identity matrix into the projection matrix

just to make sure it is clean. */

gl.glLoadIdentity();



/* Sets up the view frustrum. Make sure the near and

far clipping planes are positive. */

gl.glFrustum( -2.0, 2.0, -2.0, 2.0, 1.0, 5.0 );



/* Changes the matrix to the Modelview matrix. This

is the matrix that moves and rotates your geometry. */

gl.glMatrixMode( GL.GL_MODELVIEW );



/* Load the identity matrix. Make sure the matrix is

clean. */

gl.glLoadIdentity();

}

/* Returns the state machine */

public GL getGL() {

return( gl );

}



public void windowDeactivated(final java.awt.event.WindowEvent p1) {

}



public void windowClosed(final java.awt.event.WindowEvent p1) {

}



public void windowDeiconified(final java.awt.event.WindowEvent p1) {

}



public void windowOpened(final java.awt.event.WindowEvent p1) {

}



public void windowIconified(final java.awt.event.WindowEvent p1) {

}



public void windowClosing(final java.awt.event.WindowEvent p1) {

if( glc != null ) {

/* This has to be called to release the memory associated

with the rendering canvas. On my machine it is about

200k. */

glc.destroy();

}

setVisible( false );

dispose();

System.exit( 1 );

}



public void windowActivated(final java.awt.event.WindowEvent p1) {

}



/* Sets up the rendering canvas. */

public void setupGL() {

/* GLDrawableFactory is the call you want to make to create

a rendering canvas. There is a class called GLComponentFactory

but that was used in an earlier version of Magician.

This call sets the size of the canvas to 400 x 400. */

glc = (GLComponent)GLDrawableFactory.createGLComponent( 400, 400 );



/* Adds the rendering canvas to the JFrame. */

getContentPane().add( glc, BorderLayout.CENTER );



/* You have to make the rendering canvas visible before you call

GLComponent.initialize() or an exception will be thrown. So

do a setVisible( true ) or a pack(). */

pack();

show();



/* Gets the capabilities of the canvas. */

GLCapabilities caps = glc.getContext().getCapabilities();



/* Don''t need to set the depth bits for this app but here it is */

caps.setDepthBits( 8 );

/* Sets to RGBA pixels instead of color-indexed */

caps.setPixelType( GLCapabilities.RGBA );

/* Stores 32 per pixel. Does not change hardware settings.

JRE 1.4 is supposed to support fullscreen java apps so

is may change hardware setting then. */

caps.setColourBits( 32 );



/* Sets up double buffering for faster rendering. Does not

matter in this case. */

caps.setDoubleBuffered( GLCapabilities.DOUBLEBUFFER );



/* Sets up the listeners for the app. If you don''t add

the GLEventListener then the rendering canvas won''t

do anything. */

addWindowListener( this );

glc.addGLEventListener( this );



/* Initializes the canvas. Make sure the GLComponent is visible

on the screen or an exception will be thrown. */

glc.initialize();

}

}


I wanrned you! Didn't I warn you?! That colored chalk was forged by Lucifer himself!
"... we should have such an empire for liberty as she has never surveyed since the creation ..."Thomas Jefferson
Sorry, no. All of my Magician work has been with applications (extending JFrame or JWindow and implementing my GLEventListener on the subclass).

I can''t see why subclassing a JApplet would cause the problem you mentioned. JApplet is heavy-wieght container isn''t it (I will need to look that up to be sure)? Nothing that I know of about subclassing the JApplet should interfere with implementing the GLEventListener interface...

Like I said, I am not familiar with using Magician in applets, but if post some code I could take a look and at least brainstorm a little on what might be the problem.
I should have said that it was the java plugin that is not working. Without the java plugin a normal awt applet works fine but if I use the converter from sun and try the same applet I get the can''t find GLEventListener class. Without the plugin I can''t use JApplet but it is the plugin that is not working right. If you can just try one of the demo applets with the java plugin I would appreciate it.

I wanrned you! Didn't I warn you?! That colored chalk was forged by Lucifer himself!
"... we should have such an empire for liberty as she has never surveyed since the creation ..."Thomas Jefferson
yeah, i think a web site devoted to magician would be grea jarry
it would sure help my sorry ass out. you should also try and get gamedev.net to host it for you.

This topic is closed to new replies.

Advertisement