0

I'm trying to draw shapes using opengles in Android Native Activity. However, I found that the shape was not drawn and that there was a problem with the function below.

void GLObject::draw() {
glPushMatrix();

if (_isVisible) {
    if (transparent()) {
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }
    glEnable(GL_CULL_FACE);
    if (mode == GL_TEXTURE_MODE) {
        glEnable(GL_TEXTURE_2D);
    }
    if (gradation()) {
        glShadeModel(GL_SMOOTH);
    }
    else {
        glShadeModel(GL_FLAT);
    }

    glEnableClientState(GL_VERTEX_ARRAY);
    if (pickMode) glColor4f(colors[0], colors[1], colors[2], colors[3]);
    
    if (vertex != NULL) glVertexPointer(3, GL_FLOAT, 0, vertex);

    glEnableClientState(GL_NORMAL_ARRAY);
    if (normal != NULL) glNormalPointer(GL_FLOAT, 0, normal);


    switch (mode) {
    case GLObject::GL_COLOR_MODE:
        if (!pickMode) {
            if (colors != NULL) {
                glEnableClientState(GL_COLOR_ARRAY);
                glColorPointer(4, GL_FLOAT, 0, colors);
            }
        }
        break;
    case GLObject::GL_TEXTURE_MODE:
        glEnableClientState(GL_COLOR_ARRAY);
        if (!pickMode) {
            glEnableClientState(GL_COLOR_ARRAY);
            if (colors != NULL) glColorPointer(4, GL_FLOAT, 0, colors);
        }

        glBindTexture(GL_TEXTURE_2D, texture[0]);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        if (texCoord != NULL) glTexCoordPointer(2, GL_FLOAT, 0, texCoord);
        break;
    }

    motion();


    if (indices != NULL) glDrawElements(GL_TRIANGLE_STRIP, indiceLength, GL_UNSIGNED_SHORT, indices);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    if (transparent()) {
        glDisable(GL_BLEND);
    }
    //  
    if (mode == GL_TEXTURE_MODE) {
        glDisable(GL_TEXTURE_2D);
    }
    glDisable(GL_CULL_FACE);
}

glPopMatrix();
}


GLRectangle::GLRectangle() {
GLfloat _vertex[] = {

    0.5f, 0.5f, 0.0f,   //  ?????????
    -0.5f, 0.5f, 0.0f,  //  ???????
    -0.5f, -0.5f, 0.0f, //  ???????
    0.5f, -0.5f, 0.0f   //  ?????????
    //-0.5f, 0.5f, 0.0f  //???????
    //-0.5f, -0.5f, 0.0f,  //???????
    //0.5f, -0.5f, 0.0f,    //?????????
    //0.5f, 0.5f, 0.0f, //?????????

};

int _vertex_cnt = sizeof(_vertex) / sizeof(GLfloat);
GLfloat *_normal = new GLfloat[_vertex_cnt];
GLfloat _colors[] = {

    0.0f, 1.0f, 0.0f, 0.5f,
    0.0f, 0.0f, 1.0f, 0.5f,
    1.0f, 0.0f, 0.0f, 0.5f,
    0.0f, 1.0f, 0.0f, 0.5f,
};

GLfloat _texCoord[] = {
    0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f,
};

GLushort _indices[] = {
    2, 0, 1, 3, 2, 0
};
vertexSize = sizeof(_vertex) / sizeof(_vertex[0]);
indiceSize = sizeof(_indices) / sizeof(_indices[0]);
colorSize = sizeof(_colors) / sizeof(_colors[0]);
textureSize = sizeof(_texCoord) / sizeof(_texCoord[0]);
normalSize = getNormalArray(_vertex, &vertexSize, _indices, &indiceSize, _normal);

setVertex(_vertex, vertexSize);
setColors(_colors, colorSize);
setNormal(_normal, normalSize);
delete[] _normal;
setTextureCoord(_texCoord, textureSize);
indiceLength = indiceSize;
setIndices(_indices, indiceSize);


}

There is no problem with this code behavior, but the object is not drawn.

Could you give me a some hint?

I'm trying to draw objects using opengles in Android Native-activity, but I don't see anything

This url is a relevant my question with this post

no name
  • 51
  • 6
  • How is this different from your original question? Maybe you should update that with any new details you have. – Retired Ninja Jan 13 '21 at 08:47
  • There are no changes to the underlying source code, but I found that the function was not functioning properly. – no name Jan 13 '21 at 08:57

0 Answers0