newbie:texture laoding

Started by ug02070, November 21, 2004, 15:41:43

Previous topic - Next topic

ug02070

now that i have a 3d model loaded into lwjgl, what is the best way of adding the texture to it, the raw file only contains its vertices and nothing about its textures
thanks to all who reply
Danny :)
ps also is there a way that is there a method that will say when my object has reached the end of the screen, imagine with space invaders when the alien reaches the end of the screen,i could easily work out the position beacause of the fixed camera but was just wondering if there was a better way,
also is there a method that will translate back to 0,0,0???
thanks everyone

aaron

Hey Danny,

I wrote up a lengthy reply for you, but got an error when I posted it and my post disappeared.  :(

I'll summarise what I said here.

Basically, I believe in OpenGL, putting a texture onto a model requires that your model has texture coordinates. Since yours doesn't have them built in, you can 'generate' them using a projection, such as a planar, cylindrical or spherical projection.

I googled for a visual example, and one that I found quickly was here: http://www.ashlar.com/tutorial/textures_3.shtml

How this works is to 'wrap' a projection surface (such as a sphere) around your model. Getting texture (u, v) cooordinates for a sphere is easy, so for each vertex in your model, draw a ray out from the centre of the sphere, to the vertex and finally to the sphere. Now, this vertex grabs the (u, v) coordinates from that part of the sphere.

If you have a texture map in one of the common projections, mapping it should be a relatively easy process. However, if you want to make one, this is a bit harder. The easiest way I can see (apart from using a commercial program) would be to project your entire model onto the projection surface (eg. a sphere), and output this to an image file.

In regards to your other question, you can use GLU.gluProject() on each 3d vertex of your object's bounding box. gluProject() generates 2d screen coordinates from your world coordinates, hence if the y value of all the coordinates of the object's bounding box are greater than your screen height, it is above the screen.

What do you mean by "translate back to (0, 0, 0)?" Do you want to get a translation that will get an object at (x1, y1, z1) back to (0, 0, 0)? If so, then you could just use glTranslatef(-x1, -y1, -z1) ?

Hope this helps..

Aaron

ug02070

does anyone know how i can get the texture out of a 3ds file and onto my object??

Chman

As far as I remember, .3ds files don't store the textures... Except if it's a .max file... So textures should be with the model.

(maybe I'm wrong, but the last time I've worked with 3dsmax, model file wasn't able to store the texture file).

Chman

ug02070

all i know is that if i load it up in 3ds max it has a texture, now i use rhino, when i load it, it doesnt have one!! found a new model now that i think will work, a lwo file with a texture when it is in rhino, i have no idea how to load the texture though, there doesnt seem to be a file for the texture!! plz help

Chman

Well, to load textures with lwjgl and AWT, take a look here :
http://lwjgl.org/wiki/tiki-index.php?page=Lesson+6

If you want to use OpenIL (so fast, but it's in a very alpha version), look here :
http://lwjgl.org/wiki/tiki-index.php?page=Developers+Image+Library

Hope it helps :)

Chman