LWJGL Forum
Programming => Lightweight Java Gaming Library => Topic started by: windfall007 on September 10, 2012, 13:44:53
-
Hi,
I've been a long-time user of JOGL and have brought 2 products
to market using it. But I've recently bit the bullet and switching
over to LWJGL. In the process, I've found that LWJGL doesn't yet
have a good/robust text rendering utility (I've seen a few solutions
out there), so I ported JOGL's TextRenderer: https://github.com/sgothel/jogl/blob/master/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java
over to it, as that's something I needed for myself.
I'm wondering if the authors and users of LWJGL will find this useful,
and if so, I'd be happy to slim it down to its bare useful minimum
(it has some cruft) and contribute it to LWJGL's codebase.
.rex
-
i was missing that feature too, currently using a changed version of GLFont from here:
http://potatoland.org/code/gl/
i changed a bit the code to be more flexible, but still having a little bit bugs (some strokes in the text that aren't on the texture).
i was seeing your code, but a bit difficult to read. i noticed that u also use the AWT Font. would like to see a minimal running example / test of your renderer in action.
but nevertheless a textrenderer is really needed! even if it is just a small basic renderer, it must be a part of the basic lwjgl API i think. if still others have more demands on text-rendering, they still can do their own procedures. but a simple basic text must be possible through the normal API, my opinion...
greetz Ben
-
TWL has a nice text renderer, has lots of gui utils too.
-
I had a similar problem, but I preferred to use openGL 3+, hence my own shaders.
This makes the text problem even worse, since most existing text libraries use openGL 1.1.
I ended up making my own font loader, that could load bitmap fonts generetated with a simple tool.
You can find the tool here:
http://www.angelcode.com/products/bmfont/
Once I had the exact location, texture coordinates, etc. Drawing the text was no hard thing anymore.
If someone wants I can post the source code of that loader with an example writer and small test code.
The most use full thing about it, is that it is easy to port to JOGL and even other languages, as it only makes use of openGL to load the textures.
Rewriting the texture loading should be a matter of copy/pasting some code.
-
Personally i use Slick Util for most utility classes and font rendering. It does the trick but is a bit heavy when developing web games but that's what caching is for.
-
I had a similar problem, but I preferred to use openGL 3+, hence my own shaders.
This makes the text problem even worse, since most existing text libraries use openGL 1.1.
I ended up making my own font loader, that could load bitmap fonts generetated with a simple tool.
You can find the tool here:
http://www.angelcode.com/products/bmfont/
Once I had the exact location, texture coordinates, etc. Drawing the text was no hard thing anymore.
If someone wants I can post the source code of that loader with an example writer and small test code.
The most use full thing about it, is that it is easy to port to JOGL and even other languages, as it only makes use of openGL to load the textures.
Rewriting the texture loading should be a matter of copy/pasting some code.
I'd love to have that source code!
-
Hi, I tried to use GLFont to display text on my application but it seems it doesn't work with an OpenGL context with API version 3.2.
This is how I initialize my OpenGL context:
private void setupOpenGL() {
// Setup an OpenGL context with API version 3.2
try {
PixelFormat pixelFormat = new PixelFormat();
ContextAttribs contextAtrributes = new ContextAttribs(3, 2);
contextAtrributes.withForwardCompatible(true);
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
Display.setTitle(WINDOW_TITLE);
Display.create(pixelFormat, contextAtrributes);
GL11.glViewport(0, 0, WIDTH, HEIGHT);
} catch (LWJGLException e) {
e.printStackTrace();
this.destroyOpenGL();
System.exit(-1);
}
GL11.glClearColor(0.4f, 0.6f, 0.9f, 0f);
GL11.glViewport(0, 0, WIDTH, HEIGHT);
GL11.glLineWidth(2.0f);
GL11.glPointSize(3.0f);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
//Setup culling
GL11.glCullFace(GL11.GL_BACK);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_DEPTH_TEST);
this.exitOnGLError("setupOpenGL");
}
The OpenGL error state machine throws an error when I try to create a new GLFont with, as argument, a font made out of java.awt.Font class
// Initialize OpenGL (Display)
this.setupOpenGL();
try{
Font font = new Font("Times New Roman", Font.BOLD, 12);
this.exitOnGLError("fontcreation");
glfont = new GLFont(font);
this.exitOnGLError("glfont"); ///// HERE !
}catch(OpenGLException e){
e.printStackTrace();
this.destroyOpenGL();
System.exit(-1);
}
And I managed to reach the problematic function in the GLFont instanciation process:
GL11.glPushAttrib(GL11.GL_TEXTURE_BIT);
Does any one have an explanation? ???
Or do you know another way to do this easily? (It is for debug purpose only, I don't want to spend hours on displaying text on my screen :-\)
edit: Ok I found that the glPushAttrib() function is deprecated in OpenGL 3.x, it is no worth to use it anymore, however I remain open to your proposal of easier solutions (and working with openGL core profile of course :P)
-
I am considering porting JOGL TextRenderer to LWJGL. Before I do so, I am checking on the internet if perhaps there is some previous effort. This thread looks promising, but I do not see any links to the code WINDFALL007 has ported.
I agree with the previous posters a text renderer is needed, it may exist as a separate library (I would be happy to maintain and publish it).