Endless Terrain Query

Hello

i am currently working on a game like hill climb racing.
here is the link of what i have made till now:

here is the terrain making code:

#define MAX_HILL_POINTS 30
CCArray hillInfoArray;
struct hillStruct : public cocos2d::CCObject {
cocos2d::CCPoint point1;
cocos2d::CCPoint point2;
b2Fixture
fixture;
};

void CTerrainLayer::generateHillPoints() {
//create ground
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0, 0); //bottom-left corner
groundBodyDef.type = b2_staticBody;

groundBody = worldRef~~>CreateBody;
groundBody~~>SetUserData((void**)TAG_GROUND);
//slopes
CCPoint point1 = ccp;
for
{
CCPoint point2 = ccp;
hillStruct**hillData = new hillStruct;

float val = RandomFloat(0, 10);
point2.x = point1.x + 25.0f;
point2.y = point1.y + val * cosf(point2.x / 200.0f * b2_pi);

b2EdgeShape groundShape;
groundShape.Set(B2VEC_FROM_CCPOINT(point1), B2VEC_FROM_CCPOINT(point2));
hillData~~>fixture = groundBody~~>CreateFixture(&groundShape,0);
hillData~~>fixture~~>SetDensity(5.0f);
hillData~~>fixture~~>SetFriction(0.5f);
hillData~~>fixture~~>SetRestitution(0.2f);

//hill info data
hillData~~>point1 = point1;
hillData~~>point2 = point2;
hillInfoArray->addObject(hillData);
point1 = point2;
}
}
hillInfoArray stores all the points of the hill, and as the screen moves new points are created
and points going outside screen gets destroyed at runtime.

i have made the terrain as an b2EdgeShape, i wanted to know how can i wrap my own custom texture
on the hills/ground which have an irregular shape.

Any suggestions Please.

`void XTerrainGrid::draw()
{
Node::draw();

CC_NODE_DRAW_SETUP();

GL::blendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

for (int i = 0; i < TERRAIN_TEXTURE_SIZE; i++)
{
    if ( m_textures[i] != NULL )
    {
        GL::bindTexture2D( m_textures[i]->getName() );
        GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION  | GL::VERTEX_ATTRIB_FLAG_TEX_COORDS );

        // vertex
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, (void*)m_vertices);

        // texCoods
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, 0, (void*)m_texCoords);

        glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)GRID_VERTEX_SIZE);
    }
}

CHECK_GL_ERROR_DEBUG();

CC_INCREMENT_GL_DRAWS(1);

}
`

for (int j=0; j<(int)m_vecGrids[i].size(); j++)
{
XTerrainGrid* pGrid = new XTerrainGrid();
pGrid~~>init;
pGrid~~>setPosition(Point(j*GRID_WIDTH,i*256.0f));
this->addChild(pGrid,MAX_TERRAIN_LINE-i);
m_vecGrids[i][j] = pGrid;
}