Jump to content
  • Advertisement
Sign in to follow this  
3DViewer

OpenGL Dealing with large amount of data

This topic is 3718 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 must start saying that I am new to OpenGL. I have inherited an old piece of code that draws surfaces made of triangles. Its basic method is the following: glBegin(GL_TRIANGLES); for (i = 0; i < *n; i++) { glVertex2fv(vert[endpts[nx]-1]); nx++; glVertex2fv(vert[endpts[nx]-1]); nx++; glVertex2fv(vert[endpts[nx]-1]); } glEnd(); On top of all, this code is not using specific matrix calls such as glRotate, glTranslate and glScale to handle the object movement. It holds onto the complete view matrix and does it's own adjustments based on the inputs and then just sets the whole matrix before rendering. It is fine with small models, but when I start playing with millions of triangles, it takes about 5 seconds to render the result of a rotation/translation. I am planning to re-code the stuff, grouping the triangles to render them in 1 call, using index buffering to avoid duplicated vertices, but at the moment, I am having a problem with the following basic problem: Assuming I have already drawn the model using the above piece of code and want now to translate it using the mouse (the mouse event has returned dx and dy), How do I make the graphic card understand to use what it has already in memory and apply on it the glTranslatef(dx, dy, 0) without having to re-do the above piece of code, ie the glBegin ... glVertex2fv ... glEnd stuff? I thought of using glMultMatrixf(), so I did the following: GLfloat new_matrix[] = {1,0,0,0.5,0,1,0,0.5,0,0,1,0,0,0,0,1}; float mat[16]; int r,c; glGetFloatv(GL_MODELVIEW_MATRIX, mat); qDebug("Before glMultMatrixf"); for (c=0 ; c<16 ; c++) std::cout<<mat[c]<<" " ;std::cout<<std::endl; glMultMatrixf(new_matrix); qDebug("After glMultMatrixf"); glGetFloatv(GL_MODELVIEW_MATRIX, mat); for (c=0 ; c<16 ; c++) std::cout<<mat[c]<<" " ;std::cout<<std::endl; So I just want the model to be translate by a factor 0.5 in x and y. The outputs of my debu info are: Before glMultMatrixf -0.53704 -3.71254 -15.0809 5 -0.83904 -3.41054 -15.0809 5 0 0 0.431428 0 -0.167808 -0.742508 -3.01619 1 After glMultMatrixf -0.620944 -4.08379 -16.589 5.5 -0.922944 -3.78179 -16.589 5.5 0 0 0.431428 0 -0.167808 -0.742508 -3.01619 1 So the viewing matrix gets updated, so why not the model? Thanks for your help! -Pierre.

Share this post


Link to post
Share on other sites
Advertisement
to speed up the code you can try one of the following methods :
1. Display lists
2. vertex arays .
3. Vertex buffer objects.

as far as the matrix is concerned, where are u placing the glMultMatrix functions ?
Also, since your translation is 0.5 in each direction , probably thats why the change is not apparent ? Try drawing an axis at the origin and then see if the model is translated.

cheers

Share this post


Link to post
Share on other sites
Quote:
It is fine with small models, but when I start playing with millions
of triangles, it takes about 5 seconds to render the result of a
rotation/translation.


Move up to VBO. It requires GL 1.5
Avoid glGet calls.

Share this post


Link to post
Share on other sites
Quote:
Original post by _gl_coder_one_
1. Display lists
Display lists are handy, but they wont do much for you if you are feeding a ton of data.
Quote:
2. vertex arays.
3. Vertex buffer objects.
Vertex arrays should help a lot, and VBOs will help even more - what is best is that the second is only a small step from the first. For best results, interleave the vertices, and possibly even rearrange them for vertex cache coherence.

Share this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
Quote:
Original post by _gl_coder_one_
1. Display lists
Display lists are handy, but they wont do much for you if you are feeding a ton of data.
Quote:
2. vertex arays.
3. Vertex buffer objects.
Vertex arrays should help a lot, and VBOs will help even more - what is best is that the second is only a small step from the first. For best results, interleave the vertices, and possibly even rearrange them for vertex cache coherence.


Display list is usually as good as static VBO (at least on a NVidia display card).

Share this post


Link to post
Share on other sites
Quote:

Assuming I have already drawn the model using the above piece of code
and want now to translate it using the mouse (the mouse event has
returned dx and dy),

How do I make the graphic card understand to use what it has already
in memory and apply on it the glTranslatef(dx, dy, 0) without having
to re-do the above piece of code, ie the glBegin ... glVertex2fv ...
glEnd stuff?

There is absolutely nothing you can do. That is why the original code is considered bad.

Share this post


Link to post
Share on other sites

Hi!

Thank you to all of you!

I think that I started with the wrong assumption. I thought that when a scene has been rendered, if this one has not changed in term of new object being rendered/deleted, a simple rotation could be done without having to redraw everything.

In fact as soon I change a bit in my scene I have to render everything
all again, ie going through the original bit of code:

glBegin(GL_TRIANGLES);
for (i = 0; i < *n; i ) {
glVertex2fv(vert[endpts[nx]-1]);
nx ;
glVertex2fv(vert[endpts[nx]-1]);
nx ;
glVertex2fv(vert[endpts[nx]-1]);
}
glEnd();

With millions of triangles, I will have too many function calls.


So, my only solution is in fact to implement some VBO approach...

Could anyone redirect me to some place where VBO is explained with some code sample?

Cheers..

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!