PDA

View Full Version : need help getting quicktime to load textures


xDexx
2003.05.06, 03:44 PM
i have been looking the QTValuePak and this is what i ended up doing in my program.

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


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?

OneSadCookie
2003.05.06, 06:02 PM
Well for a start 32 * 32 * 4 is 4096, not 160...

xDexx
2003.05.07, 06:44 PM
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:

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();

OneSadCookie
2003.05.07, 07:07 PM
You're missing a call to GraphicsImportSetGWorld(gi, gw, NULL) between QTNewGWorldFromPtr and GraphicsImportDraw.

xDexx
2003.05.07, 07:20 PM
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

OneSadCookie
2003.05.07, 07:25 PM
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.

xDexx
2003.05.07, 07:39 PM
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

OneSadCookie
2003.05.07, 07:46 PM
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...)

xDexx
2003.05.07, 07:57 PM
cool thanks, i will check those out. thanks for all your help!
-brett