簡體   English   中英

切換為使用交錯式VBO-編譯但未繪制任何內容-OpenGL ES 2.0

[英]Switching to use Interleaved VBO's - compiles but nothing is drawn - opengl es 2.0

我剛剛嘗試過切換以使用交錯VBO。 我已逐步完成了創建Interleaved VBO的過程,看來它具有正確的信息初始化。

VVV NNN TT等

這是初始化緩沖區的代碼

VertexBuffer = Loader.vertexBuffer;     

final int buffers[] = new int[1];
GLES20.glGenBuffers(1, buffers, 0); 

GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, VertexBuffer.capacity(), VertexBuffer, GLES20.GL_STATIC_DRAW);  

GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

mBufferIdx = buffers[0];    

VertexBuffer.limit(0);
VertexBuffer = null;

這是我繪制模型的代碼

final int stride = (mPositionDataSize + mNormalDataSize + mTextureCoordinateDataSize) * mBytesPerFloat;

// Pass in the position information
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mBufferIdx);
GLES20.glEnableVertexAttribArray(mPositionHandle);
GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false, stride, 0);

// Pass in the normal information
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mBufferIdx);
GLES20.glEnableVertexAttribArray(mNormalHandle);
GLES20.glVertexAttribPointer(mNormalHandle, mNormalDataSize, GLES20.GL_FLOAT, false, stride,   mPositionDataSize * mBytesPerFloat);

// Pass in the texture information
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mBufferIdx);
GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
GLES20.glVertexAttribPointer(mTextureCoordinateHandle, mTextureCoordinateDataSize,  GLES20.GL_FLOAT, false,
stride, (mPositionDataSize + mNormalDataSize) * mBytesPerFloat);


// Clear the currently bound buffer (so future OpenGL calls do not use this buffer).
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

// Draw .
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, NumVertices);

在使用VBO之前,我離開了矩陣,因為這可以正常工作,而且我可以正確看到所有手柄。

我的應用程序看起來好像模型在那兒一樣在運行,但是只是看不見。 例如,我正在移動模型,並被告知何時到達某個位置,我只是看不到它,就像我搬到VBO之前一樣。

讓我知道是否需要上傳其他內容。 任何意見,將不勝感激。

更新!

我認為問題可能在於我在這里創建交錯VBO的方式

private void createVertexBuffer(float[] VertexList, float[] NormalList, float[] TextureList)
{
    final int vertexDataSize = VertexList.length + NormalList.length + TextureList.length;
    this.vertexBuffer = ByteBuffer.allocateDirect(vertexDataSize * mBytesPerFloat).order(ByteOrder.nativeOrder()).asFloatBuffer();

    int PositionOffset = 0;
    int NormalOffset = 0;
    int TextureOffset = 0;

    for(int i = 0; i < NumVerts; i++)
    {                       
        this.vertexBuffer.put(VertexList, PositionOffset, mPositionDataSize);
        PositionOffset += mPositionDataSize;
        this.vertexBuffer.put(NormalList, NormalOffset, mNormalDataSize);
        NormalOffset += mNormalDataSize;
        this.vertexBuffer.put(TextureList, TextureOffset, mTextureCoordinateDataSize);
        TextureOffset += mTextureCoordinateDataSize;            
    }
    this.vertexBuffer.position(0);
}

我可能做錯了什么?

更新碼

 mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVPMatrix");
    mMVMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVMatrix");
    mLightPosHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_LightPos");
    //mColorHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Color");

    Cube1.mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_Texture");
    Cube1.mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Position");
    Cube1.mNormalHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Normal");
    Cube1.mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_TexCoordinate");

 Cube1.SetTexture();
    Cube1.SetIdentity();
    Cube1.SetPosition();
    Cube1.SetScale(10.0f, 10.0f, 10.0f);
    Cube1.SetRotation(RotationAngle, 0.0f, 0.0f, 1.0f);
    Cube1.DrawModel(mProjectionMatrix, mViewMatrix, mMVPMatrix, mMVPMatrixHandle, mMVMatrixHandle, mLightPosHandle, mLightPosInEyeSpace); 

public void SetTexture()
{
    // Bind the texture to this unit.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle); 
    // Tell the texture uniform sampler to use this texture in the shader by binding to texture unit 0.
    GLES20.glUniform1i(mTextureUniformHandle, 0);
}

我不確定上面的代碼中的問題是什么,我如何重寫我的代碼以使用索引緩沖區並提交了另一個問題。 這里找到

除了我在另一個問題中給出的答案外,它還應為任何苦苦掙扎的人提供清晰的方法來介紹VBO和IBO。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM