04-13-2003, 05:25 PM
Hi all,
There are many ways to render a textured quad in 2D in OpenGL. What is the best way to do it? Are any of the following much faster that the others, or much slower?
1) Straight vertexes
gl.begin(GL.TRIANGLE_FAN) ;
gl.texCoordf(0.0f, 0.0f) ;
gl.vertex2i(54, 67) ;
...
gl.end() ;
Nothing is stored on the card. Coordinates are pumped straight out.
2) Translated display list
gl.translatef(x, y, 0) ;
gl.callList(MY_QUAD) ;
gl.translatef(-x, -y, 0) ;
Coordinates are stored on the card, but you need two translations before and after rendering as the quad will have to be drawn at the origin.
3) Recreated display list
if(moved) rebuildDisplayList() ;
gl.callList(MY_QUAD) ;
Coordinates stored on card at correct position, no translations required. However, display list must be rebuilt each time the quad moves.
4) Vertex arrays
gl.drawArrays(GL.TRIANGLE_FAN, i, 4) ;
Data stored in vertex arrays and texture coordinate arrays.
It's hard to fault the readability of number 1. I can't imagine 3 being a good option, unless the quad moved *very* infrequently! It's hard *not* to fault the readability of number 4, but it looks like it should work faster.
Are any of these definitely better or worse than the rest, and have I missed some significant way of getting a textured quad onto the screen?
There are many ways to render a textured quad in 2D in OpenGL. What is the best way to do it? Are any of the following much faster that the others, or much slower?
1) Straight vertexes
gl.begin(GL.TRIANGLE_FAN) ;
gl.texCoordf(0.0f, 0.0f) ;
gl.vertex2i(54, 67) ;
...
gl.end() ;
Nothing is stored on the card. Coordinates are pumped straight out.
2) Translated display list
gl.translatef(x, y, 0) ;
gl.callList(MY_QUAD) ;
gl.translatef(-x, -y, 0) ;
Coordinates are stored on the card, but you need two translations before and after rendering as the quad will have to be drawn at the origin.
3) Recreated display list
if(moved) rebuildDisplayList() ;
gl.callList(MY_QUAD) ;
Coordinates stored on card at correct position, no translations required. However, display list must be rebuilt each time the quad moves.
4) Vertex arrays
gl.drawArrays(GL.TRIANGLE_FAN, i, 4) ;
Data stored in vertex arrays and texture coordinate arrays.
It's hard to fault the readability of number 1. I can't imagine 3 being a good option, unless the quad moved *very* infrequently! It's hard *not* to fault the readability of number 4, but it looks like it should work faster.
Are any of these definitely better or worse than the rest, and have I missed some significant way of getting a textured quad onto the screen?