Hi all. I’m new to OpenGL ES development, and I’m having some serious issues getting what I would assume to be a relatively simple task completed. I’m attempting to render a “coin” and make it spin. The issue comes about when I add lighting(or a texture) to the model, at certain perspectives it has enormous errors in the model, and almost appears that the front faces are dissappearing/reappering allowing the back faces to “shine through”.
Example:
[attachment=2:1jrpk1i8]Picture 2.png[/attachment:1jrpk1i8]
[attachment=1:1jrpk1i8]Picture 3.png[/attachment:1jrpk1i8]
[attachment=0:1jrpk1i8]Picture 4.png[/attachment:1jrpk1i8]
Here’s the code(this is on an iPhone, so opengl ES 1.1), the snippet is from my run loop(gets called ~60 times per second)
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glViewport(0, 0, backingWidth, backingHeight);
static GLfloat VertexData[] = {
-1.00000f, 0.000000f, 8.74228e-008f, -1.00000f, 0.000000f, 8.74228e-008f, -1.00000f, 0.100000f, 8.74228e-008f,
-1.00000f, 0.100000f, 8.74228e-008f, -0.965926f, 0.000000f, -0.258819f,
-0.965926f, 0.000000f, -0.258819f, -0.965926f, 0.100000f, -0.258819f,
-0.965926f, 0.100000f, -0.258819f, -0.965926f, 0.000000f, 0.258819f,
-0.965926f, 0.000000f, 0.258819f, -0.965926f, 0.100000f, 0.258819f,
-0.965926f, 0.100000f, 0.258819f, -0.866025f, 0.000000f, -0.500000f,
-0.866025f, 0.000000f, -0.500000f, -0.866025f, 0.100000f, -0.500000f,
-0.866025f, 0.100000f, -0.500000f, -0.866025f, 0.000000f, 0.500000f,
-0.866025f, 0.000000f, 0.500000f, -0.866025f, 0.100000f, 0.500000f,
-0.866025f, 0.100000f, 0.500000f, -0.707107f, 0.000000f, -0.707107f,
-0.707107f, 0.000000f, -0.707107f, -0.707107f, 0.100000f, -0.707107f,
-0.707107f, 0.100000f, -0.707107f, -0.707107f, 0.000000f, 0.707107f,
-0.707107f, 0.000000f, 0.707107f, -0.707107f, 0.100000f, 0.707107f,
-0.707107f, 0.100000f, 0.707107f, -0.500000f, 0.000000f, -0.866025f,
-0.500000f, 0.000000f, -0.866025f, -0.500000f, 0.100000f, -0.866025f,
-0.500000f, 0.100000f, -0.866025f, -0.500000f, 0.000000f, 0.866025f,
-0.500000f, 0.000000f, 0.866025f, -0.500000f, 0.100000f, 0.866025f,
-0.500000f, 0.100000f, 0.866025f, -0.258819f, 0.000000f, -0.965926f,
-0.258819f, 0.000000f, -0.965926f, -0.258819f, 0.100000f, -0.965926f,
-0.258819f, 0.100000f, -0.965926f, -0.258819f, 0.100000f, -0.965926f,
-0.258819f, 0.000000f, 0.965926f, -0.258819f, 0.000000f, 0.965926f,
-0.258819f, 0.100000f, 0.965926f, -0.258819f, 0.100000f, 0.965926f,
-4.37114e-008f, 0.000000f, -1.00000f, -4.37114e-008f, 0.000000f, -1.00000f,
-4.37114e-008f, 0.100000f, -1.00000f, -4.37114e-008f, 0.100000f, -1.00000f,
-4.37114e-008f, 0.100000f, -1.00000f, 0.000000f, 0.000000f, 0.000000f,
0.000000f, 0.100000f, 0.000000f, 0.000000f, 0.100000f, 0.000000f,
0.000000f, 0.100000f, 0.000000f, 1.31134e-007f, 0.000000f, 1.00000f,
1.31134e-007f, 0.000000f, 1.00000f, 1.31134e-007f, 0.100000f, 1.00000f,
1.31134e-007f, 0.100000f, 1.00000f, 1.31134e-007f, 0.100000f, 1.00000f,
0.258819f, 0.000000f, -0.965926f, 0.258819f, 0.000000f, -0.965926f,
0.258819f, 0.100000f, -0.965926f, 0.258819f, 0.100000f, -0.965926f,
0.258819f, 0.000000f, 0.965926f, 0.258819f, 0.000000f, 0.965926f,
0.258819f, 0.100000f, 0.965926f, 0.258819f, 0.100000f, 0.965926f,
0.258819f, 0.100000f, 0.965926f, 0.500000f, 0.000000f, -0.866025f,
0.500000f, 0.000000f, -0.866025f, 0.500000f, 0.100000f, -0.866025f,
0.500000f, 0.100000f, -0.866025f, 0.500000f, 0.000000f, 0.866025f,
0.500000f, 0.000000f, 0.866025f, 0.500000f, 0.100000f, 0.866025f,
0.500000f, 0.100000f, 0.866025f, 0.707107f, 0.000000f, -0.707107f,
0.707107f, 0.000000f, -0.707107f, 0.707107f, 0.100000f, -0.707107f,
0.707107f, 0.100000f, -0.707107f, 0.707107f, 0.000000f, 0.707107f,
0.707107f, 0.000000f, 0.707107f, 0.707107f, 0.100000f, 0.707107f,
0.707107f, 0.100000f, 0.707107f, 0.866025f, 0.000000f, -0.500000f,
0.866025f, 0.000000f, -0.500000f, 0.866025f, 0.100000f, -0.500000f,
0.866025f, 0.100000f, -0.500000f, 0.866026f, 0.000000f, 0.500000f,
0.866026f, 0.000000f, 0.500000f, 0.866026f, 0.100000f, 0.500000f,
0.866026f, 0.100000f, 0.500000f, 0.965926f, 0.000000f, -0.258819f,
0.965926f, 0.000000f, -0.258819f, 0.965926f, 0.100000f, -0.258819f,
0.965926f, 0.100000f, -0.258819f, 0.965926f, 0.000000f, 0.258819f,
0.965926f, 0.000000f, 0.258819f, 0.965926f, 0.100000f, 0.258819f,
0.965926f, 0.100000f, 0.258819f, 1.00000f, 0.000000f, -1.74846e-007f,
1.00000f, 0.000000f, -1.74846e-007f, 1.00000f, 0.000000f, -1.74846e-007f,
1.00000f, 0.100000f, -1.74846e-007f, 1.00000f, 0.100000f, -1.74846e-007f,
1.00000f, 0.100000f, -1.74846e-007f
};
static GLfloat NormalData[] = {
0.000000f, -1.00000f, 0.000000f, -1.00000f, 0.000000f, 8.74228e-008f, 0.000000f, 1.00000f, 0.000000f,
-1.00000f, 0.000000f, 8.74228e-008f, 0.000000f, -1.00000f, 0.000000f,
-0.965926f, 0.000000f, -0.258819f, 0.000000f, 1.00000f, 0.000000f,
-0.965926f, 0.000000f, -0.258819f, 0.000000f, -1.00000f, 0.000000f,
-0.965926f, 0.000000f, 0.258819f, 0.000000f, 1.00000f, 0.000000f,
-0.965926f, 0.000000f, 0.258819f, 0.000000f, -1.00000f, 0.000000f,
-0.866025f, 0.000000f, -0.500000f, 0.000000f, 1.00000f, 0.000000f,
-0.866025f, 0.000000f, -0.500000f, 0.000000f, -1.00000f, 0.000000f,
-0.866025f, 0.000000f, 0.500000f, 0.000000f, 1.00000f, 0.000000f,
-0.866025f, 0.000000f, 0.500000f, 0.000000f, -1.00000f, 0.000000f,
-0.707107f, 0.000000f, -0.707107f, 0.000000f, 1.00000f, 0.000000f,
-0.707107f, 0.000000f, -0.707107f, 0.000000f, -1.00000f, 0.000000f,
-0.707107f, 0.000000f, 0.707107f, 0.000000f, 1.00000f, 0.000000f,
-0.707107f, 0.000000f, 0.707107f, 0.000000f, -1.00000f, 0.000000f,
-0.500000f, 0.000000f, -0.866025f, 0.000000f, 1.00000f, 0.000000f,
-0.500000f, 0.000000f, -0.866025f, 0.000000f, -1.00000f, 0.000000f,
-0.500000f, 0.000000f, 0.866025f, 0.000000f, 1.00000f, 0.000000f,
-0.500000f, 0.000000f, 0.866025f, 0.000000f, -1.00000f, 0.000000f,
-0.258819f, 0.000000f, -0.965926f, 0.000000f, 1.00000f, 0.000000f,
0.000000f, 1.00000f, -1.14237e-017f, -0.258819f, 0.000000f, -0.965926f,
0.000000f, -1.00000f, 0.000000f, -0.258819f, 0.000000f, 0.965926f,
0.000000f, 1.00000f, 0.000000f, -0.258819f, 0.000000f, 0.965926f,
0.000000f, -1.00000f, 0.000000f, -4.37114e-008f, 0.000000f, -1.00000f,
0.000000f, 1.00000f, -1.14237e-017f, 0.000000f, 1.00000f, 0.000000f,
-4.37114e-008f, 0.000000f, -1.00000f, 0.000000f, -1.00000f, 0.000000f,
0.000000f, 1.00000f, 1.28232e-017f, 0.000000f, 1.00000f, -1.14237e-017f,
0.000000f, 1.00000f, 0.000000f, 0.000000f, -1.00000f, 0.000000f,
1.31134e-007f, 0.000000f, 1.00000f, 0.000000f, 1.00000f, 1.28232e-017f,
0.000000f, 1.00000f, 0.000000f, 1.31134e-007f, 0.000000f, 1.00000f,
0.000000f, -1.00000f, 0.000000f, 0.258819f, 0.000000f, -0.965926f,
0.000000f, 1.00000f, 0.000000f, 0.258819f, 0.000000f, -0.965926f,
0.000000f, -1.00000f, 0.000000f, 0.258819f, 0.000000f, 0.965926f,
0.000000f, 1.00000f, 0.000000f, 0.000000f, 1.00000f, 1.28232e-017f,
0.258819f, 0.000000f, 0.965926f, 0.000000f, -1.00000f, 0.000000f,
0.500000f, 0.000000f, -0.866025f, 0.000000f, 1.00000f, 0.000000f,
0.500000f, 0.000000f, -0.866025f, 0.000000f, -1.00000f, 0.000000f,
0.500000f, 0.000000f, 0.866025f, 0.000000f, 1.00000f, 0.000000f,
0.500000f, 0.000000f, 0.866025f, 0.000000f, -1.00000f, 0.000000f,
0.707107f, 0.000000f, -0.707107f, 0.000000f, 1.00000f, 0.000000f,
0.707107f, 0.000000f, -0.707107f, 0.000000f, -1.00000f, 0.000000f,
0.707107f, 0.000000f, 0.707107f, 0.000000f, 1.00000f, 0.000000f,
0.707107f, 0.000000f, 0.707107f, 0.000000f, -1.00000f, 0.000000f,
0.866025f, 0.000000f, -0.500000f, 0.000000f, 1.00000f, 0.000000f,
0.866025f, 0.000000f, -0.500000f, 0.000000f, -1.00000f, 0.000000f,
0.866026f, 0.000000f, 0.500000f, 0.000000f, 1.00000f, 0.000000f,
0.866026f, 0.000000f, 0.500000f, 0.000000f, -1.00000f, 0.000000f,
0.965926f, 0.000000f, -0.258819f, 0.000000f, 1.00000f, 0.000000f,
0.965926f, 0.000000f, -0.258819f, 0.000000f, -1.00000f, 0.000000f,
0.965926f, 0.000000f, 0.258819f, 0.000000f, 1.00000f, 0.000000f,
0.965926f, 0.000000f, 0.258819f, 1.00000f, 0.000000f, -1.74846e-007f,
0.000000f, -1.00000f, 0.000000f, 1.00000f, 0.000000f, -1.74846e-007f,
1.00000f, 0.000000f, -1.74846e-007f, 0.000000f, 1.00000f, 0.000000f,
1.00000f, 0.000000f, -1.74846e-007f
};
static GLfloat TexCoordData[] = {
0.000000f, 0.000000f, 0.500000f, 0.000000f, 0.000000f, 0.000000f,
0.500000f, 1.00000f, 0.000000f, 0.000000f,
0.458333f, 0.000000f, 0.000000f, 0.000000f,
0.458333f, 1.00000f, 0.000000f, 0.000000f,
0.541667f, 0.000000f, 0.000000f, 0.000000f,
0.541667f, 1.00000f, 0.000000f, 0.000000f,
0.416667f, 0.000000f, 0.000000f, 0.000000f,
0.416667f, 1.00000f, 0.000000f, 0.000000f,
0.583333f, 0.000000f, 0.000000f, 0.000000f,
0.583333f, 1.00000f, 0.000000f, 0.000000f,
0.375000f, 0.000000f, 0.000000f, 0.000000f,
0.375000f, 1.00000f, 0.000000f, 0.000000f,
0.625000f, 0.000000f, 0.000000f, 0.000000f,
0.625000f, 1.00000f, 0.000000f, 0.000000f,
0.333333f, 0.000000f, 0.000000f, 0.000000f,
0.333333f, 1.00000f, 0.000000f, 0.000000f,
0.666667f, 0.000000f, 0.000000f, 0.000000f,
0.666667f, 1.00000f, 0.000000f, 0.000000f,
0.291667f, 0.000000f, 0.000000f, 0.000000f,
0.000000f, 0.000000f, 0.291667f, 1.00000f,
0.000000f, 0.000000f, 0.708333f, 0.000000f,
0.000000f, 0.000000f, 0.708333f, 1.00000f,
0.000000f, 0.000000f, 0.250000f, 0.000000f,
0.000000f, 0.000000f, 0.000000f, 0.000000f,
0.250000f, 1.00000f, 0.000000f, 0.000000f,
0.000000f, 0.000000f, 0.000000f, 0.000000f,
0.000000f, 0.000000f, 0.000000f, 0.000000f,
0.750000f, 0.000000f, 0.000000f, 0.000000f,
0.000000f, 0.000000f, 0.750000f, 1.00000f,
0.000000f, 0.000000f, 0.208333f, 0.000000f,
0.000000f, 0.000000f, 0.208333f, 1.00000f,
0.000000f, 0.000000f, 0.791667f, 0.000000f,
0.000000f, 0.000000f, 0.000000f, 0.000000f,
0.791667f, 1.00000f, 0.000000f, 0.000000f,
0.166667f, 0.000000f, 0.000000f, 0.000000f,
0.166667f, 1.00000f, 0.000000f, 0.000000f,
0.833333f, 0.000000f, 0.000000f, 0.000000f,
0.833333f, 1.00000f, 0.000000f, 0.000000f,
0.125000f, 0.000000f, 0.000000f, 0.000000f,
0.125000f, 1.00000f, 0.000000f, 0.000000f,
0.875000f, 0.000000f, 0.000000f, 0.000000f,
0.875000f, 1.00000f, 0.000000f, 0.000000f,
0.0833333f, 0.000000f, 0.000000f, 0.000000f,
0.0833333f, 1.00000f, 0.000000f, 0.000000f,
0.916667f, 0.000000f, 0.000000f, 0.000000f,
0.916667f, 1.00000f, 0.000000f, 0.000000f,
0.0416667f, 0.000000f, 0.000000f, 0.000000f,
0.0416667f, 1.00000f, 0.000000f, 0.000000f,
0.958333f, 0.000000f, 0.000000f, 0.000000f,
0.958333f, 1.00000f, 1.00000f, 0.000000f,
0.000000f, 0.000000f, 0.000000f, 0.000000f,
1.00000f, 1.00000f, 0.000000f, 0.000000f,
0.000000f, 1.00000f
};
static GLint Indices[] = {
93, 95, 105, 93, 105, 102, 92, 101, 50, 104, 94, 53, 85, 87, 95, 85,
95, 93, 84, 92, 50, 94, 86, 53, 77, 79, 87, 77, 87, 85, 76, 84,
50, 86, 78, 53, 69, 71, 79, 69, 79, 77, 68, 76, 50, 78, 70, 53,
60, 62, 71, 60, 71, 69, 59, 68, 50, 70, 61, 53, 46, 49, 62, 46,
62, 60, 45, 59, 50, 61, 48, 53, 37, 40, 49, 37, 49, 46, 36, 45,
50, 47, 39, 52, 29, 31, 40, 29, 40, 37, 28, 36, 50, 38, 30, 53,
21, 23, 31, 21, 31, 29, 20, 28, 50, 30, 22, 53, 13, 15, 23, 13,
23, 21, 12, 20, 50, 22, 14, 53, 5, 7, 15, 5, 15, 13, 4, 12,
50, 14, 6, 53, 1, 3, 7, 1, 7, 5, 0, 4, 50, 6, 2, 53,
9, 11, 3, 9, 3, 1, 8, 0, 50, 2, 10, 53, 17, 19, 11, 17,
11, 9, 16, 8, 50, 10, 18, 53, 25, 27, 19, 25, 19, 17, 24, 16,
50, 18, 26, 53, 33, 35, 27, 33, 27, 25, 32, 24, 50, 26, 34, 53,
42, 44, 35, 42, 35, 33, 41, 32, 50, 34, 43, 53, 55, 58, 44, 55,
44, 42, 54, 41, 50, 43, 57, 53, 64, 67, 58, 64, 58, 55, 63, 54,
50, 56, 66, 51, 73, 75, 67, 73, 67, 64, 72, 63, 50, 65, 74, 53,
81, 83, 75, 81, 75, 73, 80, 72, 50, 74, 82, 53, 89, 91, 83, 89,
83, 81, 88, 80, 50, 82, 90, 53, 97, 99, 91, 97, 91, 89, 96, 88,
50, 90, 98, 53, 100, 103, 99, 100, 99, 97, 101, 96, 50, 98, 104, 53
};
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, TexCoordData);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, NormalData);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, VertexData);
glBindTexture(GL_TEXTURE_2D, texture);
glRotatef(1.5f, 0.1f, 0.1f, 0.0f);
for(int i = 0; i < sizeof(Indices) / sizeof(GL_UNSIGNED_SHORT); i += 3)
{
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, &Indices[i]);
}
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
in my setup function i configure lighting with:
const GLfloat lightAmbient[] = {0.2, 0.2, 0.2, 1.0};
const GLfloat lightDiffuse[] = {1.0, 0.6, 0.0, 1.0};
const GLfloat matAmbient[] = {0.6, 0.6, 0.6, 1.0};
const GLfloat matDiffuse[] = {1.0, 1.0, 1.0, 1.0};
const GLfloat matSpecular[] = {1.0, 1.0, 1.0, 1.0};
const GLfloat lightPosition[] = {0.0, 0.0, 1.0, 0.0};
const GLfloat lightShininess = 100.0;
//Configure OpenGL lighting
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matAmbient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matDiffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matSpecular);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, lightShininess);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
any help, or hints, or berating for me for being a complete moron would be much appreciated
-pete