blitting text and images

Started by raft, March 18, 2008, 10:34:21 PM

Previous topic - Next topic

raft

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

EgonOlsen

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

raft


fireside

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

raft

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:
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:
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);
}




Melssj5

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

raft

yeap, creating font textures on the fly is handy. i just barrowed the idea and some piece of code from fenggui ;)

fireside

I copied texture pack and put it into a class, but i got an error on this line:

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

raft

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

fireside

click here->Fireside 7 Games<-

entis

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

JavaMan

As far as I know, the sw doesn't do multitexturing.

raft

Quote from: entis 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...
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

entis

Quote from: raft on April 01, 2008, 02:13:50 PM
Quote from: entis 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...
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 :)

Melssj5

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