[SOLVED] Texture & PNMImage write method

hello ,

I am trying to write an auto generated image to disk.
I can succesfully create the file but they are all black and only 1kb (256x256) - which is ofc wrong.

here my code

PNMImage* pPNMImage = new PNMImage(256, 256, 4);

for (int y = 0; y < 256; y++) 
    for (int x = 0; x < 256; x++)
      pPNMImage->set_red_val(x, y, redValue );
      pPNMImage->set_green_val(x, y, greenValue);
      pPNMImage->set_blue_val(x, y, blueValue);
      pPNMImage->set_alpha_val(x, y, 1.0f);

PT(Texture) pTex = new Texture();

bool a = pTex->write(Filename("NewTex.png"));
bool b = pPNMImage->write(Filename("NewPNMImage.png"));

delete pPNMImage;

am I missing something ?

Yes, you are using the set_red_val() etc. interfaces, which expect a color value in the range 0…255 or whatever the maxval of the current PNMImage is, instead of the set_red() etc. interface, which expect a color value in the range 0…1.

So you are actually generating a black image.


nice one mate,
I completly overlooked this.

Problem solved :slight_smile: