Appreciate the quick reply.
Don’t believe they make a valid triangle nor valid line. But for the code:
- (void)drawRect:(NSRect)dirtyRect
{
//NSLog(@"Redraw");
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glShadeModel(GL_SMOOTH);
glEnable(GL_POLYGON_SMOOTH);
glPolygonMode(GL_FRONT, GL_POINTS);
// clear our drawable
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
Vector3 color = {1.0f,0.85f,0.35f};
[self drawAnObject:hair color:color imageName:nil];
color.x = 1.0f; color.y = 0.0f; color.z = 0.0f;
[self drawAnObject:head color:color imageName:@"face.png"];
// color.x = 1.0f; color.y = 0.85f; color.z = 0.35f;
// [self drawAnObject:eye color:color imageName:nil];
color.x = 0.0f; color.y = 1.0f; color.z = 0.0f;
[self drawAnObject:upper_body color:color imageName:@"upper.png"];
color.x = 0.0f; color.y = 0.0f; color.z = 1.0f;
[self drawAnObject:lower_body color:color imageName:@"lower.png"];
// color.x = 1.0f; color.y = 0.85f; color.z = 0.35f;
// [self drawAnObject:skirt color:color imageName:nil];
if ([self inLiveResize] && !fAnimate)
glFlush ();
else
[[self openGLContext] flushBuffer];
//glReportError ();
}
// ---------------------------------
- (void) drawAnObject:(PolyMesh *)polyMesh color:(Vector3)color imageName:(NSString *)imageName
{
if (imageName != nil) {
// allocate a texture name
glGenTextures( 1, &textureid );
// blending
glEnable( GL_TEXTURE_2D );
// load the texture
NSString *filePath = [[NSBundle mainBundle] pathForResource:[imageName stringByDeletingPathExtension] ofType:[imageName pathExtension]];
textureid = SOIL_load_OGL_texture([filePath UTF8String], SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y);
if (0 == textureid) {
NSLog(@"Failed to load texture %@!", imageName);
} else {
NSLog(@"Loaded texture %@!", imageName);
glBindTexture(GL_TEXTURE_2D, textureid);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
//glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTexCoordPointer(2, GL_FLOAT, 0, polyMesh.single_texCoords);
}
} else {
NSLog(@"Texture passed as nil.");
}
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, polyMesh.single_normals);
glVertexPointer(3, GL_FLOAT, 0, polyMesh.single_vertices);
glColor3f(color.x,color.y,color.z);
glDrawArrays(GL_LINES, 0, polyMesh.numVertices);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
if (imageName != nil) {
if (0 != textureid) {
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDeleteTextures(1, &textureid);
}
}
}
Thank you.