Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (773)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
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  
  Problems with BufferStrategy  (Read 3114 times)
0 Members and 1 Guest are viewing this topic.
Offline PRE

Junior Newbie




Xuaaa


« Posted 2003-04-20 09:10:08 »

I am having problems with the bufferstrategy, and I do not know why. The code compiles and works, mas the performence it's much wort than if i do not user buferstrategy. I am gonna pass part of the code, in hope somo of you guys find a mistake. Tankz.

Here I try to get a good GC

1  
2  
3  
4  
5  
6  
7  
8  
/******* init code *****/
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();

Arena a = new Arena(gc);

(...)


Arena is a Component that draws all my map and actors. It extends canvas and it's in the paint method that she paint's all the stuff. In Arena ctor, I call super(gc);
On the other hand I have a thread that sleeps for a while and then calls repaint(from Agenda).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
/***************** where i use buffering ******/
public void paint( Graphics g )
{
      if(firstTime) {
            createBufferStrategy(2);
            bufferStrategy = getBufferStrategy();
      firstTime=false;
      }

      Graphics graphics = bufferStrategy.getDrawGraphics();

      if( bufferStrategy.contentsLost() )
      return;
      try {
            for( int i = 0; i < vTiles; ++i ) {
                  for( int j = 0; j < hTiles; ++j ) {
                        if( g.getClipBounds().intersects(terrain[i][j].getRectangle()) ) {
                              terrain[i][j].paint(graphics);
                        }
                  }
            }
            m.paint(graphics);
      } finally {
            graphics.dispose();
      }

      bufferStrategy.show();
}


What am I doind wrong? Thankz for any help guys.

[]

:: {PRE}'s Programming Depot  ::
.: "There are 10 types of people in this world. Those who know binary and those who don't."
.: HopeInMankind.cpp :3382: Confused by earlier errors, bailing out.
Offline Abuse

JGO Ninja


Medals: 70


falling into the abyss of reality


« Reply #1 - Posted 2003-04-20 09:18:50 »

Its not how your rendering, its what your rendering that might cause BufferStrategy to be slower than regular back buffering.

What is occuring inside this method?

1  
terrain[i][j].paint(graphics);
Offline PRE

Junior Newbie




Xuaaa


« Reply #2 - Posted 2003-04-20 09:36:57 »

I simply paint an Image:

1  
2  
3  
4  
5  
6  
public void paint( Graphics g )
      {
            if( img == null )
                  throw new RuntimeException("Calling Paint and image not Created!!!");
            g.drawImage(img,tile.x,tile.y,TILE_SIZE,TILE_SIZE,null);
      }


And image is loaded like this:

1  
2  
3  
4  
5  
6  
7  
8  
      public static Image getImage( String fileName )
      {
            File file = new File(fileName);
            if( !file.exists() ) {
                  reportFatalError("Image not found: /" + file.getAbsolutePath() );
            }
            return toolkit.createImage(fileName);
      }


EDIT: Oh, and the images are 45x45 png's.

:: {PRE}'s Programming Depot  ::
.: "There are 10 types of people in this world. Those who know binary and those who don't."
.: HopeInMankind.cpp :3382: Confused by earlier errors, bailing out.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Abuse

JGO Ninja


Medals: 70


falling into the abyss of reality


« Reply #3 - Posted 2003-04-20 11:15:52 »

do they have an alpha channel?

if they do, then that is why it is slower drawing them using BufferStrategy.

at the moment, AlphaCompositing is not hardware accelerated, so any drawing operation that uses AlphaCompositing will be slower when done on an image stored in vram. (such as the buffers used in BufferStrategy)

The reason for this, is because java has to read back the image from vram into main memory, perform the alphacomposite, and copy it back to vram.
Offline PRE

Junior Newbie




Xuaaa


« Reply #4 - Posted 2003-04-20 11:53:25 »

Humz... they are very simply images, I do not even know if they have an alpha chanel (how can I know that?). I tried with jpg format and it&#347; the same.

Whats your advice? I tried to save again the images (using gimp), and there were no option about alpha chanel.

:: {PRE}'s Programming Depot  ::
.: "There are 10 types of people in this world. Those who know binary and those who don't."
.: HopeInMankind.cpp :3382: Confused by earlier errors, bailing out.
Offline Jeff

JGO Coder




Got any cats?


« Reply #5 - Posted 2003-04-21 17:21:42 »

What is the platform?

Sun's JDK for Linux currently runs ontop of X, which means Page Flipping is impossible.  Instead its simulated and is likely to be slow.

JK

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline PRE

Junior Newbie




Xuaaa


« Reply #6 - Posted 2003-04-21 19:48:30 »

yep... it&#347; on linux,

So, how do I do this so that it works ok on linux and win?

:: {PRE}'s Programming Depot  ::
.: "There are 10 types of people in this world. Those who know binary and those who don't."
.: HopeInMankind.cpp :3382: Confused by earlier errors, bailing out.
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1850 views)
2018-06-10 19:43:48

EgonOlsen (1879 views)
2018-06-10 19:43:44

EgonOlsen (1245 views)
2018-06-10 19:43:20

DesertCoockie (1680 views)
2018-05-13 18:23:11

nelsongames (1345 views)
2018-04-24 18:15:36

nelsongames (1963 views)
2018-04-24 18:14:32

ivj94 (2736 views)
2018-03-24 14:47:39

ivj94 (1939 views)
2018-03-24 14:46:31

ivj94 (3029 views)
2018-03-24 14:43:53

Solater (1078 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!