Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
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 Slick-util DrawString Not Working  (Read 117 times)
0 Members and 1 Guest are viewing this topic.
Offline Damian3395

Junior Newbie





« Posted 2014-01-14 22:11:50 »

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  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
package engine;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;

public class Window {
   
   private static String title = "Ultimate Tetris";
   private static String version = "Alpha";
   private int width;
   private int height;
   private boolean fullScreen;
   private boolean vSync;
   public static boolean play = true;
   
   public Window(){
      //Load Settings
     Settings settings = new Settings();
     
      fullScreen = settings.getFullScreen();
      width = settings.getScreenWith();
      height = settings.getScreenWith();
      vSync = settings.getVSync();
     
      //Initialize Game Settings
     initialize();
   }
   
   public void initialize(){
      try{
         //Load Window
        if(fullScreen){
            Display.setFullscreen(fullScreen);
         }else{
            Display.setDisplayMode(new DisplayMode(width, height));
         }
         Display.setTitle(title + " " + version);
         Display.setVSyncEnabled(true);
         Display.create();
   
         GL11.glEnable(GL11.GL_TEXTURE_2D);    
         GL11.glDisable(GL11.GL_DEPTH_TEST);
         
         GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
   
           GL11.glViewport(0,0,width,height);
         GL11.glMatrixMode(GL11.GL_MODELVIEW);
   
         GL11.glMatrixMode(GL11.GL_PROJECTION);
         GL11.glLoadIdentity();
         GL11.glOrtho(0, width, height, 0, 1, -1);
         GL11.glMatrixMode(GL11.GL_MODELVIEW);
      }catch(LWJGLException e){
         e.printStackTrace();
         System.out.println("GAME EXITING\nFAILED TO INITIALIZE GAME DATA!");
         System.out.println("Error: Window.initialize() " + e);
         Window.play = false;
         System.exit(0);
      }
   }
   
   public static void main(String[] args){
      new Window();
      GameState state = new GameState();
     
      while(play && !Display.isCloseRequested()){
         GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
         
         state.updateGameState();
         
         Display.update();
         Display.sync(100);
      }  
     
      Display.destroy();
   }
}


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  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
package engine;

import org.lwjgl.Sys;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;

import java.awt.Font;
 

import org.newdawn.slick.Color;
import org.newdawn.slick.TrueTypeFont;

public class Debug {  
   private int fps = 0;
   private String FPS = "";
   private long lastLoopTime = getTime();
   private long lastFPSTime;
   private static long timerTicksPerSecond = Sys.getTimerResolution();
   private TrueTypeFont font;
   public boolean debugON = false;
   
   
   public Debug(){
      Font awtFont = new Font("Times New Roman", Font.BOLD, 24);
      font = new TrueTypeFont(awtFont, true);
   }
   
   private long getTime(){
      return (Sys.getTime() * 1000) / timerTicksPerSecond;
   }
   
   private void sleep(long time){
      try{
         Thread.sleep((time * timerTicksPerSecond) / 1000);
      }catch(InterruptedException e){
         e.printStackTrace();
         System.out.println("Error: Debug.sleep() " + e);
      }
   }
   
   public String getOSVersion(){
      return System.getProperty("os.version");
   }
   
   public String getOSName(){
      return System.getProperty("os.name");
   }
   
   public String getOSType(){
      return System.getProperty("os.arch");
   }
   
   public String getJavaVersion(){
      return System.getProperty("java.version");
   }
   
   public String getJavaVendor(){
      return System.getProperty("java.vendor");
   }
   
   public String getMaxRAM(){
      return Long.toString(Runtime.getRuntime().maxMemory()) + " bytes";
   }
   
   public String getTotalRAM(){
      return Long.toString(Runtime.getRuntime().totalMemory()) + " bytes";
   }
   
   public String getFreeRAM(){
      return Long.toString(Runtime.getRuntime().freeMemory()) + " bytes";
   }
   
   public String getCPUCores(){
      return Integer.toString(Runtime.getRuntime().availableProcessors());
   }
   
   public String getFPS(){
      return FPS;
   }
   
   public String getMousePosition(){
      return "X: " + Mouse.getX() + " Y: " + Mouse.getY();
   }
   
   public void calculateFPS(){
      long delta = getTime() - lastLoopTime;
      lastLoopTime = getTime();
      lastFPSTime += delta;
      fps++;
     
      if(lastFPSTime >= 1000){
         FPS = Integer.toString(fps);
         lastFPSTime = 0;
         fps = 0;
      }
   }
   
   public void draw(){
      font.drawString(10, 10, "Hello World");
   }
}


My code is based off of the tutorial created by NeHe (http://lwjgl.org/wiki/index.php?title=Slick-Util_Library_-_Part_3_-_TrueType_Fonts_for_LWJGL), and it works when I tested it out as exactly shown on the website, but when I tried to integrate it into my game engine, it no longer works.
Offline Damian3395

Junior Newbie





« Reply #1 - Posted 2014-01-14 23:32:43 »

Ignore please, I fixed it myself. Problem was due to lack of clean code. Rewrote everything. Its good.
Pages: [1]
  ignore  |  Print  
 
 

 

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 (12 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (182 views)
2014-04-01 02:16:10
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

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