Loading Texture
I've been reading through the forums and Apples dev site, but I am stumped. I am trying to load an image using QT graphics import and then load the image as a GL texture. Below is my QT graphics importer. This works without an issue.
The trouble I am having is then loading the image into a texture. I am really new with OpenGL so any help would be greatly appreciated. The code below is modified from NeHe, but I'm not sure what I am doing wrong.
I'm not sure what I may be doing wrong.
Code:
typedef struct {
size_t width;
size_t height;
size_t bitsPerComponent;
size_t bitsPerPixel;
size_t bytesPerRow;
size_t size;
CGImageAlphaInfo ai;
unsigned char *data;
} BitmapInfo;
OSErr GetBitmapFileFromPStr( Str255 str, BitmapInfo *bi )
{
FSSpec fss = ReadFile( str );
OSErr err;
GraphicsImportComponent gi;
err = GetGraphicsImporterForFile(&fss, &gi);
readBitmapInfo(gi, bi);
getBitmapData(gi, bi);
CloseComponent(gi);
return err;
}The trouble I am having is then loading the image into a texture. I am really new with OpenGL so any help would be greatly appreciated. The code below is modified from NeHe, but I'm not sure what I am doing wrong.
Code:
BitmapInfo *TextureImage;
GLuint texture;
memset(TextureImage, 0, sizeof(void *)*2);
GetBitmapFileFromPStr( "\pFont.sgi", TextureImage );
glGenTextures(1, &texture); // Create The Texture
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage->width, TextureImage->height, 0,
GL_RGB, GL_UNSIGNED_BYTE, TextureImage->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);I'm not sure what I may be doing wrong.
aside from the fact that that snippet is missing all the relevant code, why not search the forums? This question is answered at least twice a week...
You may want to download the source code from http://www.angelfire.com/mac2/yexi/Basic...Struct.dmg
There, you will find a texture loader that works with JPG, PNG, or TGA.
There, you will find a texture loader that works with JPG, PNG, or TGA.
Thanks for the above link. I was able to take my code to create a CGImage and use the above code to pass that into a GL Texture. It's cool to be able to take any QT supported file format and create the GL texture from that.
Just one thing: when creating the data buffer for the CGImage context, use calloc instead of malloc. Recently, I've tried to load some small PNG files and I was getting some noise because the buffer was not zeroed.
So, on LoadGLTextureFromCGImage():
So, on LoadGLTextureFromCGImage():
Code:
//----------------------------------------------------------------------
// Allocate memory block for bitmap buffer:
data_buffer = (GLubyte *) calloc( bitmap_byteCount, sizeof( GLubyte ) );
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| iPhone texture loading issue | yotryu | 0 | 3,127 |
Mar 11, 2009 03:40 AM Last Post: yotryu |
|
| Texture Mapping: Loading a texture from a .bmp file? | ishrock | 5 | 5,016 |
Dec 13, 2008 09:27 AM Last Post: ThemsAllTook |
|
| OpenGL Texture Loading & Sprites | corporatenewt | 2 | 10,602 |
Jan 30, 2008 12:39 PM Last Post: ynda20 |
|
| Texture Loading in Cocoa... | dave05 | 3 | 7,671 |
Dec 11, 2007 03:12 AM Last Post: DoG |
|
| Cocoa Texture Loading Code Problem | Nick | 1 | 2,776 |
Oct 28, 2005 11:44 PM Last Post: OneSadCookie |
|

