I'm having an issue trying to draw some non-rectangle sprites. For some reason the image is not mapped correctly across the triangle strip. Can anyone advise on what I might be doing wrong? Any help will be greatly appreciated.
Here's the result I'm getting:
Here's the image I'm using:
Here's the code I'm using:
class TestNode : public CCNode
{
public:
CREATE_FUNC( TestNode );
virtual bool init()
{
CCNode::init();
m_texture = CCTextureCache::sharedTextureCache()->addImage( "Test/test.png" );
m_texture->retain();
setShaderProgram( CCShaderCache::sharedShaderCache()->programForKey( kCCShader_PositionTextureColor ) );
return true;
}
virtual void draw()
{
CC_NODE_DRAW_SETUP();
ccGLEnableVertexAttribs( kCCVertexAttribFlag_PosColorTex );
ccGLBlendFunc( CC_BLEND_SRC, CC_BLEND_DST );
ccGLBindTexture2D( m_texture->getName() );
static ccVertex2F verts[4] = { {0.0f, 0.0f}, {256.0f, 0.0f}, {64.0f, 256.0f}, {192, 256.0f} };
static ccTex2F uvs[4] = { {0.0f, 1.0f}, {1.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 0.0f} };
static ccColor4B colors[4] = { {255, 255, 255, 255}, {255, 255, 255, 255}, {255, 255, 255, 255}, {255, 255, 255, 255} };
glVertexAttribPointer( kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, verts );
glVertexAttribPointer( kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, uvs );
glVertexAttribPointer( kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, colors );
glDrawArrays( GL_TRIANGLE_STRIP, 0, (GLsizei)4 );
}
protected:
CCTexture2D* m_texture;
};
==============
Update #1:
I found this: Perspective correct texturing of trapezoid in OpenGL ES 2.0
I created new a new shader that uses texture2DProj(). It's an improvement but still isn't exactly what I want. I don't want the perspective effect along the vertical axis.
Here's the new result: