Jump to content
  • Advertisement
Sign in to follow this  
cybergolem

[java] jogl triangle speed ?

This topic is 4226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to learn jogl and just made a small app that displays about 5000 triangles each frame. With a Aplication size of 300x300 pixel, I get about 450.000 Triangles each second. Is this a good value? I get the same value with or without "capabilities.setHardwareAccelerated(true)" And when I am using one display List for this triangles, i only get about 3% speed increase. What should be a good Triangle/sec (Triangle/Frame) value? My current Video-Card at work is a "Saphire Radeon 9200SE Atlantis"
public class Lesson02 {
	static Animator animator;

	public static void main(String[] args) {
		Frame frame = new Frame("Test");

		GLCapabilities capabilities = new GLCapabilities();
		capabilities.setHardwareAccelerated(true);
		GLCanvas canvas = new GLCanvas();
		animator = new Animator(canvas);
		frame.add(canvas);
		frame.setName("JOGL TEST");
		frame.setSize(300, 300);
		frame.setResizable(true);
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				animator.stop();
				System.exit(0);
			}
		});
		canvas.addGLEventListener(new Renderer());
		frame.setVisible(true);
		System.out.println(capabilities.getHardwareAccelerated());
		animator.start();
	}
}

class Renderer implements GLEventListener {
	private GLU glu = new GLU();
	public static long  lasttimer = 0,minutetimer=1000000000;
	private static boolean timerAn = false;
	double counter=0;
	private static float drehen = 0;
	

	public void display(GLAutoDrawable gLDrawable) {
		long abstand = 1;
		if (timerAn) {
			abstand = System.nanoTime() - lasttimer;
			lasttimer = System.nanoTime();
			minutetimer-=abstand;
			if (abstand < 1)
				abstand = 1;
		}
		if (minutetimer > 0 ) {
			counter+=(5.0f/0.001f);
		} else {
			System.out.println(counter + " per sec");
			counter=0;
			minutetimer=1000000000;
		}
		final GL gl = gLDrawable.getGL();
		gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
		gl.glLoadIdentity();
		gl.glTranslatef(-1.5f, 0.0f, -16.0f);
		drehen += abstand / 5000000.0f;
		gl.glRotatef(drehen, 0.0f, 0.0f, 1.0f);
		gl.glCallList(1);
	//	gl.glFlush();
	}

	public void displayChanged(GLAutoDrawable gLDrawable, boolean modeChanged,
			boolean deviceChanged) {
	}

	public void init(GLAutoDrawable gLDrawable) {
		lasttimer = System.nanoTime();
		GL gl = gLDrawable.getGL();
		gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		gl.glShadeModel(GL.GL_FLAT);
		float a=0;
		gl.glNewList(1,gl.GL_COMPILE);
		gl.glBegin(GL.GL_TRIANGLES);
		for (a = 0; a < 5; a += 0.001f) {
			gl.glVertex3f(0.0f + a, 1.0f, 0.0f - a);
			gl.glVertex3f(-1.0f + a, -1.0f, 0.0f - a);
			gl.glVertex3f(1.0f + a, -1.0f, 0.0f - a);
		}
		gl.glEnd();
		gl.glEndList();
		timerAn = true;
	}

	public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width,
			int height) {
		final GL gl = gLDrawable.getGL();

		if (height <= 0) // avoid a divide by zero error!
			height = 1;
		final float h = (float) width / (float) height;
		gl.glViewport(0, 0, width, height);
		gl.glMatrixMode(GL.GL_PROJECTION);
		gl.glLoadIdentity();
		glu.gluPerspective(45.0f, h, 1.0, 20.0);
		gl.glMatrixMode(GL.GL_MODELVIEW);
		gl.glLoadIdentity();
	}
}

Share this post


Link to post
Share on other sites
Advertisement
YOu're not really testing anything. Make an actual game and then worry about the frames per second. That said the 9200 is getting a little old.

Share this post


Link to post
Share on other sites
triangles per second depends upon what size and type of triangles you are dealing with so a triangles per second measurement doesn't mean very much out of context.

Share this post


Link to post
Share on other sites
Whether or not that's a good value depends on many other things, like the rest of your engine.

In any case, neither display lists nor immediate mode calls are what you want to be using. Ideally, you'd have a mesh class that can stick all of your vertex information into a float buffer/vertex buffer object and render using glDrawElements(). Immediate mode and display lists are unnecessary from my perspective. Using vertex arrays or preferably vertex buffer objects is going to give you the best performance you can realistically expect. There's much debate about it online, but any array method is going to be faster than all those immediate mode calls, especially with JOGL working through JNI.

Share this post


Link to post
Share on other sites
Thanks Nytehauq,

I used the same code as above, only with Vertex Buffer and i have 850.000 Trianlges each sec now. So its a gain of 100%. I will continue using this. THANKS :)

Share this post


Link to post
Share on other sites
I have a 2D engine written in both Java and C++. If I draw using the OpenGL immediate mode (glVertex) i get about 1/3 of the vertex output i'd get with C++, however if i use Vertex Buffer Objects the amount is perhaps 3/4 of the amount in C++ engine.

For simple games I don't see the problem in this, however for example as you can see that concentration camp simulator (Wyrm Online, Wurm Online?) doesn't run very well, although it is very pretty. I think it's a great example of when one should / shouldn't use Java. It's impossible to get reasonable framerates when compared to other commercial products of that scale.

Share this post


Link to post
Share on other sites
Quote:
Original post by Captain Goatse
I have a 2D engine written in both Java and C++. If I draw using the OpenGL immediate mode (glVertex) i get about 1/3 of the vertex output i'd get with C++, however if i use Vertex Buffer Objects the amount is perhaps 3/4 of the amount in C++ engine.

For simple games I don't see the problem in this, however for example as you can see that concentration camp simulator (Wyrm Online, Wurm Online?) doesn't run very well, although it is very pretty. I think it's a great example of when one should / shouldn't use Java. It's impossible to get reasonable framerates when compared to other commercial products of that scale.


Yes, but the question is, are you comparing the famerates with something of similar size? Wurm Online is huge. The landscape is also totally deformable, which cuts out a fair number of ways to speed up rendering.

And of course, there is the general issue of it being done by a SINGLE person, the client that is, not a development team.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!