LWJGL
May 22, 2012, 03:23:16 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.8.3 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: DevIL replacement, pure Java, JPEG & PNG?  (Read 8051 times)
mot
Regular nerd
**
Posts: 57


WWW
« on: April 25, 2008, 02:12:53 »

I'm looking for a replacement for DevIL to be able to switch to LWJGL 2.0 sometime... and I don't want to use the default Java libraries to be still able to strip the Windows JRE to the bare essentials.

It should be able to load JPEG and PNG or TGA with alpha channel and write at least one popular format (BMP, TGA, whatever). A pure Java portable implementation would be preferred over speed. Any suggestions?

I really need to load JPEG because some textures compress very well using JPEG and switching to a lossless format would make them way too big.

Custom image formats are not the best solution for me either, I like being able to do a "Slices" export from Photoshop and get the resulting PNG/JPEG files into the game without an additional conversion step.

Any suggestions are welcome, thanks!
Logged

Tom Andrle - Catnap Games - http://www.catnapgames.com
kappa
Administrator
Nerdus Imperius
*****
Posts: 961



« Reply #1 on: April 25, 2008, 06:16:01 »

The recommended alternative to Devil and Fmod is "slick-util"

it can be found at http://slick.cokeandcode.com/downloads/util/
with javadoc being at http://slick.cokeandcode.com/javadoc-util/
it includes examples so you can learn by example too.
Logged
Rainer
Regular nerd
**
Posts: 71


« Reply #2 on: May 15, 2008, 12:34:23 »

I'm also having problems with the texture loading.
Using this loader works:
http://www.cokeandcode.com/info/showsrc/showsrc.php?src=../spaceinvaders104/org/newdawn/spaceinvaders/lwjgl/TextureLoader.java
But this filters textures just with GL_Linear.
I tryed to build mipmaps:
GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, 3, texture.getImageWidth(), texture.getImageHeight(), GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, textureBuffer);
but all i get is:
java.lang.IllegalArgumentException: Number of remaining buffer elements is 196608, must be at least 262144
        at org.lwjgl.BufferChecks.throwBufferSizeException(BufferChecks.java:130)

Anybody got an idea how to fix this?
Logged
bobjob
Prolific Timewaster
****
Posts: 335


LWJGL: WOW SO GOOD


« Reply #3 on: May 15, 2008, 14:53:54 »

some ideas: (Im sure u tried some of these already, but ill try help the best i can)

what image format are you using? .jpg? if so then it could be a problem with the
GL11.GL_RGBA
change it to
GL11.GL_RGB

have you changed the textureBuffer at all, is it back to its first position. does it need to be fliped.

double check that the numbers from getImageWidth, and getImageHieght are not actually bigger than the image you are using.

and make sure that the image is the power of 2.
Logged

LWJGL Benchmark online test:
http://have2chat.net/benchmark/
http://have2chat.net/benchmark/fullpage.html (run full OpenGL webpage)
Rainer
Regular nerd
**
Posts: 71


« Reply #4 on: May 16, 2008, 00:04:43 »

You're right, it was the RGB thing, didn't see this one Wink
Additionally, i needed to change the order in which 2 things were done.
Logged
mot
Regular nerd
**
Posts: 57


WWW
« Reply #5 on: May 22, 2008, 05:13:08 »

Someone mentioned it was possible to use DevIL from 1.1.4 with 2.0b1, so I tried it. And it works!

First I was getting library version mismatch errors when initializing OpenAL but solved it by shuffling the initialization code so that AL.create() is called BEFORE IL.create().

And 2.0b1 works fine for me without any additional modifications required.
Logged

Tom Andrle - Catnap Games - http://www.catnapgames.com
Rainer
Regular nerd
**
Posts: 71


« Reply #6 on: May 26, 2008, 02:33:28 »

I now ran into the next Problem, i can't get transparency to work.
This Texture:

i load  with:
Code:
...
if (bufferedImage.getColorModel().hasAlpha()) {
            srcPixelFormat = GL11.GL_RGBA;
            System.out.println("loaded tex with alpha");
        } else {
            srcPixelFormat = GL11.GL_RGB;
            System.out.println("loaded tex without alpha");
        }

        // convert that image into a byte buffer of texture data
        ByteBuffer textureBuffer = convertImageData(bufferedImage, texture);
       


// produce a texture from the byte buffer
        GL11.glTexImage2D(target,
                0,
                dstPixelFormat,
                get2Fold(bufferedImage.getWidth()),
                get2Fold(bufferedImage.getHeight()),
                0,
                srcPixelFormat,
                GL11.GL_UNSIGNED_BYTE,
                textureBuffer);

        if (target == GL11.GL_TEXTURE_2D) {
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_NEAREST);
            GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, 3, texture.getImageWidth(), texture.getImageHeight(), srcPixelFormat, GL11.GL_UNSIGNED_BYTE, textureBuffer);
        }
...
which tells me the texture has alpha.

then i render with:
Code:
tex.bind();
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_BLEND);

But it renders the texture with the transparent regions in black, not transparent.
What could be wrong?
Logged
bobjob
Prolific Timewaster
****
Posts: 335


LWJGL: WOW SO GOOD


« Reply #7 on: May 26, 2008, 02:51:40 »

GL11.glAlphaFunc(GL11.GL_GREATER,0.1f); // sets aplha function
GL11.glEnable(GL11.GL_ALPHA_TEST); // allows alpha channels or transperancy
Logged

LWJGL Benchmark online test:
http://have2chat.net/benchmark/
http://have2chat.net/benchmark/fullpage.html (run full OpenGL webpage)
Rainer
Regular nerd
**
Posts: 71


« Reply #8 on: May 26, 2008, 03:00:14 »

I tried this before, unfortunately it does not change anything.
Logged
Orangy Tang
Talks Too Much
***
Posts: 199



« Reply #9 on: May 26, 2008, 03:13:02 »

Are you sure that both src and dest pixel formats are being set to RGBA?

Also, have you made sure to generate a texture id/object and have it currently bound (glBindTexture) before making your glTexImage2D calls?

Double also, I think you only need one of glTexImage2D / gluBuild2DMipmaps. glTexImage2D just uploads raw pixel data, gluBuild2DMipmaps resizes to power-of-two then uploads the texture and it's mipmaps. For now I'd get it working with one or the other first.
Logged
Rainer
Regular nerd
**
Posts: 71


« Reply #10 on: May 26, 2008, 03:31:13 »

Are you sure that both src and dest pixel formats are being set to RGBA?

Also, have you made sure to generate a texture id/object and have it currently bound (glBindTexture) before making your glTexImage2D calls?

Double also, I think you only need one of glTexImage2D / gluBuild2DMipmaps. glTexImage2D just uploads raw pixel data, gluBuild2DMipmaps resizes to power-of-two then uploads the texture and it's mipmaps. For now I'd get it working with one or the other first.
yes, both of them are RGBA.
yes, it is bound.
you're right, gluBuild2DMipmaps is enough, i deleted the glTexImage2D statement, with no resulting changes.
i have no idea whats wrong  Huh
Logged
Rainer
Regular nerd
**
Posts: 71


« Reply #11 on: May 26, 2008, 04:47:21 »

If i load the Image, the bufferedImage i get is from type TYPE_BYTE_BINARY, which has no alpha according to the documentation.
However, bufferedImage.getColorModel().hasAlpha() returns true.
Should i convert to something like TYPE_4BYTE_ABGR?
Logged
Rainer
Regular nerd
**
Posts: 71


« Reply #12 on: May 26, 2008, 06:42:22 »

found the error, really dumb one of course...
GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, 3, texture.getImageWidth(), texture.getImageHeight(), srcPixelFormat, GL11.GL_UNSIGNED_BYTE, textureBuffer); changed to
GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, 3, texture.getImageWidth(), texture.getImageHeight(), srcPixelFormat, GL11.GL_UNSIGNED_BYTE, textureBuffer);

 Cool
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!