Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  LWJGL how would i draw an image ???  (Read 5533 times)
0 Members and 1 Guest are viewing this topic.
Offline Xenon

Senior Newbie





« Posted 2012-07-13 21:53:43 »

hey there guys i am new to this forum, but im not new to java allthought im new to LWJGL, my question is bascily ... how would i load and draw a image in LWJGL ? i am not using slick and i am not going to use it either Tongue umm that really sums it all up, thanks
Offline CyanPrime
« Reply #1 - Posted 2012-07-13 21:58:57 »

hey there guys i am new to this forum, but im not new to java allthought im new to LWJGL, my question is bascily ... how would i load and draw a image in LWJGL ? i am not using slick and i am not going to use it either Tongue umm that really sums it all up, thanks
Slick, or Slick-Utils? Slick-Utils really is the best way to load a image, and the license isn't hindering if you wanna sell your product at all, so that's the only thing I can recommend.
Offline Xenon

Senior Newbie





« Reply #2 - Posted 2012-07-13 22:00:11 »

as i said i don't want to use anything else than LWJGL really Tongue
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Giovanni

Junior Member




chop!


« Reply #3 - Posted 2012-07-13 22:09:27 »

You need to convert the image for OpenGL, basically. You have to split it up in its RGB(A) components and put that in a buffer then. After that you have to flip the buffer so that it is readable for OpenGL.

This might help you: http://www.java-gaming.org/index.php?topic=25516.0
Offline sproingie

JGO Kernel


Medals: 202



« Reply #4 - Posted 2012-07-13 22:10:16 »

as i said i don't want to use anything else than LWJGL really Tongue

Then you're doing it by hand.  LWJGL doesn't come with image loaders.

Any good reason you're avoiding third party libraries?
Offline Xenon

Senior Newbie





« Reply #5 - Posted 2012-07-13 22:58:22 »

yea as i am new to LWJGL and i know java pretty well i like to make my own algorithms and such Tongue i don't really have any reason other than that, im not hating on slick tho its a great engine and i have used it b4 i just want to see how i would do without it
Offline theagentd
« Reply #6 - Posted 2012-07-13 23:34:16 »

hey there guys i am new to this forum, but im not new to java allthought im new to LWJGL, my question is bascily ... how would i load and draw a image in LWJGL ? i am not using slick and i am not going to use it either Tongue umm that really sums it all up, thanks
Slick, or Slick-Utils? Slick-Utils really is the best way to load a image, and the license isn't hindering if you wanna sell your product at all, so that's the only thing I can recommend.
2004 called, they want their texture loader back.


@Xenon: Giovanni's link should be all you need. If you don't understand something in it, you probably need to read up more on the basics of LWJGL.

Myomyomyo.
Offline CyanPrime
« Reply #7 - Posted 2012-07-14 00:47:59 »

2004 called, they want their texture loader back.

>implying slick-util isn't still the best texture loader
:3c
Offline ReBirth
« Reply #8 - Posted 2012-07-14 02:42:23 »

@cyanprime
Slick-util is not the best but it works well like a soaring eagle! Grin

Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #9 - Posted 2012-07-14 03:17:01 »

MatthiaM's PNGDecoder is by far superior to any PNG decoders out there:
1  
2  
3  
4  
5  
6  
PNGDecoder decoder = new PNGDecoder(getClass().getResourceAsStream("image.png"));
ByteBuffer buffer = BufferUtils.createByteBuffer(decoder.getWidth() * decoder.getHeight() * 4);
decoder.decode(buffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
buffer.flip();

//feed "buffer" to OpenGL

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

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #10 - Posted 2012-07-14 06:22:59 »

Wow, that PNGDecoder is nifty, ra4king!

On the subject of how to feed byte-data to your byte-buffer, I've illustrated the process here:

- Jonas
Offline theagentd
« Reply #11 - Posted 2012-07-14 11:09:07 »

2004 called, they want their texture loader back.

>implying slick-util isn't still the best texture loader
:3c
I'm not saying that it's bad, but it isn't the best one. Besides, I believe that something as fundamental as texture loading is something you should code by yourself as a learning experience. =S

Myomyomyo.
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #12 - Posted 2012-07-14 16:25:10 »

Ehhhh learning how to decode PNG is not a good idea...... Grin

Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #13 - Posted 2012-07-14 16:31:09 »

Ehhhh learning how to decode PNG is not a good idea...... Grin

Further, it's not something you'd really need to know how to do. PNG is generally supported. It's so low-level, and it's been done a gazillion times.

Offline theagentd
« Reply #14 - Posted 2012-07-14 17:38:31 »

Texture loader! Not PNG loader! >_<

Myomyomyo.
Offline Cero
« Reply #15 - Posted 2012-07-14 18:01:02 »

I couldnt write it myself. I was raised in OOP.
This whole static notion - I like to use it when appropriate, but OpenGL is crazy.

glTexImage2D pushes the data in the GPU somehow - but you still have to keep track of it... there is no Texture object which you can now use.

Offline sproingie

JGO Kernel


Medals: 202



« Reply #16 - Posted 2012-07-14 18:07:53 »

Yep, glTexImage2D operates on the last texture bound, which is global state.  After the first thousand times you cringe at how ugly that sort of thing is, you get used to it.  Welcome to OpenGL.  You think that kind of thing is awful in Java, try dealing with it in a pure functional language sometime.


Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #17 - Posted 2012-07-14 18:43:01 »

Texture loader! Not PNG loader! >_<
A texture loader is easy as pie Tongue

Offline theagentd
« Reply #18 - Posted 2012-07-14 21:50:18 »

I couldnt write it myself. I was raised in OOP.
This whole static notion - I like to use it when appropriate, but OpenGL is crazy.

glTexImage2D pushes the data in the GPU somehow - but you still have to keep track of it... there is no Texture object which you can now use.
o_O

Better give up then? I mean, the integer texture ID you already have binded is just impossible to encapsulate in your own Texture object, along with all the relevant texture data like width, height and color channels, all of which are actually even queryable from OpenGL but a bit slow? Maybe you could encapsulate the texture ID in an Integer in proper OOP spirit?  Grin

... which makes it (in addition to helping you understand OpenGL textures, Cero Pointing) the perfect introduction to handling data for OpenGL with buffers which is also very practical for VBOs or any kind of batched rendering.

Myomyomyo.
Offline Cero
« Reply #19 - Posted 2012-07-14 22:41:47 »

helping you understand OpenGL textures, Cero Pointing

Well its all interesting; but I never started learning OpenGL really, because I dont even want to use it directly... way too low level for me.
It's one of these legacy technology, terribly designed by todays standards, that have to be used on a low level, behind the scenes; but you guys do that, and I just use the TextureLoaders and whatnot =D

Offline ReBirth
« Reply #20 - Posted 2012-07-15 03:05:42 »

Hee hee I'm same with Cero Grin "way too low level for me".

Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #21 - Posted 2012-07-15 06:26:39 »

libgdx uses (for most but not all backends, eg for GWT different shenanigans are involved) stb_image by Sean Barrett. It's fast, C (so works on desktop/Android), and decodes into a format suitable for OpenGL. There is a thin native layer over the stb_image stuff called gdx2d for working with the decoded image data, drawing primitives, blending, etc. This is all hidden by the Pixmap class, which has a Java API for manipulating the data and provides a ByteBuffer containing the pixels. Textures can be created with this ByteBuffer, though most often a Texture is created from a file and a Pixmap is used under the covers.

But yeah, with only LWJGL you need to decode an image to bytes OpenGL can use, which can be nontrivial depending on the image format. Often, on the desktop, AWT is used to do the decoding. I believe this is what the slick-utils does.

Offline theagentd
« Reply #22 - Posted 2012-07-16 01:29:17 »

helping you understand OpenGL textures, Cero Pointing

Well its all interesting; but I never started learning OpenGL really, because I dont even want to use it directly... way too low level for me.
It's one of these legacy technology, terribly designed by todays standards, that have to be used on a low level, behind the scenes; but you guys do that, and I just use the TextureLoaders and whatnot =D
Heh, it's so hard to understand why others hate your own hobby.  Grin

Myomyomyo.
Offline Cero
« Reply #23 - Posted 2012-07-16 01:57:34 »

Heh, it's so hard to understand why others hate your own hobby.  Grin

I dont hate it, its just...
If I didnt want to make games actually, then fiddling around with it would be fun I guess.
Well the fact that its horribly designed still stands of course.
Maybe OpenGL 3+ is better, but of course I wont use it until its available on like 90%+ pcs...

Offline davedes
« Reply #24 - Posted 2012-07-16 12:03:12 »

Slick-Util uses Matthias' PNGDecoder, Kev's TGA decoder, and AWT for other formats. The decoders are acceptable -- it's the texture loader that makes SlickUtil a "bad" and outdated library. It doesn't support or include things you'd want to use in a modern OpenGL game -- like automatic mipmapping, non-power-of-two sizes, wrap modes, compressed textures, custom internal formats, multiple texture targets (cube maps, 1D/3D textures, arrays) etc. As far as texture loaders go, it's really just the bare minimum, and not something any serious OpenGL user should rely on. Smiley

A better texture library would support the features I mentioned earlier, as well as decoding without the need for AWT. LibGDX is pretty close, although because of its Android focus it doesn't seem too serious about DXTn texture compression or 1D/3D/arrays/etc. I have my own WIP texture library (using Matthias' decoders) that tries to include many of these features, as well as a simple DDS decoder. It might help for inspiration in your own texture loaders:
https://github.com/mattdesl/slim/tree/master/slim/src/slim/texture

Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #25 - Posted 2012-07-16 12:21:03 »

I know we have OpenGL bindings, but do we have any more abstraction than that?  Clueless
There's obviously a need for some standard tools.

Offline theagentd
« Reply #26 - Posted 2012-07-16 23:33:38 »

Maybe OpenGL 3+ is better, but of course I wont use it until its available on like 90%+ pcs...

http://store.steampowered.com/hwsurvey/

Oh, look, it almost is since OpenGL 3 works on Windows XP too. 40.94 + 37.59 + 12.95 = 91,48%. Add that you also have Linux and Mac (or not because of drivers?) and that should compensate for it.

(EDIT: I thought you wanted 95%+, therefore my "almost".)

Myomyomyo.
Offline Cero
« Reply #27 - Posted 2012-07-17 00:17:12 »

Quote
texture compression
This is relevant to my interests.

Offline theagentd
« Reply #28 - Posted 2012-07-17 02:12:34 »

Quote
texture compression
This is relevant to my interests.

It mostly used to lower the amount of VRAM needed when lots of textures need to be in memory at the same time. It can also actually improve performance if your program is very limited by memory bandwidth since it trades processing power for less memory.

It's really easy to use I think, you should just change the internal texture format when allocating the texture:
1  
glTexImage2D(GL_TEXTURE_2D, 0, compressedFormat, width, height, 0, dataFormat, dataType, data);


Basic compression formats can be found in this : extension, which is supported by literally everything.

If you already have compressed texture data on your disk which uses one of the compression algorithms OpenGL supports, you can load the already compressed data with glCompressedTexImage2D(), which looks works identically to glTexImage() but expects compressed data.

The different S3TC algorithms compress 4x4 blocks of pixels to either 64 bits or 128 bits. I don't know about the quality but expect to take a pretty big hit there considering the huge compression ratio. Since the algorithms work on 4x4 blocks of pixels it might be a good idea to at least keep texture dimensions to multiples of 4. The spec says that the padding pixels are undefined, which might screw up linear filtering even with clamping since it technically isn't the texture edge, but this is just a speculation.

BPTC is a newer compression mode which uses slightly more memory but has much better quality. However, it's only implemented by OGL3 GPUs, but since those GPUs generally have more memory than GPUs that don't support it it might be a good idea to choose the most advanced compression algorithm available since it's literally only a single changed parameter to glTexImage2D().

Any questions?

EDIT: Comparison: http://www.g-truc.net/post-0340.html

Myomyomyo.
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.

Dwinin (19 views)
2014-09-12 09:08:26

Norakomi (54 views)
2014-09-10 13:57:51

TehJavaDev (63 views)
2014-09-10 06:39:09

Tekkerue (31 views)
2014-09-09 02:24:56

mitcheeb (53 views)
2014-09-08 06:06:29

BurntPizza (37 views)
2014-09-07 01:13:42

Longarmx (23 views)
2014-09-07 01:12:14

Longarmx (27 views)
2014-09-07 01:11:22

Longarmx (26 views)
2014-09-07 01:10:19

mitcheeb (34 views)
2014-09-04 23:08:59
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!