Game Development Community

Adjusting a bitmap (software procedural textures) for TorqueIDE

by Davis Ray Sickmon, Jr · in Torque Game Engine · 12/01/2003 (1:08 am) · 9 replies

Ok, doin' some begging here for functionality for the TorqueIDE. I'm looking to build a little proof of concept thing, and I need to be able to adjust a bitmap dynamically. IE - Procedural Textures, done in software (no shaders needed or desired.) If someone has this, could I get you to part with it, so that I can see if my idea can be pulled off or not?

Yeah I know - someone will say "well, just build it yourself!" I've only got a limited number of hours per day to work on TorqueIDE (1 - 2 hours), and I'd REALLY love it if I can convince someone else to caugh up code on this one so that I can concentrate on the rest of what needs to be done on it.

Ok, begging over - Thanks! :-)

#1
12/01/2003 (5:03 am)
What sort of procedural textures are you looking for here?
#2
12/01/2003 (6:54 am)
Hi Ben -
Whoops - looks like I'm a bit of an idiot here. I think I'm asking for the wrong thing - I THOUGHT procedural textures meant anything where ya' started adjusting the texture while it was in memory, not just algorythmicly creating a texture. Ah well, some days my ignorance shows :-)

Here's what I was hoping to do - toss a bitmap on a control, and be able to get and set pixels within the bitmap (texture) through a couple of console commands. The short term proof of concept would be a VERY VERY simplistic graphic editor essentially. I've got something a little more interesting in mind for the long term, but, just being able to get and set a couple o' points from the texture would do the trick for now.

Any good ideas?
#3
12/01/2003 (7:56 am)
It could be done relatively easily, but, yeah.. its just a matter of doing it :D Im all booked up tho, sorry.
#4
12/01/2003 (8:08 am)
Huh, sounds really easy ;)
#5
12/01/2003 (8:09 am)
Bug me later and I'll do it.
#6
12/01/2003 (8:14 am)
Hm. How much later is later? :-) (As in - how much later should I bug you, not tryin' to rush ya to get it done or something.)
#7
12/01/2003 (8:33 am)
Davis,

seems like there is some existing stuff for doing this already in use in the SHADOW code. I was poking around in that code for a different reason and saw some render-to-texture stuff.

- Paul
#8
12/01/2003 (11:25 am)
Davis,

Here's how to create a 256x128 bitmap, amend it and upload it to a texture for display using whatever method you choose:-
// 256x128 (no mipmaps) @ RGBA.
[b]GBitmap* pBitmap = new GBitmap(256, 128, false, GBitmap::RGBA);[/b]
// Generate Texture from Bitmap (no name, our bitmap with edge clamping.
[b]TextureHandle myTexture = TextureHandle(NULL, pBitmap, true);[/b]
// Do something boring like fill bitmap with a set colour .. zzzzZZZ
[b]ColorI green(0,1,0,1)
for ( U32 x = 0; x < pBitmap->getWidth(0); x++ )
   for ( U32 y = 0; y < pBitmap->getheight(0); y++ )
      setColor(x,y,green);[/b]
// Update the texture.
[b]myTexture.refresh();[/b]

This is not the most efficient example but the quickest one I could muster.

Hope it helps. :)

- Melv.
#9
12/01/2003 (11:56 am)
Here is some code I used for a simple gamma correction on textures as I loaded them. Thought it might be helpful too:

GBitmap *bmp = TextureManager::loadBitmapInstance(texname);

if(!bmp)
{
	texHandles[t] = NULL;
	Con::warnf("Unable to load %s", texname);
}
else
{
	// Do really simple gamma correction
	float gamma = 2.5f;

	U8* pBits = bmp->getAddress(0,0);

	for (int j = 0; j < bmp->getWidth() * bmp->getHeight() * 3; j+=3)
	{
		float r = 0.0f, g = 0.0f, b = 0.0f;

		// extract the current RGB values
		r = (float)pBits[j];
		g = (float)pBits[j+1];
		b = (float)pBits[j+2];

		// Add in the gamma value
		r += gamma;
		g += gamma;
		b += gamma;

		// Clamp to 255
		if (r > 255.0f)
			r = 255.0f;
		if (g > 255.0f)
			g = 255.0f;
		if (b > 255.0f)
			b = 255.0f;

		// Assign the new gammanized RGB values to our image
		pBits[j] = (U8)r;
		pBits[j+1] = (U8)g;
		pBits[j+2] = (U8)b;
	}

	texHandles[t] = TextureHandle(texname, bmp, MeshTexture, false);
}