我正在尝试在 Android Native Activity 中使用 opengles 绘制形状但是没画

问题描述

我正在尝试在 Android Native Activity 中使用 opengles 绘制形状。但是发现形状没有画出来,下面的函数有问题。

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,vertex);

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


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

        glBindTexture(GL_TEXTURE_2D,texture[0]);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        if (texCoord != NULL) glTexCoordPointer(2,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.5f,//  ???????
    0.5f,0.0f   //  ?????????
    //-0.5f,0.0f  //???????
    //-0.5f,//???????
    //0.5f,//?????????
    //0.5f,//?????????

};

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

    0.0f,1.0f,};

GLfloat _texCoord[] = {
    0.0f,};

GLushort _indices[] = {
    2,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);


}

此代码行为没有问题,但未绘制对象。

你能给我一些提示吗?

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

这个网址与我的问题有关

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)