[quote]If you use PNG, you get a CUSTOM image returned. This is formatted RGBA in bytes, which fits GL nicely
[/quote]
Yes, I know, this is very nice.
However I need to construct an own 24 bpp RGB and 32 bpp RGBA BufferedImage on the fly and then try to feed it to OpenGL. The BufferedImage constructor unfortunately just knows TYPE_3BYTE_BGR and TYPE_4BYTE_ABGR.
The first one isn’t a problem anymore because I learned here, that I can use OpenGL’s GL_BGR type as source pixel format and it works well.
Just the second type (ABGR) doesn’t fit, because the GL_ABGR_EXT extenion isn’t available on my OpenGL driver (newest Detonator; says that it would do OpenGL v1.4.x).
[quote]TYPE_4BYTE_ABGR reads from the lowest byte up…
So when packed into a byte, it would be RGBA. Which order does OpenGL specify its components in, e.g.
Isn’t GL.GL_RGBA equivilent to TYPE_4BYTE_ABGR?
[/quote]
No, its the other way round. GL_RGBA needed a BufferedImage TYPE_4BYTE_RGBA which doesn’t exist.
You can emulate this by constructing a BufferedImage with TYPE_4BYTE_ABGR and then swap the colour bands (via getRaster etc.). This you can feed to OpenGL via source pixel format GL_RGBA and it works.
But… it’s a kind of overkill I think and not too handy.
How about something like:
ColorModel colorModel = new DirectColorModel
(ColorSpace.TYPE_RGB,
32,
0xFF000000, // Red Mask
0x00FF0000, // Green Mask
0x0000FF00, // Blue Mask
0x000000FF, // Alpha
false,
DataBuffer.TYPE_BYTE
);
BufferdImage textureImage = BufferedImage(colorModel,
new WritableRaster(...),
false,
new HashTable());
Then create the texture from the texture image using GL.GL_RGBA ?
Kev
[quote]How about something like:
(… Own ColourModel for RGBA BufferedImage …)
Kev
[/quote]
Sounds pretty well! I’ll have a look at. Thanks for the hint.
If it works, I think its possible to write a generic texture loader that works for any BufferedImage. So, we’d get support for anything that ImageIO supports
Kev
I’ve implemented the color model stuff. My versions of Texture and TextureLoader are at:
http://www.cokeandcode.com/jogl
I’ve modified texture a bit to remove most of the stuff (since I don’t need it) and add stuff to handle the difference between texture size and image size.
I’ve added a bit of stuff to texture loader to handle wierd size images.
It should handle all image type, so far I’ve had a reason to try it with PNG and GIF, both with alpha… still works.
Kev
Kev,
I have tried to use your code, without any success.
Here is my code segment:
loader = new TextureLoader(gl,glu);
try{
//loader.getTexture("earth","hi_res_earth.png");
loader.getTexture("earth","hi_res_earth.png",GL.GL_TEXTURE_2D,GL.GL_RGB,GL.GL_NEAREST,GL.GL_NEAREST,false,false);
}
catch(Exception e){
e.printStackTrace();
}
I get a NullPointerException at the following line in
TextureLoader.java:
gl.glGenTextures(1, tmp); <-----line 67
Here is my stack trace:
java.lang.NullPointerException
at TextureLoader.createTextureID(TextureLoader.java:67)
at TextureLoader.getTexture(TextureLoader.java:103)
at Runner.init(Test.java:202)
at Runner.display(Test.java:113)
at net.java.games.jogl.impl.GLDrawableHelper.display(GLDrawableHelper.java:74)
at net.java.games.jogl.GLCanvas$DisplayAction.run(GLCanvas.java:208)
at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:192)
at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:196)
at net.java.games.jogl.GLCanvas.display(GLCanvas.java:91)
at net.java.games.jogl.GLCanvas.paint(GLCanvas.java:102)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Can you give us a sample on how to load a texture up?
Thanks
Zak
Zak,
Looks like you got the source for loading just right. I think the problem is that I left the texture loader code using “GameFrame” and you’ve had to move it over to passing gl into the constructor.
The only thing that can be null on the line you pointed out is “gl”, and that probably means its not being initialised in the constructor…
Kev
EDIT: looking back at the code, check that when you made the small change in the consturctor, you added “this” before the assignments, e.g.:
this.gl = gl;
Common mistake, causes the null pointer since the member variable isn’t initialised.
[quote]I’ve implemented the color model stuff. My versions of Texture and TextureLoader are at:
http://www.cokeandcode.com/jogl
[/quote]
Kev, many thanks for that. Your construction of the BufferedImage via the “hard way” (own Color-model and Raster etc) is very useful. The Java2d API is very powerful (but complex to get into for a … Java newbie like me).
Finally we got a real TYPE_3BYTE_RGB and TYPE_4BYTE_RGBA BufferedImage, which is what we need to feed it to Jogl.
Wonderful. It all works perfectly now.
(This also applies to me task of mixing a 24bpp-RGB-Png with a 8bpp-Alpha-Png on the fly and feed this as RGBA to Jogl.)
Kev,
Unfourtuately, your solution worked for me, but now whenever I try to load a texture, my system hangs and forces me to pull the plug, or wait 60-90 minutes till I can gain control over the processes.
There are no errors/exceptions thrown that I have seen, but this could be a serious flaw somewhere(either in your code or the jogl codebase).
~Zak()
Flippin eck, seems to work fine for me… what platform, graphics card, driver etc have you got…
Apologises for wasting your time,
Kev
Kev,
Good news, I think it was a graphics card problem (the driver).
I am using a Nvidia Quadro4 900 XGL model, on Windows XP.
For some reason, the newest drivers from Nvidia mess up JOGL, causing it to BOMB( :o ), and its NOT your code. (;D)Once I downloaded some older drivers, it seems to work.
Now it just figuring out how to map lat/lon points on a rectangular texture map. (:-/)
Thanks
- Zak
Fantastic news
Thanks for feeding that back.
You might find this useful for the lat/long stuff:
http://pub40.ezboard.com/fasknormasknormforum.showMessage?topicID=142.topic
Kev
any news on your new loader gp ?
I’ve put everything on hold to take care of JInput because its been withering on the vine too long. That’s the bad news, the good news is that I’m making excellent progress and should be done with it JInput soon.
For completeness, Troggan has provided update versions of my loaders that fix the texture size bug (e.g. it now copes with wierd shape images) and also removed depedancy on my GameFrame code
He’s posted them here:
so which version of the code is the most complete? the original post with a TextureFactory, or this new ode that is just Texture, and TextureLoader… im on RedHat so i cant use that Quicktime implementation and what is a the GameFrame class that is referenced in TextureLoader?
Great job with all of this code, it wll surely help a lot of developers…
Btw, i think next needs to come a clean implementation for loading 3d model formats, i.e. ms3d, md2, md3, 3ds max, etc.
AFAIK, the latest and most complete texture coding is the one above a couple, the Texture and TextureLoader. It handles pretty much any format (tested so far ;)).
As to generic loaders, its not really possible without a generic scene tree/rendering framework.
Kev
hey, im experiencing some really wierd things using this code… at first things were working smoothly, and then i randomly began getting a native error when i try to run the application… im using RH 8 on an IBM Thinkpad with a 2mb NeoMagic video card. now, it seems that the application will run after a fresh reboot, but subsequent attempts to run it will randomly choose whether or not to product errors… its very very frustrating… the coe im using to run it is a port of the nehe tutorial number 7, its just a rotating textured cube with basic lighting…
i dont know what to make of the error. maybe its just the fact that this machine is such garbage, and it will work on my radeon 9500pro machine… im trying not to worry about it, but im afraid that there may be a deeper problem.
anyway, here is ther error:
EDIT:
I have other applications, and they are still running fine. maybe someone can post an application to demo this code, and i will be able to try that out. thanks for any responses.
If you want an example, you can get it there :
http://www.informatik.uni-oldenburg.de/~troggan/bodo/JOGLTest.zip
If you try that code above, please look at the FPS (printed out to the shell/dosbox) and report it there:
http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=jogl;action=display;num=1059843069
I have speed problems using that Code. Maybe you see what I am doing wrong…but hey, it doesn’t crash
Edit: Typo