OpenGL GLTools - Variable size of Vertices with GLBatch

Recommended Posts

Posted (edited)

I am very new to OpenGL so I am using GLTools to learn the basics.

For the start I would like to create a circle with adjustable tesselation (e.g. the number of triangles which form the circle).

I have a toolbar with a variable tesselation:

TwBar *bar;
void InitGUI() {
bar = TwNewBar("TweakBar");
TwDefine(" TweakBar size='200 400'");
}

Then I have these two functions and global variables which calculate the vertices for the circle:

GLBatch circle;

unsigned int tesselation = 8;

void topAndBottomGeometry(M3DVector3f *vertices, M3DVector4f *colors, const int vertOffset) {

int i = 1;
int color = 1;
for (int step = 0; step <= tesselation; step++) {
const double angle = step * ((2.0 * GL_PI) / tesselation);
const double x = width * sin(angle);
const double y = width * cos(angle);

if ((color % 2) == 0) {
}
else {
}

color++;
i++;
}
}

void CreateGeometry() {
const int amount = tesselation + 2;
M3DVector3f *vertices = (M3DVector3f*)malloc(sizeof(float) * 3 * amount);
M3DVector4f *colors = (M3DVector4f*)malloc(sizeof(float) * 4 * amount);

topAndBottomGeometry(vertices, colors, 0);

circle.Begin(GL_TRIANGLE_FAN, amount);
circle.CopyVertexData3f(vertices);
circle.CopyColorData4f(colors);
circle.End();

free(vertices);
free(colors);
}

Now, everything works fine in my GUI if the tesselation value is below or equal to the initial value (in this case 8). But if the value is any higher than 8 (doesn't matter which value), the GUI "freezes" and the circle stays the way it was like when tesselation is set to 8:

Edited by IsItSharp

Create an account

Register a new account

• 17
• 19
• 23
• 10
• 10