Hello all, I’m new to the forum, so hello!
I’m relatively new to java gaming programming, especially when it comes to graphics stuff, so apologies if this is a noobish question.
Right now I have a simple program in Full Screen Exclusive Mode that draws a moving rectangle bouncing back and forth horizontally on the screen, but I’m getting extremely bad vertical tear along the left and right sides of the rectangle. I read in multiple places that using a bufferstrategy would automatically handle this problem as long as the capabilities reported flipping as true.When I report the buffer capabilities, it tells me flipping is true, and setting the strategy to PRIOR during creation doesn’t give me any errors or anything, but tearing continues. I have posted code where I create the bufferstrategy, and then my drawing method , which is called from a simple game loop that updates the game state then draws the screen. Can you think of what might be causing this tearing issue? ???
EDIT: forgot to add that the main class is extended from Frame (awt). I also tried with JFrame, same problem.
I’m on a brand new gaming hackintosh (on mountain lion), so I’m thinking it may be a problem with my graphics drivers or something? I have a NVidea GTX680 so I can definitely support flipping… Maybe I’ll run my program on my old iMac and see if the same problem persists while I await replies.
Thanks so much in advance for your help,
Adam
Here is my bufferstrategy creation
//get graphics device
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
//set parameters for fullscreen window
this.setUndecorated(true);
this.setIgnoreRepaint(true);
this.setVisible(true);
this.setBackground(Color.gray);
// set the frame to full screen exclusive mode
gd.setFullScreenWindow(this);
// set up the buffer Strategy
this.createBufferStrategy(2);
bs = this.getBufferStrategy();
And here is my flipping part: I call drawScreen() in a while(true) loop for now. I had some FPS limiting code in but took it out to solve this issue.
public void drawScreen()
{
do {// keep repeating rendering if the drawing buffer was lost
do { //ensures that the contents of the drawing buffer are consistent in case the underlying surface was recreated
// get graphics object to draw on
Graphics2D g = (Graphics2D) bs.getDrawGraphics();
//render screen: Here I just and draw the background of the frame and the moving rectangle to g,
renderScreen(g);
//dispose the graphics
g.dispose();
} while (bs.contentsRestored()); //repeat rendering if the drawing buffer contents restored
//flip buffer
bs.show();
//sync display, fixes something on Unix
Toolkit.getDefaultToolkit().sync();
} while(bs.contentsLost()); // repeat rendering if the buffer contents were lost
}