PDA

View Full Version : Now here's an interesting texturing problem...



Mikael
10-04-2005, 06:11 AM
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 (http://upl.silentwhisper.net/uplfolders/upload1/pics.zip)

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 (http://upl.silentwhisper.net/uplfolders/upload3/texerr.gif)

(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:

memfr0b
10-04-2005, 01:09 PM
Originally posted by Mikael:

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



- The program seems to read the colors wrong. Green turns blue and so on.
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 (http://memfrob.de/~memfrob/ppm_reader.c) .

Mikael
10-04-2005, 10:37 PM
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...