Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (593)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (646)
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  
  Trouble loading textures outside the init() call  (Read 2708 times)
0 Members and 1 Guest are viewing this topic.
Offline Markus_Persson

JGO Wizard

Medals: 16
Projects: 19

Mojang Specifications

« Posted 2003-07-08 19:00:30 »


I'm attempting to port the client for a game I'm writing from LWJGL to Jogl as it seems like Jogl is better supported and is more of a "pure" gl wrapper than LWJGL.
But I'm having trouble defining textures (and various other things.. I haven't narrowed them down yet, but they seem to involve lists) outside of the init(GLDrawable) call in GLEventListener.
Since the init call is only made once (before the GLCanvas is made visible?), and I want to provide a splash screen in opengl that let's the user know what textures are being loaded and so, I've got a bit of a problem here.

I managed to get around it by turning off autoredrawing and setting the rendering thread to the current thread. That let me define textures and everything from that thread, then call display() on the canvas, and it works.

I felt this was a bit of a hack, so I asked a friend of mine who's running linux to try it... but the game started without any textures and various missing features (like the bitmaps for the fonts), just like it did for me at first.

So now my question is.. what am I doing wrong? Is there any documentation I've missed somewhere that explains this strange behavior?

The current alpha of the game client can be found at

Play Minecraft!
Offline Ken Russell

JGO Coder

Java games rock!

« Reply #1 - Posted 2003-07-09 03:17:56 »

To do this properly you need to fork off a background thread which performs just the disk I/O and conversion into the appropriate data format (e.g. byte[] or ByteBuffer). Your display() method should then pick up that loaded data from the background thread, call the appropriate OpenGL commands to define the texture objects, and update the progress bar. Once all textures have been loaded the display() method should stop displaying the progress bar and start displaying the main game.

Let me know if this isn't clear enough. For JavaOne I ported the Grand Canyon demo (, which does something similar, to Jogl but don't have those ported sources posted anywhere yet.
Offline Markus_Persson

JGO Wizard

Medals: 16
Projects: 19

Mojang Specifications

« Reply #2 - Posted 2003-07-09 11:55:14 »

That seems very messy..

If I understand the code correctly, the only proper place to make any opengl calls is in Runnables called from the GLContext (sub)class, and the buffer swapping isn't performed until the Runnable returns.. is that right?

If it is, then I really don't understand the reason for this. Why not just expose the SwapBuffers and/or MakeCurrent calls in GLContext?

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

JGO Wizard

Medals: 16
Projects: 19

Mojang Specifications

« Reply #3 - Posted 2003-07-09 15:31:20 »

Don't get me wrong, I really like and appreciate what you're doing. Smiley

Play Minecraft!
Offline Ken Russell

JGO Coder

Java games rock!

« Reply #4 - Posted 2003-07-10 05:14:44 »

I was an active developer of GL4Java for over a year and most of the errors reported were due to incorrect OpenGL context management, such as forgetting to free() the context at the end of the display() method. This has informed many of the design decisions in Jogl, including (1) making GLCanvas and GLJPanel final, (2) not exposing GLContext in the public API, and (3) not even exposing the makeCurrent/free paradigm to the bulk of the Jogl implementation. In Jogl everything is expressed as a closure that is run with the context made current. This has simplified the implementation considerably and made it much easier to add new functionality.

I used the GLContext.swapBuffers() call manually in one GL4Java application I wrote (for a progress bar), and upon porting it to Jogl found that changing the code to avoid the manual call made it a lot less of a hack.
Offline Markus_Persson

JGO Wizard

Medals: 16
Projects: 19

Mojang Specifications

« Reply #5 - Posted 2003-07-10 09:29:21 »

I still think it's strange that the only buffer swap is performed after the only legal place to execute opengl commands returns.

First of all, it's not exactly in line with the very procedural "normal" opengl thinking.
Furthermore, if you want to use a "special" opengllistener just to load a texture, you still have to rerender the entire screen to prevent artifacts. And in the case of the progress bar, that special listener would have to keep track of a lot of state in the instance instead of just in a single linear method.

That, or fork off a thread like you suggested, just to mimic C opengl behavior. :-/

I'll do my best to adapt, but I have to say I don't find this very optimal at all.
Other than that, I still love Jogl. Wink It's exactly what Java needs.

Play Minecraft!
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

deepthought (32 views)
2015-06-30 15:39:44

deepthought (34 views)
2015-06-30 15:39:09

deepthought (45 views)
2015-06-30 15:36:52

Za\'Anzabar (21 views)
2015-06-29 05:44:54

TritonDreyja (36 views)
2015-06-24 17:10:40

CopyableCougar4 (35 views)
2015-06-23 00:34:45

BurntPizza (39 views)
2015-06-21 20:36:46

cookiecompiler (82 views)
2015-06-11 15:42:53

cookiecompiler (45 views)
2015-06-11 15:41:14

NegativeZero (75 views)
2015-06-11 09:49:18
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14 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‑
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!