Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (855)
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  
  Bitmap Fonts under 1.5 and 1.1  (Read 2550 times)
0 Members and 1 Guest are viewing this topic.
Offline MGodehardt

Junior Devvie




why does the chicken cross the road?


« Posted 2004-08-04 08:49:05 »

I am using Bitmap Fonts in my Applet, is it bad to use a Image for every character Huh

how about the hueing, at the moment i use a RGBFilter to do the hueing, but for every paint, a new image is created and then flushed ( not nice ).

The Applet should be compatbile with java 1.1

I have my own image loader and i load my images from a special compressed format, so maybe its better to have only one image with all chars in it ?

load char after char and put it into one big image in the applet, hue the big image if color of text is different, so only 1 image is created flushed for each paint cycle Huh

what about performance Huh?

i noticed M$ VM 1.1 is buggy and does not flush images correctly, i am running out of memory in my applet and i am running also out of images.

Offline dranonymous

Junior Devvie




Hoping to become a Java Titan someday!


« Reply #1 - Posted 2004-08-04 12:05:07 »

Stop using that nasty 1.1 VM!   Tongue

If you're going to use 1.5 then don't try for any backward compatibility with 1.1.

My understanding is that using an image per character is the 'normal' way of doing things.  Its less intensive to blit an image than to calculate the glyph.
Offline MGodehardt

Junior Devvie




why does the chicken cross the road?


« Reply #2 - Posted 2004-08-05 08:37:41 »

ok sometimes i am paranoid, but it seems i am coding it the normal way.


Unfortunaly I HAVE TO stay 1.1 compatible, dont ask ...

20 years ago i coded bitmap fonts like i described above, so i was not thinking about the way i did it.

Question: Whats the best way for hueing a bitmap font, like i described or how to do it best under 1.4 and above Huh?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pepe

Junior Devvie




Nothing unreal exists


« Reply #3 - Posted 2004-08-05 09:09:00 »

turn your chars into palletized BufferedImages and just change the palette before painting.
Never tested, but that should do the trick.

Home page: http://frederic.barachant.com
------------------------------------------------------
GoSub: java2D gamechmark http://frederic.barachant.com/GoSub/GoSub.jnlp
Offline MGodehardt

Junior Devvie




why does the chicken cross the road?


« Reply #4 - Posted 2004-08-05 11:59:45 »

interesting --- never tried to create ( or dont know how to ) create a BufferedImage with a 8bit primitive , so my chars live in a DIB , lol

i am bound to 1.1 and upwards *coughs*, with 1.4 my bitmap drawing and colring is fast like hell, under 1.1 its normal speed, but it eats my image mem ( M$ was too lazy ) and after some time i am running out of memory ( depends on the size of user mem )

even a dispose DOES not help ( nah i am not deaf called this function ) the Image ( the native resources are held in mem )


time is running out for 1.1  only 60 days to go ....
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #5 - Posted 2004-08-05 14:25:19 »

BufferedImages didn't exist for 1.1. You could muck around with the ColorModels for the regular images, but that would be something of a PITA. A much better idea might be to create your own ImageProducer. e.g.:
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  
import java.awt.*;
import java.awt.image.*;

public class GlyphBlitter implements ImageProducer
{  
  private ColorModel model = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0);
  private ImageConsumer consumer;
  private Image image;
   
  private int width;
  private int height;
  private int[][] pixels;
   
  public GlyphBlitter(int width, int height)
  {
    this.width = width;
    this.height = height;

    //Creates space for the lower 128 characters of
    //the ASCII set.
    this.pixels = new int[128][width*height*4];
    this.image = Toolkit.getDefaultToolkit().createImage(this);
  }

  //Make sure you only pass a character between 0
  //and 127!!!
  public void setGlyph(char c, int[] pixels)
  {
    this.pixels[(int)c] = pixels;
  }
   
  //Make sure you only pass a character between 0
  //and 127!!!
  public void render(Graphics g, char c)
  {
    if(consumer != null)
    {
      consumer.setPixels(0, 0, width, height, model, pixels[(int)c], 0, width);
      consumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
    }
       
    g.drawImage(image, 0, 0, width, height, null);
  }
   
  public void addConsumer(ImageConsumer consumer)
  {
    this.consumer = consumer;
       
    consumer.setDimensions(width, height);
    consumer.setHints(ImageConsumer.TOPDOWNLEFTRIGHT |
    ImageConsumer.COMPLETESCANLINES |
    ImageConsumer.SINGLEPASS |
    ImageConsumer.SINGLEFRAME);

    consumer.setColorModel(model);
  }
   
  public boolean isConsumer(ImageConsumer imageConsumer)
  {
    //We'll take anyone
    return true;
  }
   
  public void removeConsumer(ImageConsumer imageConsumer)
  {
    //nothing to do
  }
   
  public void requestTopDownLeftRightResend(ImageConsumer imageConsumer)
  {
    //ignore
  }
   
  public void startProduction(ImageConsumer imageConsumer)
  {
    addConsumer(imageConsumer);
  }
   
  //Recolors the character
  public void setColor(char c, int color)
  {
    for(int i=0; i<pixels.length; i++)
    {
      if(pixels[(int)c][i]  != 0x00000000)
      {
        pixels[(int)c][i] = color;
      }
    }
  }  
}

I haven't actually tried compiling the above, but something like it should do the trick. All you need to do is create the object with the width and height of the characters (I'm assuming that you're using fixed width), then loop through and set the pixels for each character you need to display. Once you have it loaded, you can render the character by calling "render(Graphics g, char c)" with the character you want to draw. To recolor the character, call "setColor(int color)".

The only thing I've left up to you, is breaking up your images into individual pixel arrays for each character. I might even suggest packing the pixels directly into a file instead of breaking them up when your applet starts. A good example of pixel packing can be found in my Defender game (see: http://java.dnsalias.com/4k). Download the source code, and look in "src/tools/ImagePacker.java". That program takes a set of graphic files and packs them into a 1 bit per pixel format. A viewer is also included for debugging.

If you have any questions, feel free to ask!

Java Game Console Project
Last Journal Entry: 12/17/04
Offline MGodehardt

Junior Devvie




why does the chicken cross the road?


« Reply #6 - Posted 2004-08-06 09:09:16 »

thanks jbanes, i have already a well working pixel packer, and i am using a RGBFilter ( its the same method u use producer --> consumer model )

you only have to add a few lines ( very important for applets, create small classes ).

but it seems, there is at the moment no faster way to use bitmap fonts under 1.1 and 1.4 , so i guess i am doing everything alright ( applet is running smooth ), but i always think about improving and reducing the applet, that was the reason for me to start the thread.

I know nobody will post complete code or secrets ( i will never do because i am bound to nda ), but looking or discusiing about problems is, i think, ok and will not interfere with other problems ( like your boss )

P.S.: i do not recolor my fonts i hue 'em :-)
Pages: [1]
  ignore  |  Print  
 
 

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

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

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

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

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

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

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

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

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

Solater (909 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!