Texture mapping meshes

Moderator
Posts: 373
Joined: 2006.08
Post: #1
I have made a program that load meshes and displays them to the screen. Curently, I'm just making all of the vertices in the shapes that make up the texture map a certain color so that I can see them, but I want to be able to apply a texture to the mesh. I'm making 3D objects, and I'm just wondering how I would go about texture mapping the mesh? I'm currently reading in a mesh composed of triangles, would it be easier to texture map if I used, say, squares or diamonds? I'm really new to this whole thing, so any help in the form of links, sample code, or anything else would be apreciated Smile
-wyrmmage

(And yes, I did google 'texture mapping mesh', but I couldn't find any useful links Rasp)

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
This really isn't the right question for you to be asking Rasp

Use your modeling program to texture the mesh, and load the texture coordinates from whatever file the modeling program saves.
Quote this message in a reply
Moderator
Posts: 373
Joined: 2006.08
Post: #3
ah, ok, so....I've got the texture coordinates in the file, now how do I retrieve the texture that I'm going to texture my mesh with? Ok, don't know if that made since...
I have one texture, let's call it theTexture.bmp. After loading the texture into memory, do I need to, like, chop it up into triangles (if my mesh is made up of traingles) that are proportionate in size to how large the triangles that make up my mesh are?
Thanks,
-wyrmmage

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #4
What you need to do is decide what API you are going to use to display 3D graphics, if you go with OpenGL then you will want to try loading models without textures first of all. and once that works you can worry about texture mapping.

basically what you would do is bind the texture, then each time you plot vertices you also put down texture coordinates, OpenGL will "chop it up into triangles" for you.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 373
Joined: 2006.08
Post: #5
hmmmm...let me explain my experience in this area a bit better. I can load 3D meshes that are not textured and display them. I can load a 2D object and texture it, whether it be a quad or a triangle, or whatever. Now I just need to texture 3D meshes. Oh, and I'm only in algebra 2, so I'm not into higher level math yet Sad oh, and ya, I'm planning on using OpenGL to do the texturing and displaying of the objects.
-wyrmmage

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
Each vertex has texture coordinates. You load those texture coordinates from your file. That is all.

You're thinking too hard.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #7

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 373
Joined: 2006.08
Post: #8
heh, ok, I just thought that it would be more complex than that; if that is all you have to do, I believe that I can do that Smile
Thanks guys,
-wyrmmage

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Quote this message in a reply
Moderator
Posts: 373
Joined: 2006.08
Post: #9
ooohhh....lol. After reading your messages a ton of times, I've realized what you are saying Rasp So, let me see if I have this write:
When you specify a texture coord, OpenGL automatically goes to the image that is bound and disects it into whatever your texture coords are? I previously thought that it just took an image, and the texture coords specified where on your shape the texture was drawn....guess I was wrong.
So....am I right?
Thanks again for the help Smile
-wyrmmage

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #10
Neither of the things you said makes a great deal of sense Rasp

A texture's coordinates run 0..1 horizontally ("s") and 0..1 vertically ("t"). That means if your texture is 512x256, texture coordinates (0, 0) refer to the pixel in the lower left, (0.5, 0.5) refer to the pixel at (256,128), etc. You specify s and t for each vertex you draw.

For every triangle ('cos internal to the GL, everything is triangles -- you draw a quad, you get 2 triangles), OpenGL looks at the texture coordinates for those vertices. If you plot those texture coordinates on your texture image, they too make a triangle. That triangle of the image is what's drawn on that triangle of the geometry.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Mapping 2D texture to multiple GL_TRIANGLES ardowz 2 1,163 Mar 12, 2014 08:56 AM
Last Post: ardowz
  OpenGL and concave meshes Ashford 3 4,284 Nov 21, 2009 10:31 AM
Last Post: AnotherJake
  Texture mapping single 3D object with one draw call jeonghyunhan 1 2,806 Jul 13, 2009 06:05 AM
Last Post: ThemsAllTook
  Texture Mapping: Loading a texture from a .bmp file? ishrock 5 6,328 Dec 13, 2008 09:27 AM
Last Post: ThemsAllTook
  Calculating tangent coords for arbitrary poly meshes TomorrowPlusX 8 5,742 Jul 9, 2007 03:10 PM
Last Post: Hog