Game Development Community

Looking for guidance on loading an image

by Tim Holt · in Torque Game Engine Advanced · 08/07/2006 (1:55 pm) · 2 replies

I'm working on a modified version of the Foliage Replicator and am having some problems figuring out how to load up an image file. Specifically I want to map a black & white image mask over the top of the area covered by the FR, then before I put down a plant I check to see if the corresponding pixel is black or white. Black means no plant, white means plant OK. This lets me do things like block out a road or path for example where I don't want the grass to show up.

My problem is that I don't seem to be loading my mask image - everywhere I sample has [255,255,255].

First, here's my mask image...

www.fsl.orst.edu/lemma/gnnviz/images/test_mask_256.png
Then here are some excerpts from the code I'm using to try and load the image. This is inside of the code which calculates the actual foliage element locations. Yea I know I've got hardwired paths and such - it will become a formal parameter later, once I get it working...

// Load mask image
GBitmap *mMaskBitmap = new GBitmap (256, 256, false, GFXFormatR8G8B8A8);
mMaskBitmap->load("starter.fps/data/gnnviz/vegmasks/test_mask_256");

.
.
.

// Map the coordinate of the proposed new foliage item to image space of the mask texture
// Then get the color of the given pixel in the image texture
U32 maskX = xOffset * maskScaleX;
U32 maskY = yOffset * maskScaleY;
mMaskBitmap->getColor(maskX, maskY, maskCol);

This code runs fine, and I have confirmed that my maskX and maskY coordinates are correct - as in they are between 0-255 (which is my image size).

The problem is, every pixel I sample comes back with maskCol RGBA equal to 255, 255, 255, 255 - no variant

So... what am I doing wrong here? Any hints on the right way to load an image, and then later sample it?

#1
08/07/2006 (2:56 pm)
Ah hah! Answered my own question...

My mistake was calling GBitmap::load. Yes it does load up an image, but it doesn't store the results in the current instance but instead returns a new bitmap containing the loaded image. Looking into it's code, I saw it's just using ResourceManager->loadInstance. So I redid my "load" code as follows, and it now works...


GBitmap *mMaskBitmap = (GBitmap *) ResourceManager->loadInstance(mFieldData.mMaskFile);
	if (!mMaskBitmap) {
		Con::errorf ("Failed to load foliage mask file %s", mFieldData.mMaskFile);
	}
#2
08/07/2006 (5:54 pm)
Picture of the mask technique by the way...

www.fsl.orst.edu/lemma/gnnviz/images/Torque/foliage_masking_1.jpg

That's actually one group of fxFoliageReplicators (now called an fxMaskedFoliageReplicator) with the mask texture providing some gaps and variations inside of the coverage area.