BufferedImage to Texture

Ok… I’m going through the painful process of moving a game that is well under development from Java2D into LWJGL

I’ve already made a system that dynamically makes a huge sprite sheet and remembers where all the sprites are, so the whole binding Texture should be ready to go.

Now here’s the one method I need to implement before I can proceed (and it’ll only be called once or maybe a few times per game)

I need to make a BufferedImage into a Texture object

I don’t care if it’s really ugly or really “slow”, because it’s a very rare method

I’m having a hard time figuring out how to accomplish this. Does anyone know?

Thanks

Which part do you want the help with? Loading the texture, or converting buffered image into byte buffer?

Check out SHC’s tutorial: http://goharsha.com/lwjgl-tutorial-series/textures/
In the “Loading Textures” section

Ah, that’s the code I was wondering about, changing a buffer into a texture.

Thank you!

Or to get away from all the bit-swizzling in Java, you could try this -

When the guy says,

[quote]My textures are already allocated (as RGBA8) by this point.
[/quote]
How does one go about actually doing that?

Texture texture = ???

Thanks

I would say to read that tutorial and get an understanding on how OpenGL works. It seems you’re a bit new :). OpenGL does not have a default texture class, but it does have ways of binding texture buffers onto your graphics card. I would not recommend using random classes without knowing what your doing, but here’s a very basic one I use: http://pastebin.com/3ajgWhDF Like I said, you’d get allot more out of it, re-reading this class and that tutorial a shit-tonne of times.

Make sure to use texture coordinates when initializing the object you’re going to draw. Heres how to use it,

Texture texture;

public void initialize(){
    //Setup display before initializing texture, to create an OpenGL context to use.
    ...
    texture = Texture.loadTexture("./assets/img.png"); //Get a texture from classpath
}

public void render(){
    texture.bind();
     ...Render (with texture coordinates!!)
    texture.unbind();
}

Thanks

I’ve actually read a lot of tutorials
I would load in Textures straight from files, like you have, but I already have so much code behind my dynamically created Sprite Batches (made as a giant BufferedImage) that I would much rather just convert that into a Texture. It also makes my life easier because I don’t have to code in anywhere where each sprite is located on the batch