Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Slick2D/LWJGL angel code font problem  (Read 1424 times)
0 Members and 1 Guest are viewing this topic.
Offline Mac70
« Posted 2012-11-19 21:01:07 »

Like in topic. I have problem with angel code fonts (and any other kind of font, too). I have enabled GL_TEXTURE_2D, glEnable(GL_BLEND);, glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Below you can see how "Hello world!" is displayed, above placeholder ship:



Here is part of my code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
public static AngelCodeFont font;

public static void main(String args[]) {
         start();
         makeFonts();
         gameLoop();
    }

static public void makeFonts() {
         Font awtFont = new Font("Times New Roman", Font.BOLD, 72);
        try {
            glBindTexture(GL_TEXTURE_2D,2);
            font = new AngelCodeFont("Jadro\\TimesNewRoman32.fnt", new Image("Jadro\\TimesNewRoman32.png"));
            glBindTexture(GL_TEXTURE_2D,1);
        } catch (SlickException ex) {
            Logger.getLogger(Jadro.class.getName()).log(Level.SEVERE, null, ex);
        }
     }


1  
Core.font.drawString(0, 0, "Hello World!", Color.white);


Just in case: OpenGL creation:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
public void utworz() {
         try {
            Display.setDisplayMode(new DisplayMode(SCREEN_X,SCREEN_Y));
            Display.setTitle("Silent Space 0.0.4 --- team work prototype");
            Display.create(new PixelFormat(8,8,8));
            Display.setVSyncEnabled(true);
        } catch (LWJGLException e) {
            System.exit(0);
        }
        glClearColor(0.0f,0.0f,0.0f,0.0f);
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);
       
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glEnable(GL_TEXTURE_2D);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
       
        glLoadIdentity();
        glShadeModel(GL_SMOOTH);
        glClearDepth(1.0f);
        glDepthFunc(GL_LEQUAL);
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
       
        glEnable(GL_ALPHA_TEST);
        glAlphaFunc(GL_GEQUAL, 0.1f);
        glEnable(GL_SCISSOR_TEST);
        glEnable(GL_STENCIL_TEST);
       
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, SCREEN_X, 0, SCREEN_Y, 1, -1);
        glMatrixMode(GL_MODELVIEW);
    }

Check out my Devblog! Smiley
Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #1 - Posted 2012-11-19 21:35:49 »

Well, as you can see, it is using the regions registered for the font, on the texture loaded for the ship. Without me having any knowledge of OpenGL, I'm going to venture a guess that your try/catch block is the problem. Are you sure you need both bindTexture-calls?

- Jonas
Offline Mac70
« Reply #2 - Posted 2012-11-19 21:42:17 »

I have deleted them, but I still have the same problem.

Check out my Devblog! Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2012-11-19 21:44:06 »

Don't use glBindTexture with Slick. Instead, use this:
1  
texture.bind();


If you want to disable texturing, use this:
1  
TextureImpl.bindNone();

Offline Mac70
« Reply #4 - Posted 2012-11-19 21:48:00 »

Don't use glBindTexture with Slick. Instead, use this:
1  
texture.bind();


If you want to disable texturing, use this:
1  
TextureImpl.bindNone();


I am using Slick only to draw strings, everything other is displayed in LWJGL.

Edit: When I am rendering only text, this is what can I see:



Is there any way to "separate" displaying of text and graphics?

Check out my Devblog! Smiley
Offline davedes
« Reply #5 - Posted 2012-11-20 00:36:02 »

The problem is because Slick caches the last bound texture to minimize redundant calls to glBindTexture. When you bind your own texture, Slick still thinks the font texture is bound, and doesn't bother calling glBindTexture again. This is why you see your own texture showing up where the font glyphs should be.

The solution is to use Slick's texture binding (which you may as well since you're already using slick to decode and load font textures), or to call TextureImpl.unbind() before rendering your Slick objects. This will clear the last cached texture, forcing Slick to call glBindTexture upon rendering.

Offline Mac70
« Reply #6 - Posted 2012-11-20 13:08:24 »

The problem is because Slick caches the last bound texture to minimize redundant calls to glBindTexture. When you bind your own texture, Slick still thinks the font texture is bound, and doesn't bother calling glBindTexture again. This is why you see your own texture showing up where the font glyphs should be.

The solution is to use Slick's texture binding (which you may as well since you're already using slick to decode and load font textures), or to call TextureImpl.unbind() before rendering your Slick objects. This will clear the last cached texture, forcing Slick to call glBindTexture upon rendering.

Unfortunately TextureImpl.unbind() does not work, I still see last texture instead of text. Any other ideas? Wink

Next parts of my code, I hope them will help solve this case:

1. Current font rendering code:

1  
2  
3  
4  
5  
        glPushMatrix();
            glTranslated(0, 0, 0);
            glRotated(180, 180, 0, 0);
            Core.font.drawString(0, 0, "Hello World!", Color.white);
        glPopMatrix();


2. Current texture binding and displaying code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
        glPushMatrix();
            glTranslated(x, y, 0);
            glRotated(angleRad/(Math.PI/180), 0, 0, 1);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, szerokosc, wysokosc, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture);
            glBindTexture(GL_ADD, GL_LOAD);
            glBindTexture(GL_TEXTURE_2D,1);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            glBegin(GL_QUADS);
                glColor4f(1,1,1,1);
                glTexCoord2f(0,1); glVertex2f(-height/2, -width/2);
                glTexCoord2f(0,0); glVertex2f(-height/2, width/2);
                glTexCoord2f(1,0); glVertex2f(height/2, width/2);
                glTexCoord2f(1,1); glVertex2f(height/2, -width/2);
            glEnd();
        glPopMatrix();

Check out my Devblog! Smiley
Offline davedes
« Reply #7 - Posted 2012-11-20 17:50:56 »

Why are you calling glTexImage2D every frame?
Why are you calling it before binding your texture?
What is the call to GL_ADD, GL_LOAD for?

You really need to learn a little more about OpenGL....

Your text rendering should look like this:
1  
2  
3  
4  
5  
6  
        glPushMatrix();
            glTranslated(0, 0, 0);
            glRotated(180, 180, 0, 0);
            TextureImpl.unbind();
            Core.font.drawString(0, 0, "Hello World!", Color.white);
        glPopMatrix();


Your font loader should look like this:
1  
2  
3  
4  
5  
6  
        try {
            TextureImpl.unbind();
            font = new AngelCodeFont("Jadro\\TimesNewRoman32.fnt", new Image("Jadro\\TimesNewRoman32.png"));
        } catch (SlickException ex) {
            Logger.getLogger(Jadro.class.getName()).log(Level.SEVERE, null, ex);
        }

Offline Mac70
« Reply #8 - Posted 2012-11-20 21:51:28 »

I found the solution - I had to load my font png as texture before using it. I know that this is a workaround, but I think there is no easier way to do it.

Check out my Devblog! Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (33 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (51 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (45 views)
2014-12-05 12:39:02

SHC (59 views)
2014-12-03 16:27:13

CopyableCougar4 (60 views)
2014-11-29 21:32:03

toopeicgaming1999 (123 views)
2014-11-26 15:22:04

toopeicgaming1999 (114 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!