0

プロジェクト用に均一な色の球体を作成する作業を行っていますが、問題が発生しています。球体は正常に動作しますが、glColorPointer で色を付けようとすると表示されなくなります。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;
        }
    }
}

実際にレンダリングするコードは

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();
}

ありとあらゆる助けをいただければ幸いです。何故か本当に困っています。

4

1 に答える 1

1

カラー ポインターに GL_INT (または任意の整数型) を使用すると、可能な最大の整数値が 1.0f (最大色) に、0 が 0.0f (最小色) に線形にマップされます。

Therefore unless your values of RGB and A are in the billions, they will likely appear completely black (or transparent if that's enabled). I see that you've got alpha = 1, which will essentially be zero after conversion to float.

于 2012-12-05T06:03:49.387 に答える