Question

I have just tried switching to use Interleaved VBOs. I have stepped through the process of creating the Interleaved VBO and it appears that it has the correct information init.

VVV NNN TT etc.

Here is the code for initialising the buffer

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;

and here is my code for drawing the model

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

I left the matrices work out as this worked before using VBOs and i am seeting all the handles correctly.

My app appears to run as if the models are there but just invisible. for example i am moving a model and being told when it gets to a certain position, i just cant see it like i did before i moved to VBOs.

Let me know if i need to upload anything else. Any advice would be appreciated.

UPDATE!

I think the issue maybe in the way i create the interleaved VBO here is the code

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

What could i be doing wrong?

UPDATE CODE

 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);
}
Was it helpful?

Solution

I am not sure what my issue was in the above code how ever i re wrote my code to use an index buffer and have submitted in another question. Found here

Along with the answer i gave in the other question it should give a clear way of introducing VBO's and IBO's for any one who is struggling

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top