It would be nice to bring these routines into my iphone projects, especially if I have to create my own GUI. The thing is, all my prior graphics programming was based on direct video memory access. Sampling and writing to video memory was rather trivial, though somewhat slow because it was all done in software. Now that I'm working with OpenGL, I really don't have that direct access to video memory. This has required me to change my rendering strategy. Whereas before I was writing pixels directly into memory, now I'm forced to render my primitives using various geometries (triangles, boxes, lines). I still haven't figured out how or if I can sample pixels, though, which is essential to creating anti-aliased primitives.
I prototyped a rounded box routine today, which gives me hope for the rest these cool drawing primitives. I've incorporated this primitive into the slider program. Currently, I'm using OpenGLs GL_LINE_LOOP for basic primitives and GL_TRIANGLE_FAN for filled primitives. The rendering code is a bit clunky, being a prototype, but I like these initial results. However, I'd like to change the rendering to use GL_LINES to render the box accurately using line strips as opposed to approximating it using geometry.
The last thing I'd like to note is that I'm still not entirely comfortable with Objective-C's method syntax. From what I understand, everything in Objective-C is essentially an object which means all your routines are really methods of some object. Objective-C uses a bracket syntax to invoke methods:
[object methodNameParameter1:p1 Parameter2:p2 ParameterN: pN];.
To invoke a "local" method you use "self" as the object. So, all my rendering calls look something like:
[self drawPrimitiveX1:x1 y1:y1 x2:x2 y2:y2 color:color];
which just feels clumsy and redundant to me as opposed to something like:
drawPrimitive(x1,y1,x2,y2,color);
I created a workaround, though, by using macros. It accepts the syntax I like and expands it into the necessary objective-c code:
#define drawPrimitive(px1,py1,px2,py2,pColor) [self drawPrimitiveX1:(px1) y1:(py1) x2:(px2 )y2:(py2) color:pColor]
We'll see how this plays out as I refine the rendering code and interface. Also, as my programs which rely on these primitives get bigger and more complex, I'm sure other problems will present themselves.


No comments:
Post a Comment