Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (525)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (594)
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  
  {lwjgl} drawing font cause very low FPS and remove all the other graphics  (Read 930 times)
0 Members and 1 Guest are viewing this topic.
Offline alaslipknot
« Posted 2013-05-12 02:22:20 »

Hello,
it's the first time i try to draw font using SlickUtile, i followed the example in the main lwjgl page and then when i tried to apply it in my game the result is quite strange, i can see the text but the frame rate is between 7 and 9 and it also remove all the other  graphics after they do a little "eye flash" (i saw the level then it disappear )

i call the font from another method :
 
1  
2  
3  
4  
5  
6  
7  
// the update method
   private void update(int delta) {
      painting();
      draw.text();
     
      loop.updateFPS();
   }

the draw text method :
1  
2  
3  
4  
5  
6  
public void text() {
      TrueTypeFont font;
      Font awtFont = new Font("Times New Roman", Font.BOLD, 24);
      font = new TrueTypeFont(awtFont, true);
      font.drawString(100, 50, "test ", Color.white);
   }

the openGL initialization :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
public void initGL() {

      GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glShadeModel(GL11.GL_SMOOTH);
      GL11.glDisable(GL11.GL_DEPTH_TEST);
      GL11.glDisable(GL11.GL_LIGHTING);

      GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      GL11.glClearDepth(1);

      GL11.glEnable(GL11.GL_BLEND);
      GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();
      GL11.glOrtho(0, 800, 600, 0, 1, -1);

   }


thank you

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
Offline Longarmx
« Reply #1 - Posted 2013-05-12 02:48:07 »

First off, you are initializing and loading the font very frame. Load it once and render it every frame.

Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 139
Projects: 4
Exp: 3 years



« Reply #2 - Posted 2013-05-12 03:07:04 »

First of all, shouldn't delta be a float? Or are you just storing the time in milliseconds as opposed to .003 for example? Second, if you can't figure out why it causes low FPS (longarmx's rationale is correct, I think) you need to really think about what happens when you intialize variables and call methods....
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Quarry
« Reply #3 - Posted 2013-05-13 16:13:32 »

Longarmx is correct. You should initialize the font in the draw object's constructor. However I still don't understand why draw object doesn't contain static methods
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 139
Projects: 4
Exp: 3 years



« Reply #4 - Posted 2013-05-13 16:57:13 »

imo
1  
draw.text();
is pretty terrible code naming...
text() should not be a method, unless you are referring to texting someone. Instead, should be drawText() or something of the sort. The "draw" object would be better renamed "rednerer" or "drawer". All for code readability ofc.
Offline Grunnt

JGO Kernel


Medals: 94
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #5 - Posted 2013-05-13 17:08:59 »

text() should not be a method, unless you are referring to texting someone. Instead, should be drawText() or something of the sort. The "draw" object would be better renamed "rednerer" or "drawer". All for code readability ofc.

I think it's just some simplified test code.

Second, if you can't figure out why it causes low FPS (longarmx's rationale is correct, I think) you need to really think about what happens when you intialize variables and call methods....

Yeah, that is actually good advice. Try to read some more books and tutorials on Java programming, and learn a bit more about the garbage collector. Oracle has some pretty good tutorials on its site.

About your code:
1  
2  
3  
4  
5  
6  
public void text() {
      TrueTypeFont font;
      Font awtFont = new Font("Times New Roman", Font.BOLD, 24); // This creates a new object (which costs quite some time)
      font = new TrueTypeFont(awtFont, true);  // This creates another new object (more time wasted)
      font.drawString(100, 50, "test ", Color.white);  // Here the object is used
   } // Here both objects are discarded


Try creating the objects only once and reusing the objects, e.g.:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
private TrueTypeFont font;

public void init() {
      Font awtFont = new Font("Times New Roman", Font.BOLD, 24);
      font = new TrueTypeFont(awtFont, true);
}

public void text() {
      font.drawString(100, 50, "test ", Color.white);
}


That should resolve your performance issue.

Offline alaslipknot
« Reply #6 - Posted 2013-05-15 00:35:49 »

^
it still doesn't work  Clueless
even when i don't render the font, doing the initialization only make the whole game black but the frame rate is in it's normal state, and when i do the rendering it's always black and the frame rate go down to 7 FPS
yes am initializing it outside of the game loop

thank you

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
Offline Longarmx
« Reply #7 - Posted 2013-05-15 02:35:45 »

Have you tried to just render the font without any of your other game rendering and logic?

Offline alaslipknot
« Reply #8 - Posted 2013-05-15 15:04:44 »

Have you tried to just render the font without any of your other game rendering and logic?
yes it works when i don't do any rendering (still work when the logic is active) and also if render the font before the game rendering it also show the font with normal FPS but always a black background
the painting method :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
private void painting() {
      // clear the screen and depth buffer
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
      // draw the world
      world.setWorld();

      // draw the player
      draw.coloring("white");
      draw.fillRect(hero.getX(), hero.getY(), hero.getWidth(),
            hero.getHeight());

     
      draw.coloring("black");
      draw.drawRect(hero.getX(), hero.getY(), hero.getWidth(),
            hero.getHeight());

     
   }


ps: am not calling draw.text() now,
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  
private TrueTypeFont font;
   private Font awtFont;

   // initializing
   public void init() {

      awtFont = new Font("Times New Roman", Font.BOLD, 24);
      font = new TrueTypeFont(awtFont, true);

      loop.init();
      initHero();
      hero = new Player(heroX, heroY, heroW, heroH);
      onGround = false;
      canJump = false;
      falling = false;
      inJump = false;
      world = new World(width, height);
      myWorld = world.getWorld();

   }

   // the update method
   private void update(float delta) {

      font.drawString(100, 50, "test ", Color.white);
      //painting();
      heroUpdate();

     
      loop.updateFPS();
   }


thank you

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
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.

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

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

toopeicgaming1999 (14 views)
2014-11-26 15:20:08

SHC (27 views)
2014-11-25 12:00:59

SHC (25 views)
2014-11-25 11:53:45

Norakomi (31 views)
2014-11-25 11:26:43

Gibbo3771 (25 views)
2014-11-24 19:59:16

trollwarrior1 (38 views)
2014-11-22 12:13:56

xFryIx (77 views)
2014-11-13 12:34:49

digdugdiggy (55 views)
2014-11-12 21:11:50
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!