Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  double buffers  (Read 1544 times)
0 Members and 1 Guest are viewing this topic.
Offline jayhg99

Senior Newbie




Java games rock!


« Posted 2003-01-29 13:19:39 »

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
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #1 - Posted 2003-01-29 15:46:31 »

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 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,

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline jayhg99

Senior Newbie




Java games rock!


« Reply #2 - Posted 2003-01-29 17:49:42 »

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.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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #3 - Posted 2003-02-04 04:21:12 »

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.
Offline jayhg99

Senior Newbie




Java games rock!


« Reply #4 - Posted 2003-02-04 18:03:45 »

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
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (20 views)
2014-08-19 09:29:53

Tekkerue (21 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (55 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (27 views)
2014-08-08 02:01:56

Norakomi (35 views)
2014-08-06 19:49:38

BurntPizza (64 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!