Hello, i hope i am right here…
i was coding c++ and actionscript, but for games i need an
openGL system…but i am not very expericened in the java.
i found jogl/java(eclipse) and installed it…first 2 example on the wiki
work perfekt but i got some litte questions about it.
But a little thing i cant find in the tutorials.
you see in the code, i try a bit helpless
to use an call for an renderer loop to the opengl thing,
but i dont know how to access/handle it .
i know that every opengl things must be in the->
“class SceneView implements GLEventListener”
but how can i implement a render loop call
to update the scene every frame.
thanks for any help (and sorry for my bad english)
import javax.swing.*;
import javax.media.opengl.*;
import com.sun.opengl.util.GLUT;
import java.awt.geom.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import com.sun.opengl.util.texture.*;
import java.applet.*;
import java.awt.*;
public class fso extends JFrame
{
GLCanvas canvas;
static Thread t = null;
static int i=0;
public fso()
{
GLCapabilities cap = new GLCapabilities();
canvas = new GLCanvas(cap);
canvas.addGLEventListener(new SceneView());
getContentPane().add(canvas);
setTitle("Game Scene");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(900, 600);
setVisible(true);
}
public static void run()
{
while(true)
{
i++;
renderer(); // i want to refresh the opengl frame and this call is surly wrong
try {
t.sleep(1000/30);
} catch (InterruptedException e) { ; }
}
}
private static void renderer() {
// i think here i am wrong...
// TODO Auto-generated method stub
}
class SceneView implements GLEventListener
{
public void init(GLAutoDrawable arg0)
{
GL gl = arg0.getGL();
float l_position[] = {100.0f, 100.0f, 200.0f, 1.0f};
gl.glEnable(GL.GL_LIGHTING);
gl.glEnable(GL.GL_LIGHT0);
gl.glEnable(GL.GL_COLOR_MATERIAL);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_NORMALIZE);
gl.glEnable(GL.GL_POLYGON_SMOOTH);
gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, l_position, 0);
gl.glClearColor(0.7f, 0.7f, 0.7f, 0.0f);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glOrtho(-100, 100, -100, 100, -100, 100);
int i=120;
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glRotatef(i, 1.0f, 0.0f, 0.0f); // Rotation um die x-Achse
gl.glRotatef(-25.0f, 0.0f, 1.0f, 0.0f); // Rotation um die y-Achse
}
public void renderer(GLAutoDrawable arg0)
{
// how can i access this renderer from a loop
//to refresh here the opengl scene..or is there any
//other predefinded thing in jogl for that?
}
public void display(GLAutoDrawable arg0)
{
GL gl = arg0.getGL();
GLUT glut = new GLUT();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glColor3f(0.2f, 0.0f, 0.3f);
glut.glutSolidTeapot( 50.0 ) ;
}
public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4)
{
}
public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2)
{
}
}
public static void main(String args[])
{
//init
new fso();
//Main Loop
run();
}
}