i want to change rect UIImage to polygon image with different shape - iphone

I want to draw a rectangular UIImage to a polygon UIImage.
Like below example.
to

you will have to look into OpenGL ES, this will definately be able to draw textures onto a plain surface which is tilted, and most likely its your only option
. plus, the advantage being, you can actually animate the tilt in motion, like on coverflow
im not sure quartz can do it, but you will have to check that.

Related

UIImage rotating around its own axis? Possible?

I need a UIImageView initialized with an image that rotates around its own axis in the same way it does in this
GIF example.
My task is actually a little more complicated because I also need to turn a flat image into a thick, coin-like 3D image, but I won't bother anyone here with that. The only thing I want to know right now is whether it's possible to animate a UIImage like the example above, and if so, then how do I do it?

OpenGL, primitives with opacity without visible overlap

I'm trying to draw semi-transparent primitives (lines, circles) in OpenGL ES using Cocos2d but can't avoid the visible overlap regions. Does anyone know how to solve this?
This is a problem you usually come across pretty often, even in 3D.
I'm not too familiar with Cocos2D, but one way to solve this in generic OpenGL is to fill the framebuffer with your desired alpha channel, switch the blending mode to glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA) and draw the rectangles. The idea behind this is that you draw a rectangle with the desired transparency which is taken from the framebuffer, but in the progress mask the area you've drawn to so that your subsequent rectangles will be masked there.
Another approach is to render the whole thing to a texture or assemble the shape using polygons that don't overlap.
I'm not sure whether Cocos2D supports any of theseā€¦
I do not know what capabilities Cocos2D specifically provides, but I can see two options,
One, do not overlap like that, but rather construct more complex geometry such that each pixel is only covered once,
Two, use stencil buffer to create a mask as you draw, and to reject any pixels that are already masked.

Iphone/Ipad : What is the fastest way to draw an irregular polygon in a rectangle?

I have to draw the following shape in a rectangle. What is the best way to do it? The blue areas are the background color. The black is a border and the red is the interior color. I want to paint the black and red only.
Thanks
It totally depends on how you would use the shape; whether they will move, how many of them will be displayed, whether they will be scaled while being displayed, etc.
In general, OpenGL ES is considered to be the fastest way of drawing on iOS devices. However, if you have only a small number of those shape (say, <10~100?) and the other part of the application does not have a lot of fast animations Quart 2D is usually enough in terms of drawing, in order to, say, achieve a 30/60Hz drawing rate.
How you use Quartz2D still matters a lot. If you need to redraw the shapes frequently, you would need to draw the shape on CALayers, and rather than redrawing the shapes, you should move and transform the layers.
Comparing drawing as a bitmap and a vector shape, I believe both would work fine for this kind of shape (especially because you would not redraw the shape so often, but only work with the layer on which the image already is drawn). But if your shapes are scaled frequently, you would consider vector images for the quality of the image.
To summarize, learn (if you don't already know) how to draw into a graphics context first (see Drawing and Printing Guide for iOS). You should be able to draw a simple vector shape or a bitmap image by overriding drawRect or similar methods inside a UIView object. Then if you need to animate those shapes, learn how to create a CALayer and draw on the layer (see Core Animation Programming Guide). Finally, if you need to create many duplicates of the shape on the screen, learn how to use CGLayer to replicate an image (see Quartz 2D Programming Guide).

How can I get an OpenGl texture of a polygon shape from an image?

I have an image and a convex polygon defined by an array of x,y coordinates.
How would I go about getting a Texture2D representation of the part of the image encompassed by the polygon?
Basically I just need a texture from the image with the part outside the polygon made transparent.
If the resultant texture were also clipped to the width and height of the polygon I'd do backflips.
Any pointers/snippets would be appreciated. Thank you!
Interestingly, your question is tagged with both cocos2d and opengl, but I'll give an OpenGL-centric answer here. Rather than creating a new texture object to achieve the desired effect, I think you'd want to use the stencil buffer. The procedure would look like this:
When creating your FBO, attach a stencil buffer to it.
Clear the stencil buffer.
Turn off writes to the color and depth buffers; turn on writes to stencil.
Render the polygon and don't bother with texturing.
Re-enable writes to the color and depth buffers; turn on stencil testing.
Render a textured quad that corresponds to the bounding box of your polygon.
The iPhone 3GS and the iPhone simulator both support an 8-bit stencil buffer. For older iPhones, you might be able to do a similar trick with the framebuffer's alpha component rather than the stencil buffer...

"Beveled" Shapes in Quartz 2D

I'm familiar with some of the basics of Quartz 2D drawing, like drawing basic shapes and gradients and so on, but I'm not sure how to draw a shape with a "beveled" look, like this:
beveled circle http://www.shaggyfrog.com/junk/beveled-circle.jpg
Essentially we've got a shine on one corner, and maybe some shading in the opposite corner. I think -- I didn't make this image, although I'd like to be able to approximate it.
Any ideas? This is on the iPhone, and I'd like to use built-in frameworks and avoid any external libraries if at all possible.
There are really only a few useful approaches you can take to this problem.
Use your basic shape drawing techniques and combine them with a one or more gradient curves. (Implicit object construction) with curves/fills.
Custom build a UIView and build the object up per-pixel in a drawRect.
Pre-render your beveled/shadowed shapes and load them into an image and blit them into a UIImageView.