Skip to main content

How to make Canvas3D background transparent?

10 replies [Last post]
neil1988
Offline
Joined: 2010-09-13
Points: 0

Hi all,
I have put a Canvas3D into a JPanel, I wonder how to make the canvas3d background be transparent so people are able to see the JPanel and the 3D objects.
Thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
millerni456
Offline
Joined: 2010-12-09
Points: 0

I know this is a tad unrelated and that you're question I believe has already been aswered, but I had noticed that you used "JCanvas3D". I've actually been unaware of how to use this until now.
I do have one question regarding JCanvas3D: How do you add this to a regular JFrame?
Whenever I start my program, the JCanvas3D opens in its own window, and the statements for showing my JFrame are ignored. If you can help, that'd be great, but it isn't too important.
-Nick.

deryaaltuntas
Offline
Joined: 2011-03-22
Points: 0

Hello
I have some problem.My graphic card is new not old.But I use following state in my code, backgorund is still black.
System.setProperty("j3d.transparentOffScreen", "true");
Please help.This is my code

deryaaltuntas
Offline
Joined: 2011-03-22
Points: 0

I can not add my code correctly.When I paste my code,
my codee statements is not shown in format which I copy.
Code is in the attached link.
http://img715.imageshack.us/i/codeu.jpg/

interactivemesh
Offline
Joined: 2006-06-07
Points: 0
neil1988
Offline
Joined: 2010-09-13
Points: 0

Hi August,

Many thanks for the help. You're a pro in Java 3D. You solved a lot of problems in this forum.

I read the links, but I'm not be able to get a transparent effect, but a black background. I don't know what's the problem.

This is my code:

GraphicsDevice graphicsDevice;

if (container.getGraphicsConfiguration() != null)

{

graphicsDevice = container.getGraphicsConfiguration().getDevice();

}

else

{

graphicsDevice =

GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

}

GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();

template.setSceneAntialiasing(template.PREFERRED);

System.setProperty("j3d.transparentOffScreen", "true");

JCanvas3D canvas3d = new JCanvas3D(template, graphicsDevice);

canvas3d.setSize(200, 200);

canvas3d.setOpaque(false);

univ = new SimpleUniverse(canvas3d.getOffscreenCanvas3D());

Many thanks.

interactivemesh
Offline
Joined: 2006-06-07
Points: 0

Your call 'System.setProperty("j3d.transparentOffScreen", "true")' happens too late.

Java 3D system properties are checked only once as soon as the class VirtualUniverse is imported.

Set the property in 'public static void main(String[] args) { ... }' if at this time no Java 3D classes will be imported or set it with -Dj3d.transparentOffScreen=true when launching the program.

'transparentOffScreen' is not supported on DirectX (d3d).

August

neil1988
Offline
Joined: 2010-09-13
Points: 0

Hello August, thank you for your help. I correct my code using your way but still get a black background... I think maybe it's a graphics card problem, it's too old?

neil1988
Offline
Joined: 2010-09-13
Points: 0

Thank you for your help August, I corrected my code using your way but still got a black background, I think maybe it's the graphics card problem? Maybe it's too old?

interactivemesh
Offline
Joined: 2006-06-07
Points: 0

Please, run following Java Web Start applications. They are self-signed for setting the transparent offscreen system property.

This message should be written in the console: 'Java 3D: transparent OffScreen enabled'. The Scala application also prints some system properties. Check your OpenGL version: 'Native Version'.

JavaFX: FXScreenFlight 3.0
http://www.interactivemesh.org/testspace/webstartjavafx/fxScreenFlight_m...

An airplane should appear on your desktop without window and background.

Scala: ScCharacterCube 1.2
http://www.interactivemesh.org/testspace/webstartscala/scCharacterCube_2...

Create a transparent screenshot: enable 'Transparent Background', choose an arbitrary image size, and click on 'Render to Image'. This should result in an image with a grey/transparent background.

August

neil1988
Offline
Joined: 2010-09-13
Points: 0

Thank you very much August,
I switched to another computer and it works ;-)
So it must be the graphics card problem.
BTW, your airplane application is cool.