1
\$\begingroup\$

I have a texture and vertex which are needed to create a set of closed polygons. For this purpose I use these functions:

Code for create texture:

CCSprite* spr = CCSprite::spriteWithTexture(mShape->getTexture());

spr->setPosition(ccp(spr->getTextureRect().size.width/2, spr->getTextureRect().size.height/2));
spr->setFlipY(true);

CCRenderTexture *texture = CCRenderTexture::renderTextureWithWidthAndHeight(mShape->getTextureRect().size.width, mShape->getTextureRect().size.height);

texture->beginWithClear(1, 1, 1, 0);
spr->visit();

glColor4f(0, 0, 0, 1);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);

for(int i=0; i < innerBorders.size(); i++) {
    std::vector<Vector2d> sitePoints = innerBorders.at(i);

    for(int n=1; n < sitePoints.size(); n++ ) {
        Vector2d origin = sitePoints.at(n-1);
        Vector2d destination = sitePoints.at(n);

        drawSmoothLine(ccp(origin.GetX(), origin.GetY()), ccp(destination.GetX(), destination.GetY()), 0.25f);
    }
}

glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glColor4f(1.0, 1.0, 1.0, 1.0);

texture->end();

drawSmoothLine method:

drawSmoothLine(CCPoint pos1, CCPoint pos2, float width){
GLfloat lineVertices[12], curc[4];
GLint   ir, ig, ib, ia;
CCPoint dir, tan;

width = width*8;
dir.x = pos2.x - pos1.x;
dir.y = pos2.y - pos1.y;
float len = sqrtf(dir.x*dir.x+dir.y*dir.y);
if(len<0.00001)
    return;
dir.x = dir.x/len;
dir.y = dir.y/len;
tan.x = -width*dir.y;
tan.y = width*dir.x;

lineVertices[0] = pos1.x + tan.x;
lineVertices[1] = pos1.y + tan.y;
lineVertices[2] = pos2.x + tan.x;
lineVertices[3] = pos2.y + tan.y;
lineVertices[4] = pos1.x;
lineVertices[5] = pos1.y;
lineVertices[6] = pos2.x;
lineVertices[7] = pos2.y;
lineVertices[8] = pos1.x - tan.x;
lineVertices[9] = pos1.y - tan.y;
lineVertices[10] = pos2.x - tan.x;
lineVertices[11] = pos2.y - tan.y;

glGetFloatv(GL_CURRENT_COLOR,curc);
ir = 255.0*curc[0];
ig = 255.0*curc[1];
ib = 255.0*curc[2];
ia = 255.0*curc[3];

const GLubyte lineColors[] = {
    ir, ig, ib, 0,
    ir, ig, ib, 0,
    ir, ig, ib, ia,
    ir, ig, ib, ia,
    ir, ig, ib, 0,
    ir, ig, ib, 0,
};

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, lineVertices);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, lineColors);
glDisable(GL_TEXTURE_2D);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 6);
glEnable(GL_TEXTURE_2D);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);}

I need to get the texture of the contour (without the main texture on the background.) How can it be done using openGL ES 1.1?

\$\endgroup\$
  • \$\begingroup\$ What kind of contour are you talking about? Provide some pictures please. \$\endgroup\$ – akaltar Dec 25 '13 at 13:37
  • \$\begingroup\$ As @akaltar asked, can you give an example image? What do you mean by "get the texture of the contour"? What have you tried already, and what's not working about it? \$\endgroup\$ – Seth Battin Dec 28 '13 at 4:44