OpenGL calculating Normal of a custom shape - opengl

i have a shape with the following vertexes and faces:
static Vec3f cubeVerts[24] = {
{ -0.5, 0.5, -0.5 }, /* backside */
{ -0.5, -0.5, -0.5 },
{ -0.3, 4.0, -0.5 },
{ -0.3, 3.0, -0.5 },
{ -0.1, 5.5, -0.5 },
{ -0.1, 4.5, -0.5 },
{ 0.1, 5.5, -0.5 },
{ 0.1, 4.5, -0.5 },
{ 0.3, 4.0, -0.5 },
{ 0.3, 3.0, -0.5 },
{ 0.5, 0.5, -0.5 },
{ 0.5, -0.5, -0.5 },
{ -0.5, 0.5, 0.5 }, /* frontside */
{ -0.5, -0.5, 0.5 },
{ -0.3, 4.0, 0.5 },
{ -0.3, 3.0, 0.5 },
{ -0.1, 5.5, 0.5 },
{ -0.1, 4.5, 0.5 },
{ 0.1, 5.5, 0.5 },
{ 0.1, 4.5, 0.5 },
{ 0.3, 4.0, 0.5 },
{ 0.3, 3.0, 0.5 },
{ 0.5, 0.5, 0.5 },
{ 0.5, -0.5, 0.5 }
};
static GLuint cubeFaces[] = {
0, 1, 3, 2, /*backfaces*/
2, 3, 5, 4,
4, 5, 7, 6,
6, 7, 9, 8,
8, 9, 11, 10,
12, 13, 15, 14, /*frontfaces*/
14, 15, 17, 16,
16, 17, 19, 18,
18, 19, 21, 20,
20, 21, 23, 22,
0, 2, 14, 12, /*topfaces*/
2, 4, 16, 14,
4, 6, 18, 16,
6, 8, 20, 18,
8, 10, 22, 20,
1, 3, 15, 13, /*bottomfaces*/
3, 5, 17, 15,
5, 7, 19, 17,
7, 9, 21, 19,
9, 11, 23, 21,
0, 1, 13, 12, /*sidefaces*/
10, 11, 23, 22
};
and i want to get its normal like this:
static Vec3f cubeNorms[] = {
{ 0, 1, 0 },
{ 0, 1, 0 },
{ 0, 1, 0 },
{ 0, 1, 0 }
};
Can someone tell me how to calculate its normal and putting it inside an array so i can use all these together like this, i know something is wrong with my normal, because lighting on my shape is not right and i am also not sure if its the right way of setting up the normal, just one example is fine, ive been reading heaps of normal calculations and still can't figure out how to do it.
static void drawCube()
{
//vertexes
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, cubeVerts);
//norms
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, cubeNorms);
//faces
glDrawElements(GL_QUADS, 22 * 4, GL_UNSIGNED_INT, cubeFaces);
}

I'm going to assume your faces are counter-clockwise front-facing - I don't know if that's the case - and the quads are, of course, convex and planar.
For a face, take vertices {0, 1, 2}. I don't know the Vec3f specification (or if it's a class or C struct), but we can find the normal for all vertices in the quad with:
Vec3f va = v0 - v1; // quad vertex 1 -> 0
Vec3f vb = v2 - v1; // quad vertex 1 -> 2
Vec3f norm = cross(vb, va); // cross product.
float norm_len = sqrt(dot(norm, norm));
norm /= norm_len; // divide each component of norm by norm_len.
That gives you a unit normal for that face. If vertices are shared, and you want to give the model the perception of curvature using lighting, you'll have to decide what value of the normal should be 'agreed' upon. Perhaps the best starting point is to simply take an average of the face normals at that vertex - and rescale the result to unit length as required.

Related

Numpy divide doesn't return floats

When I run:
np.divide(np.array([0, 1, 2, 3, 4]),np.array([2, 2, 4, 4, 4]))
OR
np.array([0, 1, 2, 3, 4])/np.array([2, 2, 4, 4, 4])
OR
np.true_divide(np.array([0, 1, 2, 3, 4]),np.array([2, 2, 4, 4, 4]))
The output I get:
array([0., 0., 0., 1., 1.])
Even when the numbers are specified as floats like [0.0, 1.0, 2.0, 3.0, 4.0], the result is the same.
Expected output:
array([0., 0.5, 0.5, 0.75, 1.0])
I am unable to understand why the result is the way it is.
The print precision was set to precision=0.
Took me a while to figure that out!
Got fixed when I did:
np.set_printoptions(precision=2)

glClear() keeps the screen black

I'm developing a 2D game called Spaceland and I've ran into a problem with clearing the screen. Whenever I call glClear(GL_COLOR_BUFFER_BIT) every frame, it keeps my screen black until i stop calling it. I have tested this by assigning glClear() to a key, and when I hold it down the screen turns black, when not pressed, the quad that is spreading across the screen just grows until I clear again.
I am using glClearColor(0, 0, 0, 1) when I create a window. I have tried turning off and on glfwSwapInterval().
create() function in my Window class:
public void create(boolean vsync) {
GLFWErrorCallback.createPrint(System.err).set();
GLFWVidMode vid = glfwGetVideoMode(glfwGetPrimaryMonitor());
keys = new boolean[GLFW_KEY_LAST];
for (int i = 0; i < GLFW_KEY_LAST; i ++) {
keys[i] = false;
}
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
ID = glfwCreateWindow(vid.width(), vid.height(), TITLE, glfwGetPrimaryMonitor(), 0);
if (ID == 0)
throw new IllegalStateException("Error whilst creating window: '" + TITLE + "'");
glfwMakeContextCurrent(ID);
createCapabilities();
glClearColor(0, 0, 0, 1);
camera = new Camera(getWidth(), getHeight());
glfwSwapInterval(vsync ? 1 : 0);
}
Sprite Class:
public class Sprite {
private VertexArray vao;
private VertexBuffer
pVbo,
iVbo;
private int vertexCount;
private float scale;
private Vector3f position;
private Vector3f rotation;
private Matrix4f tMatrix;
public Sprite(float[] pos, int[] indices) {
vertexCount = indices.length;
position = new Vector3f(0, 0, 0);
rotation = new Vector3f(0, 0, 0);
scale = 0.1f;
tMatrix = MatrixHelper.createTransformationMatrix(position, rotation, scale);
vao = new VertexArray();
pVbo = new VertexBuffer(false);
iVbo = new VertexBuffer(true);
vao.bind();
pVbo.bind();
pVbo.add(pos);
vao.add();
pVbo.unbind();
iVbo.bind();
iVbo.add(indices);
iVbo.unbind();
vao.unbind();
}
public void setPosition(float x, float y, float z) {
position.x = x;
position.y = y;
position.z = z;
}
public void setRotation(Vector3f rot) {
rotation = rot;
}
public void render(int renderType) {
MatrixHelper.setTMatrixPosition(tMatrix, position);
setPosition(getPosition().x + 0.0001f, 0, 0);
System.out.println(tMatrix);
Spaceland.shader.bind();
Spaceland.shader.editValue("transformation", tMatrix);
vao.bind();
glEnableVertexAttribArray(0);
iVbo.bind();
glDrawElements(renderType, vertexCount, GL_UNSIGNED_INT, 0);
iVbo.unbind();
glDisableVertexAttribArray(0);
vao.unbind();
Spaceland.shader.unbind();
}
public Vector3f getPosition() {
return position;
}
}
I don't think you need to see my Camera class or MatrixHelper class as the problem has occured before implementing this.
Main class (ignore rose[] and roseI[] it's just a cool pattern I made as a test):
public class Spaceland {
public static Window window;
public static Sprite sprite;
public static Shader shader;
public static float[] rose = {
-0.45f, 0f,
0.45f, 0f,
0f, 0.45f,
0f, -0.45f,
-0.4f, -0.2f,
-0.4f, 0.2f,
0.4f, -0.2f,
0.4f, 0.2f,
-0.2f, -0.4f,
-0.2f, 0.4f,
0.2f, -0.4f,
0.2f, 0.4f
};
public static int[] roseI = {
0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11,
1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11,
2, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 10, 2, 11,
3, 4, 3, 5, 3, 6, 3, 7, 3, 8, 3, 9, 3, 10, 3, 11,
4, 5, 4, 6, 4, 7, 4, 8, 4, 9, 4, 10, 4, 11,
5, 6, 5, 7, 5, 8, 5, 9, 5, 10, 5, 11,
6, 7, 6, 8, 6, 9, 6, 10, 6, 11,
7, 8, 7, 9, 7, 10, 7, 11,
8, 9, 8, 10, 8, 11,
9, 10, 9, 11,
10, 11,
};
public static float[] quad = {
0.5f, 0.5f,
0.5f, -0.5f,
-0.5f, 0.5f,
-0.5f, -0.5f
};
public static int[] quadI = {
2, 0, 3,
0, 1, 3
};
public static void main(String[] args) {
init();
}
public static void loop() {
while (!window.isCloseRequested()) {
update();
render();
}
destroy(0);
}
public static void init() {
if (!glfwInit())
throw new IllegalStateException("Error whilst initialising GLFW");
window = new Window("Spaceland");
window.create(true);
shader = new Shader("src/main/java/com/spaceland/graphics/fragment.fs", "src/main/java/com/spaceland/graphics/vertex.vs");
sprite = new Sprite(quad, quadI);
loop();
}
public static void render() {
window.render();
sprite.render(GL11.GL_TRIANGLES);
}
public static void update() {
window.update();
if (window.isDown(GLFW_KEY_SPACE)) {
glClear(GL_COLOR_BUFFER_BIT);
}
}
public static void destroy(int error) {
window.destroy();
glfwTerminate();
glfwSetErrorCallback(null).free();
shader.destroy();
VertexBuffer.deleteAll();
VertexArray.destroyAll();
System.exit(error);
}
}
Please tell me if you need to see the Shader class, shader vs and fs files, or anything else.
Thanks!
glClear affects the output buffers. So it is part of rendering. If you want to clear as part of your rendering, put glClear inside your render function.
You have it inside update. I suspect that whomever is calling render and update (LWJGL, presumably?) doesn't guarantee any particular ordering to them. So each time you're asked to update you're stomping on top of the last thing you rendered.
Updates:
adjust internal state, usually partly as a function of time.
Renders:
capture current state visually.
It is not very clear in my question, but the answer is that I cleared the screen, swapped buffers, rendered, etc. Which doesn't work.
glClear(...);
glfwSwapBuffers(...);
...render...
This is how it is currently, and this doesn't work.
glClear(...);
...render...
glfwSwapBuffers(...);
This is how I do it now, and it works fine.

OpenGL dinosaur model bug: gluTessCallback issue

I am taking a computer graphics class that teaches us how to use OpenGL with the glut libraries. I have an idea for a final project that involves lighting and textures being put on a dinosaur model that I found online. My first step is to simplify the existing online code so I can begin working on my project.
Unfortunately, the online code for this model is broken, and I cannot seem to figure it out. I am not sure what gluTessCallback does, but my program is very upset with two lines of this code that is making it impossible to run this program on Visual Studio 2012.
Below is the code, and I have indicated which two lines are giving me the trouble.
typedef enum {
RESERVED, BODY_SIDE, BODY_EDGE, BODY_WHOLE, ARM_SIDE, ARM_EDGE, ARM_WHOLE,
LEG_SIDE, LEG_EDGE, LEG_WHOLE, EYE_SIDE, EYE_EDGE, EYE_WHOLE, DINOSAUR
} displayLists;
GLfloat angle = -150; /* in degrees */
GLboolean doubleBuffer = GL_TRUE, iconic = GL_FALSE, keepAspect = GL_FALSE;
int moving, begin;
int W = 300, H = 300;
GLdouble bodyWidth = 2.0;
int newModel = 1;
GLfloat body[][2] = { { 0, 3 },{ 1, 1 },{ 5, 1 },{ 8, 4 },{ 10, 4 },{ 11, 5 },
{ 11, 11.5 },{ 13, 12 },{ 13, 13 },{ 10, 13.5 },{ 13, 14 },{ 13, 15 },{ 11, 16 },
{ 8, 16 },{ 7, 15 },{ 7, 13 },{ 8, 12 },{ 7, 11 },{ 6, 6 },{ 4, 3 },{ 3, 2 },
{ 1, 2 } };
GLfloat arm[][2] = { { 8, 10 },{ 9, 9 },{ 10, 9 },{ 13, 8 },{ 14, 9 },{ 16, 9 },
{ 15, 9.5 },{ 16, 10 },{ 15, 10 },{ 15.5, 11 },{ 14.5, 10 },{ 14, 11 },{ 14, 10 },
{ 13, 9 },{ 11, 11 },{ 9, 11 } };
GLfloat leg[][2] = { { 8, 6 },{ 8, 4 },{ 9, 3 },{ 9, 2 },{ 8, 1 },{ 8, 0.5 },{ 9, 0 },
{ 12, 0 },{ 10, 1 },{ 10, 2 },{ 12, 4 },{ 11, 6 },{ 10, 7 },{ 9, 7 } };
GLfloat eye[][2] = { { 8.75, 15 },{ 9, 14.7 },{ 9.6, 14.7 },{ 10.1, 15 },
{ 9.6, 15.25 },{ 9, 15.25 } };
GLfloat lightZeroPosition[] = { 10.0, 4.0, 10.0, 1.0 };
GLfloat lightZeroColor[] = { 0.8, 1.0, 0.8, 1.0 }; /* green-tinted */
GLfloat lightOnePosition[] = { -1.0, -2.0, 1.0, 0.0 };
GLfloat lightOneColor[] = { 0.6, 0.3, 0.2, 1.0 }; /* red-tinted */
GLfloat skinColor[] = { 0.1, 1.0, 0.1, 1.0 }, eyeColor[] = { 1.0, 0.2, 0.2, 1.0 };
void
extrudeSolidFromPolygon(GLfloat data[][2], unsigned int dataSize,
GLdouble thickness, GLuint side, GLuint edge, GLuint whole)
{
static GLUtriangulatorObj *tobj = NULL;
GLdouble vertex[3], dx, dy, len;
int i;
int count = dataSize / (int)(2 * sizeof(GLfloat));
if (tobj == NULL) {
tobj = gluNewTess(); /* create and initialize a GLU
polygon tesselation object */
/////////////////////////////////////////////////////////////////////////////////////////
// THESE LINES WILL NOT COMPILE. Says that the glBegin and glVertex2fv are incompatable.
gluTessCallback(tobj, GLU_BEGIN, glBegin);
gluTessCallback(tobj, GLU_VERTEX, glVertex2fv); /* semi-tricky */
/////////////////////////////////////////////////////////////////////////////////////////
gluTessCallback(tobj, GLU_END, glEnd);
}
glNewList(side, GL_COMPILE);
glShadeModel(GL_SMOOTH); /* smooth minimizes seeing
tessellation */
gluBeginPolygon(tobj);
/////////////////////////////////////////////////////////////////////////////////////////
// ALSO A PROBLEM WITH THIS SECTION OF CODE?
for (i = 0; i < count; i++) {
vertex[0] = data[i][0];
vertex[1] = data[i][1];
vertex[2] = 0;
gluTessVertex(tobj, vertex, data[i]);
}
gluEndPolygon(tobj);
glEndList();
/////////////////////////////////////////////////////////////////////////////////////////
glNewList(edge, GL_COMPILE);
glShadeModel(GL_FLAT); /* flat shade keeps angular hands
from being "smoothed" */
glBegin(GL_QUAD_STRIP);
for (i = 0; i <= count; i++) {
/* mod function handles closing the edge */
glVertex3f(data[i % count][0], data[i % count][1], 0.0);
glVertex3f(data[i % count][0], data[i % count][1], thickness);
/* Calculate a unit normal by dividing by Euclidean
distance. We * could be lazy and use
glEnable(GL_NORMALIZE) so we could pass in * arbitrary
normals for a very slight performance hit. */
dx = data[(i + 1) % count][1] - data[i % count][1];
dy = data[i % count][0] - data[(i + 1) % count][0];
len = sqrt(dx * dx + dy * dy);
glNormal3f(dx / len, dy / len, 0.0);
}
glEnd();
glEndList();
glNewList(whole, GL_COMPILE);
glFrontFace(GL_CW);
glCallList(edge);
glNormal3f(0.0, 0.0, -1.0); /* constant normal for side */
glCallList(side);
glPushMatrix();
glTranslatef(0.0, 0.0, thickness);
glFrontFace(GL_CCW);
glNormal3f(0.0, 0.0, 1.0); /* opposite normal for other side */
glCallList(side);
glPopMatrix();
glEndList();
}
void
makeDinosaur(void)
{
GLfloat bodyWidth = 3.0;
extrudeSolidFromPolygon(body, sizeof(body), bodyWidth,
BODY_SIDE, BODY_EDGE, BODY_WHOLE);
extrudeSolidFromPolygon(arm, sizeof(arm), bodyWidth / 4,
ARM_SIDE, ARM_EDGE, ARM_WHOLE);
extrudeSolidFromPolygon(leg, sizeof(leg), bodyWidth / 2,
LEG_SIDE, LEG_EDGE, LEG_WHOLE);
extrudeSolidFromPolygon(eye, sizeof(eye), bodyWidth + 0.2,
EYE_SIDE, EYE_EDGE, EYE_WHOLE);
glNewList(DINOSAUR, GL_COMPILE);
glMaterialfv(GL_FRONT, GL_DIFFUSE, skinColor);
glCallList(BODY_WHOLE);
glPushMatrix();
glTranslatef(0.0, 0.0, bodyWidth);
glCallList(ARM_WHOLE);
glCallList(LEG_WHOLE);
glTranslatef(0.0, 0.0, -bodyWidth - bodyWidth / 4);
glCallList(ARM_WHOLE);
glTranslatef(0.0, 0.0, -bodyWidth / 4);
glCallList(LEG_WHOLE);
glTranslatef(0.0, 0.0, bodyWidth / 2 - 0.1);
glMaterialfv(GL_FRONT, GL_DIFFUSE, eyeColor);
glCallList(EYE_WHOLE);
glPopMatrix();
glEndList();
}
void
recalcModelView(void)
{
glPopMatrix();
glPushMatrix();
glRotatef(angle, 0.0, 1.0, 0.0);
glTranslatef(-8, -8, -bodyWidth / 2);
newModel = 0;
}
void
redraw(void)
{
if (newModel)
recalcModelView();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glCallList(DINOSAUR);
glutSwapBuffers();
}
/* ARGSUSED2 */
void
mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
moving = 1;
begin = x;
}
if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
moving = 0;
}
}
/* ARGSUSED1 */
void
motion(int x, int y)
{
if (moving) {
angle = angle + (x - begin);
begin = x;
newModel = 1;
glutPostRedisplay();
}
}
GLboolean lightZeroSwitch = GL_TRUE, lightOneSwitch = GL_TRUE;
void
controlLights(int value)
{
switch (value) {
case 1:
lightZeroSwitch = !lightZeroSwitch;
if (lightZeroSwitch) {
glEnable(GL_LIGHT0);
}
else {
glDisable(GL_LIGHT0);
}
break;
case 2:
lightOneSwitch = !lightOneSwitch;
if (lightOneSwitch) {
glEnable(GL_LIGHT1);
}
else {
glDisable(GL_LIGHT1);
}
break;
}
glutPostRedisplay();
}
int
main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("glutdino");
glutDisplayFunc(redraw);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutCreateMenu(controlLights);
glutAddMenuEntry("Toggle right light", 1);
glutAddMenuEntry("Toggle left light", 2);
glutAttachMenu(GLUT_RIGHT_BUTTON);
makeDinosaur();
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
gluPerspective( /* field of view in degree */ 40.0,
/* aspect ratio */ 1.0,
/* Z near */ 1.0, /* Z far */ 40.0);
glMatrixMode(GL_MODELVIEW);
gluLookAt(0.0, 0.0, 30.0, /* eye is at (0,0,30) */
0.0, 0.0, 0.0, /* center is at (0,0,0) */
0.0, 1.0, 0.); /* up is in postivie Y direction */
glPushMatrix(); /* dummy push so we can pop on model
recalc */
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);
glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}
I tried to make it clear where the problem is. OpenGl is bringing me to my wit's end. Is there nowhere I can get a simple 3D dinosaur model to play with on the internet?
I hope you can provide me some insight on this gluTessCallback issue so I can get this working. All I want is a solid dinosaur model.
Looking at the man page, the signature of the callback passed to gluTessCallback() depends on the enum value passed as the second argument. This means that if you're using C++, or a version of C that uses function prototypes, you will need a typecast to cast your function to the type expected by gluTessCallback().
According to the man page, the argument type is defined as _GLUfuncptr. However, that type is not defined in the glu.h header I found. The type according to the spec and header is a function with no arguments and a return type of GLvoid. You can define your own function type for this, and then cast to it:
typedef GLvoid (*TessFuncPtr)();
gluTessCallback(tobj, GLU_BEGIN, (TessFuncPtr)glBegin);
gluTessCallback(tobj, GLU_VERTEX, (TessFuncPtr)glVertex2fv);
If you're just learning OpenGL, you should be aware that almost all of the calls in this code are deprecated and obsolete. This includes:
Immediate mode rendering (glBegin, glEnd, etc).
Display lists.
Matrix stack.
Fixed function lighting and material definitions.
I think you would be much better off learning a current version of OpenGL. For example the tessellation functionality you are trying to use was defined close to 25 years ago. Aside from being deprecated, I don't think it was ever widely used in the first place.

Python process increasing memory RAM usage

I have been using python some months and this problem just appear two or three days ago.
At this moment I am running this code in the IDLE 3.4.3 python GUI :
x = [1,2,3,4,5]
for i in x:
x.append((i * (i + 1))/2)
print(x)
But this hasnt output or error(is not the only one), the console just is opened and its waiting(like thinking)
and then i check the process in task admin and i see that the process start in 30-35 mb
and after One or Two minutes the process is consuming:
I have not installed new software or something with the OS, this happen in two different laptops(W7 and W10), could be this code, I know(its works if I create a new empty list) but what about other simple instructions like 1+1
I have tried with diferent IDEs, and python versions including architecture.
First I was using iPython notebook and Spyder because I need to plot and Anaconda comes with everything ready, but the kernel always said Busy and without output; I restart, interrupt, new kernel but doesnt work and this happen just this week, because i was working perfectly so I had to remove it because this is happening.
Someone has idea what is happening?
To see what is happening, let me modify your code slightly
x = [1,2,3,4,5]
for i in x:
x.append((i * (i + 1))/2)
print(x)
if len(x) > 20:
break
print(x)
The output looks like this
[1, 2, 3, 4, 5, 1.0]
[1, 2, 3, 4, 5, 1.0, 3.0]
[1, 2, 3, 4, 5, 1.0, 3.0, 6.0]
[1, 2, 3, 4, 5, 1.0, 3.0, 6.0, 10.0]
[1, 2, 3, 4, 5, 1.0, 3.0, 6.0, 10.0, 15.0]
[1, 2, 3, 4, 5, 1.0, 3.0, 6.0, 10.0, 15.0, 1.0]
[1, 2, 3, 4, 5, 1.0, 3.0, 6.0, 10.0, 15.0, 1.0, 6.0]
[1, 2, 3, 4, 5, 1.0, 3.0, 6.0, 10.0, 15.0, 1.0, 6.0, 21.0]
[1, 2, 3, 4, 5, 1.0, 3.0, 6.0, 10.0, 15.0, 1.0, 6.0, 21.0, 55.0]
[1, 2, 3, 4, 5, 1.0, 3.0, 6.0, 10.0, 15.0, 1.0, 6.0, 21.0, 55.0, 120.0]
[1, 2, 3, 4, 5, 1.0, 3.0, 6.0, 10.0, 15.0, 1.0, 6.0, 21.0, 55.0, 120.0, 1.0]
[1, 2, 3, 4, 5, 1.0, 3.0, 6.0, 10.0, 15.0, 1.0, 6.0, 21.0, 55.0, 120.0, 1.0, 21.0]
[1, 2, 3, 4, 5, 1.0, 3.0, 6.0, 10.0, 15.0, 1.0, 6.0, 21.0, 55.0, 120.0, 1.0, 21.0, 231.0]
[1, 2, 3, 4, 5, 1.0, 3.0, 6.0, 10.0, 15.0, 1.0, 6.0, 21.0, 55.0, 120.0, 1.0, 21.0, 231.0, 1540.0]
[1, 2, 3, 4, 5, 1.0, 3.0, 6.0, 10.0, 15.0, 1.0, 6.0, 21.0, 55.0, 120.0, 1.0, 21.0, 231.0, 1540.0, 7260.0]
[1, 2, 3, 4, 5, 1.0, 3.0, 6.0, 10.0, 15.0, 1.0, 6.0, 21.0, 55.0, 120.0, 1.0, 21.0, 231.0, 1540.0, 7260.0, 1.0]
append simply adds a new value to the end of a list, so what you've done is created an infinite loop where x is just going to grow bigger and bigger. Basically every time the iterator draws a number from x a new number is added to the end of x, so the iterator will always have 5 more numbers to draw before it completes.
As the iterator keeps running, x keeps getting bigger and bigger and consuming more and more memory.
To fix this infinite loop you can either store the results in a different list or have a break condition like I used above if you really want the results to be appended to x. Also, if you are meaning to replace the values in x you can do something like this
x = [1,2,3,4,5]
for i, v in enumerate(x):
x[i] = (v * (v + 1))/2
print(x)
which outputs
[1.0, 3.0, 6.0, 10.0, 15.0]
Hope that helps.

Incorrectly rendering Isocahedron in OpenGL

I'm trying to draw an Isocahedron in OpenGL with c++. I keep getting close but having some missing faces. I have found 3 different sets of vertex/index data on multiple sites, most often the data listed below
float X = 0.525731112119133606f;
float Z = 0.850650808352039932f;
float temppts[12][3] = { { -X, 0.0f, Z }, { X, 0.0f, Z }, { -X, 0.0f, -Z }, { X, 0.0f, -Z },
{ 0.0f, Z, X }, { 0.0f, Z, -X }, { 0.0f, -Z, X }, { 0.0f, -Z, -X },
{ Z, X, 0.0f }, { -Z, X, 0.0f }, { Z, -X, 0.0f }, { -Z, -X, 0.0f } };
GLushort tempindicies[60] =
{ 1, 4, 0, 4, 9, 0, 4, 5, 9, 8, 5, 4, 1, 8, 4,
1, 10, 8, 10, 3, 8, 8, 3, 5, 3, 2, 5, 3, 7, 2,
3, 10, 7, 10, 6, 7, 6, 11, 7, 6, 0, 11, 6, 1, 0,
10, 1, 6, 11, 0, 9, 2, 11, 9, 5, 2, 9, 11, 2, 7};
This code is adapted from a book and multiple sites display it working, though they are drawing immediate and I'm using vbo/ibo. Can anyone point me to some working vertex/index data or tell me what is going wrong transferring this to buffer objects? The three different data all have differently incorrect icosahedrons, each with different faces missing.
I have checked over my bufferData calls many times and tried several drawing modes ( TRIANGLES, TRIANGLE_STRIP ... ) and am convinced the index data is wrong somehow
I used the mesh coordinates (vertices) and the triangle connectivity from Platonic Solids (scroll down to icosahedron). I've pasted a screen shot from that file below. When calling glDrawElements I used GL_TRIANGLES.
Icosahedron
Another thing to watch out for is back face culling. Initially switch off backface culling.
glDisable(GL_CULL_FACE);