Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Select Pixel Transparency


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 HelloSkitty   Members   -  Reputation: 152

Like
0Likes
Like

Posted 13 May 2012 - 11:26 AM

So I looked for ways to make individual pixels transparent rather than an entire window, and found this:

jPanel1 = new javax.swing.JPanel() {
	  protected void paintComponent(Graphics g) {
		  if (g instanceof Graphics2D) {
			  final int R = 240;
			  final int G = 240;
			  final int B = 240;

			 Paint p =
			  new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 0),
				  getWidth(), getHeight(), new Color(R, G, B, 255), true);
			  Graphics2D g2d = (Graphics2D)g;
			  g2d.setPaint(p);
			  g2d.fillRect(0, 0, getWidth(), getHeight());
	   } else {
	  super.paintComponent(g);
	   }
	 }
}

from here: http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/#Enabling-Per-Pixel-Translucency


Now the problem I have is that this is drawing the transparency directly to the JFrame. This is a problem when using this with a game, because there are serious flickering issues.

I tried double-buffering the transparency in the image I loop-draw, but it was no avail.

public void interpolatedDensity(int i,int j) {
//stuff
return 150<<24 | rCol<<16 | gCol<<8 | bCol;
//Partial transparency
}
public void paint() {
  for (int i=0;i<800;i++) {
   for (int j=0;j<800;j++) {
    int c=field.interpolatedDensity(i,j);
    dbPlasma.setElem(i+j*800,c); //The DataBuffer for BetterDoubleBuffer
   }
  }
 //Stuff
 g.drawImage(betterDoubleBuffer,0,0,null);
}
//Transparency ignored when painting

Is there a way around this, or is there no way for a java-based (action, at least 10 FPS) game to make use of window transparency?
A penny for my thoughts? Do you think I have only half a brain?

Not-so-proud owner of blog: http://agathokakologicalartolater.wordpress.com/

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS