Please join us at the new JavaWorld Q&A Forums. Your existing login will work there. The discussions here are now read-only.


JavaWorld Talkback >> 959764

Pages: 1
JavaWorld
addict


Reged: 06/20/03
Posts: 482
Hello JOGL
      #15652 - 02/19/05 12:27 AM

Hello JOGL

Post Extras: Print Post   Remind Me!   Notify Moderator  
Gene Davis
Unregistered




Re: Hello JOGL [Re: JavaWorld]
      #48825 - 06/07/07 05:50 PM


Updated HelloWorld.java:
Code:
  
package com.genedavis;

import javax.media.opengl.*;


public class HelloWorld {
public static void main (String args[]) {
try {
System.loadLibrary("jogl");
System.out.println(
"Hello World! (The native libraries are installed.)"
);
GLCapabilities caps = new GLCapabilities();
System.out.println(
"Hello JOGL! (The jar appears to be available.)"
);
} catch (Exception e) {
System.out.println(e);
}
}
}



Post Extras: Print Post   Remind Me!   Notify Moderator  

Unregistered




Re: Hello JOGL [Re: JavaWorld]
      #48827 - 06/07/07 05:52 PM


Updated SimpleJoglApp.java:
Code:
  
package com.genedavis;

import java.awt.*;
import javax.swing.*;
import javax.media.opengl.*;


/**
* This is a basic JOGL app. Feel free to
* reuse this code or modify it.
*/
public class SimpleJoglApp extends JFrame {
public static void main(String[] args) {
final SimpleJoglApp app = new SimpleJoglApp();


// show what we've done
SwingUtilities.invokeLater (
new Runnable() {
public void run() {
app.setVisible(true);
}
}
);
}


public SimpleJoglApp() {
//set the JFrame title
super("Simple JOGL Application");


//kill the process when the JFrame is closed
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


//only two JOGL lines of code ... and here they are
GLCanvas glcanvas = new GLCanvas();
glcanvas.addGLEventListener(new SimpleGLEventListener());


//add the GLCanvas just like we would any Component
getContentPane().add(glcanvas, BorderLayout.CENTER);
setSize(500, 300);


//center the JFrame on the screen
centerWindow(this);
}


public void centerWindow(Component frame) {
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();


if (frameSize.width > screenSize.width )
frameSize.width = screenSize.width;
if (frameSize.height > screenSize.height)
frameSize.height = screenSize.height;


frame.setLocation (
(screenSize.width - frameSize.width ) >> 1,
(screenSize.height - frameSize.height) >> 1
);
}
}



Post Extras: Print Post   Remind Me!   Notify Moderator  
Gene Davis
Unregistered




Re: Hello JOGL [Re: JavaWorld]
      #48828 - 06/07/07 05:55 PM


Updated SimpleJogEventListener.java:
Code:
  
package com.genedavis;

import javax.media.opengl.*;


/**
* For our purposes only two of the
* GLEventListeners matter. Those would
* be init() and display().
*/
public class SimpleGLEventListener implements GLEventListener
{


/**
* Take care of initialization here.
*/
public void init(GLAutoDrawable drawable) {


}


/**
* Take care of drawing here.
*/
public void display(GLAutoDrawable drawable) {


}


/**
* Called when the GLDrawable (GLCanvas
* or GLJPanel) has changed in size. We
* won't need this, but you may eventually
* need it -- just not yet.
*/
public void reshape(
GLAutoDrawable drawable,
int x,
int y,
int width,
int height
) {}


/**
* If the display depth is changed while the
* program is running this method is called.
* Nowadays this doesn't happen much, unless
* a programmer has his program do it.
*/
public void displayChanged(
GLAutoDrawable drawable,
boolean modeChanged,
boolean deviceChanged
) {}
}



Post Extras: Print Post   Remind Me!   Notify Moderator  
Gene Davis
Unregistered




Re: Hello JOGL [Re: JavaWorld]
      #48829 - 06/07/07 05:58 PM


Updated SecondJoglApp.java:
Code:
  
package com.genedavis;

import java.awt.*;
import javax.swing.*;
import javax.media.opengl.*;


/**
* This is a basic JOGL app. Feel free to
* reuse this code or modify it.
*/
public class SecondJoglApp extends JFrame {


public static void main(String[] args) {
final SecondJoglApp app = new SecondJoglApp();


//show what we've done
SwingUtilities.invokeLater (
new Runnable() {
public void run() {
app.setVisible(true);
}
}
);
}


public SecondJoglApp() {
//set the JFrame title
super("Second JOGL Application");


//kill the process when the JFrame is closed
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


//only two JOGL lines of code ... and here they are
GLCanvas glcanvas = new GLCanvas();
glcanvas.addGLEventListener(new SecondGLEventListener());

//add the GLCanvas just like we would any Component
getContentPane().add(glcanvas, BorderLayout.CENTER);
setSize(500, 300);


//center the JFrame on the screen
centerWindow(this);
}


public void centerWindow(Component frame) {
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();


if (frameSize.width > screenSize.width )
frameSize.width = screenSize.width;
if (frameSize.height > screenSize.height)
frameSize.height = screenSize.height;
frame.setLocation (
(screenSize.width - frameSize.width ) >> 1,
(screenSize.height - frameSize.height) >> 1
);
}
}



Post Extras: Print Post   Remind Me!   Notify Moderator  
Gene Davis
Unregistered




Re: Hello JOGL [Re: JavaWorld]
      #48830 - 06/07/07 05:59 PM


Updated SecondGLEventListener.java:
Code:
  
package com.genedavis;

import javax.media.opengl.*;
import javax.media.opengl.glu.*;


/**
* For our purposes only two of the GLEventListeners matter.
* Those would be init() and display().
*/
public class SecondGLEventListener implements GLEventListener
{


/**
* Take care of initialization here.
*/
public void init(GLAutoDrawable gld) {
GL gl = gld.getGL();
GLU glu = new GLU();


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


gl.glViewport(0, 0, 500, 300);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluOrtho2D(0.0, 500.0, 0.0, 300.0);
}


/**
* Take care of drawing here.
*/
public void display(GLAutoDrawable drawable) {


float red = 0.0f;
float green = 0.0f;
float blue = 0.0f;


GL gl = drawable.getGL();


gl.glClear(GL.GL_COLOR_BUFFER_BIT);


gl.glPointSize(5.0f);


for (int i=0; i<50; i++) {


red -= .09f;
green -= .12f;
blue -= .15f;


if (red < 0.15) red = 1.0f;
if (green < 0.15) green = 1.0f;
if (blue < 0.15) blue = 1.0f;


gl.glColor3f(red, green, blue);


gl.glBegin(GL.GL_POINTS);
gl.glVertex2i((i*10), 150);
gl.glEnd();
}
}


public void reshape(
GLAutoDrawable drawable,
int x,
int y,
int width,
int height
) {}
public void displayChanged(
GLAutoDrawable drawable,
boolean modeChanged,
boolean deviceChanged
) {}
}



Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 1 anonymous users are browsing this forum.

Moderator:   

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 8621

Rate this topic

Jump to

Contact us JavaWorld

Powered by UBB.threads™ 6.5.5