PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Questions about loading TGAs...

stefanminning · 08 Dec 2001, 15:20 UTC
Hi all,

having worked through the tutorials I'm now trying to set up my own little project; however, being rather new to PPC development in C++, I'm experiencing some trouble with EasyCE.

1. What I want to do seems rather simple, but I can't quite figure it out: I'd like to load a TGA which is smaller than 240x320 and tile it on the canvas. Whatever I tried didn't work as the images' height and width would always be 'overlooked' and the image would just draw 3 lines of 240 pixels instead of the intended 24x30 image!
2. Somewhat related to the above: How can I load a small TGA (say 30x30) and then draw it at a specific position on the canvas?

Any help would be appreciated!

Thanks,
Stefan
Hello Stefan

First are you happy that your targa file is the same resolution as EasyCE requires? I don't use EasyCE but I do load Targa files & they are as easy as graphics formats come so you must have a basic mistake somewhere

Also if you can debug by writing values to the screen using the built in print feature in EasyCE to see what's actually in your X & Y variables.

Hope this helps you start the debug process

Ian
Stefan,

EasyCE doesn't look at the resolution of an image file. Look at it this way: EasyCE loads a string of pixels from the file. Where you cut off each line is up to you. When you load directly to the screen canvas, the pixels are cut off at 240 pixels, since that's where the next line begins. So if you want to display a 30x30 image, you need to cut off the image yourself at 30 pixels per line, like this:

Code:

PIXEL* image = new PIXEL[30 * 30];
PIXEL* canvas = getbuffer();
tgaload( "myimage.tga", 30, 30, image );
for ( int x = 0; x < 30; x++ ) for ( int y = 0; y < 30; y++ )
  *(canvas + x + y * 240) = *(image + x + y * 30);


Notice that I add 240 to the canvas pointer for each line (the y-position) since the canvas is 240 pixels wide. Also notice that I add 30 pixels for each line to the source image pointer, since that image is 30 pixels wide.

It helps to stop looking at the screen as 240x320 pixels, but rather 64000 consequtive pixels that happen to be arranged in 320 lines of 240 pixels. In memory, there's no indication of this hardware boundary of 240 pixels.

- Jacco.
stefanminning · 09 Dec 2001, 09:00 UTC
Hi Jacco,

thanks a lot, your explanation was just what I needed - works like a charm now :-)

Thanks,
Stefan
is it just me or did you really mean 76800 pixels instead of 64000?
hehe, jacco got too much of ms-dos mode 13h
Hehe you're right. :) So that's why my latest game has a black bar at the bottom of the screen. :)