# OpenGL A 2D Grid

## 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[i][s][0],this.array[i][s][1],this.array[i][s][2]); gl.glVertex3f(this.array[i][s+1][0],this.array[i][s+1][1],this.array[i][s+1][2]); gl.glEnd(); gl.glBegin(gl.GL_LINES); gl.glColor3d(1.0f,0.0f,0.0f); gl.glVertex3f(this.array[i][s][0],this.array[i][s][1],this.array[i][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[i][s][0],this.array[i][s][1],this.array[i][s][2]); gl.glVertex3f(this.array[i][s+1][0],this.array[i][s+1][1],this.array[i][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[i][s][0],this.array[i][s][1],this.array[i][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[i][s][0],this.array[i][s][1],this.array[i][s][2]);gl.glVertex3f(this.array[i][s+1][0],this.array[i][s+1][1],this.array[i][s+1][2]);gl.glColor3d(1.0f,0.0f,0.0f);gl.glVertex3f(this.array[i][s][0],this.array[i][s][1],this.array[i][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

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627653
• Total Posts
2978433
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 10
• 12
• 22
• 13
• 33