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)
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
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.
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.
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.