Some quick help getting started with certain Carbon functions

Apprentice
Posts: 12
Joined: 2008.01
Post: #1
I need a Carbon C program that does nothing more than copy a specific portion of a resource PICT (for instance, a 32x32 portion at location y=64, x=64 from PICT resource 135) and display it on the screen at a certain location (let's just say y=42, x=132). I want it as simple as possible, so I'm assuming that it would use CopyBits(). It doesn't have to do anything with the desktop or menu bar or anything, it only has to do the bare minimum to make something appear on the screen. Also, the program should quit when an arrow key is hit. That's it! Hopefully that will all fit in main() and take up less than a page.

I've been wanting to make my own games for a very long time, but I just haven't been able to get everything working like I want to. I've made animated sprites with just the paint-pixel command in qBASIC for DOS, and I know C well enough to make very complex text-based programs, like a MadLib generator in MPW and the old Haunted House in Xcode. In fact, I've converted the chapter 6 source code from Mac Game Programming into a playable checkers program with AI and my own custom font engine (with all of the graphics and fonts in a resource file). But that was quite a task, especially for someone who doesn't know C++. I tried to learn C++ at one time, but I gave up because I would really like to make some games with C first. So that's why I want the barebones graphics funtions, I want to start my own program from scratch rather than trying to change programs that I get out of books (especially when they are in the wrong language!). I just haven't been able to figure out how get past all the GWorlds and off-screen buffers and C++, all I want is C pure and simple.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
You do *not* want to start learning the Resource Manager (not recommended since 10.0.0), QuickDraw (officially deprecated since 10.4) or Carbon (absent from 64-bit, AKA unofficially deprecated, since 10.5).

One possible starting point is this (to toot my own horn): OneSadCookie: Xcode/GLUT Tutorial

There are plenty of other possibilities of course, but if you want to make games with graphics in C, OpenGL is (almost) nonnegotiable.
Quote this message in a reply
Apprentice
Posts: 12
Joined: 2008.01
Post: #3
However, I have a G4 iMac and I just want to program something that will fit in with the older books that I have. I don't want to start reading yet another programming book (Red book, Blue book, whatever), and at this point I don't care about forward compatibility. I'm not a game developer yet. Eventually I plan on learning C++ and worrying about following Apple programming guidelines and whatnot, but right now I just want to start the quick and dirty way.

Quote:There are plenty of other possibilities of course, but if you want to make games with graphics in C, OpenGL is (almost) nonnegotiable.

How common is it for someone to make games without graphics?

Anyway, I'm a little wary of using OpenGL because I've heard something about it not working with certain hardware (especially PC graphics cards). Am I completely misinformed?

Just skimmed through your tutorial, and it looks like it's exactly what I want, except it doesn't cover loading and displaying pixmaps. If there's a simple way to do this with resources and OpenGL, then I might try it out.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
zmwworm Wrote:How common is it for someone to make games without graphics?

Very... they're called "text adventures", "MUDs" and so forth.

Quote:Anyway, I'm a little wary of using OpenGL because I've heard something about it not working with certain hardware (especially PC graphics cards). Am I completely misinformed?

Yes. Might have been true 8+ years ago, certainly isn't now.

Quote:Just skimmed through your tutorial, and it looks like it's exactly what I want, except it doesn't cover loading and displaying pixmaps. If there's a simple way to do this with resources and OpenGL, then I might try it out.

This is called "texture loading" in OpenGL. It's the kind of thing where you'll copy and paste some code from someone and forget about how it works for a year or so.

You won't use resources, you'll load images from regular old image files on your disk.
Quote this message in a reply
Apprentice
Posts: 12
Joined: 2008.01
Post: #5
OneSadCookie Wrote:Very... they're called "text adventures", "MUDs" and so forth.

People aren't still making money off those, are they?

Quote:This is called "texture loading" in OpenGL. It's the kind of thing where you'll copy and paste some code from someone and forget about how it works for a year or so.

You won't use resources, you'll load images from regular old image files on your disk.

Sounds very good, I'm sold! Except if I ever made a commercial game I might not want players to be able to mess with my graphics. Oh well, I can worry about that later. So you probably don't have to answer this since I can do my own research, but what's the code for "texture loading"? Does the red/blue book put it simply and plainly enough for a newb like me?

I know that OpenGL is centered on 3D, so does 2D pictures involve somehow treating the screen as a single polygon or something (as "texture loading" suggests)?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
There's no point stressing about allowing people to mess with your graphics, whatever format you ship them in, it won't be possible and is unlikely even to be difficult.

If you search these forums you'll get about a million hits about texture loading, some more useful than others. Neither the red nor blue book is likely to help you out on this front.

OpenGL doesn't care if you do 2D or 3D, it's completely neutral. If you follow the tutorial I posted you should get a good grip on how to do 2D graphics in OpenGL.
Quote this message in a reply
Apprentice
Posts: 12
Joined: 2008.01
Post: #7
OneSadCookie Wrote:There's no point stressing about allowing people to mess with your graphics, whatever format you ship them in, it won't be possible and is unlikely even to be difficult.

If I'm using regular PICT files and whatnot, how could there be any difficulty or impossibility in just opening up the files?
Quote this message in a reply
Member
Posts: 245
Joined: 2005.11
Post: #8
I think he meant that it's not possible to stop people messing with your graphics, and it's unlikely to be difficult to mess with them.
It is possible to encrypt the files using a proprietary format if you really want to. You could just stick all your data in an encrypted archive (password-protected zip or something which is probably a bit simpler, but since your graphics are visible on screen, they can be recovered from the VRAM (or you can just take a screen shot). With 3D graphics this is less true, since they will be rotated in three dimensions and possibly affected by lighting, but if someone wants to access your images badly enough, they probably will. Encrypting other assets such as 3D models and level data may be more worthwhile.
The thing is, you'll probably find that it is several years before any of this actually becomes an issue for you.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
Even in 3D, there are easy hooks into GL to grab full-quality images from. It's so easy to do, there's no point trying to prevent it (and chances are, nobody will want to anyway), and cf. Q3A, the easier you make it, the more longevity your game will have...
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #10
I can't imagine a situation where it would be important to prevent users from fiddling with the graphics or even the geometry (maybe I don't have a big enough imagination...). Even if they are the super-duperest-bestest graphics in the world, they're still just graphics. And more importantly they will be property of whoever made them via copyright, if not implied copyright at that, so they can't be sold or used by anyone else anyway without your permission.
Quote this message in a reply
Moderator
Posts: 373
Joined: 2006.08
Post: #11
AnotherJake Wrote:I can't imagine a situation where it would be important to prevent users from fiddling with the graphics or even the geometry

a trick that used to be a bit more common than it is now in multiplayer games: make all the textures a good deal more transparent so you can see through walls....great for sniping! Grin

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #12
wyrmmage Wrote:a trick that used to be a bit more common than it is now in multiplayer games: make all the textures a good deal more transparent so you can see through walls....great for sniping! Grin
Nice! I've never heard of that one before.

To counter that, I imagine buildings and hide-behind-able objects simply wouldn't use transparent textures (no blending, no see), which shouldn't really be a problem as far as graphics quality degradation in the general case, like a wall or crate. Billboards (like bushes) would still be vulnerable to it though.
Quote this message in a reply
Apprentice
Posts: 12
Joined: 2008.01
Post: #13
Quote:I think he meant that it's not possible to stop people messing with your graphics, and it's unlikely to be difficult to mess with them.
It is possible to encrypt the files using a proprietary format if you really want to. You could just stick all your data in an encrypted archive (password-protected zip or something which is probably a bit simpler, but since your graphics are visible on screen, they can be recovered from the VRAM (or you can just take a screen shot).

I'm thinking more of people editing the game rather than stealing intellectual property. Like you said, you can get the graphics from anything with a screenshot.

Quote:The thing is, you'll probably find that it is several years before any of this actually becomes an issue for you.

I agree.

Quote:Even in 3D, there are easy hooks into GL to grab full-quality images from. It's so easy to do, there's no point trying to prevent it (and chances are, nobody will want to anyway), and cf. Q3A, the easier you make it, the more longevity your game will have...

That may be true, but only up to a point. If you have an option on your game menu called "Edit the game's graphics" and it also helps you post your work on the internet, then any longevity gain from having a varied game experience will probably be offset by the large ratio of garbage compared to real work that will be produced by players. On the other hand, if you make your own file formats and then create your own encyption for them, you will be no better off, since it will be virtually impossible for people to change your game. You could go Blizzard's route, and allow people to change only what you want them to (and make it relatively easy). But this still has a lot of newbie garbage associated with it. I think that the best way is to make it moderately difficult for players to edit your game, so that only the trully commited will be making new artwork and levels and whatnot. However, this isn't a hard and fast rule since the specifics depend heavily on the type of game you're talking about. And what do I know anyway?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Functions not being initialised onKeyDown Yendall 1 987 Apr 15, 2014 01:31 PM
Last Post: OneSadCookie
  Help with getting started Filsk15 9 7,853 Nov 19, 2011 10:38 AM
Last Post: fugufish
  Getting Started makinggames 9 6,202 Jun 17, 2009 05:15 PM
Last Post: wyrmmage
  Help Getting Started onedeveloper 8 5,055 Oct 1, 2008 05:49 AM
Last Post: ThemsAllTook
  Intel Mac -> Many Warnings (deprecated functions) dave05 3 4,454 Sep 6, 2006 03:19 PM
Last Post: aarku