I am using the following link for source code for drawing a 3D cube in iOS.
http://www.raywenderlich.com/5235/beginning-opengl-es-2-0-with-glkit-part-2
Here is a code snippet of my update routine:
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {
glClearColor(30/255.0, 30/255.0, 30/255.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
// Enable transparency
//glEnable(GL_BLEND);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
[[self effect] prepareToDraw];
glBindVertexArrayOES(_vertexArray);
glDrawElements(GL_TRIANGLES, sizeof(Indices)/sizeof(Indices[0]), GL_UNSIGNED_BYTE, 0);
// Cleanup: Done with the current blend function
//glDisable(GL_BLEND);
}
I am trying to create a cube with a texture that has transparency, and ultimately draw the underlying faces. I've attached my actual texture. What it looks like right now is a cube showing all faces with no transparency showing the underlying faces. If I uncomment the blend routines, it draws a transparent cube that blends on the background, but the other faces.
Here's part of how I load my texture:
_effect = [[GLKBaseEffect alloc] init];
NSDictionary * options = @{ GLKTextureLoaderOriginBottomLeft: @YES };
NSError *error;
NSString *path = [[NSBundle mainBundle] pathForResource:@"Texture200x200" ofType:@"png"];
GLKTextureInfo *info = [GLKTextureLoader textureWithContentsOfFile:path options:options error:&error];
if (info == nil) {
NSLog(@"Error loading file: %@", error.localizedDescription);
}
[[[self effect] texture2d0] setName:info.name];
[[[self effect] texture2d0] setEnabled:YES];
[[[self effect] texture2d0] setEnvMode:GLKTextureEnvModeDecal];
The texture is just a poka-dot texture with solid dots and the negative space being completely transparent. I am very new to openGL. Thank you for the help!
I am including a link of what I am trying to accomplish. Just to close to the end, and you'll see how the textures are blending together.