Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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 488 times)
0 Members and 1 Guest are viewing this topic.
Offline nhmllr

Senior Duke


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?

Thanks
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: http://goharsha.com/lwjgl-tutorial-series/textures/
In the "Loading Textures" section

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

Senior Duke


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!
Online 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 -

http://www.java-gaming.org/topics/bufferedimage-to-lwjgl-texture/25516/msg/234102/view.html#msg234102

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

Senior Duke


Medals: 1
Projects: 3


slow and steady...


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

When the guy says,

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

How does one go about actually doing that?

1  
Texture texture = ???

Thanks
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: 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,
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
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();
}
Offline nhmllr

Senior Duke


Medals: 1
Projects: 3


slow and steady...


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

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
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (39 views)
2014-10-17 03:59:02

Norakomi (29 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (57 views)
2014-10-14 00:39:48

TehJavaDev (57 views)
2014-10-14 00:35:47

TehJavaDev (48 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
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

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!