views:

52

answers:

1

Hello,

I'm new to OpenGL. I'm playing around with it using JOGL. I'm using this model.

I am successfully rendering it to the window. However, I would like to apply textures/materials. I'm not entirely sure how to do this.

From the .obj file:

f 6307/4525/3 6303/4524/3 6327/4523/3 6315/4526/3
usemtl kahki_light_pave_W.png
f 6445/3470/305 6437/4623/305 6593/4624/305 6597/4625/305
f 6594/4626/306 6438/4627/306 6446/4628/306 6598/4629/306
f 6595/4630/307 6439/4631/307 6447/4632/307 6599/4633/307
f 6448/3482/308 6440/4634/308 6596/4635/308 6600/4636/308

Wikipedia tells me that everything after the usemtl statement and before the next usemtl statement is supposed to use khaki_light_pave_W.png. However, I'm not sure how do this in OpenGL.

There are a bunch of vertices defined at the top of the file:

v 19.886690 3.093822 -21.149584
v 23.886690 3.093822 -21.149584
vt 0.918121 0.920883
vt 0.918121 0.959193
vt -0.537323 1.541370
vt -0.537323 1.503060
vt 0.462677 0.503060

Do I need to use the vt vertices for the texture? The f statements include indices. Are these indicies into the v vertices, vt, or both?

Thanks.

+1  A: 

tl;dr: The vt entries specify texture coordinates and the f entries index (1-based!) into three separate arrays (v, vt, and vn).

From the spec, section "Referencing vertex data":

For all elements, reference numbers are used to identify geometric vertices, texture vertices, vertex normals, and parameter space vertices.

Each of these types of vertices is numbered separately, starting with 1. This means that the first geometric vertex in the file is 1, the second is 2, and so on. The first texture vertex in the file is 1, the second is 2, and so on. The numbering continues sequentially throughout the entire file. Frequently, files have multiple lists of vertex data. This numbering sequence continues even when vertex data is separated by other data.

In addition to counting vertices down from the top of the first list in the file, you can also count vertices back up the list from an element's position in the file. When you count up the list from an element, the reference numbers are negative. A reference number of -1 indicates the vertex immediately above the element. A reference number of -2 indicates two references above and so on

genpfault
Ok, so given a set of vt points and an image, what opengl calls do I need to apply the texture? Given a line like `f 1/2/3 4/5/6 7/8/9`, how do I know what vertex list it's indexing in to?
Rosarch
There's just one vertex list per OBJ: all `f` elements index into it.
genpfault
Ok, but what you posted above says that each vertex type is numbered separately? so if it says f 1/2, how do I know if it is referring to v[1] and v[2] or vt[1] and vt[2]?
Rosarch
Read the spec section right below it, "Referencing groups of vertices". The first index is the vertex, the second is the texture coordinate, and the third is the normal.
genpfault