iDevGames Forums
Loading a PICT from a file - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Loading a PICT from a file (/thread-6551.html)

Loading a PICT from a file - hyperutila - Jan 13, 2004 06:37 PM

Okay, I'm kind of new at macintosh programming, though I know the basics of c++. I'm trying to write a program in Carbon that will load a PICT file that I specify(meaning that I already know its location) to a buffer that will then draw it to the screen. From looking through the documentation that came with XCode, I determined that I either need an FSSpec structure, or FSRef structure that will contain information on the file. But how do I do that? And once I do, how do I get it to the screen? Also, what is a file reference number and how do I get it? I'm kind of confused Wacko . Please help me out.

Loading a PICT from a file - OneSadCookie - Jan 13, 2004 08:26 PM

You might like to look at QTValuePak. There's a version at until iDevGames gets the file downloads section working again.

One of those samples is about as simple as you can get, loading any kind of image and drawing it into a window. In particular, it shows how to turn a POSIX path into an FSRef into an FSSpec.

Loading a PICT from a file - hyperutila - Jan 13, 2004 11:29 PM

Thanks, I'll try it out!

Loading a PICT from a file - szymczyk - Jan 14, 2004 12:10 AM

If you're drawing a PICT, it would be a lot easier to use a PICT resource instead of a PICT file. You wouldn't have to worry about FSSpecs and FSRefs. With a PICT resource, all you have to do is call GetPicture() to load the PICT into memory and DrawPicture() to do the drawing.

Loading a PICT from a file - hyperutila - Jan 14, 2004 07:27 PM

That would all be fine and good, except I don't know how to assign a resource ID to a the imported PICT resource, and that's necessary for the GetPicture function to work. How do you import a resource and assign it an ID?

Loading a PICT from a file - szymczyk - Jan 14, 2004 08:45 PM

Download ResEdit from Apple's site. It's an old program so it runs in Classic on OS X. Open your PICT file in ResEdit. Create a new file in ResEdit. Copy the PICT resource from the PICT file to the new file. ResEdit will give it an ID of 128, but you can change it if you want.

Add the resource file you created in ResEdit to your project. If you're using Xcode, make sure this file appears in the Resource Manager Resources section of your target. Xcode places resource files in the Bundle Resources section when you add them.

Loading a PICT from a file - FCCovett - Jan 14, 2004 10:10 PM

You can also work with bundles, which is the new way of doing things in OSX. If you choose this path, you need to load a bundle, then load the URL for the file you want, and then create a PICT image from that URL. It's quite simple; don't be intimidated by the length of the CoreFoundation commands. I have posted the source code of a game I've been working on for a while that is full of examples of how to use Carbon and OpenGL to set up a 2D sprite engine. It's newbie code, but it works; just check my profile and my previous posts to find that thread with the link to the source code and some specs.

Loading a PICT from a file - hyperutila - Jan 15, 2004 08:44 PM

Thanks, that's good to know! I'll try it out. Can DrawPicture() use masks? By the way, using GraphicsImport worked well, but I think that it might have a little bit of a slow draw rate, or maybe I'm doing something wrong. Thanks.

Loading a PICT from a file - FCCovett - Jan 15, 2004 08:58 PM

If you are going to use mask for alpha channels, you probably should be looking at importing PNG pictures to build OpenGL textures instead of working with Quickdraw. In Quickdraw, you need to specify a mask on CopyBits. Download the sample code of Glypha III from the downloads section of this site to see how it's done in Quickdraw. Damn, you can adapt a lot of stuff from that code if you have Resourcer to edit the resource file.