SPGL Shader/render State examples

Howdy

I’ve been picking through spgl with a view to appropriating the clever stuff that I haven’t the fortitude to reinvent, starting with the com.shavenpuppy.jglib.renderer stuff.
I suspect that if I mess up the implementation of the State object, I’ll bork the sorting and any performance benefit will disappear.

Does anyone have any concrete examples of State objects, and/or the Shaders that produce them, that I can peruse? Even trivial ones would be a great help.

Cheers

Yeah, I do believe I used it to render the backgrounds in Alien Flux. But it’s very simple stuff unfortunately.

The trick is to get your States sorted so that the most expensive state changes are called least often.

Cas :slight_smile:

Anything is good. Is the source available anywhere? I take it you don’t use it anymore? I suppose it’s just sprites all over the shop for your stuff nowadays…

Just as a sanity check of what I’m thinking:

from most expensive to least

  • Shader programs
  • texture id
  • server attributes
  • client attributes
  • any more?

Encode the expensive stuff into the top bits of the sort order, and the expensive changes should be minimised.

Are there any gotchas with the radix sort? Do I need to worry about the range of sort order values being too expansive?

Cheers

I’ll dig up some source when I get home. As for RadixSort, as far as I know there are no gotchas at all. Just make sure you give different integer IDs to each state as appropriate (texture ID for example makes a good sort index for it).

Cas :slight_smile:

Champion, I’ll see how that goes.

Next to fall under my avaricious eye: Font rendering…

My font rendering code is quite nice but really it needs to be ditched and incorporated in to the sprite engine so that glyphs are just sprites.

Cas :slight_smile:

Well that went well.

http://base.googlehosted.com/base_media?q=hand-5526589143872013816&size=1

Java output on the top, followed by mine, and then the packed texture.

Changes made:

  • Glyphs hold their own image data, rather than the Font
  • Floating-point layout
  • More dynamic - glyphs can be added as needed
  • Font generator substantially refactored
  • Uses the rectangle packer

I’ve flung it all up Google code if anyone wants a look.

So, in summary, huzzah for the spgl!

edit: Incidentally, does anyone have any recommendations for fonts that definitely have kerning values? I’ve scanned through the 103 fonts on this system and not found any kerning pairs, so I’m wondering if there aren’t any or if I’ve borked the kerning computation.

edit2: Nevermind, found the problem (which, incidentally, existed in SPGL too). Text rendering with kerning now works.

ooh what problem was that? (Not that I’ve ever had a problem ???)

Cas :slight_smile:

On line 474 of FontConverter you call drawGlyphVector() directly on the special graphics object, rather than using a TextLayout - which is apparently where the kerning information appears from. - and passing in the graphics object. The Javadocs refer to using a TextLayout, it just doesn’t happen in the code.

Also, Java doesn’t render with kerning by default, you need to derive the font with the appropriate TextAttribute map. Haven’t tested that one myself, but that’s what the docs say.

The code that works for me is linked above.

Hmmm, sounding like a bit of an ingrate here :-\ I’m not, honest!

Oh, interesting. I had been trying to figure out how to get kerning info, but it my experience KERNING_ON didn’t do anything (even with fonts that obviously have kerning in other apps).

What font are you using?

Running

	private static void kerningHunt()
	{
		String[] fonts =
				GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
		System.out.println( fonts.length + " Available font families : " );

		for( String fontname : fonts )
		{
			System.out.println( "Hunting for kerning in " + fontname );
			FontFactory ff = new FontFactory( fontname );

			boolean found = false;

			for( int i = 0; i < defaultCharSet.length() && !found; i++ )
			{
				for( int j = 0; j < defaultCharSet.length() && !found; j++ )
				{
					char prev = defaultCharSet.charAt( i );
					char next = defaultCharSet.charAt( j );
					float k = ff.computeKerning( prev, next );

					if( k != 0 )
					{
						found = true;
						System.out.println( "\tkerning found!" );
						// System.out.println( "\t" + prev + " -> " + next +
						// " = " + k );
					}
				}
			}
		}
	}

Gave me the output


106 Available font families : 
Hunting for kerning in AlArabiya
	kerning found!
Hunting for kerning in AlBattar
	kerning found!
Hunting for kerning in AlHor
	kerning found!
Hunting for kerning in AlManzomah
	kerning found!
Hunting for kerning in AlMateen-Bold
Hunting for kerning in AlMohanad
	kerning found!
Hunting for kerning in AlMothnna-Bold
Hunting for kerning in AlYermook
	kerning found!
Hunting for kerning in AnjaliOldLipi
Hunting for kerning in AR PL ShanHeiSun Uni
Hunting for kerning in AR PL ZenKai Uni
Hunting for kerning in Arab
	kerning found!
Hunting for kerning in Bitstream Charter
Hunting for kerning in Bitstream Vera Sans
	kerning found!
Hunting for kerning in Bitstream Vera Sans Mono
Hunting for kerning in Bitstream Vera Serif
	kerning found!
Hunting for kerning in Century Schoolbook L
Hunting for kerning in Cortoba
	kerning found!
Hunting for kerning in Courier 10 Pitch
Hunting for kerning in DejaVu Sans
	kerning found!
Hunting for kerning in DejaVu Sans Condensed
	kerning found!
Hunting for kerning in DejaVu Sans Light
	kerning found!
Hunting for kerning in DejaVu Sans Mono
Hunting for kerning in DejaVu Serif
	kerning found!
Hunting for kerning in DejaVu Serif Condensed
	kerning found!
Hunting for kerning in Dialog
Hunting for kerning in DialogInput
Hunting for kerning in Dimnah
	kerning found!
Hunting for kerning in Dingbats
Hunting for kerning in Electron
	kerning found!
Hunting for kerning in FreeMono
Hunting for kerning in FreeSans
	kerning found!
Hunting for kerning in FreeSerif
	kerning found!
Hunting for kerning in Furat
	kerning found!
Hunting for kerning in Garuda
Hunting for kerning in Gentium
	kerning found!
Hunting for kerning in GentiumAlt
	kerning found!
Hunting for kerning in Granada
	kerning found!
Hunting for kerning in Graph
	kerning found!
Hunting for kerning in Hani
	kerning found!
Hunting for kerning in Haramain
	kerning found!
Hunting for kerning in Hor
	kerning found!
Hunting for kerning in Japan
	kerning found!
Hunting for kerning in Jet
	kerning found!
Hunting for kerning in Kayrawan
	kerning found!
Hunting for kerning in Khalid
	kerning found!
Hunting for kerning in Kochi Gothic
Hunting for kerning in Kochi Mincho
Hunting for kerning in Lohit Gujarati
Hunting for kerning in Lohit Hindi
Hunting for kerning in Lohit Punjabi
Hunting for kerning in Lohit Tamil
Hunting for kerning in Loma
	kerning found!
Hunting for kerning in Lucida Bright
Hunting for kerning in Lucida Sans
Hunting for kerning in Lucida Sans Typewriter
Hunting for kerning in Luxi Mono
Hunting for kerning in Luxi Sans
	kerning found!
Hunting for kerning in Luxi Serif
	kerning found!
Hunting for kerning in Mallige
Hunting for kerning in MalOtf
Hunting for kerning in Mashq
	kerning found!
Hunting for kerning in Mashq-Bold
	kerning found!
Hunting for kerning in Metal
	kerning found!
Hunting for kerning in MgOpen Canonica
	kerning found!
Hunting for kerning in MgOpen Cosmetica
Hunting for kerning in MgOpen Modata
	kerning found!
Hunting for kerning in MgOpen Moderna
	kerning found!
Hunting for kerning in Monospaced
Hunting for kerning in Mukti Narrow
Hunting for kerning in Nada
	kerning found!
Hunting for kerning in Nagham
	kerning found!
Hunting for kerning in Nice
	kerning found!
Hunting for kerning in Nimbus Mono L
Hunting for kerning in Nimbus Roman No9 L
Hunting for kerning in Nimbus Sans L
Hunting for kerning in Norasi
	kerning found!
Hunting for kerning in OpenSymbol
Hunting for kerning in Ostorah
	kerning found!
Hunting for kerning in Ouhod-Bold
Hunting for kerning in Petra
	kerning found!
Hunting for kerning in Phetsarath OT
Hunting for kerning in Purisa
Hunting for kerning in Rachana_w01
Hunting for kerning in Rasheeq-Bold
Hunting for kerning in Rehan
	kerning found!
Hunting for kerning in Salem
	kerning found!
Hunting for kerning in SansSerif
Hunting for kerning in Serif
Hunting for kerning in Shado
	kerning found!
Hunting for kerning in Sharjah
	kerning found!
Hunting for kerning in Sindibad
	kerning found!
Hunting for kerning in Standard Symbols L
Hunting for kerning in Tarablus
	kerning found!
Hunting for kerning in Tholoth
	kerning found!
Hunting for kerning in Tlwg Typist
Hunting for kerning in TlwgMono
Hunting for kerning in TlwgTypewriter
Hunting for kerning in UnBatang
Hunting for kerning in UnDotum
Hunting for kerning in URW Bookman L
Hunting for kerning in URW Chancery L
Hunting for kerning in URW Gothic L
Hunting for kerning in URW Palladio L
Hunting for kerning in utkal
Hunting for kerning in Vemana2000

I tried to attach the list of kerning values that I found, but it’s too big for the boards ::slight_smile:

Also, I don’t find any kerning information unless I derive the source font like so:


Map<TextAttribute, Object> attributes = new HashMap<TextAttribute, Object>();
attributes.put( TextAttribute.KERNING, TextAttribute.KERNING_ON );
srcFont = java.awt.Font.decode( fontName ).deriveFont( attributes );

Ah, you know what it is, a Java 6 implementation by a certain, uh, “fruit” company currently ignores KERNING_ON. Weird. The Sun implementation uses it.

BTW you don’t have to use TextLayout or the faux Graphics2D - using font.layoutGlyphVector() has kerning.

Sorry to hijack the thread!

Yeah, can’t say I ever noticed kerning not working using the code as it is. It Just Worked.

Cas :slight_smile: