LWJGL how would i draw an image ???

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 :stuck_out_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.

as i said i don’t want to use anything else than LWJGL really :stuck_out_tongue:

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

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

Any good reason you’re avoiding third party libraries?

yea as i am new to LWJGL and i know java pretty well i like to make my own algorithms and such :stuck_out_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

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.

implying slick-util isn’t still the best texture loader
:3c

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

MatthiaM’s PNGDecoder is by far superior to any PNG decoders out there:


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

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:

http://img443.imageshack.us/img443/4820/feedyourbytebuffer.jpg

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

Ehhhh learning how to decode PNG is not a good idea… ;D

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.

Texture loader! Not PNG loader! >_<

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.

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.

A texture loader is easy as pie :stuck_out_tongue:

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? ;D

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

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