I want to get hold of some concepts in openGLES. I was trying to understand http://iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-part-6_25.html.
I tried to fill a polygon with textures which are smaller and bigger the polygon. I wanted the texture to warp and fill the polygon. However the result was not what I expected. Could some body point me where I am doing it wrong? Please.
My Project is downloadable at http://www.4shared.com/file/JusLcoCs/TestingOpenGLES.html?
the HelloWorldLayer Class has
-(id) init
{
if( (self=[super init])) {
CGSize screenSize = [[CCDirector sharedDirector] winSize];
CCSprite* spriteForPolygonTexture = [CCSprite spriteWithFile:@"openGLKing.png"];
ccTexParams tp = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_CLAMP_TO_EDGE};
[spriteForPolygonTexture.texture setTexParameters:&tp];
Polygon* samplePolygon = [[Polygon alloc] initWithSprite:spriteForPolygonTexture];
samplePolygon.position = ccp(2*screenSize.width/3, 2*screenSize.height/3);
[self addChild:samplePolygon];
CCSprite* spriteForPolygonTexture2 = [CCSprite spriteWithFile:@"openGLKingBig.png"];
[spriteForPolygonTexture2.texture setTexParameters:&tp];
Polygon* samplePolygon2 = [[Polygon alloc] initWithSprite:spriteForPolygonTexture2];
samplePolygon2.position = ccp(1*screenSize.width/3, 1*screenSize.height/3);
[self addChild:samplePolygon2];
}
return self;
}
the polygon class is
-(id)initWithSprite:(CCSprite*)_sprite
{
if((self = [super init]))
{
self.spriteForPolygonTexture = _sprite;
}
return self;
}
-(void)draw
{
//Drawing outline
CGPoint verts[] = {{-69.5, 76.0},{82.5, 76.0},{135.5, -67.0} ,{-110.5, -62.0}};
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glColor4f(1, 1, 1, 1);
glVertexPointer(2, GL_FLOAT, 0, verts);
glDrawArrays(GL_LINE_LOOP, 0, 4);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
//Filling the Diagram with Texture
glDisableClientState(GL_COLOR_ARRAY);
CGPoint verts2[] = {{-69.5, 76.0},{82.5, 76.0},{-110.5, -62.0},{135.5, -67.0}};
CGPoint texCords[] = {{0,0},{1,0},{0,1},{1,1}};
glBindTexture(GL_TEXTURE_2D, spriteForPolygonTexture.texture.name);
glVertexPointer(2, GL_FLOAT, 0, verts2);
glTexCoordPointer(2, GL_FLOAT, 0, texCords);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glEnableClientState(GL_COLOR_ARRAY);
}
Please point me to few good related posts too. Thank you