A
Anony
Gast
tag die herren,
ich will ein 2d spiel mit hilfe von jogl programmieren. vom verständnis hab ich da kein wirkliches problem - jedoch mit der performance. hier mal ein ganz simples beispiel, mit grottiger performance:
weis von euch jemand warum das so langsam ist? doublebuffer?
danke schon mal - anony
ich will ein 2d spiel mit hilfe von jogl programmieren. vom verständnis hab ich da kein wirkliches problem - jedoch mit der performance. hier mal ein ganz simples beispiel, mit grottiger performance:
Java:
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import net.java.games.jogl.GL;
import net.java.games.jogl.GLCanvas;
import net.java.games.jogl.GLCapabilities;
import net.java.games.jogl.GLDrawable;
import net.java.games.jogl.GLDrawableFactory;
import net.java.games.jogl.GLEventListener;
public class classTest extends JFrame {
public JTabbedPane tabbedPaneHandle = null;
public GLCapabilities glCapabilitiesHandle = null;
public GLCanvas glCanvasHandle = null;
public static void main(String[] args) {
new classTest();
}
public classTest() {
this.setSize(800, 600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.glCapabilitiesHandle = new GLCapabilities();
this.glCapabilitiesHandle.setDoubleBuffered(true);
this.glCapabilitiesHandle.setHardwareAccelerated(true);
this.glCanvasHandle = GLDrawableFactory.getFactory().createGLCanvas(this.glCapabilitiesHandle);
class glEventListenerCustomized implements GLEventListener {
public void init(GLDrawable arg0) {
GL gl = arg0.getGL();
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glViewport(0, 0, 800, 600);
gl.glOrtho(0.0, 800.0, 600.0, 0.0, 0.0, 128.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void display(GLDrawable arg0) {
GL gl = arg0.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
for (int intFor01 = 0; intFor01 < 20; intFor01 += 1) {
for (int intFor02 = 0; intFor02 < 20; intFor02 += 1) {
try {
if ((intFor01 % intFor02 % 3) == 0) {
gl.glColor3d(0.0, 1.0, 0.0);
} else if ((intFor01 % intFor02 % 3) == 1) {
gl.glColor3d(1.0, 0.0, 0.0);
} else if ((intFor01 % intFor02 % 3) == 2) {
gl.glColor3d(0.0, 0.0, 1.0);
}
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2i(0, 0);
gl.glVertex3i(intFor01 * 32, intFor02 * 32, 0);
gl.glTexCoord2i(0, 1);
gl.glVertex3i(intFor01 * 32 + 32, intFor02 * 32, 0);
gl.glTexCoord2i(1, 0);
gl.glVertex3i(intFor01 * 32 + 32, intFor02 * 32 + 32, 0);
gl.glTexCoord2i(1, 1);
gl.glVertex3i(intFor01 * 32, intFor02 * 32 + 32, 0);
gl.glEnd();
} catch (Exception e) {
}
}
}
gl.glFlush();
}
public void displayChanged(GLDrawable arg0, boolean arg1, boolean arg2) {
}
public void reshape(GLDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
}
}
this.glCanvasHandle.addGLEventListener(new glEventListenerCustomized());
this.add(this.glCanvasHandle);
this.setVisible(true);
new Thread() {
public void run() {
do {
classTest.this.glCanvasHandle.display();
} while (true);
}
}.start();
}
}
weis von euch jemand warum das so langsam ist? doublebuffer?
danke schon mal - anony