I am trying to figure out this crazy world of OpenGL, specifically on mac and iphone.
I have a function that takes a path to a image and turns it into an opengl texture. bmp seems to work fine but not png. The problem is that when I use NSBitmapImageRep to get the pixel data which represents it as having one pane. the cautionary if statement blocks any weird stuff from happening.
I have a function that takes a path to a image and turns it into an opengl texture. bmp seems to work fine but not png. The problem is that when I use NSBitmapImageRep to get the pixel data which represents it as having one pane. the cautionary if statement blocks any weird stuff from happening.
Code:
- (void)textureFromPath:(NSString *)path textureID:(GLuint *)texName {
NSBitmapImageRep *bitmap = [NSBitmapImageRep imageRepWithContentsOfFile:path];
int samplesPerPixel = 0;
//glPixelStorei(GL_UNPACK_ROW_LENGTH, [bitmap pixelsWide]); // 4
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // 5
if (*texName == 0)
glGenTextures (1, texName);
glBindTexture(GL_TEXTURE_2D, *texName);
//glBindTexture(GL_TEXTURE_RECTANGLE_ARB, *texName);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,
GL_TEXTURE_MIN_FILTER, GL_LINEAR);
samplesPerPixel = [bitmap samplesPerPixel];
if(![bitmap isPlanar] &&
(samplesPerPixel == 3 || samplesPerPixel == 4)) {
glTexImage2D(GL_TEXTURE_2D, //GL_TEXTURE_RECTANGLE_ARB,
0,
samplesPerPixel == 4 ? GL_RGBA8 : GL_RGB8,
[bitmap pixelsWide],
[bitmap pixelsHigh],
0,
samplesPerPixel == 4 ? GL_RGBA : GL_RGB,
GL_UNSIGNED_BYTE,
[bitmap bitmapData]);
}
[bitmap release];
}