What API do 2D MacOSX games use?

DJBlufire
Unregistered
 
Post: #31
I finally figured out how to work my sprite engine in OpenGL and looking back it's not hard at all. The drawing function takes 10 lines of code to do and there are only a few special OGL functions that set it all up. I'd definately recommend OpenGL for 2D stuff.
Quote this message in a reply
DCoder
Unregistered
 
Post: #32
Quote:Originally posted by DJBlufire
I finally figured out how to work my sprite engine in OpenGL and looking back it's not hard at all.


Cool. I assume this is for your Arbetare product?

I don't suppose you'd be interested in putting together a short tutorial? I don't think I'd really need it any more, but in general, I think there's a desperate lack of 2D info out there for beginner OpenGL developers. I am planning on doing one or more myself as I move into that arena -- mainly to solidify my understanding.

-daniel
Quote this message in a reply
DJBlufire
Unregistered
 
Post: #33
Quote:Originally posted by DCoder
Cool. I assume this is for your Arbetare product?

I don't suppose you'd be interested in putting together a short tutorial? I don't think I'd really need it any more, but in general, I think there's a desperate lack of 2D info out there for beginner OpenGL developers. I am planning on doing one or more myself as I move into that arena -- mainly to solidify my understanding.

-daniel


This isn't for Arbetare, I'm working on this as part of a final project for my programming class.

I think I could put together a tutorial, just give me some time. I really wish there had been one when I started to research this stuff Smile
Quote this message in a reply
Member
Posts: 20
Joined: 2003.04
Post: #34
Woohoo! yes, plleeeeease make that tutorial :-) Would be a god-send!
Quote this message in a reply
DJBlufire
Unregistered
 
Post: #35
OK Smile

Just let me finish the project and work out all the kinks... then I know that my technique works and I could use it as an example in the tutorial.
Quote this message in a reply
Member
Posts: 233
Joined: 2003.05
Post: #36
As mentioned earlier, OpenGL 2D engines can have a blurry or "soft" look to them, but it seems to be avoidable.

If you are NOT using Ortho projection then there are two things you need to do to keep pixel perfect imagery.

Without Ortho
One you need to keep your imagery at an exact Z distance.
With the perspective set up like so:
gluPerspective( 45.0f, ratio, 0.1f, 1000.0f );
with an 800x600 resolution the z distance to draw your textured quad would be -90.24.

Yes, that's an odd number, but you can find them by setting up a simple testing program that allows you to move a quad forward and back until it looks pixel perfect, then just record the number.

Two, you need to offset your quad by a tiny amount. I found this on an obscure web page through a google search. Basically, you offset by 0.375. Something like this:
glTranslatef(destX+0.375,-destY+0.375,destZ);

And yes, this feels a bit hackish, but it seems to work. Rolleyes

Another way of dealing with this is to make a texture with a resolution HIGHER than you want it to look in the final game. That way you don't get pixel perfection (and you have to guess a bit with sizes and things) but it won't look "soft."

You may wonder why you'd even WANT to do 2D without Ortho. Basically, it's for adding a 3-D twist to your graphics, like flipping, shrinking, enlarging... lighting effects.

With Ortho:
At least on my system, Ortho only works correctly up to 300 pixels over and 200 pixels down. After that everything gets that soft look.

In other words, you place your quad in the upper left hand corner of the screen and it's crisp and perfect. As soon as you move to the lower right hand side. You end up with the blurry soft look. This feels like something is broken in OpenGL or its implementation on my card... BUT Quartz Extreme works perfectly on my comp, so...

The solution?
if (destX > 300)
{
glTranslatef(0.05, 0.0, 0.0);
}

if (destY > 200)
{
glTranslatef(0.0,-0.05, 0.0);
}

Yes, it seems goofy Wacko and like some sort of hack, but guess what? It works perfectly. Btw, this works in ANY of the common resolutions. Odd, eh?

Now, I know this all sounds like voodoo, and I personally hate these solutions. If someone has some insight into this, and a better way to handle it all, I'm VERY interested. Wow

It's been awhile since I looked at this code, and I'm just getting back into it, so please excuse any wierdness. :?:

One thing that might make your mileage vary is that I am using large textures with all of my animation frames in a grid. When I draw the quad I use just the portion of the texture that is the current frame. I don't remember if I confirmed that this blurry soft look happens even when you use the ENTIRE texture for your quad.

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
Member
Posts: 233
Joined: 2003.05
Post: #37
I just wanted to mention that if you are making a 2D game and considering using OpenGL, I would also suggest using SDL.

SDL is a framework that is LGPL'd. So, you'd have to give a link to a site that has the latest version to download and include a readme citing the frameworks you've used, but that's about it. You are completely free to use it for commercial products without any obligations other than those I just mentioned.

Anyway, for a game that won't be using the system GUI, SDL and OpenGL is all you need.

The big payoff is that both are cross platform. So, you can develop on your Mac, release on the Mac first, then once you get a following, release on the PC and Linux (and several other platforms) with VERY little effort.

If you haven't looked into SDL, I'd recommend it. There are several Mac developers that contribute to the code. It is extremely cross platform friendly, and the mail list is constantly active.

If you like, it can handle event grabbing, joystick support, mouse support, threads, sound... and it's all cross platform.

You don't NEED to use OpenGL with it, either, that just seems to be the way to get optimal performance now a days.

So, Check it out.

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #38
ok, just to answer the big blurry 2D opengl thing:
In CocoaBlitz I use
Code:
gluOrtho2D(0, THE_VIEW_WIDTH, 0, THE_VIEW_HEIGHT);
to make all my pixels sharp.

OpenGL is faster _by far_ over quartz or QD, especially for large full screen graphics and when drawing transformed sprites.

I'm glad people are considering CB a viable option; the more feedback I get, the better I can make CB. I've looked at CSKs openGL implementation, and Vinay's on the right track if you're looking to rebuild stuff you've already made with CSK. However, he's still a ways off before a public release.

I'll try to make some more demos for CB as soon as I can. If anybody wants to help, I'll host demos on variableaspect or link.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
mkeC
Unregistered
 
Post: #39
I just want to say that I was avoiding OpenGL like the plauge.
I'm just learning Cocoa, I don't know C or C++, and just spend a week figuring out NSImage.

But when I downloaded CocoaBlitz all of my problems were instantly solved. It took a bit to understand how "cells" were being used as sprites. But after a couple hours I'd say its pretty intuitive. Some documentation would be nice but if you stare at the code in the CBWindowDemo and the header files you can quickly figure out what is going on.

I'd say there is NOT much reason to use plain old Quartz if your starting from scatch. When CSK gets OpenGL that will be even more reason to abandon plain old Quartz for sprite animation. I'll admit that my Quartz code was a feeble hack but the speed increase is truly breathtaking.

OK I'll settle down now...

-Mike
Quote this message in a reply
Sage
Posts: 1,234
Joined: 2002.10
Post: #40
Quote:Originally posted by aaronsullivan
In other words, you place your quad in the upper left hand corner of the screen and it's crisp and perfect. As soon as you move to the lower right hand side. You end up with the blurry soft look. This feels like something is broken in OpenGL or its implementation on my card... BUT Quartz Extreme works perfectly on my comp, so...


I have the same problem. And BTW the redbook spec with .375 or .5 offsets is only for lines and points. Not triangle/quad geometry.

The bad thing about this is that, although Quartz Extreme aligns perfectly, Apple's sample GL code (OpenGL Image, or other examples that use Ortho2D) have the same problem.

I think it's a bug in GL. I've submitted a bug to RADAR about it. You can see examples of the problem and a test app at http://homepage.mac.com/arekkusu/bugs/gl...exact.html
Quote this message in a reply
Sage
Posts: 1,234
Joined: 2002.10
Post: #41
Quote:Originally posted by mkeC
I'd say there is NOT much reason to use plain old Quartz if your starting from scatch... I'll admit that my Quartz code was a feeble hack but the speed increase is truly breathtaking.


I agree. I converted my fractal drawing app from Quartz to GL last week. It draws around 45k antialiased lines. The speed improvement was over 100x. A set that takes 8 seconds to draw inQuartz takes 0.06 seconds in GL.

Yes, I know about NSBezier path intersection problems. And I was using CG directly, with small segment lengths.

Quartz is just terribly slow. Hopefully it'll be optimized more in Panther.
Quote this message in a reply
CobraMantis
Unregistered
 
Post: #42
Humm...
Well, I've been wanting to learn OpenGL for quite some time now, but have never really gotten around to doing so. The game I'm working on currently is using QuickDraw. Reading through this thread has made me wonder whether I should switch to OpenGL instead.

I currently have zero experience with OpenGL. How hard would it be to learn enough about it to be able to use it for a fairly simple 2D game? You guys have mentioned that it's a good deal faster than Quartz for 2D games, so I assume it would also be much faster than QD?

Thanks!
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #43
OpenGL is the fastest way to draw to the screen. Quartz and QuickDraw get left in the dust. Cool
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #44
Learning how to use OpenGL for 2D would not be difficult (particularly not for someone who can understand CopyBits Wink).

There are a number of people on this forum who've made the leap recently, and there was some talk of making a tutorial. Perhaps someone in that boat could step up here?
Quote this message in a reply
Patrick
Unregistered
 
Post: #45
On older macines without graphics acceleration, QuickDraw will blow away OpenGL - I've noticed that software opengl has a terrible rendering speed. Some people still use iMacs/old powerbooks and the Rage IIc/Rage LT Pro chips in them don't support GL well AFAIK.

If your game doesn't need fancy GL effects, I'd think it would be better to go with QuickDraw for maximum compatibility. Just my two cents.
Quote this message in a reply
Post Reply