Author Topic: Rendering inside an SWT canvas  (Read 10314 times)

jjzazuet

  • Jr. Member
  • **
  • Posts: 16
    • Unsung Stories
Rendering inside an SWT canvas
« on: October 21, 2012, 06:27:23 AM »
Hello there. Jesús again.

I think I'm starting to make progress on my application.  8)

One more question though. I plan to use an SWT based interface to let the user interact with the 3D scene.

Using plain LWJGL I know it's possible to embed the GL canvas inside SWT; but I'm not sure on how to do this with Bonzai's framework.

Is it possible to embed the GL canvas created by the engine into an SWT frame? Is there any reference code available?

Thanks again for your time and help!

JZM

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Rendering inside an SWT canvas
« Reply #1 on: October 23, 2012, 11:59:23 AM »
I think I'm starting to make progress on my application.  8)
Great !


You can embed the 3d Canvas inside SWT by implementing the IApplication interface.

The exemple below implements it with a JFrame, but you can do similar stuff with SWT (as you said it supports Canvas): UserWindow.

Ps: You'll have to upgrade with last build to have access to initApp (which was protected).
« Last Edit: October 23, 2012, 12:03:29 PM by jerome_j »

jjzazuet

  • Jr. Member
  • **
  • Posts: 16
    • Unsung Stories
Re: Rendering inside an SWT canvas
« Reply #2 on: October 24, 2012, 06:28:25 AM »
Hi again. Thanks for the information.

Having looked at the example code I think I may still need to check if Bonzai is tightly integrated with AWT. The reason being these two lines in the example's init() method:


My assumption is that the second line assigns to the application the instance of the AWT Canvas where LWJGL has been initialized. If this is indeed the case then I may need to use the SWT-AWT bridge support classes since, in the end, what IApplication gets is in fact an AWT compoent. But that may slow things down a bit... :P

Instead, is there a way to configure LWJGL to render to an instance of  that doesn't require AWT/Swing objects?

I mean, I could simply instruct LWJGL's class to render instead to my own instance of an SWT GLCanvas inside 's method, but I'm not sure if this will mess up with Bonzai internally :P.

The following example code illustrates how to initialize LWJGL directly inside SWT.

http://goo.gl/dOXg9

Am I close to finding a solution?

Thanks again for your time and help!

JZM

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Rendering inside an SWT canvas
« Reply #3 on: October 24, 2012, 12:31:44 PM »
Ah ok, I tought you were talking about using the lwjgl's gl canvas inside SWT.

Basically, you'll need to create the bindings for SWT GLCanvas by implementing an ISceneTarget and managing IGLApi. I've made a quick binding, so you can reuse it:
SwtSceneTarget
SwtComponent

There's possibly some small adaptation and some fixme comment to review, but most of the engine should be working.
Let me know of the necessary changes (if any) to maintain this code for others.

A test code using swt with an existing tutorial BonzaiEngineInSwt.
« Last Edit: October 24, 2012, 12:36:07 PM by jerome_j »

jjzazuet

  • Jr. Member
  • **
  • Posts: 16
    • Unsung Stories
Re: Rendering inside an SWT canvas
« Reply #4 on: October 24, 2012, 05:26:31 PM »
Awesome!

I'll integrate the SWT bindings in my code and let you know if I run into any issues.

Thanks again for your time and help!

JZM

jjzazuet

  • Jr. Member
  • **
  • Posts: 16
    • Unsung Stories
Re: Rendering inside an SWT canvas
« Reply #5 on: October 26, 2012, 01:25:09 AM »
OMG it works!

Wow :O

Thanks again man! I'll do some code cleanup on the SWT bindings and keep updating my progress.

Cheers!

JZM