GLTools - Variable size of Vertices with GLBatch 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'"); TwAddVarRW(bar, "Tesselation", TW_TYPE_UINT32, &tesselation, ""); } 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) { m3dLoadVector3(vertices[0], 0, 0, vertOffset); m3dLoadVector4(colors[0], 0, 0, 1, 1); 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) { m3dLoadVector4(colors[i], 0, 0, 1, 1); } else { m3dLoadVector4(colors[i], 0, 1, 0, 1); } m3dLoadVector3(vertices[i], x, y, vertOffset); 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: Tesselation at 8 Tesselation at 6 http://bit.ly/2VNz8It https://ift.tt/eA8V8J
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'"); TwAddVarRW(bar, "Tesselation", TW_TYPE_UINT32, &tesselation, ""); } 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) { m3dLoadVector3(vertices[0], 0, 0, vertOffset); m3dLoadVector4(colors[0], 0, 0, 1, 1); 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) { m3dLoadVector4(colors[i], 0, 0, 1, 1); } else { m3dLoadVector4(colors[i], 0, 1, 0, 1); } m3dLoadVector3(vertices[i], x, y, vertOffset); 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: Tesselation at 8 Tesselation at 6 http://bit.ly/2VNz8It
from GameDev.net http://bit.ly/2DQS8eT
from GameDev.net http://bit.ly/2DQS8eT
ليست هناك تعليقات