Author Topic: Runtime-generated textures  (Read 1568 times)

Offline AW999

  • int
  • **
  • Posts: 57
    • View Profile
Runtime-generated textures
« on: July 13, 2010, 07:47:05 pm »

Once I've generated the textures I need via my code, what's the easiest way to transfer that array to a usable texture graphic which jPCT can use?  I assume for a .bmp, I just need to reverse the array so it's "upside down" and then add a header?  Or is it best to use premade conversion code from a library? Or am I way off base...?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Runtime-generated textures
« Reply #1 on: July 13, 2010, 10:39:40 pm »
Depends on the format of the generated texture. If it's an int[]-array or similar, the best way is to use an ITextureEffect.

Offline AW999

  • int
  • **
  • Posts: 57
    • View Profile
Re: Runtime-generated textures
« Reply #2 on: July 13, 2010, 11:06:59 pm »
Depends on the format of the generated texture. If it's an int[]-array or similar, the best way is to use an ITextureEffect.

  Just an array of pixels in RGB format. Is there an example of using ITextureEffect for something like this?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Runtime-generated textures
« Reply #3 on: July 13, 2010, 11:18:08 pm »
I have various ITextureEffect implementations lying around here, but i guess they would confuse more than they might help, because they do too much.

The steps are pretty simple:

  • Implement the ITextureEffect-interface and let the apply()-method copy your generated pixel data into the dest int[]-array
  • Assign the effect to an empty texture of that size (Texture.setEffect())
  • Apply the effect (Texture.applyEffect())
  • Remove the effect (Texture.removeEffect())

That's basically all there is to do. Hope this helps.