Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple polygon texture mapping / iOS / cocos2d

I got some problems with opengl and cocos2d. I suck with opengl i know. I was trying to find just a simple answer but no luck.

What I'm trying to do is to map a texture like this:

Example

... so i got points

CGPoint points[4];

points[0] = ccp(x1,y1);
points[1] = ccp(x2,y2);
points[2] = ccp(x3,y3);
points[3] = ccp(x4,y4);

Whats next :( ?

All I want to do is map that texture on that polygon. I will show it in "idiot" way :)

enter image description here

like image 570
Marek Avatar asked Feb 17 '26 09:02

Marek


1 Answers

Firstly I would design the texture with the bottom horizontal and then rotate the sprite at the end, as this makes it a whole lot easier.

I would load the texture into a UIImage. Then use CGContexts to remove the triangular portions in the top corners.

Then load that UIImage into a CCTexture2D which I would then create a sprite from. Then rotate the sprite, so that it is at the required orientation.

Alternatively, if you don't need the texture to be generated programmatically you could just remove the corners from the texture, using gimp, photoshop or pixelmator. Then just load that texture the same way you would load any other.

like image 167
tustvold Avatar answered Feb 19 '26 23:02

tustvold