سؤال

I am teaching myself opengl es. I recently figured out how to parse/load a mesh from .OBJ file. I am now trying to apply a texture to it, I know I can only use one set of indices.. other than that I am lost as to the concept and code required to draw a texture onto my cube. A detailed/semi-detailed explanation of what's required, code, and description of what is happening would be soooo much appreciated. I haven't found much for opengl es on this subject and the explanations are a bit vague for me. Please remember I am using opengl es. Thanks in advance. BTW if it helps this is the .OBJ file

enter code here
# Blender v2.62 (sub 0) OBJ File: ''

www.blender.org

mtllib untitled.mtl o Cube_Cube.002 v 1.067472 -0.769912 -1.117719 v 1.067472 -0.769912 0.882281 v -0.932528 -0.769912 0.882281 v -0.932527 -0.769912 -1.117719 v 1.067473 1.230088 -1.117718 v 1.067472 1.230088 0.882282 v -0.932528 1.230088 0.882281 v -0.932528 1.230088 -1.117719 vt 0.951958 0.112804 vt 0.951958 -0.887196 vt -0.048042 -0.887196 vt -0.048042 0.112804 vt 0.058859 0.112804 vt 0.058859 1.112804 vt 1.058859 1.112804 vt 1.058859 0.112804 vt 0.951958 1.112804 vt -0.941141 0.112804 vt -0.941141 -0.887196 vt 0.951958 0.058859 vt -0.048042 0.058859 vt 0.951958 -0.941141 vt 1.951958 -0.941141 vt -0.048042 -0.941141 usemtl Material.001 s off f 5/1 1/2 4/3 f 5/1 4/3 8/4 f 3/5 7/6 8/7 f 3/5 8/7 4/8 f 2/1 6/9 3/4 f 6/1 7/4 3/3 f 1/5 5/6 2/10 f 5/5 6/10 2/11 f 5/12 8/13 6/14 f 8/12 7/14 6/15 f 1/12 2/14 3/16 f 1/12 3/16 4/13

P.S. I understand how to read/parse/understand these aspects of the file. I just need clarification on how I am supposed to use one indexbuffer for the texture and vertices while making only one call to drawelements. Thanks again!

هل كانت مفيدة؟

المحلول

I don't know if blender can do it, but some tools exists to export .obj with a single set of indices. This will look like this:

f 6/6/6 1/1/1 4/4/4 
f 4/4/4 1/1/1 3/3/3 
f 1/1/1 2/2/2 3/3/3 
f 12/12/12 2/2/2 1/1/1 
f 11/11/11 12/12/12 1/1/1 
f 11/11/11 81/81/81 12/12/12 

For instance, UDK does this when you export a scene (made of StaticMesh) to .obj format. Using a tool that exports .obj in such way is the easiest solution for you. You can however rebuild the arrays yourself from what you read from the .obj in your code, but it's a boring and unnecessary time consuming operation.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top