LWJGL
June 19, 2013, 16:28:23 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.9.0 released!
 
   Home   Help Search Login Register  



Pages: 1 [2] 3
  Print  
Author Topic: Displaying Text in OpenGL  (Read 23938 times)
Schnitter
Newbie
*
Posts: 43


« Reply #15 on: March 22, 2008, 02:42:05 »

Question:
I'm using the Slick-Code like this:
TrueTypeFont ttf = new TrueTypeFont(new Font("Arial", Font.BOLD, 50), true);
[...]
And in the render-method:
ttf.drawString(500, 500, "Hello World Smiley");

But the only thing I get is this:
http://planschkuh.pl.ohost.de/errorScreen1.jpg

Where's the  problem? I couldn't find any tutorial for the slick-code Sad
Logged
Matzon
Administrator
Demigod
*****
Posts: 2239



« Reply #16 on: March 22, 2008, 03:06:46 »

the TestUtils (org.newdawn.slick.tests.TestUtils) does the following:

Code:
        java.awt.Font awtFont = new Font("Times New Roman", 1, 16);
        org.newdawn.slick.Font font = new TrueTypeFont(awtFont, false);
        ...
        font.drawString(150F, 300F, "HELLO LWJGL WORLD", Color.yellow);

mind you, it does have some init code that may or may not be relevant.

I am not entirely sure where the source code to the slick-util package is ...
Logged

Schnitter
Newbie
*
Posts: 43


« Reply #17 on: March 22, 2008, 05:04:41 »

Mh, I looked into the code and it works now!

I think it was the "Arial"-Font. I don't know why it didn't work, but with "Times New Roman" it works Wink

Thanks!
Logged
Se7enDays
Newbie
*
Posts: 5


« Reply #18 on: March 22, 2008, 09:40:32 »

Hmm, i also tried the Slick demo. It works. But when i try to create a font and draw it in my lwjgl program it only shows a black screen. Can someone help me? How does you code look like, Schnitter?
Logged
Schnitter
Newbie
*
Posts: 43


« Reply #19 on: March 22, 2008, 10:04:48 »

I get it to work like this: http://nopaste.info/24ab6d6807.html

But I got another - huge - problem! :/
I want my 0/0 point in the bottom left corner. but because of
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();

It is in the upper left corner!(I think it's because of this).
And when I don't write this code - the text is the wrong way round!
I think I could solve the problem by compiling the slick-code myself - but that would be soooo much work Sad
Logged
Matthias
Talks Too Much
***
Posts: 180


WWW
« Reply #20 on: March 22, 2008, 10:12:36 »

If you would setup a real projection matrix - eg using glOrtho it would be much easier Smiley
Logged

Schnitter
Newbie
*
Posts: 43


« Reply #21 on: March 22, 2008, 10:38:16 »

Can anybody tell me how to set up a projection matrix correctly? :S
Logged
bobjob
Prolific Timewaster
****
Posts: 335


LWJGL: WOW SO GOOD


« Reply #22 on: March 22, 2008, 18:21:39 »

Here is some source code that displays bitmaps fonts, it will also have the code for setting up ortho(2D) view
http://nehe.gamedev.net/data/lessons/lwjgl/lesson13.jar
Logged

LWJGL Benchmark online test:
http://have2chat.net/benchmark/
http://have2chat.net/benchmark/fullpage.html (run full OpenGL webpage)
Schnitter
Newbie
*
Posts: 43


« Reply #23 on: March 22, 2008, 19:21:33 »

Using the code from the nehe-tutorial
Code:
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        // Select The Projection Matrix
        GL11.glLoadIdentity(); // Reset The Projection Matrix

        // Calculate The Aspect Ratio Of The Window
        GLU.gluPerspective(45.0f,
                (float) PresentParameters.getWidth() / (float) PresentParameters.getHeight(),
                0.1f, 100f);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        // Select The Modelview Matrix
I can see nothing^^ There is just a black window Sad
I render my sprites to (x, y, 0f). Is that right? And if not - the text is also wrong :/
Logged
bobjob
Prolific Timewaster
****
Posts: 335


LWJGL: WOW SO GOOD


« Reply #24 on: March 23, 2008, 06:30:53 »

a function to setup 2d mode   

Code:
public static void set2DMode() {
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glMatrixMode(GL11.GL_PROJECTION);                        // Select The Projection Matrix
    GL11.glPushMatrix();                                     // Store The Projection Matrix
    GL11.glLoadIdentity();                                   // Reset The Projection Matrix
    GL11.glOrtho(0, Settings.width, 0, Settings.height, -1, 1);                          // Set Up An Ortho Screen
    GL11.glMatrixMode(GL11.GL_MODELVIEW);                         // Select The Modelview Matrix
    GL11.glPushMatrix();                                     // Store The Modelview Matrix
     //GL11.glLoadIdentity();                                   // Reset The Modelview Matrix
}

a function to set it back to 3d mode

Quote
public static void set3DMode() {
    GL11.glMatrixMode(GL11.GL_PROJECTION);                        // Select The Projection Matrix
    GL11.glPopMatrix();                                      // Restore The Old Projection Matrix
    GL11.glMatrixMode(GL11.GL_MODELVIEW);                         // Select The Modelview Matrix
    GL11.glPopMatrix();                                      // Restore The Old Projection Matrix
    GL11.glEnable(GL11.GL_DEPTH_TEST);
}
Logged

LWJGL Benchmark online test:
http://have2chat.net/benchmark/
http://have2chat.net/benchmark/fullpage.html (run full OpenGL webpage)
Schnitter
Newbie
*
Posts: 43


« Reply #25 on: March 23, 2008, 06:52:35 »

It seems that I can not let an TrueTypeTexture-variable null. I got 2 of them and one was null. By setting both to new TrueTypeFont(f, true), it worked.
Using you method to set the 2d-mode, it works. but the text is still the wrong way round.
Here is the complete Code:
http://nopaste.info/e0a2c896da_nl.html
Logged
bobjob
Prolific Timewaster
****
Posts: 335


LWJGL: WOW SO GOOD


« Reply #26 on: March 23, 2008, 08:34:50 »

not sure how 2 fix the problem as i use my own custom Font class.

if my text is going the wrong way round i can just change the test co-ordinates myself.

but ill take a stab at what might work:
1. depending on the direction try change the, ortho bounds. so there going in an oposite direction.
2. Is there a way to setup ortho/2d view in the class you are using
Logged

LWJGL Benchmark online test:
http://have2chat.net/benchmark/
http://have2chat.net/benchmark/fullpage.html (run full OpenGL webpage)
Schnitter
Newbie
*
Posts: 43


« Reply #27 on: March 23, 2008, 09:01:18 »

I always wanted to do it myself - so, do you know any tutorial to use ttf-fonts in lwjgl-applications?
I think it'll be not easy but I want to try it.
Oh, I already looked into the slick-code but it didn't help Sad
Logged
bobjob
Prolific Timewaster
****
Posts: 335


LWJGL: WOW SO GOOD


« Reply #28 on: March 23, 2008, 10:36:11 »

dunno about ttf fonts, I just use bitmap fonts.

is it only that the fonts are displaying the wrong direction?

if so: then change the line
GL11.glOrtho(0, Settings.width, 0, Settings.height, -1, 1);                          // Set Up An Ortho Screen
to
GL11.glOrtho(Settings.width, 0,  0, Settings.height, -1, 1);                          // Set Up An Ortho Screen

or something like that
Logged

LWJGL Benchmark online test:
http://have2chat.net/benchmark/
http://have2chat.net/benchmark/fullpage.html (run full OpenGL webpage)
Schnitter
Newbie
*
Posts: 43


« Reply #29 on: March 23, 2008, 10:55:16 »

yes, I know. But doing it like this, everyting else is also thw wrong way round Sad
Logged
Pages: 1 [2] 3
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!