Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
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   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / OpenGL Development / Loading and rendering bitmaps on: 2006-09-26 10:21:18
Hi guys im new to java and opengl and im in the middle of a making a system to load and render bitmaps mainly for fonts. I got all the loading stuff working (at least i think it is) but i cant render the bitmap to my screen.

heres the code i use to load the bitmap


bytebuffer = ByteBuffer.allocateDirect(256);
FileInputStream in = null;
      
int c;
int i = 0;

try{
//create the file input stream
in = new FileInputStream("fonts.bmp");
//read the file and put it into the byte buffer
while((c = in.read()) != -1){
bytebuffer.put((byte)c);
i++;
}
//catch any errors   
} catch(Exception  e){
System.out.println(e);
e.printStackTrace();
}

//make sure stream is closed.       
if (in != null) {
try{
           
in.close();
}catch(IOException e){
System.out.println("Close error");
}
}

The above code reads from a file called fonts.bmp, its a bitmap image of a word (made in MS paint, monochrome).
Im just practising how to load bitmaps.
Any way i have this in my render loop

GL11.glRasterPos2i (20, 20);
GL11.glColor3f (1.0f, 1.0f, 1.0f);
GL11.glBitmap (32, 8, 0.0f, 0.0f, 11.0f, 0.0f, bytebuffer);

and this in my init method
GL11.glPixelStorei (GL11.GL_UNPACK_ALIGNMENT, 1);

I get no fonts on the screen, while evrything else renders fine.

2  Java Game APIs & Engines / Java 2D / Re: Fliping image horizontally on: 2006-01-10 13:17:33
I cant i get an error message.
G:\JFiles\WorkingTitle\Sprite.java:55: cannot find symbol
symbol  : method drawImage(java.awt.Image,java.awt.geom.AffineTransform,<nulltype>)
location: class java.awt.Graphics
                g.drawImage(image,AffineTransform.getScaleInstance(1,-1),null);
                 ^


This is in the Sprite class.
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  
public class Sprite {
   /** The image to be drawn for this sprite */
   private Image image;
   
   /**
    * Create a new sprite based on an image
    *
    * @param image The image that is this sprite
    */

   public Sprite(Image image) {
     
      this.image = image;
   }
   
   /**
    * Get the width of the drawn sprite
    *
    * @return The width in pixels of this sprite
    */

   public int getWidth() {
      return image.getWidth(null);
   }

   /**
    * Get the height of the drawn sprite
    *
    * @return The height in pixels of this sprite
    */

   public int getHeight() {
      return image.getHeight(null);
   }
   
   /**
    * Draw the sprite onto the graphics context provided
    *
    * @param g The graphics context on which to draw the sprite
    * @param x The x location at which to draw the sprite
    * @param y The y location at which to draw the sprite
    */

   public void draw(Graphics g,int x,int y) {
     
      g.drawImage(image,x,y,image.getWidth(null),image.getHeight(null),null);
         
   }
}

This, the Sprite storage
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  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;

import javax.imageio.ImageIO;

/**
 * A resource manager for sprites in the game. Its often quite important
 * how and where you get your game resources from. In most cases
 * it makes sense to have a central resource loader that goes away, gets
 * your resources and caches them for future use.
 * <p>
 * [singleton]
 * <p>
 * @author Kevin Glass
 */

public class SpriteStore {
   /** The single instance of this class */
   private static SpriteStore single = new SpriteStore();
   
   /**
    * Get the single instance of this class
    *
    * @return The single instance of this class
    */

   public static SpriteStore get() {
      return single;
   }
   
   /** The cached sprite map, from reference to sprite instance */
   private HashMap sprites = new HashMap();
   
   /**
    * Retrieve a sprite from the store
    *
    * @param ref The reference to the image to use for the sprite
    * @return A sprite instance containing an accelerate image of the request reference
    */

   public Sprite getSprite(String ref) {
      // if we've already got the sprite in the cache

      // then just return the existing version

      if (sprites.get(ref) != null) {
         return (Sprite) sprites.get(ref);
      }
     
      // otherwise, go away and grab the sprite from the resource

      // loader

      BufferedImage sourceImage = null;
     
      try {
         // The ClassLoader.getResource() ensures we get the sprite

         // from the appropriate place, this helps with deploying the game

         // with things like webstart. You could equally do a file look

         // up here.

         URL url = this.getClass().getClassLoader().getResource(ref);
         
         if (url == null) {
            fail("Can't find ref: "+ref);
         }
         
         // use ImageIO to read the image in

         sourceImage = ImageIO.read(url);
      } catch (IOException e) {
         fail("Failed to load: "+ref);
      }
     
      // create an accelerated image of the right size to store our sprite in

      GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
      Image image = gc.createCompatibleImage(sourceImage.getWidth(),sourceImage.getHeight(),Transparency.BITMASK);
     
      // draw our source image into the accelerated image

      image.getGraphics().drawImage(sourceImage,0,0, sourceImage.getWidth(),sourceImage.getHeight(),null);
     
      // create a sprite, add it the cache then return it

      Sprite sprite = new Sprite(image);
      sprites.put(ref,sprite);
     
      return sprite;
   }
   
   /**
    * Utility method to handle resource loading failure
    *
    * @param message The message to display on failure
    */

   private void fail(String message) {
      // we'n't available
     // we dump the message and exit the game

      System.err.println(message);
      System.exit(0);
   }
}
3  Game Development / Newbie & Debugging Questions / Flipping image Horizontally problem on: 2006-01-10 08:32:21
Hi guys, i need help, im a java newbi and i have been trying this for days now and with out any luck.
I need to flip an image horizontally about its x axis. I tried to negative the width (-image.getWidth())
but i get really wierd results, the colour gets all messed up.

Im using  Accelerated Java 2D, based on this tutorial found here.
http://www.cokeandcode.com/node/6

I just need to figure out to flip images that are Accelerated. See the tutorial for more info.
thx for your help guys, i really appreciate it.
4  Java Game APIs & Engines / Java 2D / Re: Fliping image horizontally on: 2006-01-10 06:42:14
So theres nothing i can do about this? I am using a nividia driver. I really need help with this.
5  Java Game APIs & Engines / Java 2D / Re: Fliping image horizontally on: 2006-01-09 12:57:07
Nope, tried that already, the colour gets all messed up again.
6  Java Game APIs & Engines / Java 2D / Fliping image horizontally on: 2006-01-09 12:24:01
Hi guys, i need help, im a java newbi and i have been trying this for days now and with out any luck.
I need to flip an image horizontally about its x axis. I tried to negative the width (-image.getWidth())
but i get really wierd results, the colour gets all messed up.

Im using  Accelerated Java 2D, based on this tutorial found here.
http://www.cokeandcode.com/node/6

I just need to figure out to flip images that are Accelerated. See the tutorial for more info.
thx for your help guys, i really appreciate it.
Pages: [1]
 

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 (18 views)
2014-07-30 21:08:39

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

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

Dwinin (13 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 (44 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 18:29:50

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

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