Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 26, 2013 1:58 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: SWT Canvas Rendering
PostPosted: Wed Jun 17, 2009 4:13 am 
Offline

Joined: Wed Jun 17, 2009 3:36 am
Posts: 3
I know opengl can be rendered to an swt canvas with lwjgl but, i'd like to use all of slick's features in an rcp application in the future. How can i do that now?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 17, 2009 6:24 am 
Offline
Game Developer
User avatar

Joined: Sun May 25, 2008 9:45 am
Posts: 578
Something similar to:
https://bob.newdawnsoftware.com/repos/s ... ainer.java

_________________
SingSong Karaoke - http://singthegame.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 18, 2009 9:09 am 
Offline

Joined: Wed Jun 17, 2009 3:36 am
Posts: 3
Thanks. Its works using the SWT AWT Bridge embeding the canvas in an SWT shell.

Screenshot
http://www.screencast.com/t/l7lUSi42

There's little issue with both the CanvasContainerTest and this one. rendering isn't started until the mouse is click in the canvas area . The requestFocus() method is called in the CanvasGameContainer contructor but has no effect until requestFocus() is called after container.start().
Code:
   public static void main(String[] argv) {
      try {
         CanvasGameContainer container = new CanvasGameContainer(new CompositeContainerTest());
         
         shell = new Shell();
         shell.setSize(500,500);
         display = shell.getDisplay();
         shell.setLayout(new GridLayout());
         shell.setText("CompositeContainerTest");

         final Menu mBar = new Menu(shell, SWT.BAR);
         shell.setMenuBar(mBar);
         final MenuItem fileItem = new MenuItem(mBar, SWT.CASCADE);
         fileItem.setText("File");
         final Menu fileMenu = new Menu(fileItem);
         fileItem.setMenu(fileMenu);
         for (int i = 0; i < 5; i++) {
            final MenuItem importItem = new MenuItem(fileMenu, SWT.NONE);
            importItem.setText("Item " + i);
         }      
         
         Composite containerComp = new Composite(shell, SWT.EMBEDDED);
         containerComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

         java.awt.Frame containerFrame = SWT_AWT.new_Frame(containerComp);
         containerFrame.add(container);

container.getContainer().setAlwaysRender(true);      
      container.requestFocus();
      container.start();
         
         shell.open();
         while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
               display.sleep();
            }
         }
         shell.dispose();   
      } catch (Exception e) {
         e.printStackTrace();
      }
   }   


Last edited by tsku on Sun Jun 21, 2009 3:41 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 18, 2009 5:44 pm 
Offline
Game Developer
User avatar

Joined: Sun May 25, 2008 9:45 am
Posts: 578
Use GameContainer#setAlwaysRender(true).

_________________
SingSong Karaoke - http://singthegame.com


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 13, 2010 12:05 pm 
Offline
Regular
User avatar

Joined: Mon Mar 05, 2007 11:05 pm
Posts: 111
Location: Burträsk, Norrland, Sweden
Just learned about SWT and after reading this post I've got a shell up n' running with a Slick Canvas! I've really wanted this for a long time! It's really great to be able to implement a SWT framework into a level editor for example, and to render directly from the game engine makes it all the better!

So everyone that wants a Swing/AWT solution to your Slick apps, give SWT a try instead!
I got a AWT window up yesterday and right away I can say it was a lot more buggy, the fps was nothing as near good as when I render it in SWT.
Now I gotz all the parts for making a great editor environment for my games!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 13, 2010 12:54 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
Maybe you should just use Display.setParent together with a AWT Canvas - this gives you the fasted possible performance (like a stand alone Display) and you don't need any additional native libs (besides LWJGL).

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 04, 2010 1:54 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
This works nice. Just wondering though, does input work if it's inside a canvas? I'm thinking I probably have to setup some input handler between SWT -> Slick

EDIT: Disregard. Either it started magically working or I'm an idiot. :shock: I guess it just needed focus or something.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group