Now here's an interesting texturing problem...

Hi!

I’m working on an assignment for school and it’s driving me crazy! I am supposed to texture a quad by reading data from a PPM file. The PPM reader was supplied to us and we only have to read a 256*256 texture and apply it to an object.

Now the problem is that I can apply some textures, but if I change the motive it might not be read correctly anymore. Take a look at the two “textures” below. I had to zip the files to upload them to my space. The source code of the project is also included.

Textures, including source

The texture with just the black “O” on the white background (Image1.ppm) is read correctly. The same picture with a small rectangle copied from a grass texture applied to the middle (test.ppm) won’t be read correctly! Click the link below to see what it looks like when the texture is applied:

Picture of the problem

(The black lines are just the coordinate axes).

As you can see, the texture isn’t read correctly approximately starting from where the grass texture begins.

I might also add a few more things:

  • If I create a 256 by 256 image and manually paint it with different colors, there aren’t any problems with reading it correctly. If I, however, paste a photo (or part of one) into the same image, i won’t be read correctly anymore.

  • The program seems to read the colors wrong. Green turns blue and so on.

I just think this problem is extremely strange and I can’t find anything that would cause the program to read some pixels but not others. It just doesn’t make any sense! :mad:

Originally posted by Mikael:
[b]

  • If I create a 256 by 256 image and manually paint it with different colors, there aren’t any problems with reading it correctly. If I, however, paste a photo (or part of one) into the same image, i won’t be read correctly anymore.
    [/b]

The screenshot you posted, looks as if reading of the file terminates prematurely. This might be caused by the file being opened as “r” instead of the correct “rb” (ppm is a binary file format).

[b]

  • The program seems to read the colors wrong. Green turns blue and so on.
    [/b]
    This would indicate, that one byte of the header is not being skipped, so that the green values in the image file are being read as blue values.

If the change from “r” to “rb” in the fopen call does not fix the problem for you, i have put a rewritten version of the ReadTexture function .

Thank you so much! The change from “r” to “rb” fixed both the premature termination of the read operation AND the incorrect colors! All looks nice and dandy now! :cool:

The person responsible for the course (and consequently the PPM reader) is going to hear about this…