• Advertisement
Sign in to follow this  

Select Pixel Transparency

This topic is 2169 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement