Skip to main content

Simple Java OpenGL Textures Manager



I'm trying to make a simple textures manager for a 2D tile-based project.





What I have is a class that has a hashmap of strings (texture name) and textures. If the name doesn't exist in the hashmap, it uses TextureIO.newTexture(..) to create it and store it into the hashmap.





This is the error I get when I try to load a texture:







Exception in thread "Timer-0" javax.media.opengl.GLException: java.lang.IllegalArgumentException: Illegally formatted version identifier: "null"

at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:271)

at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:410)

at javax.media.opengl.GLCanvas.display(GLCanvas.java:244)

at com.sun.opengl.util.Animator.display(Animator.java:144)

at com.sun.opengl.util.FPSAnimator$1.run(FPSAnimator.java:95)

at java.util.TimerThread.mainLoop(Unknown Source)

at java.util.TimerThread.run(Unknown Source)

Caused by: java.lang.IllegalArgumentException: Illegally formatted version identifier: "null"

at com.sun.opengl.impl.FunctionAvailabilityCache$Version.<init>(FunctionAvailabilityCache.java:354)

at com.sun.opengl.impl.FunctionAvailabilityCache.initAvailableExtensions(FunctionAvailabilityCache.java:133)

at com.sun.opengl.impl.FunctionAvailabilityCache.isExtensionAvailable(FunctionAvailabilityCache.java:104)

at com.sun.opengl.impl.GLContextImpl.isExtensionAvailable(GLContextImpl.java:351)

at com.sun.opengl.impl.GLImpl.isExtensionAvailable(GLImpl.java:30493)

at com.sun.opengl.util.texture.Texture.updateImage(Texture.java:416)

at com.sun.opengl.util.texture.Texture.updateImage(Texture.java:381)

at com.sun.opengl.util.texture.Texture.<init>(Texture.java:182)

at com.sun.opengl.util.texture.TextureIO.newTexture(TextureIO.java:445)

at com.sun.opengl.util.texture.TextureIO.newTexture(TextureIO.java:465)

at dqs.manager.TextureManager.loadTexture(TextureManager.java:31)

at dqs.world.World.draw(World.java:59)

at dqs.scene.GameScene.display(GameScene.java:58)

at com.sun.opengl.impl.GLDrawableHelper.display(GLDrawableHelper.java:78)

at javax.media.opengl.GLCanvas$DisplayAction.run(GLCanvas.java:435)

at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:194)

at javax.media.opengl.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java:452)

at java.awt.event.InvocationEvent.dispatch(Unknown Source)

at java.awt.EventQueue.dispatchEventImpl(Unknown Source)

at java.awt.EventQueue.access$000(Unknown Source)

at java.awt.EventQueue$1.run(Unknown Source)

at java.awt.EventQueue$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(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)

Caused by: java.lang.NullPointerException

at com.sun.opengl.impl.FunctionAvailabilityCache$Version.<init>(FunctionAvailabilityCache.java:309)

... 30 more

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

at com.sun.opengl.impl.mipmap.Mipmap.closestFit(Mipmap.java:252)

at com.sun.opengl.impl.mipmap.Mipmap.gluBuild2DMipmaps(Mipmap.java:726)

at javax.media.opengl.glu.GLU.gluBuild2DMipmapsJava(GLU.java:1525)

at javax.media.opengl.glu.GLU.gluBuild2DMipmaps(GLU.java:1581)

at com.sun.opengl.util.texture.Texture.updateImage(Texture.java:523)

at com.sun.opengl.util.texture.Texture.updateImage(Texture.java:381)

at com.sun.opengl.util.texture.Texture.<init>(Texture.java:182)

at com.sun.opengl.util.texture.TextureIO.newTexture(TextureIO.java:445)

at com.sun.opengl.util.texture.TextureIO.newTexture(TextureIO.java:465)

at dqs.manager.TextureManager.loadTexture(TextureManager.java:31)

at dqs.world.World.draw(World.java:59)

at dqs.scene.GameScene.display(GameScene.java:58)

at com.sun.opengl.impl.GLDrawableHelper.display(GLDrawableHelper.java:78)

at javax.media.opengl.GLCanvas$DisplayAction.run(GLCanvas.java:435)

at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:194)

at javax.media.opengl.GLCanvas.maybeDoSingleThreadedWorkaround(GLCanvas.java:412)

at javax.media.opengl.GLCanvas.display(GLCanvas.java:244)

at javax.media.opengl.GLCanvas.paint(GLCanvas.java:277)

at sun.awt.RepaintArea.paintComponent(Unknown Source)

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.dispatchEventImpl(Unknown Source)

at java.awt.EventQueue.access$000(Unknown Source)

at java.awt.EventQueue$1.run(Unknown Source)

at java.awt.EventQueue$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)

at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)

at java.awt.EventQueue$2.run(Unknown Source)

at java.awt.EventQueue$2.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(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)







The error occurs the moment I call loadTexture from within my TextureManager.





Here is the TextureManager code:







public class TextureManager {



private static HashMap<String, Texture> textureMap;



public TextureManager() {



textureMap = new HashMap<String, Texture>();



}



public static void loadTexture(String name) {



if(textureMap.containsKey(name)) return;



try {



textureMap.put(name, TextureIO.newTexture(new File("textures/" + name + ".png"), true));

}

catch (GLException e) {



e.printStackTrace();

}

catch (IOException e) {



e.printStackTrace();

}

}



public static void bindTexture(String name) {



textureMap.get(name).bind();

}

}







A TextureManager object has already been created earlier in the code via:







new TextureManager();







This is the code that I called it using:







TextureManager.loadTexture("tree");







The path textures/tree.png exists too.





I did something similar to this in an older project, but instead of using a hashmap, I hard coded a variable in the TextureManager for every texture I used (not many). I suspect It's because the thread lacks a GL context because my old TextureManager passed GL in via the constructor, but never used it in the code. The draw function that called the loadTexture function also passed in a GL variable.


Comments

  1. Ah I figured out what was causing the problem. I was binding the texture within the glBegin and glEnd calls.

    Thanks for everyone that had a look at my question, though unfortunately I didn't include the code that would have provided the solution in my question. Apologies for that.

    Hopefully this is still able to help someone else in the future!

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?

CCNA 3 Final Exam => latest version

1 . Which security protocol or measure would provide the greatest protection for a wireless LAN? WPA2 cloaking SSIDs shared WEP key MAC address filtering   2 . Refer to the exhibit. All trunk links are operational and all VLANs are allowed on all trunk links. An ARP request is sent by computer 5. Which device or devices will receive this message? only computer 4 computer 3 and RTR-A computer 4 and RTR-A computer 1, computer 2, computer 4, and RTR-A computer 1, computer 2, computer 3, computer 4, and RTR-A all of the computers and the router   3 . Refer to the exhibit. Hosts A and B, connected to hub HB1, attempt to transmit a frame at the same time but a collision occurs. Which hosts will receive the collision jamming signal? only hosts A and B only hosts A, B, and C only hosts A, B, C, and D only hosts A, B, C, and E   4 . Refer to the exhibit. Router RA receives a packet with a source address of 192.168.1.65 and a destination address of 192.168.1.161...