Slow JOGL Performance on new Macbook PRO

Hi,

Newbie here so please be gentle :slight_smile:

I’m trying to build a hex-mapped turn-based game. I started out with processing and ran into performance problems, rendering the map taking 800ms each time. I built a stand-along program that uses JOGL 2 that only draws the hex-map and as soon as there are many hexes, it takes a very long time to draw, i.e. 1200ms to draw 1200 hexes (30 rows, 40 columns).
The JOGL display function is really simple, it clears the background, and then draws the hexes in a loop. Each hex is drawn by using a glBegin(GL_LINE_LOOP) call, followed by 6 glVertex2d for each vertex, and finished off with a glEnd. I push the matrix at the beginning of each render and at the beginning of each row, and then pop them out respectively.

My machine is a brand new Macbook PRO and I simply don’t understand how this is taking so long. I ran the JOGL Gears demo from JNLP, and maximised the window, and it runs very smoothly. So, on the assumption that a whole lot more lines and quads are being rendered in the Gears demo, I must be doing something wrong.

Any advice?

Thanks in advance!

AFAIK lines are not accelerated on modern hardware.

Further, once you converted it to use triangles, you might also want to render as much as possible in a few OpenGL calls.

http://www.java-gaming.org/index.php/topic,24272.0.html

Hi!

First of all, this problem has nothing to do with JOGL in particular, it would happen even with plain C/C++ OpenGL. Secondly, as Riven said, lines are not accelerated on modern hardware, splitting your hexes into triangles can be done easily with a very naive algorithm. Thirdly, you use immediate rendering (glBegin, glEnd, etc…) which is extremely slow. I succeeded in drawing between 150 000 and 1 500 000 triangles with an “old” (ATI Radeon 9250 Pro) graphics card and JOGL. Fourthly, avoid doing a lot of calls to glPushMatrix & glPopMatrix, rather use the same approach than current scenegraphs like Ardor3D (I wrote a JOGL 2.0 renderer for this engine). In your case, maybe you should compute the exact geometry by appliying the transform(s) on your vertices. Thank you for using JOGL 2.0.

Best regards.

Thanks guys! Your advice really helped. The problem was indeed far too many calls to glBegin, vertex, and end. Reading the articles on vertex arrays and buffers led me to another one on display lists and simply switching the sequence of begin, 6 x vertex and end into a single list and calling that multiple times, even within the same transforms, and matrix stack functions, and even still using GL_LINE_LOOP, yielded a render time of around 3 ms!!! Now I know I’ve chosen the simplest, probably least beneficial way of doing this, and have more options up my sleeve for later.

Cheers!

That’s really odd. In my experience, display lists are a wash vs immediate mode for these kinds of low numbers of vertices per list.

Maybe it becomes accelerated when it’s in a display list - that’s the only thing that comes to mind. Not sure that’s even possible, though.

FYI: 3ms is still slow, and is no indication whatsoever that lines are suddenly accelerated.

Well, something else must be going on, that was just a hypothesis. Switching to a 6-vertex display list per hex doesn’t account for going from 1200 to 3 ms. On its own, it shouldn’t account for much of an improvement, if any.

Yeah, I figured it’s not necessarily that lines are accelerated, it’s just that this is essentially a board game so if after all the additional stuff I need to draw it ends up being about 10ms, I’m more than happy with that. At any rate, your post helped me a lot. Thank you.