Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (537)
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  
  ? GLJPanel and the init() method ?  (Read 2191 times)
0 Members and 1 Guest are viewing this topic.
Offline Z-Knight

Senior Member


Medals: 1



« Posted 2008-01-16 01:47:08 »

I'm fairly new to JOGL so be lenient...I have started a project where I'm using the GLJPanel() for my main panel (vs the GLCanvas) because of the Swing interaction that I need.   I use the init() method to load textures and to load 3DS models.  Everything works great in that basic state until I resize the window...the code calls init() every time the window is resized.  In some instances this just forces a reread of my textures and models and for the textures that is no problem but for the models it causes the window not to repaint at all. 

I realize that on resizing the reshape() function gets called in OpenGL and I've coded in OpenGL where I loaded textures in my init() function (yes they were globally defined and not local copies) and everything worked fine.  I could resize the OpenGL window and init() would not appear to be called again, but for some reason I'm getting the init() to be called for every resize.   I know I'm doing something wrong.  I know if I switch to GLCanvas() then I don't see init() being called again so what is the issue with the GLJPanel() and init().

I think what I would really like to find is some example code for how to setup the GLJPanel() with loading textures and then I could go from there...any suggestions?
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #1 - Posted 2008-01-16 08:59:00 »

Repeated calls to GLEventListener.init() are an essentially inevitable consequence of using the GLJPanel. The backing store (pbuffer or bitmap / pixmap) has a fixed size and needs to be expanded as the GLJPanel increases in size. This is why it is best to design your GLEventListeners in a way that init() can be called multiple times with no adverse side-effects.

Please look at the jogl-demos workspace for examples. Nearly all of the demos run inside the demos.jrefract.JRefract harness, where they are run inside GLJPanels as opposed to GLCanvases.
Offline Z-Knight

Senior Member


Medals: 1



« Reply #2 - Posted 2008-01-16 17:00:41 »

Thank you for that confirmation...I suspected as much but could not find a reference on the net to verify this.
   
    btw, this has been discussed already in other posts such as this one ( http://www.java-gaming.org/forums/index.php?topic=16295.msg128795#msg128795 )...unfortunately I plead ignorance of the topic and of JOGL but I do apologize for double postings.


I guess I need to review what goes into an init() method to begin with because loading the textures and models in it is obviously incorrect...since they would be repeatedly loaded with resizes.  Yes I can put a static flag check to ensure those textures and models are read only once but when I did this my scene end up getting cleared out so I must be forcibly clearing the scene without knowing it.  Maybe the JRefract example will help...thanks. (or if anyone else has an example I would not be opposed to seeing it.)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Z-Knight

Senior Member


Medals: 1



« Reply #3 - Posted 2008-01-16 22:38:51 »

Talking with others I realized that because the GLJPanel() resize causes the GLContext to be destroyed and so that is why I lose my textures and models.  It was suggested that I essentially build a separate GLContext at the start where I load my textures and models (make it current initially and then release it), then follow this with building the normal GLContext for my scene and then share the initial context data with it in the init() function (i.e. following resizes, etc).  Has anyone done this? And have you been successful?  The extent of my knowledge in JOGL is still quite small so I suspect this will be quite an adventure.


As a last resort I guess I can revert to using a GLCanvas()...I was intending to use the GLJPanel() because I was mixing my 3D view with 2D Swing panel but can someone elaborate on what the major issues are with employing a GLCanvas() in a JPanel() in a JFrame()?  Thanks.
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #4 - Posted 2008-01-17 21:43:56 »

As a last resort I guess I can revert to using a GLCanvas()...I was intending to use the GLJPanel() because I was mixing my 3D view with 2D Swing panel but can someone elaborate on what the major issues are with employing a GLCanvas() in a JPanel() in a JFrame()?  Thanks.

See the section "Heavyweight and Lightweight Issues" in the JOGL Users' Guide.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (17 views)
2014-08-01 22:53:16

CogWheelz (15 views)
2014-08-01 22:51:43

CopyableCougar4 (20 views)
2014-08-01 19:37:19

CogWheelz (19 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (42 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36
Resources for WIP games
by CogWheelz
2014-08-01 18:20:17

Resources for WIP games
by CogWheelz
2014-08-01 18:19:50

List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22
java-gaming.org 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‑gaming.org
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!