Loading a PICT from a file

hyperutila
Unregistered
 
Post: #1
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
You might like to look at QTValuePak. There's a version at http://onesadcookie.is-a-geek.net/~keith...Pak.tar.gz 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.
Quote this message in a reply
hyperutila
Unregistered
 
Post: #3
Thanks, I'll try it out!
Quote this message in a reply
Member
Posts: 111
Joined: 2002.06
Post: #4
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.

Mark Szymczyk
http://www.meandmark.com
Quote this message in a reply
hyperutila
Unregistered
 
Post: #5
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?
Quote this message in a reply
Member
Posts: 111
Joined: 2002.06
Post: #6
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.
Quote this message in a reply
Member
Posts: 156
Joined: 2002.11
Post: #7
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.
Quote this message in a reply
hyperutila
Unregistered
 
Post: #8
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.
Quote this message in a reply
Member
Posts: 156
Joined: 2002.11
Post: #9
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.
Quote this message in a reply
Post Reply