Opengl 将glColorPointer与GLDrawerElements一起使用会导致不绘制任何内容

Opengl 将glColorPointer与GLDrawerElements一起使用会导致不绘制任何内容,opengl,Opengl,我正在为一个项目制作统一颜色的球体,我遇到了一个问题。球体运行良好,但当我尝试使用GLCOLORPOINT给它们上色时,它们不再出现。当我调用glGetError时,OpenGL没有显示任何错误,所以我不知道为什么会发生这种情况 生成顶点、颜色等的代码: void SphereObject::setupVertices() { //determine the array sizes //vertices per row (+1 for the repeated one at th

我正在为一个项目制作统一颜色的球体,我遇到了一个问题。球体运行良好,但当我尝试使用GLCOLORPOINT给它们上色时,它们不再出现。当我调用glGetError时,OpenGL没有显示任何错误,所以我不知道为什么会发生这种情况

生成顶点、颜色等的代码:

void SphereObject::setupVertices()
{
    //determine the array sizes
    //vertices per row (+1 for the repeated one at the end) * three for each coordinate
    //times the number of rows
    int arraySize = myNumVertices * 3;
    myNumIndices = (myVerticesPerRow + 1) * myRows * 2;
    myVertices = new GLdouble[arraySize];
    myIndices = new GLuint[myNumIndices];
    myNormals = new GLdouble[arraySize];
    myColors = new GLint[myNumVertices * 4];

    //use spherical coordinates to calculate the vertices
    double phiIncrement = 360 / myVerticesPerRow;
    double thetaIncrement = 180 / (double)myRows;
    int arrayIndex = 0;
    int colorArrayIndex = 0;
    int indicesIndex = 0;
    double x, y, z = 0;

    for(double theta = 0; theta <= 180; theta += thetaIncrement)
    {
        //loop including the repeat for the last vertex
        for(double phi = 0; phi <= 360; phi += phiIncrement)
        {
            //make sure that the last vertex is repeated
            if(360 - phi < phiIncrement)
            {
                x = myRadius * sin(radians(theta)) * cos(radians(0));
                y = myRadius * sin(radians(theta)) * sin(radians(0));
                z = myRadius * cos(radians(theta));
            }
            else
            {
                x = myRadius * sin(radians(theta)) * cos(radians(phi));
                y = myRadius * sin(radians(theta)) * sin(radians(phi));
                z = myRadius * cos(radians(theta));
            }

            myColors[colorArrayIndex] = myColor.getX();
            myColors[colorArrayIndex + 1] = myColor.getY();
            myColors[colorArrayIndex + 2] = myColor.getZ();
            myColors[colorArrayIndex + 3] = 1;

            myVertices[arrayIndex] = x;
            myVertices[arrayIndex + 1] = y;
            myVertices[arrayIndex + 2] = z;

            if(theta <= 180 - thetaIncrement)
            {
                myIndices[indicesIndex] = arrayIndex / 3; 

                myIndices[indicesIndex + 1] = (arrayIndex / 3) + myVerticesPerRow + 1;

                indicesIndex += 2;
            }

            arrayIndex += 3;
            colorArrayIndex += 4;
        }
    }
}
任何和所有的帮助都将不胜感激。由于某些原因,我真的有点困难。

当您使用GL_INT(或任何整数类型)作为颜色指针时,它会线性地将最大可能的整数值映射到1.0f(最大颜色),并将0映射到0.0f(最小颜色)


因此,除非RGB和A的值达到数十亿,否则它们很可能会显示为完全黑色(如果启用,则显示为透明)。我看到alpha=1,在转换为float之后,它基本上是零。

您的其他上下文状态是什么?在你的纹理环境逻辑中,你如何处理顶点颜色?你所说的上下文状态是什么意思?另外,纹理逻辑也没有涉及,因为没有进行纹理处理。啊,那么对于标准的0-255,我需要使用一个字节?我很惊讶,我没有在任何地方看到这一点,甚至在红皮书中。不管怎样,谢谢你。
void SphereObject::render()
{
    glPushMatrix();
    glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
    glEnableClientState(GL_COLOR_ARRAY);
    glColorPointer(4, GL_INT, 0, myColors);
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_DOUBLE, 0, myVertices);
    glDrawElements(GL_QUAD_STRIP, myNumIndices, GL_UNSIGNED_INT, myIndices);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    glPopClientAttrib();
    glPopMatrix();
}