texcord : how to apply a image to a mesh

Questions and answers about the how and why of making maps.
Post Reply
User avatar
big_daddy2
Private First Class
Private First Class
Posts: 131
Joined: Sat May 06, 2006 1:06 am
Location: the middle of nowhere, USA

texcord : how to apply a image to a mesh

Post by big_daddy2 »

i was wondering if u have an image how do u use a texcord with it?
User avatar
Tedius
Sergeant First Class
Sergeant First Class
Posts: 142
Joined: Tue Sep 19, 2006 6:10 pm
Contact:

Post by Tedius »

<h1>Fun with texcoords:</h1> by Tedius

I am guessing by the way you phrased your question that you may have a few steps to go before you are able to use texcoords successfully. But just in case, you or someone else is bound to find this useful. I am hoping you can make a simple mesh face. The code may look something like this:

Code: Select all

mesh
  vertex -16 75 0   #0
  vertex 16 75 0    #1
  vertex 16 75 24   #2
  vertex -16 75 24  #3

   face
    vertices 0 1 2 3
   endface
end
If you don't understand that, I dont blame you. Just stare at it for a while and you will eventually figure it out.

Take a picture such as http://images.bzflag.org/wtf.png and imagine that the bottom left corner is the point (0,0) and the upper right-hand corner is (1,1). Therefore, the four points we will refer to in texcoords are:
lower left -> 0 0
lower right -> 1 0
upper right -> 1 1
upper left -> 0 1

Below we will define the material as wtf, (I think it stands for wabbits taste funny), refer to the the material when we define the face, define the four corners as listed above, and then apply those corners to the vertices in the face. Here goes:

Code: Select all

material 
  name wtf
  addtexture http://images.bzflag.org/wtf.png
end
mesh
  vertex -16 75 0   #0
  vertex 16 75 0    #1
  vertex 16 75 24   #2
  vertex -16 75 24  #3

  texcoord 0 0  #0
  texcoord 1 0  #1
  texcoord 1 1  #2
  texcoord 0 1  #3
  face
    vertices 0 1 2 3
    texcoords 0 1 2 3
    matref wtf
  endface
end
Now your homework is to change the texcoord part. You can double it so you have a bunny on top of another like so:

Code: Select all

  texcoord 0 0  #0
  texcoord 1 0  #1
  texcoord 1 2  #2
  texcoord 0 2  #3
You can chop the bunny in half by putting in ".5" You can even skew the poor guy by putting in random numbers between 0 and 1 in those places.

mmm pancakes:

Code: Select all

texcoord .15 .5625  #0
  texcoord .625 .5625  #1
  texcoord .625 .857  #2
  texcoord .15 .857  #3
Edit: much apologies to big_daddy2. It turns out I underestimated him, he had no trouble with it at all.
Sorry, mate.
this signature intentionally left blank
User avatar
Grace F
Sergeant
Sergeant
Posts: 978
Joined: Sun Oct 01, 2006 12:29 pm
Location: Adelaide, AUSTRALIA

Post by Grace F »

You helped me out heaps though :D Cheers Tedius
Image
Image
User avatar
big_daddy2
Private First Class
Private First Class
Posts: 131
Joined: Sat May 06, 2006 1:06 am
Location: the middle of nowhere, USA

Post by big_daddy2 »

ya my image is side ways with the code u gave me, how do i make it up and down instead?
User avatar
Tedius
Sergeant First Class
Sergeant First Class
Posts: 142
Joined: Tue Sep 19, 2006 6:10 pm
Contact:

Post by Tedius »

Your texcoord should match up with the vertices. In my example, the vertices were listed in order from the lower left hand around to the upper left hand corner. If it is sideways, just switch your texcoords around like this:

Code: Select all

face 
    vertices 0 1 2 3 
    texcoords 1 2 3 0 
    matref wtf 
  endface 
or possibly this:

Code: Select all

face 
    vertices 0 1 2 3 
    texcoords 3 0 1 2
    matref wtf 
  endface 
[/code]
this signature intentionally left blank
User avatar
big_daddy2
Private First Class
Private First Class
Posts: 131
Joined: Sat May 06, 2006 1:06 am
Location: the middle of nowhere, USA

Post by big_daddy2 »

i did that and it is still side ways but the other way
User avatar
Winny
Grouchy
Grouchy
Posts: 2381
Joined: Wed Aug 24, 2005 12:27 am
Location: Ottawa eh?
Contact:

Post by Winny »

If you want a quick and dirty solution:

Put your image in a photo editor, and rotate it. I've done that a few times.
User avatar
TD-Linux
Sergeant
Sergeant
Posts: 724
Joined: Wed Apr 27, 2005 8:26 pm
Location: Mountain View, CA

Post by TD-Linux »

Hmm, I can't remember exactly how I got this to work for me. Just try ordering the texcoords different ways (keep them in numerical order kinda, just start at different numbers). I can't remember, but I think 0,0 on a texcoord is the upper left of a texture... that might be what is messing you up.
Post Reply