I'm new in OpenGL-ES 2.0 and try to parse .obj file and draw on Android.
And I've succeed draw a simple cube with parsed data from .obj file
the 'v' (vertex coords)
and the first values of 'f' line (v index)
but the next step, I need to draw 'Texture' with .obj data, I found there is 'Texture Index' and I've no idea how can I use this 'Texture Index' with my codes
GLES20.glVertexAttribPointer(mPositionHandle, 3, GLES20.GL_FLOAT, false, VSTRIDE, vertexCoords);
GLES20.glEnableVertexAttribArray(mPositionHandle);
GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false, TSTRIDE, textureCoords);
GLES20.glEnableVertexAttribArray(maTextureHandle);
...
GLES20.glDrawElements(GLES20.GL_TRIANGLES, indexLength, GLES20.GL_UNSIGNED_SHORT, vertexIndices);
I think, only 'Vertex indices' parameter can use on glDrawElements API. How can I use glDrawElements with 'Vertex Indices' and 'Texture Indices'?
You can´t use texture indices with GLES20.glDrawElements.
GLES20.glDrawElements can't draw elements with multiple textures, it will allways use the "current texture"
You set the Current texture binding a previosusly created texture. GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureID); //Next call of glDrawElements will use this texture
It's a good idea to order vertices by the texture id and execute one GLES20.glDrawElements call for each texture id
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.