PDA

View Full Version : high-quality curve



rafal
04-22-2012, 06:30 AM
i want to plot high-quality curve - simple chart but very huge size more than 200MB.
a problem exists when it is ploting on slower graphics card because chart manipulations take not aceptable time.
all operations i need are move, zoom, scale, cut.
please help me by provide link to example c++ program and teling me what should be done with this matter. im new in opengl but i understand it little, unfotunatelly havent any of experience with OGL.

rafal
04-22-2012, 08:01 AM
heh ptobably any responce because of my bad english :(

i know the simlilar problem with a texture can be resolved using Mipmaps. is there a way to resolve my ?

ZbuffeR
04-22-2012, 01:39 PM
More probably no response because you ask people to "provide link to example c++ program".

If card need less line to be interactive, do that. Create less detailed plots that will be used during interactive manipulation by the user.

You can skip 1 in 4 points of the plot for example, and even do that with several levels, like mipmaps. And whenever you measure a too long rendering time per frame, go to a simpler level, etc.

rafal
04-22-2012, 02:03 PM
thx, yes i can do that but ir little complicate the code.
i think use some kind of buffers is that i want. but i still dont know ay more... i ve try to use vbo buffer but this g card hasnt cuda.

are there any way to simple draw this line in buffer once and then only use just ready buffer in paint routine ?

rafal
04-22-2012, 02:42 PM
i try to ask again uding kuttke different questions.

is it possible (and how) to use some kind of opengl bufferes to render high quiality lines to avoid rendering at every redraw ?

im looking for some base solution because the code has to be very portable, so on.

Very Thanks for any help !

rafal
04-23-2012, 03:38 AM
what is wrong woth that code ? is Qt part of paint body :
if (buffer1 == NULL)
{
buffer1 = new QGLBuffer(QGLBuffer::VertexBuffer);
buffer1->setUsagePattern(QGLBuffer::DynamicDraw);

if (!buffer1->create())
{
qFatal("cant create buffer");
delete buffer1;
buffer1 = NULL;
return;
}

buffer1->bind();
buffer1->allocate(sizeof(GLdouble) * 2 * samples.size());
if (!buffer1->map(QGLBuffer::WriteOnly))
{
qFatal("cant map buffer");
buffer1->unmap();
buffer1->release();
delete buffer1;
buffer1 = NULL;
return;
}
buffer1->unmap();
buffer1->release();
}

if (buffer1)
{
buffer1->bind();
void *mapped = buffer1->map(QGLBuffer::WriteOnly);
QVector2D* posns = (QVector2D *)mapped;

for (int i=0; i<samples.size();i++)
posns[i] = QVector2D(samples[i].sx, samples[i].sy);

buffer1->unmap();
buffer1->release();

// glEnableClientState(GL_VERTEX_ARRAY); need this ?
buffer1->bind();
glDrawArrays(curve->style(), 0, samples.size()); //i think here something is wrong
buffer1->release();
}

Dan Bartlett
04-23-2012, 04:12 AM
You're not telling OpenGL where to retrieve the vertex data from. You need to have some glVertexPointer/ gl{***}Pointer calls in there. eg.



glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY); // only if you want per-vertex color
buffer1->bind();
// tell OpenGL to grab vertex data from the start of buffer1 (the currently bound buffer object), with 2 double co-ordinates per vertex, tightly packed
glVertexPointer(2, GL_DOUBLE, 0 {or vertex size}, BUFFER_OFFSET(0));
glColorPointer(...); // only if you want per-vertex color
buffer1->release();

// note: buffer doesn't need to be bound at point of draw call
// OpenGL records which buffer was bound when you call gl***Pointer and stores it.
// this means you can tell OpenGL to retrieve data from different buffer objects for each attribute if you wish.
glDrawArrays(curve->style(), 0, samples.size());

rafal
04-23-2012, 04:42 AM
is that means buffer must be mapped before glVertexPointer ?
if not then how can i get BUFFER_OFFSET ?

Dan Bartlett
04-23-2012, 05:35 AM
When a buffer object is bound, the "pointer" argument is an offset into that buffer. Since "pointer" is declared as
const GLvoid * pointer then most languages will require a type-cast to convert the offset into this.

If you look at http://www.opengl.org/wiki/Vertex_Buffer_Object , for C++ they use:

#define BUFFER_OFFSET(i) (reinterpret_cast<void*>(i))

rafal
04-23-2012, 05:56 AM
please take a loook - still ctashed.

#define BUFFER_OFFSET(i) (reinterpret_cast<void*>(i))
if (buffer1 == NULL)
{
buffer1 = new QGLBuffer(QGLBuffer::VertexBuffer);
buffer1->setUsagePattern(QGLBuffer::DynamicDraw);
//buffer1->setUsagePattern(QGLBuffer::StaticDraw);
if (!buffer1->create())
{
qFatal("cant create buffer");
delete buffer1;
buffer1 = NULL;
return;
}
buffer1->bind();
buffer1->allocate(sizeof(GLdouble) * 2 * samples.size());

if (!buffer1->map(QGLBuffer::WriteOnly))
{
qFatal("cant map buffer");
buffer1->unmap();
buffer1->release();
delete buffer1;
buffer1 = NULL;
return;
}
buffer1->unmap();
buffer1->release();
}

if (buffer1)
{
buffer1->bind();
void *mapped = buffer1->map(QGLBuffer::WriteOnly);
QVector2D* posns = (QVector2D *)mapped;

for (int i=0; i<samples.size();i++)
posns[i] = QVector2D(samples[i].sx, samples[i].sy);

buffer1->unmap();
buffer1->release();

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY); // only if you want per-vertex color
buffer1->bind();

glVertexPointer(2, GL_DOUBLE, sizeof(plotSample), BUFFER_OFFSET(0) );
buffer1->release();

glDrawArrays(curve->style(), 0, samples.size());
}

ZbuffeR
04-23-2012, 06:11 AM
Please use code blocks when you post code on the forum. It makes it more readable and increase your chances of getting good help. It is the little icon with a # when you are on the full reply view.

rafal
04-23-2012, 06:19 AM
ok i try ...

#define BUFFER_OFFSET(i) (reinterpret_cast<void*>(i))
if (buffer1 == NULL)
{
buffer1 = new QGLBuffer(QGLBuffer::VertexBuffer);
buffer1->setUsagePattern(QGLBuffer::DynamicDraw);
//buffer1->setUsagePattern(QGLBuffer::StaticDraw);
if (!buffer1->create())
{
qFatal("cant create buffer");
delete buffer1;
buffer1 = NULL;
return;
}
buffer1->bind();
buffer1->allocate(sizeof(GLdouble) * 2 * samples.size());

if (!buffer1->map(QGLBuffer::WriteOnly))
{
qFatal("cant map buffer");
buffer1->unmap();
buffer1->release();
delete buffer1;
buffer1 = NULL;
return;
}
buffer1->unmap();
buffer1->release();
}

if (buffer1)
{
buffer1->bind();
void *mapped = buffer1->map(QGLBuffer::WriteOnly);
QVector2D* posns = (QVector2D *)mapped;

for (int i=0; i<samples.size();i++)
posns[i] = QVector2D(samples[i].sx, samples[i].sy);

buffer1->unmap();
buffer1->release();

glEnableClientState(GL_VERTEX_ARRAY);
// glEnableClientState(GL_COLOR_ARRAY); // only if you want per-vertex color
buffer1->bind();

glVertexPointer(2, GL_DOUBLE, samples.size(), 0 );
buffer1->release();

glDrawArrays(curve->style(), 0, samples.size());
}

rafal
04-23-2012, 06:21 AM
the code above doesnt work. no idea why. i need a bit help stil.

Dan Bartlett
04-23-2012, 07:54 AM
Since AFAICT samples.size() is the number of vertices, then you shouldn't be using this as the stride argument (stride = how many bytes between consecutive vertices, or tightly packed if 0)

glVertexPointer(2, GL_DOUBLE, samples.size(), 0 );
should probably be

glVertexPointer(2, GL_DOUBLE, 0, 0 );

rafal
04-23-2012, 08:08 AM
THX, now something is plotted from the buffer even it is not rxactly it should be - probably i need a bit work on that.

again thank You and i be back if it is work at last.