double buffers

I have an application which uses double buffers to paint the screen constantly in window mode. When I place the mouse cursor on the screen, I can see that the mouse cursor is shaking as the screen gets painted, which is understandable since the screen gets refreshed constantly. I assume that I’m not using the page flipping feature since I’m in the window mode not full screen mode. The application uses menu bars and popup menus which prevent me from using full screen mode.

However, if I first execute the sample program MultiBufferTest.java at http://java.sun.com/docs/books/tutorial/extra/fullscreen/example.html and then run the application again , the mouse cursor on the screen does not shake any more as the screen gets repainted, which is what I want. I studied the MultiBufferTest.java which uses BufferStrategy, DisaplyMode and full screen mode. I just do not understand why program MultiBufferTest.java could have impact on my application. It has to have something to do with VRAM. How can I take some of features from MultiBufferTest.java and merge with my application so that I can get rid of the mouse cursor shaking when refreshing the screen and at same time still running in window mode ?

Jay

how are you doing the double buffering in your current app?

i think MultiBufferTest.java uses BufferStrategy (I havn’t actually looked at the source).
This does indeed create the backbuffer[s] in Vram, which may well avoid the ‘shaking’ cursor problem.

btw, when you say the mouse cursor is ‘shaking’, do you mean flickering?
I seem to remember older ATI gfx cards had this problem when doing windowed directdraw stuff.

abu,

Yes, you are correct that MultiBufferTest.java uses BufferStrategy in full screen mode and I really mean that mouse cursor flickering.

I do not use BufferStrategy in my current application. Here is the part of code that does the double buffering and drawing on the screen :

Image background=null;
Image background_img ;
Graphics2D background_g2;

// initial background buffer
public void initBackBuffer()
{
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getDefaultScreenDevice();

  GraphicsConfiguration gc = device.getDefaultConfiguration();

  background =  gc.createCompatibleImage(width, height,Transparency.TRANSLUCENT); 
  background_g2 = (Graphics2D) background.getGraphics(); 

  background_img=ImageToolkit.getImage("background.jpg",this); 
  background_g2.drawImage(background_img,0,0,this.width,this.height,this); 

}

public void paint(Graphics g)
{
updateScreen(g);
}

public synchronized void updateScreen(Graphics g)
{

        Graphics2D g2 = (Graphics2D)g; 

        // Call initBackBuffer for the first time 
        if (background == null) { 
              initBackBuffer(); 

        } 
        
        if(g != null) 
        {
              //paint the screen
              waitingForRepaint = false; 
              g2.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_SPEED); 
              // Draw the background buffer to the screen. 
              g2.drawImage(background, 0, 0, this); 

        } 
        else 
        {
              //copy the background image to the back buffer
              background_g2.drawImage(background_img,0,0,width,height,this); 
              //copy all the sprite objects to the back buffer
              for(int i=0; i< numObj; i++)
              {
                    sbObj[i].draw(background_g2);
              }
        }

}

I’m going to try to use BufferStrategy in window mode to see if I can get rid of mouse cursor flickering.

Jay

You will get mouse pointer flickering (most notably on older video boards which do not have hw support for fancy cursors, like the ones in Win2k/XP), because we actually hide the pointer before copying the bits to the screen, and then show it afterwards to avoid the cursor being overwritten by the image copy.

Unfortunately, with software cursors you will get flickering even with BufferStrategy, because of the way DirectX handles this: the cursor will be painted only on the primary surface (a documented DirectX feature), so it’ll be visible only every other frame in case of one backbuffer strategy.

The way to fix this is to render the cursor by yourself - that is, set a transparent image as a cursor, track mouse position and render whatever you want as mouse pointer. This is actually the way any native DirectX game does it.

Thanks guys . Yes, it must have something to do with the video card. I do not see any mouse flicking on my desktop. But the mouse cursor flicks on my laptop as the back buffer is refreshing the screen. The bufferstrategy does not help in this case. However, the mouse flicking issue goes away after I run the demo program MultiBufferTest.java. I commented out the codes that deal with the bufferstrategy and display mode but left along the part that sets full screen mode in MultiBufferTest.java. It is the setFullScreenWindow statement in MultiBufferTest.java somehow helps with mouse flicking issue. I do not understand why executing a setFullScreenWindow in one program could affect another. I tried to simulate the effect by entering full screen and exiting out the full screen at beginning of application, which needs to run in window mode. But it messes up the all screen drawings.

Jay