Author Topic: blitting text and images  (Read 53750 times)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
blitting text and images
« on: March 18, 2008, 10:34:21 pm »
here is two small and (hopefully) handy classes for blitting text and images. i'm posting them hoping they may be helpful

TexturePack packs several arbitrary sized images into a jPCT texture. it automatically layouts images and adjusts Texture size.

GLFont creates GL renderable (blittable) fonts out of awt Fonts.

in the below image, the bubble images are blitted with TexturePack and text is blitted with GLFont :)


note: these two classes use new FrameBuffer.blit(..) method in the upcoming 1.16 release

cheers,
r a f t

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: blitting text and images
« Reply #1 on: March 18, 2008, 11:19:13 pm »
Both classes are very useful IMHO. I like the TexturePack-thingy most, because it can help to reduce texture memory usage on lower end cards (well, it also helps on better cards, but it may not matter on those).
If i could only find the time to do that bloody game that i have in my mind and put those classes (as well as Paul's SoundManager) to use... :-\

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: blitting text and images
« Reply #2 on: March 18, 2008, 11:24:28 pm »
serve youself ;D

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: blitting text and images
« Reply #3 on: March 19, 2008, 04:01:57 am »
Is texture pack needed for GLFont?  Don't suppose you have a little demo or something to look at?  I'm still kind of learning all this.
click here->Fireside 7 Games<-

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: blitting text and images
« Reply #4 on: March 19, 2008, 04:04:21 pm »
yes, GLFont uses TexturePack behind the scenes. it creates an image for each chracter and packs all these images into a texture with TexturePack

there is nothing special using it. just create a GLFont somewhere in time:
Code: [Select]
GLFont glFont = GLFont.getGLFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
and at the end of your game loop, after FrameBuffer.update() before FrameBuffer.display() draw any string with it:
Code: [Select]
while (running) {
   // your game logic and rendering here
   buffer.update();
   glFont.blitString(frameBuffer, "this is a blitted text", x, y, Color.ORANGE);   
   buffer.display(null);
}



Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: blitting text and images
« Reply #5 on: March 19, 2008, 06:14:03 pm »
I made a text blitter method for strings too but I guess I will better try this classes. Actually my text blitting method is working fine but my image editor is paint so the quality is too bad.
Nada por ahora

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: blitting text and images
« Reply #6 on: March 19, 2008, 06:27:29 pm »
yeap, creating font textures on the fly is handy. i just barrowed the idea and some piece of code from fenggui ;)

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: blitting text and images
« Reply #7 on: March 20, 2008, 02:30:40 am »
I copied texture pack and put it into a class, but i got an error on this line:

Code: [Select]
buffer.blit(texture, entry.bounds.x, entry.bounds.y, destX, destY, entry.bounds.width, entry.bounds.height,
destWidth, destHeight, transparency, additive, color);


error:

The method blit(int[], int, int, int, int, int, int, int, int, boolean) in the type FrameBuffer is not applicable for the arguments (Texture, int, int, int, int, int, int, int, int, int, boolean, Color)   
click here->Fireside 7 Games<-

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: blitting text and images
« Reply #8 on: March 20, 2008, 02:39:04 am »
as written in first message: these two classes use new FrameBuffer.blit(..) method in the upcoming 1.16 release ;)

download the 116r3, from http://www.jpct.net/download/beta/jpctapi116rc3.zip

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: blitting text and images
« Reply #9 on: March 20, 2008, 04:03:09 am »
Very Nice.  Thanks.
click here->Fireside 7 Games<-

Offline entis

  • byte
  • *
  • Posts: 32
    • View Profile
Re: blitting text and images
« Reply #10 on: April 01, 2008, 01:25:45 pm »
Is it possible to use these classes with sw renderer? As I understood here multitexturing is used... and I don't know whether jpct allows to use multitexturing with sw renderer...

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: blitting text and images
« Reply #11 on: April 01, 2008, 02:01:17 pm »
As far as I know, the sw doesn't do multitexturing.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: blitting text and images
« Reply #12 on: April 01, 2008, 02:13:50 pm »
Is it possible to use these classes with sw renderer? As I understood here multitexturing is used... and I don't know whether jpct allows to use multitexturing with sw renderer...
there is no multitexturing here, so you can use these classes for sw renderer. albeit i would stick to java2d for sw renderer, which performs better and looks nicer

Offline entis

  • byte
  • *
  • Posts: 32
    • View Profile
Re: blitting text and images
« Reply #13 on: April 01, 2008, 04:32:56 pm »
Is it possible to use these classes with sw renderer? As I understood here multitexturing is used... and I don't know whether jpct allows to use multitexturing with sw renderer...
there is no multitexturing here, so you can use these classes for sw renderer. albeit i would stick to java2d for sw renderer, which performs better and looks nicer

thanks, then I 'll try :)

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: blitting text and images
« Reply #14 on: April 14, 2008, 03:00:37 pm »
OK I have added it to my project, but how can I check the lenght of the string to be placed in the screen in just one line.

I noticed there is a method to get the String boundaries, but I want to get the index inside the string to fit a certain width. How can I do this? I have been thinking on recursively cheking the middle of the String until getting an aproximation to the required width, but this may need to check many string boundaries width for each text blitted.
Nada por ahora