Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (542)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (606)
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  
  AWTGLCanvas using in Swing  (Read 1542 times)
0 Members and 1 Guest are viewing this topic.
Offline Mac_Systems

Junior Devvie




I love my Java


« Posted 2005-04-05 11:03:07 »

Hi,

i allready included a well working version of the AWTGears Demo as a Test in my Swing App. Looking at the CPU Usage i like it very much Smiley
Now i would like to include it more in my new Project, but i have trouble with that AWT/Swing mixing in this case: I displayed a AWTGLCanvas, later the user clicks on a button and the Canvas will disapear(removed from JPanel), when the user clicks again the canvas will be added again to the JPanel, i also see that the Thread is running and outs the FPS each 5 Seconds but i cannot see any Gears again, the Panel remains black.Can someone give me a hint what to do ?

May i have to save the GL Context ?

Stay Tuned,
Jens


The Network is the Music
http://www.mac-systems.de
Offline princec

« JGO Spiffy Duke »


Medals: 439
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2005-04-05 11:46:49 »

Post a quick sample.

Cas Smiley

Offline Mac_Systems

Junior Devvie




I love my Java


« Reply #2 - Posted 2005-04-05 12:02:26 »

Ok, there is the Code that do the Switch between
both Views when user hits a Button:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
public class PlaylistSpectrumPanel
      extends JPanel implements Toogleable
{
  private static Logger log = Logger.getLogger(PlaylistSpectrumPanel.class);

  /**
   * The Spectrum Panel
   */

  private final SpectrumPanel spectrumPanel;
  /**
   * The Playlist Panel
   */

  private final Playlist playlistPanel;

  private boolean isSpectrumShown = true;

  private ServerPanel serverPanel = new ServerPanel(new ServerTable());

  private JComponent lastFileView = null;

  private final AWTCanvasTest awtCanvas;

  public PlaylistSpectrumPanel(AWTCanvasTest awtCanvas, SpectrumPanel spectrumPanel, Playlist playlistPanel)
  {
      super();
      this.spectrumPanel = spectrumPanel;
      this.playlistPanel = playlistPanel;
      this.awtCanvas = awtCanvas;
      setLayout(new BorderLayout());
      add(awtCanvas, BorderLayout.CENTER);
      lastFileView = playlistPanel;

      System.out.println("awtCanvas.getPreferredSize():" + awtCanvas.getPreferredSize());

  }

  public void toogle()
  {
      toogleSpectrum();
  }

  /**
   * Switch between Spectrum and Playlist view
   */

  private final void toogleSpectrum()
  {
      if (isSpectrumShown)
      {
        //remove(spectrumPanel);
        remove(awtCanvas);
        add(lastFileView, BorderLayout.CENTER);
        awtCanvas.donotShow();
      }
      else
      {
        remove(lastFileView);
        switchView();
        //add(spectrumPanel, BorderLayout.CENTER);
        add(awtCanvas, BorderLayout.CENTER);
        awtCanvas.showAgain();
      }

      isSpectrumShown = isSpectrumShown ? false : true;
      revalidate();
      updateUI();
  }

  private final void switchView()
  {
      if (lastFileView.equals(playlistPanel))
      {
        lastFileView = serverPanel;
      }
      else
      {
        lastFileView = playlistPanel;
      }
      System.out.println("New View:" + lastFileView);
  }


}



Actual the SpectumPanel isnt used by this example,
AWTCanvasTest is the GLGear Test from LWJGL Examples (the heavyweight canvas), with this extension:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
 
  public void showAgain()
  {
      canvas0.setVisible(true);
      canvas0.addNotify();
  }
 
  public void donotShow()
  {
      canvas0.setVisible(false);
      canvas0.removeNotify();
  }


The Network is the Music
http://www.mac-systems.de
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mac_Systems

Junior Devvie




I love my Java


« Reply #3 - Posted 2005-04-06 12:54:15 »

I Tested a bit more whats wrong, for me it seems that i lost the Draw Context when removing the Canvas, but im not able to restore it,
the API Doc to makeCurrent in AWTGLVCanvas:

makeCurrent

public void makeCurrent()
                throws LWJGLException

   Make the canvas' context current. It is highly recommended that the context is only made current inside the AWT thread (for example in an overridden paint()).

   Throws:
       LWJGLException


Looked at the LWJGL Sources paint(Graphics g) is declared as final,and seems to do what i tried ..setting the GL Context again,so i was not able to overwrite it ...

Also i implemented componentShown(...) and componentRemoved(...)..this Methods will not invoked when my canvas should show up again. The Shown Method should be called when adding the Canavs again, maybe a bug  (But not responsible for my prob. )  Huh

Anyone can help ?

thx,
jens

The Network is the Music
http://www.mac-systems.de
Offline Mac_Systems

Junior Devvie




I love my Java


« Reply #4 - Posted 2005-04-06 17:59:34 »

Hi again ,

strange things going on there:

When i change the glClearColor to a Random Color the background  will change randomly, but the Gears will not drawn ....

Anyone know how to setup GL again ? It should be done in componentResize ..but it do now work for me, maybe someone has an example ..

Sorry for flooding the board,
Jens


The Network is the Music
http://www.mac-systems.de
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.

Elsealabs (20 views)
2014-12-28 10:39:27

CopyableCougar4 (21 views)
2014-12-28 02:10:29

BurntPizza (25 views)
2014-12-27 22:38:51

Mr.CodeIt (15 views)
2014-12-27 04:03:04

TheDudeFromCI (20 views)
2014-12-27 02:14:49

Mr.CodeIt (26 views)
2014-12-23 03:34:11

rwatson462 (60 views)
2014-12-15 09:26:44

Mr.CodeIt (48 views)
2014-12-14 19:50:38

BurntPizza (98 views)
2014-12-09 22:41:13

BurntPizza (116 views)
2014-12-08 04:46:31
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

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50
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!