Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (499)
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 714 times)
0 Members and 1 Guest are viewing this topic.
Offline alaslipknot
« Posted 2013-05-12 04: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

Am trying ...
hoping that it works
Offline Longarmx
« Reply #1 - Posted 2013-05-12 04: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: 114
Projects: 4
Exp: 3 years



« Reply #2 - Posted 2013-05-12 05: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 18: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: 114
Projects: 4
Exp: 3 years



« Reply #4 - Posted 2013-05-13 18: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 Wizard


Medals: 55
Projects: 9
Exp: 5 years


Complex != complicated


« Reply #5 - Posted 2013-05-13 19: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 02: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

Am trying ...
hoping that it works
Offline Longarmx
« Reply #7 - Posted 2013-05-15 04: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 17: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

Am trying ...
hoping that it works
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.

xsi3rr4x (44 views)
2014-04-15 18:08:23

BurntPizza (40 views)
2014-04-15 03:46:01

UprightPath (56 views)
2014-04-14 17:39:50

UprightPath (38 views)
2014-04-14 17:35:47

Porlus (54 views)
2014-04-14 15:48:38

tom_mai78101 (77 views)
2014-04-10 04:04:31

BurntPizza (136 views)
2014-04-08 23:06:04

tom_mai78101 (236 views)
2014-04-05 13:34:39

trollwarrior1 (197 views)
2014-04-04 12:06:45

CJLetsGame (205 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!