Java 3D: Where can I insert a “post rendering” FX?

心已入冬 提交于 2021-02-11 15:59:43

问题


I extended a Canvas3D and then I override the method "postSwap()", but my odd-even line effect is flickering a lot, what could be another good point for inserting this process?

public void postSwap() {
    Graphics2D g2 = (Graphics2D)this.getGraphics();
    Map map = new HashMap();
    map.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    g2.addRenderingHints(map);
    g2.setColor(WipideaApplet.BCK2);
    int h = this.getHeight(), w = this.getWidth();
    for (int i=0;i<h;i++) {
        if (i%2==0)
            g2.drawLine(0, i, w, i);
    }
}

回答1:


I found a good solution by myself which I post here to share it, if you have another one please post it :-)

@Override
public void postRender() {
    super.postRender();
    getGraphics2D().setColor(WipideaApplet.BCK2);
    int h = this.getHeight(), w = this.getWidth();
    for (int i=0;i<h;i++) {
            if (i%2==0) {
                getGraphics2D().drawLine(0, i, w, i);
            }
    }
    getGraphics2D().flush(true);
}

Pratically getGraphics2D().flush(true); is the most important, because avoid any flickering, at least on my centrino duo :-)



来源:https://stackoverflow.com/questions/789063/java-3d-where-can-i-insert-a-post-rendering-fx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!