标签: doublebuffered

你如何在游戏中加倍缓冲java?

因此,在我正在进行的游戏中,我有一个大理石跟随鼠标,但当它这样做时屏幕闪烁.

背景包括两个jpegs和9个矩形.我该如何进行双缓冲呢?这是主窗口的代码.

/**
 * Write a description of class Window here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Window extends JApplet implements MouseMotionListener
{
    private BufferedImage image; 
    private BufferedImage side;
    private int mouseX;
    private int mouseY;

    public Window(){
        try {
            image = ImageIO.read(new File("Backgrounds/violet.jpg"));
            side = ImageIO.read(new File("Backgrounds/side margin.jpg"));
        } catch (IOException ex) { }    
    }   

    private void delay(int delay)
    {
        try {
            Thread.sleep(delay);
        } catch (InterruptedException e) {}
    }

    public …
Run Code Online (Sandbox Code Playgroud)

java graphics doublebuffered

6
推荐指数
1
解决办法
3万
查看次数

自定义控件中的双缓冲子控件(C#)

我想双缓冲包含按钮的自定义控件.我已经尝试了各种方法来双重缓冲控件; SetStyle,BufferedGraphicsContext和绘制到位图.这些都适用于控件的自定义绘图,但它们都不会处理将按钮绘制到后台缓冲区.我该如何实现这一目标?

c# drawing doublebuffered winforms

5
推荐指数
1
解决办法
2941
查看次数

WinForms - Form.DoubleBuffered属性是否会影响对该表单的控制?

Form 具有DoubleBuffered属性(bool,继承自Control).

如果将此设置为true,那么由于在表单上,​​是否所有控件都以双缓冲方式放置在屏幕上?或者您是否需要担心自己的DoubleBuffered属性?

.net c# doublebuffered winforms

5
推荐指数
1
解决办法
2829
查看次数

WGL:没有双缓冲+多次采样=失败?

我通常使用wglChoosePixelFormatARB()这些参数(以及其他参数)创建像素格式:

WGL_DOUBLE_BUFFER_ARB = GL_TRUE
WGL_SAMPLE_BUFFERS_ARB = GL_TRUE
WGL_SAMPLES_ARB = 4
Run Code Online (Sandbox Code Playgroud)

即双缓冲和x4多重采样.这很好用.
但是当我尝试转换双缓冲时:

WGL_DOUBLE_BUFFER_ARB = GL_FALSE
WGL_SAMPLE_BUFFERS_ARB = GL_TRUE
WGL_SAMPLES_ARB = 4
Run Code Online (Sandbox Code Playgroud)

调用wglChoosePixelFormatARB()失败(或者说它没有创建任何东西)
当我有效地关闭多重采样时:

WGL_DOUBLE_BUFFER_ARB = GL_FALSE
WGL_SAMPLE_BUFFERS_ARB = GL_TRUE
WGL_SAMPLES_ARB = 1
Run Code Online (Sandbox Code Playgroud)

我再次正常工作.

有没有固有的东西阻止非双缓冲像素格式与多重采样一起使用?

我正在关闭双缓冲的原因是为了实现无约束的帧速率.使用双缓冲,我得到的帧速率仅高达60 FPS(这款笔记本电脑液晶显示器的工作频率为60Hz).但是通过双缓冲关闭,我可以达到1500 FPS.有没有办法通过双缓冲来实现这一目标?

opengl multisampling frame-rate doublebuffered wgl

5
推荐指数
1
解决办法
1756
查看次数

如何在Java2D中进行双缓冲?

我在屏幕上使用Java2D绘制了一堆原语,我得到了很多撕裂/闪烁.

如何启用/使用双缓冲,以便将其从屏幕上拉出然后显示整个事物?

java doublebuffered java-2d

5
推荐指数
1
解决办法
4373
查看次数

双缓冲C#

我正在尝试实现以下方法:void Ball :: DrawOn(Graphics g);

该方法应该绘制球的所有先前位置(存储在队列中)并最终绘制当前位置.我不知道这是否重要,但我使用g.DillEllipse(...)打印以前的位置,使用g.FillEllipse(...)打印当前位置.

问题是,你可以想象有很多绘图要做,因此显示开始闪烁很多.我曾寻找过双缓冲的方法,但我能找到的就是这两种方式:

1)System.Windows.Forms.Control.DoubleBuffered = true;

2)SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint,true);

在尝试使用第一个时,我得到一个错误,解释说在此方法中,由于其保护级别,属性DoubleBuffered无法访问.虽然我无法想象如何使用SetStyle方法.

是否有可能将缓冲区加倍,而我拥有的所有访问权限都是我在方法中输入的图形对象?

提前致谢,

编辑:我创建了以下类

namespace doubleBuffer
{
    class BufferedBall : System.Windows.Forms.Form{
        private Ball ball;
        public BufferedBall(Ball ball)
        {
            this.ball = ball;
        }

    public void DrawOn(Graphics g){
        this.DoubleBuffered = true;
        int num = 0;
        Rectangle drawArea1 = new Rectangle(5, 35, 30, 100);
        LinearGradientBrush linearBrush1 =
        new LinearGradientBrush(drawArea1, Color.Green, Color.Orange, LinearGradientMode.Horizontal);
        Rectangle drawArea2 = new Rectangle(5, 35, 30, 100);
        LinearGradientBrush linearBrush2 =
           new LinearGradientBrush(drawArea2, Color.Black, …
Run Code Online (Sandbox Code Playgroud)

c# graphics doublebuffered

5
推荐指数
1
解决办法
7252
查看次数

尽管双重缓冲,但自动收报机仍在闪烁

有没有人知道如何摆脱闪烁?我研究了SO,网络,尝试了很多不同的东西,比如把TickerControl放入双缓冲面板和双缓冲时没有在OnPaint()中绘图:为什么它不起作用?除了许多其他的东西.它仍然闪烁,不是每次重复,而是每秒几次.

此外,即使在OnPaint中删除"g.Clear(BackColor)"后,仍然必须清除背景,因为文本继续可读地滚动.

这里是我的TickerControl类的相关部分:

class TickerControl : Control
{
    private static readonly StringFormat stringFormat = new StringFormat(StringFormatFlags.NoWrap);

    private const int padding = 40;
    private const int scrollSleep = 10;
    private const int scrollAdvancePixels = 1;

    private float textWidth;
    private float currentX;

    private static readonly Timer scrollTimer = new Timer();

    public TickerControl()
    {
        this.SetStyle(ControlStyles.UserPaint |
                      ControlStyles.AllPaintingInWmPaint |
                      ControlStyles.OptimizedDoubleBuffer
                      , true);
        scrollTimer.Tick += AdvanceText;
        scrollTimer.Interval = scrollSleep;
        scrollTimer.Enabled = true;
    }

    private void AdvanceText(object sender, EventArgs e)
    {
        if (IsDisposed)
            return; …
Run Code Online (Sandbox Code Playgroud)

c# doublebuffered flicker winforms

5
推荐指数
2
解决办法
6040
查看次数

在Java中实现双缓冲

我有一个简单的Java JFrame画布.我每半秒左右更新屏幕上的内容,并且闪烁.我想实现双缓冲以消除闪烁,但我对Java很新,并且不熟悉如何这样做.我找到了一些例子,但不知道如何将他们的方法实现到我的.

以下是我现在如何处理的基本设置.这不是我的确切代码 - 只是基本设置的一个示例.

感谢任何正确方向的推动!

public class myCanvas extends Canvas{
    //variables
    Color rectColor=Color.red;

    public myCanvas()
    {
    }

    public void paint(Graphics graphics)
    {
        //initial setup, such as
        graphics.setColor(rectColor);
        graphics.fillRect(X,Y,W,H);
    }
    public static void main(String[] args)
    {
        myCanvas canvas = new myCanvas();
        JFrame frame = new JFrame("GUI");
        frame.setSize(frameWidth,frameHeight);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(canvas);
        frame.setVisible(true);
        while(true){
            rectColor=Color.green;
            canvas.validate();
            canvas.repaint();
            Thread.sleep(500);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

java graphics doublebuffered

5
推荐指数
1
解决办法
7089
查看次数

在 fb_var_screeninfo 中设置 yres_virtual 时出现无效参数错误

我正在尝试为 Linux 创建一个直接写入帧缓冲区 /dev/fb0 的应用程序。为了使其成为双缓冲,我尝试使虚拟屏幕成为屏幕大小的两倍。这是我写的程序:

struct fb_var_screeninfo screeninfo_var;
struct fb_fix_screeninfo screeninfo_fixed;
unsigned int* screenbuffer;

void gfx_init()
{
    fb0 = open("/dev/fb0", O_RDWR);
    if(fb0 == 0)
        error("Could not open framebuffer located in /dev/fb0!");

    if (ioctl(fb0, FBIOGET_FSCREENINFO, &screeninfo_fixed) == -1)
        error("Could not retrive fixed screen info!");

    if (ioctl(fb0, FBIOGET_VSCREENINFO, &screeninfo_var) == -1)
        error("Could not retrive variable screen info!");

    screeninfo_var.xres_virtual = screeninfo_var.xres;
    screeninfo_var.yres_virtual = screeninfo_var.yres * 2;
    screeninfo_var.width = screeninfo_var.xres;
    screeninfo_var.height = screeninfo_var.yres;
    screeninfo_var.xoffset = 0;
    screeninfo_var.yoffset = 0;

    if (ioctl(fb0, FBIOPUT_VSCREENINFO, &screeninfo_var) == …
Run Code Online (Sandbox Code Playgroud)

c linux framebuffer doublebuffered

5
推荐指数
1
解决办法
3156
查看次数

GDI+ 双缓冲:后缓冲双色单色

我正在尝试使用 C++、Windows api 和 GDI+ 构建一个非常简单的图形应用程序。第一次尝试构建应用程序时,引入了严重的闪烁,因此此代码尝试使用双缓冲,但失败了。hdcBuf 是后备缓冲区。

当尝试使用 GDI+ Graphics::DrawCachedBitmap 将某些内容绘制到后台缓冲区时,位图将以黑白双色绘制。

LoadBitmapRes 从 EXE 资源创建一个 CachedBitmap;该函数适用于单缓冲。

代码有什么问题吗?提前致谢!

全球的:

CachedBitmap* fish;
HDC hdc;
HDC hdcBuf;
HBITMAP hbmpBuf;
Graphics* gfxBuf;
Run Code Online (Sandbox Code Playgroud)

WM_创建:

hdc = GetDC(hwnd);
hdcBuf = CreateCompatibleDC(hdc);
hbmpBuf = CreateCompatibleBitmap(hdcBuf, 640, 480);
SelectObject(hdcBuf, hbmpBuf);
gfxBuf = Graphics::FromHDC(hdcBuf); 
fish = LoadBitmapRes(gfxBuf, MAKEINTRESOURCE(FISH2), "SPRITE");
Run Code Online (Sandbox Code Playgroud)

WM_PAINT:

HDC temp = BeginPaint(hwnd, &ps);
gfxBuf->DrawCachedBitmap(fish, x, y);
BitBlt(temp, 0, 0, 640, 480, hdcBuf, 0, 0, SRCCOPY);
EndPaint(hwnd, &ps);
Run Code Online (Sandbox Code Playgroud)

c++ windows winapi doublebuffered

4
推荐指数
1
解决办法
1215
查看次数