need help getting quicktime to load textures
i have been looking the QTValuePak and this is what i ended up doing in my program.
then here is the drawFile() function
my image is 32x32 pixels. it displays an image but its all screwed up and is nothing like the one i made. what am i doing wrong?
Code:
GWorldPtr gw;
FSRef fsref;
FSSpec spec;
Boolean dirSize;
Rect imageSize;
void* buffer;
FSPathMakeRef((const UInt8*)"/Users/brettsawyer/Desktop/face.pict", &fsref, &dirSize);
FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, &spec, NULL);
buffer = malloc(160);
QTNewGWorldFromPtr(&gw, k32ARGBPixelFormat, 0, NULL, NULL,
0, buffer, 128);
drawFile(&spec, &imageSize);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,32, 32, 0,GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV,buffer);
DisposeGWorld(gw);
free(buffer);
glBegin(GL_QUADS);
glTexCoord2i((x - TILESIZE/2),(y - TILESIZE/2));
glVertex2i((x - TILESIZE/2),(y - TILESIZE/2));
glTexCoord2i((x + TILESIZE/2),(y - TILESIZE/2));
glVertex2i((x + TILESIZE/2),(y - TILESIZE/2));
glTexCoord2i((x + TILESIZE/2),(y + TILESIZE/2));
glVertex2i((x + TILESIZE/2),(y + TILESIZE/2));
glTexCoord2i((x - TILESIZE/2),(y + TILESIZE/2));
glVertex2i((x - TILESIZE/2),(y + TILESIZE/2));
glEnd();then here is the drawFile() function
Code:
void drawFile(const FSSpec *fss, const Rect *boundsRect)
{
GraphicsImportComponent gi;
GetGraphicsImporterForFile(fss, &gi);
GraphicsImportSetBoundsRect(gi, boundsRect);
GraphicsImportDraw(gi);
CloseComponent(gi);
}my image is 32x32 pixels. it displays an image but its all screwed up and is nothing like the one i made. what am i doing wrong?
Well for a start 32 * 32 * 4 is 4096, not 160...
ok so i rewrote some of it and now it draws the image!
but its weird, it draws the image right below the apple it isnt even in the window, and the items i drew with open are all discolored and some are missing. i am thinking that i am just not drawing my little image is the right spot, anyone know what i need to do to fix this? thanks for the help! here is my code:
but its weird, it draws the image right below the apple it isnt even in the window, and the items i drew with open are all discolored and some are missing. i am thinking that i am just not drawing my little image is the right spot, anyone know what i need to do to fix this? thanks for the help! here is my code:Code:
GWorldPtr gw;
FSRef fsref;
FSSpec spec;
Boolean dirSize;
Rect imageSize;
void* buffer;
GraphicsImportComponent gi;
FSPathMakeRef((const UInt8*)"/Users/brettsawyer/Desktop/face.pict", &fsref, &dirSize);
FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, &spec, NULL);
GetGraphicsImporterForFile(&spec, &gi);
GraphicsImportGetNaturalBounds(gi, &imageSize);
buffer = malloc(TILESIZE * TILESIZE * 4);
QTNewGWorldFromPtr(&gw, k32ARGBPixelFormat, &imageSize, NULL, NULL,
0, buffer, TILESIZE * 4);
GraphicsImportDraw(gi);
CloseComponent(gi);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, TILESIZE, TILESIZE, 0, GL_BGRA_EXT,
GL_UNSIGNED_INT_8_8_8_8_REV, buffer);
DisposeGWorld(gw);
free(buffer);
glBegin(GL_QUADS);
glTexCoord2i((x - TILESIZE/2),(y - TILESIZE/2));
glVertex2i((x - TILESIZE/2),(y - TILESIZE/2));
glTexCoord2i((x + TILESIZE/2),(y - TILESIZE/2));
glVertex2i((x + TILESIZE/2),(y - TILESIZE/2));
glTexCoord2i((x + TILESIZE/2),(y + TILESIZE/2));
glVertex2i((x + TILESIZE/2),(y + TILESIZE/2));
glTexCoord2i((x - TILESIZE/2),(y + TILESIZE/2));
glVertex2i((x - TILESIZE/2),(y + TILESIZE/2));
glEnd();
You're missing a call to GraphicsImportSetGWorld(gi, gw, NULL) between QTNewGWorldFromPtr and GraphicsImportDraw.
now i THINK its drawing in the window but i think its enlarging it massivly. i added that line then all that was in the window was a white background and a black line, then i went in to my face.pict and changed the background to blue and now i have a blue screen with a black line. would the GWorld window size be a different ratio and 32x32 is just massive? maybe i need to tell quicktime that the window i have is 640x480 or something? thanks for all your help! you are my hero!
-brett
-brett
I suspect you just have your texture coordinates and/or vertex coordinates wrong. Have you changed the projection anywhere? Try using (0, 0), (1, 0), (1, 1), (0, 1) as your texture coordinates.
that worked! but i dont understand why. when texturing if a square is 600pixels by 300 pixels then when i put a texture on it at (0,0),(1,0),(1,1),(0,1) the texture will fill the whole square? also the way i have it set up is it loads the image everytime it draws about 350 32x32 squares, so it is really slow. how would i load the texture once then refer to it each time i want to each square?
thanks!
-brett
thanks!
-brett
Sounds like you need a basic OpenGL tutorial. You can try NeHe (http://nehe.gamedev.net) or jump straight into the red book (http://fly.cc.fer.hr/~unreal/theredbook/)
In short, texture ID 1 now has the image associated with it, so if you want to use the texture again, you can just go glBindTexture(GL_TEXTURE_2D, 1); again without the need for the glTexImage2D.
Texture coordinates always run 0..1, 0..1 (unless you're using the GL_EXT_texture_rectangle extension, but that's an advanced topic...)
In short, texture ID 1 now has the image associated with it, so if you want to use the texture again, you can just go glBindTexture(GL_TEXTURE_2D, 1); again without the need for the glTexImage2D.
Texture coordinates always run 0..1, 0..1 (unless you're using the GL_EXT_texture_rectangle extension, but that's an advanced topic...)
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Starting with SDL, can't load BMP :( | ngoles | 10 | 6,621 |
Feb 21, 2007 11:25 AM Last Post: djork |
|
| How can I load a PNG without premultiplied alpha? | Prime | 6 | 5,525 |
Feb 15, 2005 08:52 PM Last Post: arekkusu |
|
| SDL & Quicktime | DM6 | 4 | 2,904 |
Jul 4, 2004 08:22 AM Last Post: Steven |
|
| Help deciding how to load textures? | Mars_999 | 1 | 1,927 |
Feb 20, 2003 10:09 PM Last Post: henryj |
|
| Where can I get a library to load 3D Models? | Mars_999 | 4 | 3,703 |
Aug 25, 2002 06:05 AM Last Post: ggadwa |
|

