texturing issue

Hi all

I am trying to apply a texture on some cylinders. The textures I use are flags from different countries (USA, FRANCE and GERMANY).

Here is what I do :

        # create model
        self.model = self.loadModel("cylinder")
        # set parent
        self.model.reparentTo(parent)
        # set size
        self.model.setScale(self.radius,self.radius,0.01)
        # set color
        self.model.setTransparency(TransparencyAttrib.MDual)
        self.model.setColor(1,1,1,1)
        # set texture
        if(self.countryName == "FRANCE"):
            flag = loader.loadTexture("textures/france.png")
        elif(self.countryName == "USA"):
            flag = loader.loadTexture("textures/usa.png")
        elif(self.countryName == "GERMANY"):
            flag = loader.loadTexture("textures/germany.png")
        flag.setWrapU(Texture.WMRepeat)
        flag.setWrapV(Texture.WMRepeat)
        self.model.setTexture(flag)

And here is the result:
picasaweb.google.co.uk/morel.jer … 9611700882

The vaguely yellow circles are the cylinders with the german flag, the red ones are the one with the american flag, and the pink ones are the one with the french flag.

I tried different scales of textures (6060px to 1600900px) but the result is always the same. Do you have any idea about why I can’t display the flag “normally” ?

first of all. textures should always have a sizw with a power of 2 simply because most graficcards demands it… means sizes like 64x512 or 128x265 or 32x32.
if the textures dont show up at all try to change your code to:

self.model.setTexture(flag, 1 )

notice the “,1” after the flag.
if you still cant see anything you should check the uv-coordinates of your cylinder.
for tests you could automatically generate those uv-coords to check if the rest is working. just try adding

self.model.setTexGen(TextureStage.getDefault(), TexGenAttrib.MWorldPosition)

hope this helps… if it’s still messy just write again =)
greetings,
ThomasEgi

Be sure you have read this manual page: http://panda3d.org/manual/index.php/Simple_Texturing and that you understand the importance of texture coordinates (UV’s).

Also read http://panda3d.org/manual/index.php/Choosing_a_Texture_Size and note in particular the last paragraph:

The placement of the texture on your model is determine by the model’s UV’s, and if it doesn’t have any UV’s at all, it will just smear one pixel of your texture over the whole model.

David

ThomasEgi > thanks a lot, it works

drwr > I read all of that. But I also know that the code I produce tends to be not deterministic at all. Therefore I tried with multiple sizes.

Thanks to ThomasEgi it works. But the texture is repeated on the whole surface (quite logical when I take a look at the code). However I’m trying to magnify the texture so that it covers the whole cylinder. But I have no idea of how to do that. It tried the setMagFilter attribute, but it doesn’t do anything.

Can someone help me ?

that’s exactly WMRepeat does. try WMClamp.
and you can simplify the texture name :

flag = loader.loadTexture("textures/%s.png" %(self.countryName.lower()))

ynjh_jo > The problem with WMClamp is that it expands the border (not the border color, but the image border). what I want to do is have the whole texture magnified to the object size. But I couldn’t find anything in the doc about that.

then scale up the UV so it’s completely fit on 0…1