Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Advanced Graphics flickering
Advanced Graphics flickering [message #455940] Mon, 23 May 2005 14:14 Go to next message
Eclipse UserFriend
I saw that SWT 3.1M5 added support for some cool graphical stuff, some of
which I've been really waiting for in SWT. I tried the Snippet10 example,
and it worked fine out of the box. I wanted to test some animation, so I
added a simple timer to rotate the text, and that was when I noticed the
problem. As the text rotates, it flickers fairly badly. Has anyone else
noticed this? At this point, my company is deciding between SWT and
wxWidgets for this project, but we'd **much** rather use SWT if it can do
what we need.

Here's the code I was using (adapted from Snippet10):

/*
* Drawing with transformations, paths and alpha blending
*
* For a list of all SWT example snippets see
*
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/dev.html#snippets
*/
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

import java.util.*;

public class GraphicsTest {
static int theta = 0;

public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);

shell.setText("Advanced Graphics");
FontData fd = shell.getFont().getFontData()[0];
final Font font = new Font(display, fd.getName(), 60, SWT.BOLD |
SWT.ITALIC);

final Image image = new Image(display, 640, 480);
final Rectangle rect = image.getBounds();
GC gc = new GC(image);
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillOval(rect.x, rect.y, rect.width, rect.height);
gc.dispose();

shell.addListener(SWT.Paint, new Listener() {
public void handleEvent(Event event) {
GC gc = event.gc;
Transform tr = new Transform(display);
tr.translate(50, 120);
tr.rotate(theta);
gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width /
2, rect.height / 2);
gc.setAlpha(100);
gc.setTransform(tr);
Path path = new Path(display);
path.addString("SWT", 0, 0, font);
gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
gc.fillPath(path);
gc.drawPath(path);
tr.dispose();
path.dispose();
}
});

Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
public void run() {
theta = (theta+1)%360;
display.asyncExec(new Runnable() {
public void run() {
shell.redraw();
}
});
}
};
timer.scheduleAtFixedRate(timerTask, 0, 100);

shell.setSize(shell.computeSize(rect.width / 2, rect.height / 2));
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}

image.dispose();
font.dispose();
display.dispose();
}
}
Re: Advanced Graphics flickering [message #455945 is a reply to message #455940] Mon, 23 May 2005 15:56 Go to previous messageGo to next message
Eclipse UserFriend
The GraphicsExample of the the org.eclipse.swt.example module contains
an example for double buffering. See
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.exa mples/src/org/eclipse/swt/examples/graphics/

Stephan Michels.
Re: Advanced Graphics flickering [message #455946 is a reply to message #455945] Mon, 23 May 2005 16:59 Go to previous messageGo to next message
Eclipse UserFriend
I don't see any double buffering happening in that code. Only one Image is
ever instantiated, so there's no secondary buffer object. Maybe I'm just
missing something there.

At any rate, the problem doesn't look like the flickering that happens
with normal buffering problems. I added some println calls to the painting
code, and I can see that there are times when the text isn't rendered for
many consecutive redraws. Sometimes the text reappears quickly (a few
redraws), sometimes it is gone for multiple seconds (30-50 redraws). I'm
only asking for 10 frames per seconds in my example code, which doesn't
seem unreasonable at all.

I should mention that I'm using GTK, so maybe there are some issues with
the Cairo version of the code?
Re: Advanced Graphics flickering [message #455947 is a reply to message #455946] Mon, 23 May 2005 17:40 Go to previous messageGo to next message
Eclipse UserFriend
>I don't see any double buffering happening in that code. Only one Image is
>ever instantiated, so there's no secondary buffer object. Maybe I'm just
>missing something there.

It's the canvas that's buffered.

Look in "void createCanvas(Composite parent)". It's creating a new GC on a
buffer that isn't drawn to the screen until it has been filled with what
will be painted onto the screen, then the buffer is painted over what you
are currently viewing, thus, "killing" flicker and "double buffering" it.

Hope that helps.

Emil
Re: Advanced Graphics flickering [message #455950 is a reply to message #455947] Mon, 23 May 2005 21:06 Go to previous messageGo to next message
Eclipse UserFriend
It turns out that I'm not very smart. I was looking at the wrong example.
Sorry Stephan!

The example looks great under Windows. Very fast. I'll have to give it a
shot under Linux tomorrow and see how it works when powered by Cairo.
Re: Advanced Graphics flickering [message #455989 is a reply to message #455950] Tue, 24 May 2005 11:43 Go to previous message
Eclipse UserFriend
Got the example working under Linux, but performance still blew. However,
upgrading to Cairo 0.4.0 worked MUCH better. As a word of warning to you
Gentoo users out there, Cairo 0.1.23 is probably not a very good choice,
so make sure you upgrade.
Previous Topic:Getting all children from a tree
Next Topic:is is a bug of swt?
Goto Forum:
  


Current Time: Tue Sep 16 08:59:55 EDT 2025

Powered by FUDForum. Page generated in 0.04430 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top