Texturing a mesh

Started by
8 comments, last by bargasteh 19 years, 1 month ago
what is the best way to texture a mesh or part of a mesh ? for example lets say we have a mesh with lots of triangles and we want to texture the whole mesh with one textrure and put another texture in the middle of it ? Is there any good tutorial to explain this? Thank you for your help.
OpenGl + C++
Advertisement
I think you could use a shader to do it.
Without order nothing can exist - without chaos nothing can evolve.
My screen flicker and blink alot when I enable the texture with
glEnable(GL_TEXTURE_2D);
what is going on ?

I do this :

//////////////////Texture///////////////
glEnable(GL_TEXTURE_2D); // This Enable the Texture mapping
id_texture=LoadBitmap("texture1.bmp"); // The Function LoadBitmap() return the current texture ID
// If the last function returns -1 it means the file was not found so we exit from the program
if (id_texture==-1)
{
MessageBox(NULL,"Image file: texture1.bmp not found", "NoImage",MB_OK | MB_ICONERROR);
exit (0);
}
//////////////////Texture///////////////
setupLights ();


please, why its like this?
OpenGl + C++
Let me draw it so you would undestand better what I meant:

..................
|\ |\ |\ |\ |
| \ | \ | \ | \ |
| \| \| \| \|
..................
..................
|\ |\ |\ |\ |
| \ | \ | \ | \ |
| \| \| \| \|
..................

Imagin this is my mesh with lots of triangles and I have a simple BMP file that should be textured at the top of that mesh.
what is the easiest way to do this?
I dont want a code from you, I just want to know when I put the texture in memory how I can apply it to all the triangle so at the end the final result will be the same as the original BMP file.
Thank you
for some reason the above text doesnt show properly when I press confirm
OpenGl + C++
Well your U,V texture coordiantes range from 0.0 to 1.0.
So when texturing your mesh, give the texture coordinates that represent the part of the image that is supposed to be covering than polygon.

for example you want to cover these QUADS with with a square texture.

._ ._ .|  |  |._ ._ .|  |  |._ ._ .the coordiantes for the exture are 0.0 ....................... 1.0   U.                         ..                         ..                         ..                         ..                         ..                         ..                         ..                         ..                         ............................1.0 V(i think I got the axis and direction right)


So the texture coordinates for the upper left quad are going to be

0.0,0.0 ______ 0.0,0.25     |          |     |          |     |          |0.25,0.0_______ 0.25,0.25
Thank you snisarenko, I gave you an extremely helpful point :)
How do you put that white area in your posts (where you just typed)?
What you said is really cool but the problem is when I want to do it with Triangle, I dont know the algorithm to do it, I did it on paper for one day but at the end I couldnt cover all the triangles with that texture.!
Is there any specific algorithm that does this perfectly? or do you think about something helpful?

Thank you again
OpenGl + C++
Quote:Original post by bargasteh
How do you put that white area in your posts (where you just typed)?


Enclose what you want in the box with a <source></source> tag, only use the square [] brackets instead of the <>'s.

So it should look something like this:

[ source]
//stuff in box
//more stuff in box
[ /source]

Without that space in the source tag.
Without order nothing can exist - without chaos nothing can evolve.
you can simply search the x and y min and max and then interpolate each point of each triangle in function of its x and y.

but i'm not and expert so...
Thanks
When I hard code the texture in my code it works and its fine, but I just wanted a faster way to texture it on a mesh, because size of the mesh changes (the number of row, col), therfore I need to devide the width and height of my texture by the number of col and rows. well its a pain in ass but I am trying to do it. Is there any better way to do it?
Thanks
OpenGl + C++
Thanks
When I hard code the texture in my code it works and its fine, but I just wanted a faster way to texture it on a mesh, because size of the mesh changes (the number of row, col), therfore I need to devide the width and height of my texture by the number of col and rows. well its a pain in ass but I am trying to do it. Is there any better way to do it?
Thanks
//COOL I CAN PUT CODE HERE :)


[Edited by - bargasteh on March 2, 2005 9:02:50 AM]
OpenGl + C++

This topic is closed to new replies.

Advertisement