java - lwjgl freezes on creation of Font object -


i making simple game of snake, because can, , stumbled across interesting bug. trying use slick-util draw text on screen, whenever try create font object game freezes. here code. highlighted section prints 'a' once.

package tlf.snake.main;   import tlf.snake.main.game.helper.pos; import tlf.snake.main.game.input.input;  import java.awt.font;  import java.nio.bytebuffer; import java.nio.intbuffer;  import org.lwjgl.bufferutils; import org.lwjgl.glfw.glfwwindowposcallback; import org.lwjgl.glfw.glfwwindowsizecallback; import org.lwjgl.glfw.glfwvidmode; import org.lwjgl.opengl.glcontext;  import org.newdawn.slick.truetypefont;  import static org.lwjgl.glfw.callbacks.glfwsetcallback; import static org.lwjgl.glfw.glfw.*; import static org.lwjgl.opengl.gl11.*; import static org.lwjgl.system.memoryutil.null;  /**  * @author thislooksfun  */ public class snakegame {     private static final game game = new game();      private int width = game.gamewidth*15;     private int height = game.gameheight*15;      private static final int minwidth = game.gamewidth*10;     private static final int minheight = game.gameheight*10;      private pos lastpos;      private int size = 10;     private boolean resized = false;      private boolean running = false;      private long window;      private static snakegame instance;      public truetypefont font;      public snakegame()     {         instance = this;     }      private void init()     {         if (glfwinit() != gl_true) {             system.out.println("error initializing");             //todo handle             return;         }          glfwwindowhint(glfw_resizable, gl_false);          window = glfwcreatewindow(width, height, "neat snake", null, null);          if (window == null) {             system.out.println("error creating window");             //todo handle             return;         }          bytebuffer vidmode = glfwgetvideomode(glfwgetprimarymonitor());         glfwsetwindowpos(window, (glfwvidmode.width(vidmode) - width) / 2, (glfwvidmode.height(vidmode) - height) / 2);         initcallbacks();         glfwmakecontextcurrent(window);         glfwshowwindow(window);          glcontext.createfromcurrent();          glclearcolor(0.0f, 0.0f, 0.0f, 1.0f);         gldepthfunc(gl_never);         gldisable(gl_depth_test);          setortho();         gldisable(gl_texture_2d);          initfonts();          running = true;         resized = true;          game.start();     }      private void initcallbacks()     {         glfwsetcallback(window, glfwwindowsizecallback(new glfwwindowsizecallback.sam()         {             @override             public void invoke(long window, int width, int height)             {                 resized = true;                 width = width;                 height = height;                  if (width < minwidth && height >= minheight) {                     glfwsetwindowsize(window, minwidth, height);                     glfwsetwindowpos(window, lastpos.x-10, lastpos.y);                 } else if (width >= minwidth && height < minheight) {                     glfwsetwindowsize(window, width, minheight);                     glfwsetwindowpos(window, lastpos.x-10, lastpos.y);                 } else if (width < minwidth && height < minheight) {                     glfwsetwindowsize(window, minwidth, minheight);                     glfwsetwindowpos(window, lastpos.x-10, lastpos.y);                 } else                     lastpos = getwindowpos();                  render();                 setortho();             }         }));          glfwsetcallback(window, glfwwindowposcallback(new glfwwindowposcallback.sam()         {             @override             public void invoke(long window, int xpos, int ypos)             {                 lastpos = new pos(xpos, ypos);             }         }));          glfwsetkeycallback(window, new input());     }      private pos getwindowpos()     {         intbuffer xbuf = bufferutils.createintbuffer(4);         intbuffer ybuf = bufferutils.createintbuffer(4);         glfwgetwindowpos(window, xbuf, ybuf);          return new pos(xbuf.get(0), ybuf.get(0));     }      private void setortho()     {         glmatrixmode(gl_projection);         glloadidentity();         glortho(0, width, height, 0, 1, -1);         glmatrixmode(gl_modelview);     }      private void initfonts()     {         system.out.println("a");         font awtfont = new font("default", font.bold, 24);         system.out.println("a");         font = new truetypefont(awtfont, true);         system.out.println("a");     }      public void start()     {         init();         while (running)         {             update();             render();             if (glfwwindowshouldclose(window) == gl_true) {                 running = false;             }         }     }      private void update()     {         glfwpollevents();         game.tick();     }      private void render()     {         if (resized) {             setortho();             calctilesize();             resized = false;         }          glclear(gl_color_buffer_bit | gl_depth_buffer_bit);          game.render();          glfwswapbuffers(window);     }      public static snakegame instance()     {         return instance;     }      private void calctilesize()     {         int sh, sw;         sh = (int)math.floor((1.0f*height)/game.gameheight);         sw = (int)math.floor((1.0f*width)/game.gamewidth);          size = sh > sw ? sw : sh;     }      public int tilesize()     {         return size;     }      public void stop()     {         running = false;     } } 

any ideas?
thanks,
-tlf

have tried font "arial" or "serif"? guess "default" not valid name font in windows.

try this:

font awtfont = new font("times new roman", font.bold, 24); font = new truetypefont(awtfont, false); 

or, if have .ttf file try this:

try {     inputstream inputstream = resourceloader.getresourceasstream("anotherfont.ttf");     font awtfont = font.createfont(font.truetype_font, inputstream);     awtfont = awtfont2.derivefont(24f);     font = new truetypefont(awtfont2, false);       } catch (exception e) {     e.printstacktrace(); }    

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -