1

データ配列を VBO (glGen など) に変更すると、テクスチャ付きの立方体があり、立方体は灰色でレンダリングされますglVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, 0, myBuf);。問題は何ですか?私を助けてください。

 - (void)render:(CADisplayLink*)displayLink {
        glClearColor(0.0f, 1.0f,0.5f, 1.0f);


   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glEnable(GL_DEPTH_TEST);

        CC3GLMatrix *projection = [CC3GLMatrix matrix];
        float h = 4.0f * self.frame.size.height / self.frame.size.width;
        [projection populateFromFrustumLeft:-2 andRight:2 andBottom:-h/2 andTop:h/2 andNear:2 andFar:4];
        glUniformMatrix4fv(_projectionUniform, 1, 0, projection.glMatrix);
        CC3GLMatrix *modelView = [CC3GLMatrix matrix];
        [modelView populateFromTranslation:CC3VectorMake(sin(CACurrentMediaTime()), 0, -2)];
        _currentRotation += displayLink.duration * 90;
        [modelView rotateBy:CC3VectorMake(_currentRotation, _currentRotation, -1)];
        glUniformMatrix4fv(_modelViewUniform, 1, 0, modelView.glMatrix);

        // 1
        glViewport(0, 0, self.frame.size.width, self.frame.size.height);
        // 2

        glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
        glActiveTexture(GL_TEXTURE0);

        glBindTexture(GL_TEXTURE_2D, texture[0].texID);
        glUniform1i(uniformTexture, 0);
        glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, 0, 0);
          glEnableVertexAttribArray(_positionSlot);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cubeIndexes);
        glVertexAttribPointer(ATTRIB_TEXCOORD, 2, GL_FLOAT, 0, 0, texCoord);
        glEnableVertexAttribArray(ATTRIB_TEXCOORD);

        glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, (void*)0);

        //glBindTexture(GL_TEXTURE_2D, 0);
        glBindBuffer(GL_ARRAY_BUFFER,0);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
        [_context presentRenderbuffer:GL_RENDERBUFFER];
    }
4

1 に答える 1

0

頂点バッファに詳細を適用するには、クライアントの状態を使用する必要があります。glEnableClientStateおよびglClientActiveTextureの手動エントリを参照してください。

この方法でコードを変更してみてください。

    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
    glEnableClientState(GL_VERTEX_ARRAY); // NEW! we need to enable client state.
    glActiveClientTexture(GL_TEXTURE0); // CHANGED! We need to use textures in the client state.

静的TexCoordsと動的頂点を使用してglDrawElementsを呼び出す方法も参照してください。

どのバージョンのOpenGLを使用していますか?OpenGLES2.0を願っています

于 2011-10-28T02:24:34.413 に答える