简体   繁体   English

GLES20解析obj文件和顶点,纹理索引

[英]GLES20 parse obj file and vertex, texture indices

I'm new in OpenGL-ES 2.0 and try to parse .obj file and draw on Android. 我是OpenGL-ES 2.0的新手,尝试解析.obj文件并在Android上绘制。

And I've succeed draw a simple cube with parsed data from .obj file 而且我已经成功地绘制了一个简单的多维数据集,其中包含来自.obj文件的已解析数据

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 但是下一步,我需要使用.obj数据绘制“纹理”,我发现存在“纹理索引”,我不知道如何在代码中使用该“纹理索引”

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. 我认为,只有“顶点索引”参数可以在glDrawElements API上使用。 How can I use glDrawElements with 'Vertex Indices' and 'Texture Indices'? 如何将glDrawElements与“ Vertex Indices”和“ Texture Indices”一起使用?

You can´t use texture indices with GLES20.glDrawElements. 您不能将纹理索引与GLES20.glDrawElements一起使用。

GLES20.glDrawElements can't draw elements with multiple textures, it will allways use the "current texture" GLES20.glDrawElements无法绘制具有多个纹理的元素,它将始终使用“当前纹理”

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 最好按纹理ID对顶点进行排序,并对每个纹理ID执行一个GLES20.glDrawElements调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM