Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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  
  Help! Why so low FPS when i try to draw images  (Read 1041 times)
0 Members and 1 Guest are viewing this topic.
Offline Kebo

Junior Newbie




Java games rock!


« Posted 2006-01-21 05:19:05 »

Can anyone here explain why i only get 30FPS when i try to draw my map. The problem is this line:

1  
g.drawImage(image[ (map[y][x][0]) ], (x * 32), (y * 32), null);


If i remove it everything runs fine in around 60FPS wich is what i want. Tile.gif is just a normal 16x16 gif file

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  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
import java.awt.*;
import javax.swing.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;

public class T extends JFrame{
   
   BufferedImage[] image = new BufferedImage[1];
   int[][][] map = new int[100][100][1];
   
   T(boolean full) throws Exception{
      super("Game");
     
      BufferedImage bi = ImageIO.read(new File(System.getProperty("java.class.path") + "/tile.gif"));
      image[0] = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
      image[0].getGraphics().drawImage(
            bi.getSubimage(0, 0, 16, 16), 0, 0, 32, 32, null);
     
      setUndecorated(full);
      setIgnoreRepaint(true);
     
      if(full){
         GraphicsDevice device = getGraphicsConfiguration().getDevice();
         device.setFullScreenWindow(this);
         device.setDisplayMode(new DisplayMode(640, 480, 16, 0));
      }
      else{
         setSize(640, 480);
         show();
      }
     
     
      createBufferStrategy(2);
      BufferStrategy strategy = getBufferStrategy();
     
      int[] colors = {0x00ffff, 0x000000};
     
      int fps = 0;
      long time = System.currentTimeMillis();
      long runTime = System.currentTimeMillis();
      long lastFps = 0;
      int drFps = 0;
      Graphics2D g;
     
      while(System.currentTimeMillis() - runTime < 10000){
         
         long delta = System.currentTimeMillis() - time;
         time = System.currentTimeMillis();
         lastFps += delta;
         fps++;
         
         if(lastFps >= 1000){
            drFps = fps;
            fps = 0;
            lastFps = 0;
         }
         
         g = (Graphics2D)strategy.getDrawGraphics();
         g.setColor(new Color(0x0000ff));
         g.fillRect(0, 0, 640, 480);
         
         int startx  = 0;
         int maxx = startx + (640 / 32) + 1;
         
         int starty = 0;
         int maxy = starty + (480 / 32) + 1;
         
         for(int y = 0; y < maxy; y++){
            for(int x = startx; x < maxx; x++){
               g.drawImage(image[ (map[y][x][0]) ], (x * 32), (y * 32), null);
            }
         }
         g.setColor(new Color(0xffffff));
         g.drawString("FPS: " + drFps, 2, 40);
         g.dispose();
         strategy.show();
         Thread.yield();
      }

      System.exit(0);
     
   }
   
   public static void main(String[] args) throws Exception{
      new T(true);
   }

}
Offline SluX

Junior Duke





« Reply #1 - Posted 2006-01-21 12:16:42 »

I guess that problem is that u don't make your Buffered image using GraphicsConfiguration's createCompatible image method.
So when java copies your images to graphics it first must make conversion into current config.

But if u are using java 1.5 , almost all images should be menaged......

"Intelligence is the most beautiful gift and the greatest temptation which one life can receive from the gods."Me Cheesy
Play strategic football
Offline Jeff

JGO Coder




Got any cats?


« Reply #2 - Posted 2006-01-22 18:55:42 »

Id ask this over in the 2D topic, but ask yourself this question: Is there anything very different about this image comapred to the others you draw? In particualr, does it have transparency or is it otherwise ina different pixel format?

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

Junior Newbie




Java games rock!


« Reply #3 - Posted 2006-01-22 19:53:58 »

Thank you. The problem had to do with transparency. When i changed to , BufferedImage.TYPE_INT_RGB (instead of ARGB) it runs much smoother. Is it supposed to work like that??


Offline Jeff

JGO Coder




Got any cats?


« Reply #4 - Posted 2006-01-22 21:56:21 »

There are limits on how Transparency can be acceleerated on Windows.  This is due to inherent limits in DirectDraw on which Java2D up to now has been based.

There is work going on to move to a 3D base for the code udnelying Java2D much as WIndows itself is moving to 3D with vista.  As that work progresses soem of these limist will vanish.

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

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (66 views)
2014-10-14 00:35:47

TehJavaDev (59 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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