Dynamically Access Bitmaps in ImageMaps
by Tim Kreger · in Torque Game Builder · 08/24/2006 (8:21 pm) · 3 replies
Hi,
I'm trying to set up a console method to change a pixel colour in an on screen sprites imagemap. I want to use this to allow the user to draw directly into a sprites imagemap. I've added to the imagedatablock code a couple of functions to get the source bitmap colour and to set it. The get works fine however the set isn't working. I think what I'm not doing properly is changing the pixel value of the sprites instance of the image map. I'm not sure where I can actually get the sprites instance rather than the imagemap datablocks.
Any pointers?
Cheers
Tim
I'm trying to set up a console method to change a pixel colour in an on screen sprites imagemap. I want to use this to allow the user to draw directly into a sprites imagemap. I've added to the imagedatablock code a couple of functions to get the source bitmap colour and to set it. The get works fine however the set isn't working. I think what I'm not doing properly is changing the pixel value of the sprites instance of the image map. I'm not sure where I can actually get the sprites instance rather than the imagemap datablocks.
Any pointers?
Cheers
Tim
About the author
#2
08/31/2006 (12:13 am)
Heres the solution, I worked out its better to avoid the src bit map and just work directly with the texture bitmap. This actually effects all instances of the image map.void t2dImageMapDatablock::getTexBitmapColor(U32 frame, const U32 x, const U32 y, ColorI& rColor)
{
TextureHandle tex = getImageMapFrameTexture(frame);
GBitmap* bmp = tex.getBitmap();
bmp->getColor(x, y, rColor);
}
void t2dImageMapDatablock::setTexBitmapColor(U32 frame, const U32 x, const U32 y, ColorI& rColor)
{
TextureHandle tex = getImageMapFrameTexture(frame);
GBitmap* bmp = tex.getBitmap();
bmp->setColor(x, y, rColor);
tex.refresh();
}
ConsoleMethod(t2dImageMapDatablock, getTexBitmapColor, const char*, 5, 5, " (vect color) - Get texel color at index.")
{
S32 frame = dAtoi(argv[2]);
S32 x = dAtoi(argv[3]);
S32 y = dAtoi(argv[4]);
ColorI color;
// Get Texture Color
object->getTexBitmapColor(frame, x, y, color);
// Create Returnable Buffer.
char* pBuffer = Con::getReturnBuffer(32);
// Format Buffer.
dSprintf(pBuffer, 32, "%d %d %d %d", color.red, color.green, color.blue, color.alpha );
// Return Color
return pBuffer;
}
//-----------------------------------------------------------------------------
// Set ImageMap Texture Colour.
//-----------------------------------------------------------------------------
ConsoleMethod(t2dImageMapDatablock, setTexBitmapColor, void, 9, 9, " (vect color) - Set texel color at index.")
{
S32 frame = dAtoi(argv[2]);
S32 x = dAtoi(argv[3]);
S32 y = dAtoi(argv[4]);
ColorI color;
color.red = dAtoi(argv[5]);
color.green = dAtoi(argv[6]);
color.blue = dAtoi(argv[7]);
color.alpha = dAtoi(argv[8]);
// Set Texture Color
object->setTexBitmapColor(frame, x, y, color);
}
#3
03/12/2010 (10:46 pm)
4 years late. but thank you !!
Torque 3D Owner Tim Kreger
after a fair bit of noodling I'm getting closer to a solution. The srcBitmaps I'm writing too are actually the bit maps. The problem seems to be in updating the textures which I've fiddled with a bit but arent making any progress. So to reframe my question:
1/ I write a new pixel value into the instance of the srcBitmap.
2/ I then need to make this altered bitMap be written to the texture on screen.
Can anyone give me suggestions as to what steps I need to take to do this.
Heres some stuff I've tried.
1/ Load the srcbitmap, change the pixel value, then call loadTexture. This has the effect of returning the srcBitmap to its original state.
2/ Copying the altered bitMap into the Tetxures biitmap field. This seems to do nothing.
I keep thinking this shouldn't be as difficult as I'm making it and maybe I'm barking up the wrong tree.
Any idea or pointer would be greatly appreciated.
Tim