nuero
2006.07.05, 03:37 PM
I downloaded NSGLImage from the mac site, but it will only load po2 textures. If I attempt to load a NPO2 image, it displays the image in a distorted unrecognizable way.
I am using a powerBook G4 with a GeForce4 MX. I also downloaded glview and it lists GL_TEXTURE_RECTANGLE_EXT as one of the enxtensions I have.
I need to be able to load npo2 textures. I have tried several other techniques all without success. Any help would be greatly appreciated.
here is a portion of the code
-(void)loadTextureFromFile:(NSString*)filePath;
{
// First, deallocate any image reps we might have.
if(bmpRep)
{
[bmpRep release];
// We also need to delete our texture ID
glDeleteTextures(1, &txID);
}
if(!filePath)
return;
// Get raw bitmap data from the NSImage
bmpRep = [[NSBitmapImageRep imageRepWithContentsOfFile:filePath] retain];
// Set the image height & width for convenience
imgWidth = [bmpRep size].width;
imgHeight = [bmpRep size].height;
[self genImageInfo:[filePath lastPathComponent]];
// Set our scaling factors
scaleX = imgWidth / scaleFactor;
scaleY = imgHeight / scaleFactor;
NSLog(@"Image: %d x %d", imgWidth, imgHeight);
[self getTextureInfo];
// Run through our initialization routine
[self initGL];
}
-(void)initGL
{
GLuint err = 0;
// Enable texturing
glEnable(GL_TEXTURE_RECTANGLE_EXT);
// Enable client storage
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 1);
glPixelStorei(GL_UNPACK_ROW_LENGTH, imgWidth);
// Generate a texture ID
glGenTextures(1, &txID);
// Bind to our newly created texture ID
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, txID);
// Specify the texture
glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, bpp, imgWidth, imgHeight, 0, GL_RGB, datatype, [bmpRep bitmapData]);
err = glGetError();
if(err)
{
NSLog(@"WARNING: OpenGL Error 0x%x while loading texture with glTexImage2D().", err);
[self discardData];
ready = NO;
return;
}
// Rebuild our geometry to match the texture
[self genQuad];
ready = YES;
}
-(void)drawTexture
{
// Bail if our image rep is invalid
if(!bmpRep)
return;
// Bail out if we have no image data
if(![bmpRep bitmapData])
return;
// Shut off depth and face culling
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
// Enable texturing
glEnable(GL_TEXTURE_RECTANGLE_EXT);
// Make sure we've got the right texture
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, txID);
// Set color so we get full display
glColor4f(1.0, 1.0, 1.0, 1.0);
// Draw it!
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); // Lower Left
glVertex3f(glQuad[0].x, glQuad[0].y, glQuad[0].z); // Upper Right
glTexCoord2f(imgWidth, 0.0); // Lower Right
glVertex3f(glQuad[1].x, glQuad[1].y, glQuad[1].z); // Upper Left
glTexCoord2f(imgWidth, imgHeight); // Upper Right
glVertex3f(glQuad[2].x, glQuad[2].y, glQuad[2].z); // Lower Left
glTexCoord2f(0.0, imgHeight); // Upper Left
glVertex3f(glQuad[3].x, glQuad[3].y, glQuad[3].z); // Lower Right
glEnd();
// Gotta turn this off here, or we die
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 0);
// Turn all the other stuff back on
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glEnable(GL_CULL_FACE);
// Reset the blending function to its previous state
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
I am using a powerBook G4 with a GeForce4 MX. I also downloaded glview and it lists GL_TEXTURE_RECTANGLE_EXT as one of the enxtensions I have.
I need to be able to load npo2 textures. I have tried several other techniques all without success. Any help would be greatly appreciated.
here is a portion of the code
-(void)loadTextureFromFile:(NSString*)filePath;
{
// First, deallocate any image reps we might have.
if(bmpRep)
{
[bmpRep release];
// We also need to delete our texture ID
glDeleteTextures(1, &txID);
}
if(!filePath)
return;
// Get raw bitmap data from the NSImage
bmpRep = [[NSBitmapImageRep imageRepWithContentsOfFile:filePath] retain];
// Set the image height & width for convenience
imgWidth = [bmpRep size].width;
imgHeight = [bmpRep size].height;
[self genImageInfo:[filePath lastPathComponent]];
// Set our scaling factors
scaleX = imgWidth / scaleFactor;
scaleY = imgHeight / scaleFactor;
NSLog(@"Image: %d x %d", imgWidth, imgHeight);
[self getTextureInfo];
// Run through our initialization routine
[self initGL];
}
-(void)initGL
{
GLuint err = 0;
// Enable texturing
glEnable(GL_TEXTURE_RECTANGLE_EXT);
// Enable client storage
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 1);
glPixelStorei(GL_UNPACK_ROW_LENGTH, imgWidth);
// Generate a texture ID
glGenTextures(1, &txID);
// Bind to our newly created texture ID
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, txID);
// Specify the texture
glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, bpp, imgWidth, imgHeight, 0, GL_RGB, datatype, [bmpRep bitmapData]);
err = glGetError();
if(err)
{
NSLog(@"WARNING: OpenGL Error 0x%x while loading texture with glTexImage2D().", err);
[self discardData];
ready = NO;
return;
}
// Rebuild our geometry to match the texture
[self genQuad];
ready = YES;
}
-(void)drawTexture
{
// Bail if our image rep is invalid
if(!bmpRep)
return;
// Bail out if we have no image data
if(![bmpRep bitmapData])
return;
// Shut off depth and face culling
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
// Enable texturing
glEnable(GL_TEXTURE_RECTANGLE_EXT);
// Make sure we've got the right texture
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, txID);
// Set color so we get full display
glColor4f(1.0, 1.0, 1.0, 1.0);
// Draw it!
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); // Lower Left
glVertex3f(glQuad[0].x, glQuad[0].y, glQuad[0].z); // Upper Right
glTexCoord2f(imgWidth, 0.0); // Lower Right
glVertex3f(glQuad[1].x, glQuad[1].y, glQuad[1].z); // Upper Left
glTexCoord2f(imgWidth, imgHeight); // Upper Right
glVertex3f(glQuad[2].x, glQuad[2].y, glQuad[2].z); // Lower Left
glTexCoord2f(0.0, imgHeight); // Upper Left
glVertex3f(glQuad[3].x, glQuad[3].y, glQuad[3].z); // Lower Right
glEnd();
// Gotta turn this off here, or we die
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 0);
// Turn all the other stuff back on
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glEnable(GL_CULL_FACE);
// Reset the blending function to its previous state
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}