Problems with texturing a part of a Object

hey guys,
I’m working with openGl es 2.0 and want do develop an App for Android.

i’m creating a sphere and i want to texture only a piece of this sphere.
here is an example what i mean: [ATTACH=CONFIG]2209[/ATTACH]

drawing the sphere:

  [at] Override
    public void onDrawFrame(GL10 glUnused) {
         ....

        GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

        ....

        GLES20.glVertexAttribPointer(
                    maPositionHandle, NUM_FLOATS_PER_VERTEX,
                    GLES20.GL_FLOAT, false,
                    0, sphere.getVertexBuffer().get(0));

            GLES20.glVertexAttribPointer(maTextureHandle, NUM_FLOATS_PER_TEXTURE,
                    GLES20.GL_FLOAT, false,
                    0, sphere.getTextureBuffer().get(0));
 
            GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0,sphere.getCountVertices());

        GLES20.glDisableVertexAttribArray(maPositionHandle);
        GLES20.glDisableVertexAttribArray(maTextureHandle);

        checkGlError("glDrawArrays");
        GLES20.glFinish();

calculate the sphere:

 private void createSphereWithTextureCordNeu(Float stepsZ, Float stepsBezugsgrade, float radius,int begrenzungZ, int begrenzungX)
    {
        Float x1,y1,z1;
        Float x2,y2,z2;
        Float bezugsgradeZ2, bezugsgradeZ1;
        Float xTextureZ2,yTextutueZ2, xTextureZ1, yTextutueZ1;

        Float stepAngleZ=new Float(0);
        Float stepAngleBezugsgrade=new Float(0);

        ArrayList<Float> testZ=new ArrayList<>();

        //calculate stepAngle
        stepAngleZ=180/stepsZ;
        stepAngleBezugsgrade=360/stepsBezugsgrade;


        ArrayList<Float> floatCounterVertices=new ArrayList<>();
        ArrayList<Float> floatCounterTexture=new ArrayList<>();


        for (float angleZ = 0.0f; angleZ+stepAngleZ <=180.0f; angleZ += stepAngleZ) {

            z1 = (float)Math.cos(Math.toRadians(angleZ) * radius);
            bezugsgradeZ1 = (float)Math.sin(Math.toRadians(angleZ) * radius);

            z2 = (float)Math.cos((Math.toRadians(angleZ + stepAngleZ) ) * radius);
            bezugsgradeZ2 = (float)Math.sin((Math.toRadians(angleZ + stepAngleZ)) *radius);

            // Fixed latitude, 360 degrees rotation to traverse a weft
            for (float angleBezugsgrade = 0.0f; angleBezugsgrade <= 360.0f; angleBezugsgrade += stepAngleBezugsgrade) {
                //calculate point 2
                x2 = calcVertexCos(angleBezugsgrade,bezugsgradeZ2);
                y2 = calcVertexSin(angleBezugsgrade,bezugsgradeZ2);

                //calculate Texture
                    xTextureZ2 = calcTextureX(angleBezugsgrade, begrenzungX);
                    yTextutueZ2 = calcTextureY(angleZ + stepAngleZ, begrenzungZ);

                    xTextureZ1=xTextureZ2;
                    yTextutueZ1 = calcTextureY(angleZ, begrenzungZ);

                //punkte ins ARRay übergeben
                floatCounterVertices.add(x2);
                floatCounterVertices.add(z2);
                floatCounterVertices.add(y2);

                floatCounterTexture.add(xTextureZ2);
                floatCounterTexture.add(yTextutueZ2);



                //calculate point 1
                x1 = calcVertexCos(angleBezugsgrade, bezugsgradeZ1);
                y1 = calcVertexSin(angleBezugsgrade, bezugsgradeZ1);

                //Punkte ins Array uebergeben
                floatCounterVertices.add(x1);
                floatCounterVertices.add(z1);
                floatCounterVertices.add(y1);

                floatCounterTexture.add(xTextureZ1);
                floatCounterTexture.add(yTextutueZ1);

            }
        }
        final float[] vertices = new float[floatCounterVertices.size()];
        final float[] texture = new float[floatCounterTexture.size()];

        //copy floats into floatArray[]
        for(int i=0; i<floatCounterVertices.size();i++)
        {
            vertices[i]=floatCounterVertices.get(i);
        }

        //copy texture
        //all texture with -2 gets filters in fragment shader. so it will get black
        for(int i=0; i<floatCounterTexture.size();i++)
        {
            if(i>131 && i<138) {
                texture[i] = floatCounterTexture.get(i);
            }
            else{
                texture[i]=-2;
            }
        }

        countVertices=floatCounterVertices.size();

        FloatBuffer floatBufferVertex = OpenGlHelper.createFloatBuffer(countVertices * NUM_FLOATS_PER_VERTEX* Float.SIZE);
        floatBufferVertex.put(vertices);
        floatBufferVertex.position(0);
        this.mVertexBuffer.add(floatBufferVertex);

        FloatBuffer floatBufferTexture = OpenGlHelper.createFloatBuffer(countVertices * NUM_FLOATS_PER_TEXTURE * Float.SIZE);
        floatBufferTexture.put(texture);
        floatBufferTexture.position(0);
        this.mTextureBuffer.add(floatBufferTexture);

    }

fragment shader:

#extension GL_OES_EGL_image_external : require
                    precision mediump float;
                    varying vec2 vTextureCoord;
                    uniform samplerExternalOES sTexture;


void clamp_to_border_factor (vec2 coords)
{
    bvec2 out1 = greaterThan (coords, vec2 (1,1));
    bvec2 out2 = lessThan (coords, vec2 (0,0));

    bool do_clamp = (any (out1) || any (out2));
    if(do_clamp)
    {
        gl_FragColor=vec4(0.0f, 0.0f, 0.0f, 0.0f);;
    }
    else
    {
        gl_FragColor = texture2D(sTexture, vTextureCoord);
    }
}

void main() {
    clamp_to_border_factor(vTextureCoord);
    }

here is my problem:
i want to texture only one trinangle.
the programm draws the texture of the triangle but also a little bit more at the right and left border.
why? what im doing wrong?
[ATTACH=CONFIG]1340[/ATTACH]

That won’t work. Where some of a triangle’s vertices have valid texture coordinates but others have -2, the texture coordinates for fragments within that triangle will be the result of interpolating between the valid texture coordinates and -2, meaning that some of the fragments will have texture coordinates within the valid range.

If you want to disable texturing for specific triangles, the usual approach is to add texture seams to the mesh, i.e. vertices which are shared between textured and untextured triangles need to not be shared, so that one vertex can have valid texture coordinates while the other doesn’t.

An alternative approach is to use 3D texture coordinates, with the third coordinate e.g. equal to zero for valid texture coordinates and some non-zero value for invalid coordinates. The fragment shader can then examine the third coordinate and if it’s not equal to zero (even if it’s only slightly different), don’t perform texturing. This will result in texturing being disabled for a triangle if any of its vertices have invalid texture coordinates.

thank you.
i found a solution.

now, i will just calatulate the vertices which i want to use.

so i change the code.
its working fine but i got one wrong triangle. i dont want that triangle.
it goes from the object to the origin of MPV matrix.

here are two pictures.

one picture in front view and the 2nd pic, the object is 70 degress turned

[ATTACH=CONFIG]2215[/ATTACH]
[ATTACH=CONFIG]2216[/ATTACH]

i only changed this method.

private void createSphereWithTextureCord(Float stepsZ, Float stepsBezugsgrade, float radius,int begrenzungZ, int begrenzungX)
    {
        Float x1,y1,z1;
        Float x2,y2,z2;
        Float bezugsgradeZ2, bezugsgradeZ1;
        Float xTextureZ2,yTextutueZ2, xTextureZ1, yTextutueZ1;

        Float stepAngleZ=new Float(0);
        Float stepAngleBezugsgrade=new Float(0);

        ArrayList<Float> testZ=new ArrayList<>();

        //calculate stepAngle
        stepAngleZ=180/stepsZ;
        stepAngleBezugsgrade=360/stepsBezugsgrade;





        for (float angleZ = 0.0f; angleZ+stepAngleZ <=180.0f; angleZ += stepAngleZ) {

            ArrayList<Float> floatCounterVertices=new ArrayList<>();
            ArrayList<Float> floatCounterTexture=new ArrayList<>();

            z1 = (float)Math.cos(Math.toRadians(angleZ) * radius);
            bezugsgradeZ1 = (float)Math.sin(Math.toRadians(angleZ) * radius);

            z2 = (float)Math.cos((Math.toRadians(angleZ + stepAngleZ) ) * radius);
            bezugsgradeZ2 = (float)Math.sin((Math.toRadians(angleZ + stepAngleZ)) *radius);

            // Fixed latitude, 360 degrees rotation to traverse a weft
            for (float angleBezugsgrade = 0.0f; angleBezugsgrade <= 360.0f; angleBezugsgrade += stepAngleBezugsgrade) {
                //Texture berechnet
                //y hoehe(180 degree=nordpol->suedpol)
                //y hoehe (360 degree=nordpol->suedpole->nordpole)
                //x breite (einmal rum)
                //Texture
                
               if(!isPointOutOfRange(angleBezugsgrade, angleBezugsgrade+stepAngleBezugsgrade,begrenzungX,
                                        angleZ, angleZ+stepAngleZ,begrenzungZ)) {
                    //Punkt2 berechen
                    x2 = calcVertexCos(angleBezugsgrade, bezugsgradeZ2);
                    y2 = calcVertexSin(angleBezugsgrade, bezugsgradeZ2);

                    //Punkt2 berechen
                    x1 = calcVertexCos(angleBezugsgrade, bezugsgradeZ1);
                    y1 = calcVertexSin(angleBezugsgrade, bezugsgradeZ1);

                    //Texture 2 berechnen
                    xTextureZ2 = calcTextureX(angleBezugsgrade, begrenzungX);
                    yTextutueZ2 = calcTextureY(angleZ + stepAngleZ, begrenzungZ);

                    //Texture 1 berechnen
                    xTextureZ1 = xTextureZ2;
                    yTextutueZ1 = calcTextureY(angleZ, begrenzungZ);

                    //punkte 2 ins ARRay übergeben
                    floatCounterVertices.add(x2);
                    floatCounterVertices.add(z2);
                    floatCounterVertices.add(y2);

                    floatCounterTexture.add(xTextureZ2);
                    floatCounterTexture.add(yTextutueZ2);

                    //punkte 1 ins ARRay übergeben
                    floatCounterVertices.add(x1);
                    floatCounterVertices.add(z1);
                    floatCounterVertices.add(y1);

                    floatCounterTexture.add(xTextureZ1);
                    floatCounterTexture.add(yTextutueZ1);
                }
            }

            //if there no vertices then i dont have to copy something to the vertexbuffer
            if(floatCounterVertices.size()>0) {

                final float[] vertices = new float[floatCounterVertices.size()];
                final float[] texture = new float[floatCounterTexture.size()];

                //copy floats into floatArray[]
                for (int i = 0; i < floatCounterVertices.size(); i++) {
                    vertices[i] = floatCounterVertices.get(i);
                }

                for (int i = 0; i < floatCounterTexture.size(); i++) {
                    texture[i] = floatCounterTexture.get(i);
                }

                countVertices = floatCounterVertices.size();

                FloatBuffer floatBufferVertex = OpenGlHelper.createFloatBuffer(countVertices * NUM_FLOATS_PER_VERTEX * Float.SIZE);
                floatBufferVertex.put(vertices);
                floatBufferVertex.position(0);
                this.mVertexBuffer.add(floatBufferVertex);

                FloatBuffer floatBufferTexture = OpenGlHelper.createFloatBuffer(countVertices * NUM_FLOATS_PER_TEXTURE * Float.SIZE);
                floatBufferTexture.put(texture);
                floatBufferTexture.position(0);
                this.mTextureBuffer.add(floatBufferTexture);
            }
        }
    }

and here is a dump from the vertexbuffer. i dont no why i get this result, because there is no vertex with the coordinate 0,0,0 (origin of MPV Matrix)
i set the breakpoint at near the end of this method.
LINE: “this.mTextureBuffer.add(floatBufferTexture);”

//Array 1
vertices = {float[18] [at] 830030548688} 
 0 = -0.9848077
 1 = 6.123234E-17
 2 = 0.17364818
 3 = -0.96984625
 4 = 0.17364818
 5 = 0.17101006
 6 = -1.0
 7 = 6.123234E-17
 8 = 1.2246469E-16
 9 = -0.9848077
 10 = 0.17364818
 11 = 1.2060416E-16
 12 = -0.9848077
 13 = 6.123234E-17
 14 = -0.17364818
 15 = -0.96984625
 16 = 0.17364818
 17 = -0.17101006


//Array 2
vertices = {float[18] [at] 830030555696} 
 0 = -0.96984625
 1 = -0.17364818
 2 = 0.17101006
 3 = -0.9848077
 4 = 6.123234E-17
 5 = 0.17364818
 6 = -0.9848077
 7 = -0.17364818
 8 = 1.2060416E-16
 9 = -1.0
 10 = 6.123234E-17
 11 = 1.2246469E-16
 12 = -0.96984625
 13 = -0.17364818
 14 = -0.17101006
 15 = -0.9848077
 16 = 6.123234E-17
 17 = -0.17364818


does anybody has a solution?

heare are picture again from the post before:
[ATTACH=CONFIG]1351[/ATTACH]
[ATTACH=CONFIG]1352[/ATTACH]