Hi All,
I'm playing around with a new idea for a game, and would really like to use 3D sprites. The game mechanics themselves will work just fine in 2D, I just want to give it all a bit more depth.
So after searching these forums, and google, I found Jeff LaMarche's Blender Exporter, and his sample iPhone project (with the ship - http://iphonedevelopment.blogspot.com/2009/07/fixed-improved-blender-export-script.html).
I also found this forum thread... http://www.cocos2d-iphone.org/forum/topic/743 , which had some helpful pointers...
So as a quick test, I grabbed the ship.h file and texture from Jeff's sample (above), created a CCLayer subclass, and overrode the "init" and "draw" methods with the following, but it just crashes on glDrawArrays() with "EXC_BAD_ACCESS"...
- (id)init{
if( (self=[super init]) ) {
OpenGLTexture3D *theTexture = [[OpenGLTexture3D alloc] initWithFilename:@"texture.jpg" width:512 height:512];
self.texture = theTexture;
[theTexture release];
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
return self;
}
- (void)draw{
glColor4f(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self.texture bind];
//glBindTexture(GL_TEXTURE_2D, self.texture);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnable(GL_BLEND);
//glBindTexture(GL_TEXTURE_2D, self.texture);
glVertexPointer(3, GL_FLOAT, 0, &CubeVertexData[0].vertex);
glNormalPointer(GL_FLOAT, 0, &CubeVertexData[0].normal);
glTexCoordPointer(2, GL_FLOAT, 0, &CubeVertexData[0].texCoord);
glDrawArrays(GL_TRIANGLES, 0, kCubeNumberOfVertices);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}
I'm afraid my OpenGL is still quite flaky, as I've so far had no need to understand it. I can see this changing soon though...
Could anyone help me out please?
Thanks,
Dunc.