Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (687)
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 753 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?
Online 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 - hybrid visual IDE for creative coding
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.

Dwinin (72 views)
2015-11-07 13:29:08

Rems19 (81 views)
2015-10-31 01:36:56

Rems19 (74 views)
2015-10-31 01:32:37

williamwoles (107 views)
2015-10-23 10:42:59

williamwoles (93 views)
2015-10-23 10:42:45

Jervac_ (106 views)
2015-10-18 23:29:12

DarkCart (135 views)
2015-10-16 00:58:11

KaiHH (116 views)
2015-10-11 14:10:14

KaiHH (156 views)
2015-10-11 13:26:18

BurntPizza (171 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 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!