Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
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  
  Using video ram to store images?  (Read 2547 times)
0 Members and 1 Guest are viewing this topic.
Offline Harley Rana

Junior Member




Java games rock!


« Posted 2002-11-17 01:15:43 »

Hi i know video ram is the best place to store images, bliting from video ram into the current buffer should be heaps quicker.

The question is how do you load the image into the video ram?

Is it being done automaticlly?

What is the best design to load and blit images?

Thanks heaps for any help!
Harley.
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #1 - Posted 2002-11-17 09:00:33 »

First off you'll have to be using 1.4, otherwise you won't be able to take advantage. Secondly have a look for VolatileImage, which is stored only in vRam and which you need to do management of image loss manually. However there are a couple of snafus that may trip you up with volative images, namely i dont think you can do any sort of transparency  Shocked

There's also 'AutomaticImages' which are regular BufferedImages which the VM will attempt to cache in vRam, and handle management itself. With the correct massaging you can also get these to have 1-bit transparency and still be hardware accelerated.

A code snippit from my (now on permanent hold,  Embarrassed ) Phoenix project:
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  
      /** Loads image, creates automatic image/buffered image and copies it into it.
        * Currently only tested with gifs, so undefined if any other file path is passed to it.
        */

      public BufferedImage loadImage(String filename, boolean solid)
      {
            // Load image from file.
           Image tempImage = new ImageIcon(filename).getImage();
           
            BufferedImage sprite = null;
           
            // Get dimensions of image
           int spriteW = tempImage.getWidth(null);
            int spriteH = tempImage.getHeight(null);
           
            if (spriteW != -1)
            {
                  // If a solid tile, load as such. Otherwise use bitmask transparency
                 if (solid)
                              sprite = graphicsConfig.createCompatibleImage(spriteW, spriteH, Transparency.OPAQUE);
                  else
                              sprite = graphicsConfig.createCompatibleImage(spriteW, spriteH, Transparency.BITMASK);
                 
                 
                  // Copy from Image to BufferedImage
                 Graphics2D g = (Graphics2D)sprite.getGraphics();
                 
                  g.drawImage(tempImage, null, null);
                  g.dispose();
            }
            else
            {
                  System.out.println("Error loading images: " + filename + " not found");
            }
           
            return sprite;
      }


Jeff et al, if you're reading this - how long until we see a full site with the articles section up again?

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Harley Rana

Junior Member




Java games rock!


« Reply #2 - Posted 2002-11-19 06:46:27 »

So the key method is createCompatibleImage, which is used to create AutomaticImages.

Is there much difference between normal awt.Images, loaded from ImageIO, to automatic images?
Assuming the sprites are tranparent.

Thanks.
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 2002-11-20 02:34:36 »

Currently none of the images loaded with ImageIO are accelerated, as opposed to those loaded with Toolkit.getImage() , for example.
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #4 - Posted 2002-11-20 02:41:53 »

Also, note that in order to take advantage of those images being accelerated, you need to copy them to the accelerated back-buffer. You should use VolatileImage for the back-buffer.
Check out the articles on
http://java.sun.com/products/java-media/2D/
for more info.
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #5 - Posted 2002-11-20 04:18:25 »

I hope that the Toolkit.getImage methods will soon be replaced under the hood with the ImageIO stuff anyway.. it will get rid of some redundant code...   If so, I assume that ImageIo based images will be accelerated.. maybe for 1.5?

Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #6 - Posted 2002-11-21 04:37:21 »

Yep, that's the plan.
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.

CogWheelz (16 views)
2014-07-30 21:08:39

Riven (22 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43
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!