PDA

View Full Version : Texture Problem



Booba
04-23-2002, 07:20 AM
I want to know how can I do to apply different textures to a same object.
Because I load a map in ASE Format and I want to have a texture for the wall and

a another texture for the ground and a another for the sky etc...

I have done this :

const
nb_texture = 4;
arr_texture : array[0..NB_TEXTURE-1] of string =
(
'texture1.bmp', //id 1
'texture2.bmp', //id 2
'texture3.bmp', //id 3
'texture4.bmp', //id 4
);

a procedure which creates the texture with this array (which works correctly =)

and for example to apply the "texture2.bmp" to a cube :
BEGIN

glBindTexture( GL_TEXTURE_2D, 2);

glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0.0,1.0); glVertex3f(-150,+25,0);
glTexCoord2f(0.0,0.0); glVertex3f(-150,-25,0);
glTexCoord2f(1.0,1.0); glVertex3f(+150,+25,0);
glTexCoord2f(1.0,0.0); glVertex3f(+150,-25,0);
glEnd;

END

It's works perfectly to apply only one texture to an object, but what can I do to

apply different textures to different parts of an object.

With a map in ASE I want to apply different textures to the different *GEOMOBJECT

Thank you very much.

Devulon
04-23-2002, 07:37 AM
I am very familiar with ASE (Ascii Scene Export) Files. The issue of using a different texture with different *GEOMOBJECT is as simple as binding whichever texture you want on the object before you draw each object. As simple as...

BindTexture(1);
DrawObject(1);
Bind Texture(2);
DrawObject(2);
...

The issue I believe at hand for you involves drawing a single object with separate parts of the object recieving separate textures. (I assume you don't mean multitexturing). If you look at the ASE file you will see that each face of a mesh object contains a material ID. This is simply the sub material id that is assigned using any of the many methods in 3d studio max. The sub material id of each face corresponds to the sub material in a multi material material. I know it sounds sortof confusing. I am assuming you understand the way that the multiple material material works in max. The easiest way to draw objects of this type (but certainly not the most efficient way) is like this.

DrawObject(obj)
{
For M = EachMaterial
{
BindTexture(); // bind the texture for the sub material
forAllFaces
{
if(face.materialid == M)
drawface
} // end for all faces
} // end for all materials

Forgive my rather poor psuedo code. This is the basic idea. A more efficient way is to sort the faces by material. Then you save the if statement that is executed for every material for every face.

Let me know if this helps.
Happy Coding.

Devulon

davepermen
04-23-2002, 08:35 AM
****in crossposter

davepermen
04-23-2002, 10:06 AM
**** it...
if u have the solution tell me if not shut ur motha ****a
mouse.

thats the mail i got (you can do it officially if you want)

to your problem:
i don't know the ase-file very well, but the help you got should be quite ok.. as you know i think, you can only bind one texture at a time (per texture stage in multitexturing), so you have to call glBegin glEnd for each texture (or glDrawArrays or one of the equivalents..)

how ase stores it, sorry i don't know, but first: you got the answer i think yet, second: just save the mesh, at least its a textfile so it should be quite useful yet to get infos out of it..
http://www.flipcode.com/cgi-bin/msg.cgi?showThread=00002433&forum=general&id=-1

thats his other post..


don't get that stressy cause of this.. just post it at one place.. i f you don't get the answer, move to another one and comment that you tried it...

and, not to flame you or blame you, but this question is yet existing so if you know all those forums you _could_ find the info possibly, dunno..