# OpenGL A 2D Grid

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

## Recommended Posts

Hello, I am learning OpenGL with JOGL. I drew a 100*100 2D grid and made a sine wave on it. I did this through 4 method below: 1. I used gl.glBegin(GL.GL_LINES) and gl.glEnd() around every piece of line. for(int i = 0; i < 100-1; i++) for(int s = 0; s < 100-1; s++) { gl.glBegin(gl.GL_LINES); gl.glColor3d(1.0f,0.0f,0.0f); gl.glVertex3f(this.array[s][0],this.array[s][1],this.array[s][2]); gl.glVertex3f(this.array[s+1][0],this.array[s+1][1],this.array[s+1][2]); gl.glEnd(); gl.glBegin(gl.GL_LINES); gl.glColor3d(1.0f,0.0f,0.0f); gl.glVertex3f(this.array[s][0],this.array[s][1],this.array[s][2]); gl.glVertex3f(this.array[i+1][s][0],this.array[i+1][s][1],this.array[i+1][s][2]); gl.glEnd(); } 2. I used gl.glBegin(GL.GL_LINES) and gl.glEnd() around every curve across the grid. for(int i = 0; i < 100-1; i++) { gl.glBegin(gl.GL_LINES); gl.glColor3d(1.0f,0.0f,0.0f); for(int s = 0; s < 100-1; s++) { gl.glVertex3f(this.array[s][0],this.array[s][1],this.array[s][2]); gl.glVertex3f(this.array[s+1][0],this.array[s+1][1],this.array[s+1][2]); } gl.glEnd(); } for(int i = 0; i < 100-1; i++) { gl.glBegin(gl.GL_LINES); gl.glColor3d(1.0f,0.0f,0.0f); for(int s = 0; s < 100-1; s++) { gl.glVertex3f(this.array[s][0],this.array[s][1],this.array[s][2]); gl.glVertex3f(this.array[i+1][s][0],this.array[i+1][s][1],this.array[i+1][s][2]); } gl.glEnd(); } 3. Use GL_LINE_STRIP 4. Put method3 in a display list I found the FPS becomes higher and higher from 1 to 4. Maybe I know why method3 is faster than method2, because GL_LINE_STRIP passes less vertices than GL_LINES to the pipeline. But I don't know why there are increments between method1 and 2, method 3 and 4. Can you explain it? I enlarged the screen resolution, the FPS of the first 3 methods were almost the same as before, but the FPS of method4 turned much bigger. Why? Moreover, I want to try this two methods: 5. Use a vertex array without displaylist. 6. Use a vertex array and put it into a display list. And I know it's a little bit hard to realize this two methods because Java has no pointer. However, can you tell me what's gonna happen if I applied this two methods? Thank you in advance!

##### Share on other sites
hi Terry_Tao,

2 is faster than 1 because you draw 100 lines with each glBegin/glEnd not only one,

try
gl.glBegin(gl.GL_LINES);for(int i = 0; i < 100-1; i++)for(int s = 0; s < 100-1; s++){gl.glColor3d(1.0f,0.0f,0.0f);gl.glVertex3f(this.array[s][0],this.array[s][1],this.array[s][2]);gl.glVertex3f(this.array[s+1][0],this.array[s+1][1],this.array[s+1][2]);gl.glColor3d(1.0f,0.0f,0.0f);gl.glVertex3f(this.array[s][0],this.array[s][1],this.array[s][2]);gl.glVertex3f(this.array[i+1][s][0],this.array[i+1][s][1],this.array[i+1][s][2]);}}gl.glEnd();

4 is faster than 3 because in a display list the geometry is stored in a gfx optimized manner and there is only on call to opengl,

hope it helps,
greets
tgar

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 23
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631768
• Total Posts
3002242
×