I have the following code that in the first lines, it creates a grayscale image with the size of 256x 256 pixels of a perlin noise. And then the following lines it basically just duplicate the image and then flip it 4 times to form a image in the size of 1024 x 1024. The returning array has the following format:
[[0.5, 0.3, 0.2, 0.1, 0.0],
[0.5, 0.3, 0.2, 0.1, 0.0],
[0.5, 0.3, 0.2, 0.1, 0.0],
[0.5, 0.3, 0.2, 0.1, 0.0],
[0.5, 0.3, 0.2, 0.1, 0.0],
[0.5, 0.3, 0.2, 0.1, 0.0]]
where each number is equals a white value, I already use matplot lib to check if the array renders a image and it does. However, when I execute the following code:
def generate_texture(self):
#texture_size is defined as 1024 at __init__
lin = np.linspace(45, 57, self.texture_size / 4, endpoint=False)
x, y = np.meshgrid(lin, lin)
primary = perlin(x,y)
half_quadrant = np.append(primary, np.flip(primary, axis=1), axis=1) #duplicate and then flip the image
full_quadrant = np.append(half_quadrant, np.flip(half_quadrant, axis=0), axis=0) #merge it together
half_complete = np.append(full_quadrant, np.flip(full_quadrant, axis=1), axis=1) #flip all again
complete = np.append(half_complete, np.flip(half_complete, axis=0), axis=0) #merge it all again
complete = ndimage.gaussian_filter(complete, 10) #apply gaussian blur
complete = np.clip(complete, 0, 1) # clamp all values in the interval of 0 to 1
current_texture = Texture('noise') #create the texture
current_texture.setup2dTexture(self.texture_size, self.texture_size, Texture.T_float, Texture.F_luminance) #set texture values
current_texture.setRamImageAs(complete, "A") #add data from the array to the texture
return current_texture
I get the following error:
Known pipe types:
wglGraphicsPipe
(all display modules loaded.)
Traceback (most recent call last):
File "D:\Projetos\End Of Time - Pandas\src\engine_testing\main.py", line 100, in <module>
app = MyApp()
File "D:\Projetos\End Of Time - Pandas\src\engine_testing\main.py", line 19, in __init__
self.setup_planet()
File "D:\Projetos\End Of Time - Pandas\src\engine_testing\main.py", line 74, in setup_planet
self.model.setTexture(self.generate_texture(), 0)
File "D:\Projetos\End Of Time - Pandas\src\engine_testing\main.py", line 40, in generate_texture
current_texture.setRamImageAs(complete, "A")
TypeError: buffer.itemsize does not match Texture component size
Which to me is quite weird because I tested with len and such and I am sure the array has the same size that I set the texture with. I checked the documentation on setRamImageAs but I don’t get any details about the second parameter or how should I proceed to setup a grayscale picture. What exactly should be the correct configuration for that method?