need help getting quicktime to load textures

xDexx
Unregistered
 
Post: #1
i have been looking the QTValuePak and this is what i ended up doing in my program.
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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Well for a start 32 * 32 * 4 is 4096, not 160...
Quote this message in a reply
xDexx
Unregistered
 
Post: #3
ok so i rewrote some of it and now it draws the image! Smile 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();
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
You're missing a call to GraphicsImportSetGWorld(gi, gw, NULL) between QTNewGWorldFromPtr and GraphicsImportDraw.
Quote this message in a reply
xDexx
Unregistered
 
Post: #5
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
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
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.
Quote this message in a reply
xDexx
Unregistered
 
Post: #7
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
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
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...)
Quote this message in a reply
xDexx
Unregistered
 
Post: #9
cool thanks, i will check those out. thanks for all your help!
-brett
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Starting with SDL, can't load BMP :( ngoles 14 11,144 Jan 21, 2014 11:19 AM
Last Post: SethWillits
  How can I load a PNG without premultiplied alpha? Prime 6 7,411 Feb 15, 2005 08:52 PM
Last Post: arekkusu
  SDL & Quicktime DM6 4 3,389 Jul 4, 2004 08:22 AM
Last Post: Steven
  Help deciding how to load textures? Mars_999 1 2,304 Feb 20, 2003 10:09 PM
Last Post: henryj
  Where can I get a library to load 3D Models? Mars_999 4 4,228 Aug 25, 2002 06:05 AM
Last Post: ggadwa