Hi,

is there any way to draw a Mathematical Curve in OpenGL with Dynamic Arrays ???

I interpolate the Curve by Calculating different Points along the x-Axis, and Connect them via

GL_LINES :

glBegin(GL_LINES) ;

… Here must be a “Dynamic” Vertex-Array

… Adding more and more Points…

glEnd() ;

The Problem is: I don’t know, how many Points I need, to draw the Curve, so, i mus dynamical add another Point to the Line.

Does Anyone know, how to implement this ???

Greeting’s

DanDanger

I would suggest generating your vertices into some structure supporting easy insert, such as a list. Then, inside the glBegin(), just walk the list and issue the vertices, as stored in the list.

Yeah,

I think, that should do it.

But, is there any other way to implement it ?

Linked-Lists are a little bit “Overloaded”.

I just want to draw a Curve

Greetings

DanDanger

If you just want to add vertices to the end of the array, just do this:-

float* array=0;

int mem=0;

int count=0;

void AddPointToGlobalArray(float x,float y,float z)

{

if (count>=mem)

{

mem = count+100;

array = (float*)realloc(array, sizeof(float)*3*mem);

}

array[count*3]=x;*

array[count3+1]=y;

array[count*3+2]=z;

count++;

}

I don’t understand why linked lists are “overloaded” (or, I believe he meant to say, “overkill”).

If he wants to subdivide a curve to some specific tolerance (which it sounds like he wants to do) then he just needs to find a good data structure for doing that. If you don’t want to be memcpy()-ing a vector out towards the end, to insert in the middle, a linked list is the right data structure.

Of course, you can’t submit a linked-list as-is to OpenGL; you need to somehow traverse it when you’re done, whereas a vector can be submitted as-is, so it’s all in which case ends up being better for your specific case.

However, if you find yourself with a problem, and there’s some common data structure that will solve the problem, I would consider that “great” rather than “overkill,” because if I can use a data structure I understand, that means I probably won’t be writing a bunch of buggy code I’ll have to debug.