PDA

View Full Version : 2D - 20000 Polylines - blinking



opessoa
06-12-2013, 01:01 PM
I have 20000 polylines to draw, when I make PAN, these redraw are blinking...

I use vector and glVertexPointer(3, GL_DOUBLE, 0, data());

What is the best way to do it?

I'm using glortho with gltranslated.

cireneikual
06-12-2013, 02:00 PM
You probably are not double-buffering. How you enable it depends on your windowing system.

Dan Bartlett
06-12-2013, 02:16 PM
Use double buffering to reduce flicker as cireneikual said.

To increase performance make sure your data uses single-precision floats and change GL_DOUBLE to GL_SINGLE too, since most hardware will need to perform this conversion otherwise. If the data is static, or doesn't change often then using VBOs can save re-submitting the same data to the GPU every time. Also, make sure your data() call isn't doing more work than it needs to.

GClements
06-12-2013, 03:07 PM
To increase performance make sure your data uses single-precision floats and change GL_DOUBLE to GL_SINGLE too
There isn't a "GL_SINGLE"; for single-precision floats, use GL_FLOAT.

opessoa
06-13-2013, 06:22 AM
Use double buffering to reduce flicker as cireneikual said.

To increase performance make sure your data uses single-precision floats and change GL_DOUBLE to GL_SINGLE too, since most hardware will need to perform this conversion otherwise. If the data is static, or doesn't change often then using VBOs can save re-submitting the same data to the GPU every time. Also, make sure your data() call isn't doing more work than it needs to.

Hi Dan...

I'm using opengl with MFC, yes, is double buffered. I change double to float, but doesn't makes diference...

How to use VBO with opengl 1.1? (MFC default)

This is my aproximetely "structure".



struct POINT
{
double x;
double y;
double z;
}
vector <POINT> test;

//include a lot of vertex

glVertexPointer(3, GL_DOUBLE, 0, test.data());
glDrawArrays(GL_LINE_STRIP,0,test.size());

tonyo_au
06-13-2013, 07:44 PM
How to use VBO with opengl 1.1? (MFC default)
MFC has nothing to do with OpenGL. How are you initializing OpenGL? You can use any version of OpenGL your driver supports inside MFC.

Dan Bartlett
06-14-2013, 07:28 AM
You will need to load the OpenGL functions used for buffer objects either yourself (http://www.opengl.org/wiki/Load_OpenGL_Functions) or using a loading library (http://www.opengl.org/wiki/OpenGL_Loading_Library) (recommended). There are quite a few tutorials out there for using buffer objects (http://www.opengl.org/wiki/Buffer_Object) especially vertex buffer objects (VBOs).

A good tutorial on modern OpenGL usage is here (http://www.arcsynthesis.org/gltut/), with the page introducing buffer objects here (http://www.arcsynthesis.org/gltut/Basics/Tut01%20Following%20the%20Data.html). Another tutorial can be found here (http://www.opengl-tutorial.org/), with the page about buffer objects here (http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/).

If you're not ready for modern OpenGL (as shaders/VAOs/generic attributes/ etc. all need to be understood before you can start drawing triangles), here's a couple of older tutorials from Google: http://www.songho.ca/opengl/gl_vbo.html http://www.ozone3d.net/tutorials/opengl_vbo.php

A simple adaptation of your code to use VBOs would look something like this (untested):

struct POINT
{
GLfloat x;
GLfloat y;
GLfloat z;
}
vector <POINT> test;
...
// create a single VBO + load data to it
GLuint vbo1;
glGenBuffers(1, &vbo1);
glBindBuffer(GL_ARRAY_BUFFER, vbo1);
glBufferData(GL_ARRAY_BUFFER, test.size() * sizeof(POINT), data(), GL_STATIC_DRAW);

// the combination of the buffer object currently bound to GL_ARRAY_BUFFER & glVertexPointer tells OpenGL
// that the vertex data should be retrieved from offset 0 in vbo1, rather than from a client-side vertex array.
glBindBuffer(GL_ARRAY_BUFFER, vbo1);
glVertexPointer(3, GL_FLOAT, sizeof(POINT), BUFFER_OFFSET(0));
//glColorPointer(...);
//glNormalPointer(...)

glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINE_STRIP, 0, test.size());

// unbind/disable
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisableClientState(GL_VERTEX_ARRAY);