Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (563)
Games in Android Showcase (151)
games submitted by our members
Games in WIP (605)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  BufferedImage to Texture  (Read 547 times)
0 Members and 1 Guest are viewing this topic.
Offline nhmllr

Senior Devvie

Medals: 1
Projects: 3

slow and steady...

« Posted 2014-06-24 16:58:09 »

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?

Offline trollwarrior1
« Reply #1 - Posted 2014-06-24 17:02:50 »

Which part do you want the help with? Loading the texture, or converting buffered image into byte buffer?
Offline Longarmx
« Reply #2 - Posted 2014-06-24 17:07:42 »

Check out SHC's tutorial:
In the "Loading Textures" section

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nhmllr

Senior Devvie

Medals: 1
Projects: 3

slow and steady...

« Reply #3 - Posted 2014-06-24 17:47:53 »

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

Thank you!
Offline nsigma
« Reply #4 - Posted 2014-06-25 07:48:27 »

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

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline nhmllr

Senior Devvie

Medals: 1
Projects: 3

slow and steady...

« Reply #5 - Posted 2014-06-26 00:01:40 »

When the guy says,

My textures are already allocated (as RGBA8) by this point.

How does one go about actually doing that?

Texture texture = ???

Offline Spacebeans
« Reply #6 - Posted 2014-06-26 00:14:15 »

I would say to read that tutorial and get an understanding on how OpenGL works. It seems you're a bit new Smiley. 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: 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(){
     ...Render (with texture coordinates!!)
Offline nhmllr

Senior Devvie

Medals: 1
Projects: 3

slow and steady...

« Reply #7 - Posted 2014-06-26 00:24:43 »


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
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

wxwsk8er (49 views)
2015-03-20 15:39:46

Fairy Tailz (42 views)
2015-03-15 21:52:20

Olo (26 views)
2015-03-13 17:51:59

Olo (29 views)
2015-03-13 17:50:51

Olo (33 views)
2015-03-13 17:50:16

Olo (40 views)
2015-03-13 17:47:07

ClaasJG (29 views)
2015-03-10 11:36:42

ClaasJG (36 views)
2015-03-10 11:33:01

Pippogeek (45 views)
2015-03-05 14:36:23

Pippogeek (37 views)
2015-03-05 13:56:12
How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!