I'm looking for a good example of a basic OpenGL App for Mac OS X, but not too simple.
I have a good solid base of experience with iOS and objective-c, but I've never built a Mac OS X App.
All I've been able to find are super simple examples that do all the drawing and logic in drawRect: or overly complex examples with layers and layers of abstraction. I don't want to use Glut, SDL, or any other 3rd party libs or engines.
I want to be able to drive a Game Loop and use CADisplayLink like I do on my iOS games. I'd also rather not use .xib files because I like to understand what's going on and having that black box there hides too much for me, although I'd be happy to use it as a first step if it got me everything else (game loop, CADisplayLink, etc).
My iOS code creates it's OpenGL Views by hand, but there seems to be enough of a difference between iOS and OS X that I'm having trouble making heads or tails of it. I just need to get a Window and an OpenGL view and be able to draw to that via the game loop.
Can someone point me to a good resource? The Apples examples jump between to simple and too complex as does everything else I can find on the Internet.
Sorry I can't answer to your questions. I always did use XIB files (a looong time ago, I too always wanted to re-invent the wheel, but now I'm lazy and prefer getting stuff done :p) and I never used display links.
What don't you like about overriding drawRect: ?
And the sample I used to get started with OpenGL was this one : http://developer.apple.com/library/mac/#samplecode/CocoaGL/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004501
Not too complicated, and simple enough to understand it (and it doesn't use any XIB, if I remember well :p)
Related
New user to the site, but I have used it in the past so I felt it best to ask my question here, for the best chance of getting a response.
What I'm dealing with is one object, this being the sprite for my latest app, which I need to check for when it comes in to contact with another object, in this case, a tunnel which will curve.
Now, I'm aware of CGRectIntersectsRect, however I can't see that being helpful, as if I've got 2 UIImages, that being the top and bottom of a "mountain", and said pieces curving, there's no doubt that the sprite would touch the "rectangle".
What I need is something to trigger when the sprite hits the actual wall, however my limited knowledge of Objective-C isn't helping my case.
I imagine someone out there will know what I can do to resolve this, as for all I know it could be a simple solution.
Thank you in advance everyone!
First, I'd probably not build these basic pieces yourself. For iOS 7, you can use SpriteKit, which is built-in. If you want to support older versions of iOS, look at cocos2d (it's good for iOS 7, too).
But to the question, one approach for detecting arbitrary overlaps is to draw both objects into a buffer and check if there are any overlapping pixels (for instance, by drawing one in in pure red, and another in pure green, and then looking for pixels that have both). For a discussion of how to do this kind of thing in Core Graphics, see Clipping a CGRect to a CGPath, which provides sample code for the simplest version (checking for the intersection of a rectangle and curve), but the same approach can be used more generally. Note that this drawing can get expensive if you're doing it constantly, so usually you first check whether the bounding rectangles overlap. That tells you whether it's even worth the trouble to look closer.
But first I'd look at SpriteKit.
I need to add typical finger drawing to an app.
(The usual.... choose colors, erase, thickness - just the usual you see in every app made.)
It's hard to believe I have to program this from scratch, in this day and age?
It's hard to believe there is not a common solution for this?
All I could find is...
https://github.com/levinunnink/Smooth-Line-View
Review: that is a (beautifully written) example fragment of a few lines of code being how to draw with a path, with a good smooth result. It works perfectly, but it's just for drawing one "path." For example, you can't make a drawing with more than one color. there is no undo or anything like that. (See also note on the fourth review item here regarding path-math.)
https://github.com/sumanthk2006/Smooth-Line-View-1 (variation of above, but does not run under ARC, unfortunately demo does not properly launch etc)
Review: this is "abandonedware" or maybe "frustrationware" :) It does not run and is not ARC-ready. It is a seemingly well-written class that claims to do undo, colors, erase, etc. It even has a proper delegate to track your button states. But it doesn't work.
UPDATE Regarding this paackage. As a matter of fact, if you massage it it works well. Suggest (i) throw away the example app files. (ii) using modern Xcode, use the "convert to ARC project" feature on the two main files. There are a coupe little problems like it should use awakeFromNib. If you get it working it actually does everything, really well.
THERE ARE SERIOUS BUGS in SmoothLineView1. just to be clear, it suffers some serious bugs - you'll see there's a "streaking" effect when you draw.
http://www.cdframeworks.com/product/brushengine
Review: This commercial package (under $100) is well made and email support is fast. Unfortunately it does not have undo so it's not suitable for many situations. (Also does not have erase.)
Mentioned below is this popular article:
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_freehand-drawing/
Review: this is a good article on the actual TECHNOLOGY of drawing curves, on the let's say "path-math". Unfortunately it's no help at all if you need a working, ready to use, drawing package (with the obvious features, undo, erase, colors etc) to use in an iOS app. Thus for example, whatever actual solution you were using, you may, perhaps, want to apply the math concepts in this article.
I appreciate that the basic concepts are very simple, it's easy enough to "start from scratch". But it's just - ridiculous - to have to do from scratch for something so commonplace. Is there a solid package I'm missing?
It's fairly amazing that the four scratchy references above are the only things out there.
Any ideas? What's the best package today (late 2013) for adding drawing to an iOS app? THANKS.
As of 2017, I use https://github.com/acerbetti/ACEDrawingView/.
It can be used through cocoa pods, and provide full functionality over integrating a drawing feature in your app (color, brush, size, eraser, undo/redo/, etc).
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_freehand-drawing/ has a good, clear tutorial on smooth freehand drawing on the ios. If you just follow the tutorial, you can implement it easily into whatever app you are trying to make. It has stuff about increasing line quality and smoothness, and stroke quality.http://www.raywenderlich.com/18840/ is another tutorial on a simple drawing app, self-contained. You can combine aspects of both to get what you want.
edit: https://developer.apple.com/library/ios/samplecode/GLPaint/Introduction/Intro.html is the GLPaint sample provided by apple, which includes detecting shake. I thought it seemed more official, since it's from apple
to answer your question, there is no package for drawing directly, but there is a UIKit class, UIBezierPath, that lets you draw shapes made of straight lines or some curves.
I have developed a Canvas prototype of a game (kind of), and even though I have it running at a decent 30 FPS in a desktop browser, the performance on iOS devices is not what I hoped (lots of unavoidable pixel-level manipulation in nested x/y loops, already optimized as far as possible).
So, I'll have to convert it to a mostly native ObjC app.
I have no knowledge of ObjC or Cocoa Touch, but a solid generic C background. Now, I guess I have two options -- can anyone recommend one of them and whether they are at all possible?
1) Put the prototype into a UIWebView, and JUST do the pixel buffer filling loops in C. Can I get a pointer to a Canvas pixel array living in a web view "into C", and would I be allowed to write to it?
2) Make it all native. The caveat here is that I use quite a few 2D drawing functions too (bezierCurveTo etc.), and I wouldn't want to recode those, or find drawing libraries. So, is there a Canvas-compatible drawing API available in iOS that can work outside a web view?
Put the prototype into a UIWebView, and JUST do the pixel buffer filling loops in C
Nah. Then just embed a web view into your app and continue coding in JavaScript. It's already JITted so you don't really have to worry about performance.
Can I get a pointer to a Canvas pixel array living in a web view "into C"
No, not directly. If you are a hardcore assembly hacker and reverse engineer, then you may be able to do it by looking at the memory layout and call stack of a UIWebView drawing to a canvas, but it's just nonsense.
and would I be allowed to write to it?
Once you program your way down to that, I'm sure you would.
Make it all native.
If you wish so...
The caveat here is that I use quite a few 2D drawing functions too (bezierCurveTo etc.), and I wouldn't want to recode those, or find drawing libraries.
You wouldn't have to do either of those, instead you could just read the documentation of the uber awsum graphix libz called CoreGraphics. It comes by default with iOS (as well as OS X, for the record).
So, is there a Canvas-compatible drawing API available in iOS that can work outside a web view?
No, I don't know of one.
Translating your objective c code to html5 sounds like a daunting task, How about a 3rd option where you don't have to change your JavaScript code ?
http://impactjs.com/ejecta
Ejecta is like a Browser without the Browser. It's specially crafted
for Games and Animations. It has no DIVs, no Tables, no Forms – only
Canvas and Audio elements. This focus makes it fast.
Yes, it's open source
https://github.com/phoboslab/Ejecta
Is it even possible to continue rendering and updating while resizing the window so that it doesn't stretch?
This is pretty deeply baked into XNA's Game class's behaviour. I'm dealing with this exact problem now, but I don't have a good solution yet. EDIT: I how now found a solution - but it doesn't answer the bit about scaling - so I've posted it as a question/answer pair over here.
You could possibly dive in with reflection and disconnect the events that pause the game's timer when you start resizing (and unpause it when you stop). I haven't tried this yet, I'm a bit loathe to do it without understanding why they exist in the first place.
(Personally I am thinking of having my game subscribe to the resize start/end events as well, and then pumping Update myself on an appropriate timer until XNA comes back. I wasn't going to worry about the scaling of the display.)
One way to work around this problem is to replace the Game class entirely. The XNA WinForms Sample provides a suitable replacement - although you have to implement your own Draw/Update loop and timing. I've just tested this in an old level editor and it works just as you want when resized.
Although it does slow down quite a bit when you make the window larger, as it constantly re-allocates the backbuffer to make it bigger. You could replace that behaviour to make it over-allocate the backbuffer size, so it doesn't reallocate so often.
The underlying problem has something to do with win32, and is described in some detail in this thread on GameDev.net. But it doesn't really provide a satisfying solution either.
It might be interesting to note that the WinForms sample draws on its OnPaint method (and you get a loop by constantly calling Invalidate). Whereas XNA's built-in Game class subscribes to Application.Idle.
Information:
I want to do some tasks on images such as resize, crop, rotate and so on.
I hope they could be objects so that I can manipulate them one by one easily. In development time we could run up to several images at the same time to working on, just a-little-like game programming.
I see there's several things to choose toghether with XCode:
- Cocoa (default?)
- Quartz2D
- OpenGL (ES 2.0?)
- Cocos2D/Box2D
I'm new to mobile development as well as iOS.
Question:
- Because I could choose only one to start with, which should I choose? Or are there any other libraries/frameworks?
I've used Cocos2d Cocos2d for a game and it was pretty easy to pick up and manipulate images on screen. As it is build on top of OpenGL it abstracts you away from the nuts and bolts. But also it might be a bit heavy for your needs.
So if you can do what you need in Cocoa then use that but if you need more then look at Cocos2d.