PDA

View Full Version : Loading 3D textures (JOGL)



marce
07-22-2009, 10:16 AM
When you load a 2D texture, then you have to draw it on a primitive figure, like a QUAD.

What about 3D models? How are they drawned to screen? Are there any tutorials on this? Are OBJ models easiest to work with?

dletozeun
07-22-2009, 01:17 PM
Hem, are you asking for 3D model rendering or 3d texture rendering? The thread title and your question don't match.

marce
07-22-2009, 04:38 PM
Since I donīt know anything about 3D texture rendering or 3D model rendering I would appreciate a short howto about both of them.

1) How do I load a 3D model?
2) How do I load a 3D texture (in the same way as I load a 2D texture?)?
3) Are OBJ models easiest to work with?

MaxH
07-22-2009, 04:44 PM
What about 3D models? Are OBJ models easiest to work with? OBJ format is very easy to work with. One reason is because it's ASCII as opposed to binary. So you can look at it with your favorite text editor. It's fairly easy to understand too. A simple OBJ file describing a cube is included below. Lines beginning with 'v' define vertices. The 3 values after the letter 'v' are the x, y, and z coordinate for that vertex. Lines beginning with 'f' define faces (polygons). In this example they are all quads. In general they could have any number of vertices >= 3. The first face definition says to connect the fifth vertex to the 7th to the 3rd to the 1st. This would make a quad defining one face of the cube. Do you think you could write an OpenGL program to draw this obj file in wireframe? OBJ files get more complex than this. For example, face normals, material definitions, and texture coordinates can be specified. And of course, a LOT more than 6 faces are usually defined.

v -1 -1 1
v -1 -1 -1
v -1 1 1
v -1 1 -1
v 1 -1 1
v 1 -1 -1
v 1 1 1
v 1 1 -1

f 5 7 3 1
f 3 4 2 1
f 7 8 4 3
f 6 8 7 5
f 2 6 5 1
f 4 8 6 2

If you want to pursue this, the first step is to write a small OpenGL program to display this OBJ file in wireframe. Then extend it to render the cube with simple coloring. Then extend that to render the cube with lighting (which brings normals into play). Then extend it to handle textures (which is done on a face by face basis). The NeHe Tutorials follow a similar track except that they don't use OBJ files to define models.

How do you feel about coding? Is writing 500 lines of code more than you are willing to do to write an OBJ reader/renderer?

Good luck.

marce
08-19-2009, 07:19 AM
Thanks and sorry for a late reply.

So the vertex values (the values beginning with a "v") are the values set in a, for example, glVertex(x, y, z)?

I still donīt understand the faces. You say they define the connections between the vertices, what happens if I donīt connect the vertices?

Question: do at least the vertex values and face values have to exist in an OBJ file?

What are the "vn" and "vt" values that might appear in a OBJ file?

And why give the OBJ file the extension *.obj? Why not just *.txt since itīs just a text file? Is it just a convention to name it .obj?

_NK47
08-19-2009, 08:15 AM
if you don't "connect" the faces you have to render plain vertices as they are stored or given to the GPU. faces are anything more then 3 vertices to represent a polygon. a face of 3 polygons is a triangle since GPUs render triangles to represent a whole mesh. face indices are just "indices" that point which point into the vertex buffer to see which vertex to pick.

vertices [v0,v1,v2,v3,v4,v5,v6,v7] = containing f.e. position, texcoords, normals, tangets, colors, etc.
indices = [0,2,1] = uses v0,v2 and v1 to create a triangle