Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Core Image and cocoa-based game.

Core Image and cocoa-based game.
Thread Tools
Amorya
Mac Elite
Join Date: Mar 2001
Location: England
Status: Offline
Reply With Quote
Aug 31, 2005, 07:45 PM
 
I am writing a game which will use a tiled background. I'll have an array of tiles (for "house", "enemy", "sword", "player", "shop" etc - classic RPG fare). These get tesselated to form the main display of the game. I haven't coded this yet.

I can work out how to do this storing the tiles as NSImages, and drawing them into an NSView. That would work.

Thing is, I'd like to use some Core Image filters. And I want to use the filters on the composited display - for example, adding a circular glow centred on the player. As far as I can see, though, you can only apply a filter to a CIImage.


So what's the best way to proceed?


Option one
  • Store my tiles as CGImages.
  • Draw them into an offscreen CGContext.
  • Create a CIImage out of this context.
  • Apply filters.
  • Draw the CIImage of the composited display to an onscreen CIContext.
Seems like it'd work, but each time there's a tiny change on my map, it has to re-compute the whole display, even if only one tile changed. How quick would this be?

Option two
Something using CIImageAccumulator.
I've been trying to work out what this class actually does. Does it allow me to change one tile, and have the filters still applied and auto-update the area I changed?

Option three
Is there some way of applying filters directly to a CIContext?
If there is, I could set up my filters whenever they need changing (which is periodically when the light level changes in game), and replace tiles when they need replacing (which is whenever someone moves), the two things being entirely independent of each other.

Option four
Something else entirely.


Amorya
What the nerd community most often fail to realize is that all features aren't equal. A well implemented and well integrated feature in a convenient interface is worth way more than the same feature implemented crappy, or accessed through a annoying interface.
     
parallax
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Aug 31, 2005, 11:45 PM
 
"NSImage" and "game" in the same breath always makes me wary. In a broader sense of option 4, have you considered using OpenGL?
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Detrius
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status: Offline
Reply With Quote
Sep 1, 2005, 02:54 AM
 
You could also just straight up use Core Image and Core Graphics. If 10.3 compatibility isn't important, you could use different CGLayers to store each of the images that you would show on the screen. These would then be drawn to the screen, and when you are done, you would either flush or synchronize the CGContext.

I've done the CoreGraphics stuff a lot recently, but I haven't touched any of the CoreImage stuff, so I won't be much help there. But w/r to OpenGL, you can use CoreGraphics to draw straight into an OpenGL context, which speeds up the drawing.
ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
Amorya  (op)
Mac Elite
Join Date: Mar 2001
Location: England
Status: Offline
Reply With Quote
Sep 1, 2005, 06:36 AM
 
If 10.3 compatibility isn't important, you could use different CGLayers to store each of the images that you would show on the screen. These would then be drawn to the screen, and when you are done, you would either flush or synchronize the CGContext.
10.3 compatibility is not important.

I have heard the bad things about NSImage performance too - that's one reason I'm investigating alternatives.

When you say use different CGLayers to store each image, do you mean each tile of my game? Or each frame of the composited map?

Originally Posted by parallax
"NSImage" and "game" in the same breath always makes me wary. In a broader sense of option 4, have you considered using OpenGL?
Briefly. I have never used it before... but I guess I could learn if needed. One thing I wanted Core Image for is lighting effects - to add glows around the lights in the game, and darken the unlit parts of the map. If I'm using OpenGL for 2D stuff, could I perhaps still use its lighting effects?


Amorya
What the nerd community most often fail to realize is that all features aren't equal. A well implemented and well integrated feature in a convenient interface is worth way more than the same feature implemented crappy, or accessed through a annoying interface.
     
Millennium
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Sep 1, 2005, 07:53 AM
 
Originally Posted by Amorya
Briefly. I have never used it before... but I guess I could learn if needed. One thing I wanted Core Image for is lighting effects - to add glows around the lights in the game, and darken the unlit parts of the map. If I'm using OpenGL for 2D stuff, could I perhaps still use its lighting effects?
This should at least be possible to some degree. If nothing else, you should be able to draw into the CGImage as you were planning, but render the CGImage into an OpenGL texture rather than an NSImage onscreen. There's probably a better way to do it, but this ought to do the job.
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 05:52 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,