Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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  
  LibGDX BufferedImage to Texture  (Read 3191 times)
0 Members and 1 Guest are viewing this topic.
Offline novasharp

Junior Duke


Medals: 1
Projects: 1


Gamemaker


« Posted 2013-04-10 01:13:57 »

Is there any way to convert a BufferedImage to a Texture?

novasharp
Offline BurntPizza
« Reply #1 - Posted 2013-04-10 01:16:23 »

If you are using LibGDX, I have to say that I don't recommend also using BufferedImages (from Java2D), instead you could use a Pixmap, or if you really do need BufferedImages, then I guess you could use ImageIO to save the image to a file, bring the file back in as a texture, then delete the file, but that seems quite hacky and inefficient.
Offline ReBirth
« Reply #2 - Posted 2013-04-10 02:01:28 »

Try to not mix libgdx with java2d. +1 for pixmap.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline StumpyStrust
« Reply #3 - Posted 2013-04-10 06:38:18 »

If you are using libgdx, you should NEVER EVER touch anything from java2d.

Have fun.  Cheesy


PS:

You should be able to get a pixel array from the bufferedimage and create a libgdx texture from that. Look at how to take a bufferedimage and make it into a opengl texture. Hell, you could just use that search box with the cob webs on it.

http://www.java-gaming.org/index.php?topic=25516.0

Offline Cero
« Reply #4 - Posted 2013-04-10 13:49:39 »

we wrote our own screenshot method which uses bufferedimages sort of:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public static void takeScreenshot(String outputfile)
{
                 ByteBuffer screenContents = ByteBuffer.allocateDirect(Display.getWidth() * Display.getHeight() * 4).order(ByteOrder.LITTLE_ENDIAN);
         GL11.glReadPixels(0, 0, Display.getWidth(), Display.getHeight(), GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, screenContents);
         BufferedImage img = new BufferedImage(Display.getWidth(), Display.getHeight(), BufferedImage.TYPE_INT_RGB);
         
         ImageUtil.putToBufferedImage(img, screenContents, false, true);
         
         // save the image
         ImageUtil.saveBufferedImage(img, outputfile);
}


Because this: http://code.google.com/p/libgdx-users/wiki/Screenshots
Has some kind of color error.
some colors are wrong and stuff using that code

Offline davedes
« Reply #5 - Posted 2013-04-10 16:17:36 »

What is wrong with PixmapIO?

The problem with BufferedImage is that it won't work with iOS, Android, WebGL, or GLFW (maybe useful for OSX 10.7 users). It's also generally slow.

Offline novasharp

Junior Duke


Medals: 1
Projects: 1


Gamemaker


« Reply #6 - Posted 2013-04-10 23:45:47 »

The problem is that I have to read in images from a inputstream and after a few google searches, I didn't see a clear way to do this.

novasharp
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #7 - Posted 2013-04-11 04:51:43 »

Never actually tried this but I suppose you could read the bufferedimage pixel by pixel into the texture (does it use a raster or something? idk)
Offline Nate

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #8 - Posted 2013-04-11 05:20:12 »

https://github.com/libgdx/libgdx/blob/master/extensions/gdx-tools/src/com/badlogic/gdx/tools/hiero/unicodefont/GlyphPage.java#L160

Offline novasharp

Junior Duke


Medals: 1
Projects: 1


Gamemaker


« Reply #9 - Posted 2013-04-11 10:33:54 »

Thanks for the suggestions. I managed to fix it. I create a Gdx2DPixmap which can load from input streams, then I use that to create a pixmap, then I use the pixmap to create a texture.

1  
2  
3  
Gdx2DPixmap gpm = new Gdx2DPixmap(menuBackground, Gdx2DPixmap.GDX2D_FORMAT_RGB888);
Pixmap pixmap = new Pixmap(gpm);
Texture background = new Texture(bgPixmap);

novasharp
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #10 - Posted 2013-04-11 11:41:25 »

Because this: http://code.google.com/p/libgdx-users/wiki/Screenshots
Has some kind of color error.
some colors are wrong and stuff using that code
I think this bug could be fixed as there are already 2 helpers in JOGL to do that:
- com.jogamp.opengl.util.awt.Screenshot
- com.jogamp.opengl.util.GLReadBufferUtil (AWT-free, you can use it with TextureData and TextureIO)

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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 (52 views)
2014-10-17 03:59:02

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

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

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

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

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

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

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

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

BurntPizza (86 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!