java - Drawing text to display -
i'm trying draw text screen in lwjgl following this tutorial. problem when ever draw text screen, draws but when draw quad with text, quad not show.
game class
package moa.bermudez; import static org.lwjgl.opengl.gl11.*; import java.awt.font; import java.io.inputstream; import moa.bermudez.utils.artist; import org.lwjgl.lwjglexception; import org.lwjgl.opengl.display; import org.lwjgl.opengl.displaymode; import org.newdawn.slick.truetypefont; public class game { public static final int width = 320; public static final int height = width * 9 / 16; public static final int scale = 3; public static final string name = "----"; public static final float version = 0.1f; public static final int max_fps = 60; private truetypefont font; private boolean fontas = true; public game() { try { display.setdisplaymode(new displaymode(width * scale, height * scale)); display.settitle(name + " " + version); display.create(); } catch(lwjglexception e) { e.printstacktrace(); display.destroy(); } init(); while(!display.iscloserequested()) { setcamera(); update(); display.sync(max_fps); } display.destroy(); } public void update() { glclear(gl_color_buffer_bit); font.drawstring(0, 0, "this text showing"); artist.drawquad(0, 0, 100, 100); // not showing. display.update(); } public void setcamera() { glmatrixmode(gl_projection); glloadidentity(); glviewport(0, 0, width * scale, height * scale); glortho(0, width * scale, height * scale, 0, 1, -1); glmatrixmode(gl_modelview); glenable(gl_texture_2d); glenable(gl_blend); glblendfunc(gl_src_alpha, gl_one_minus_src_alpha); } public void init() { try { inputstream inputstream = moa.bermudez.fonts.font.default_font; font awtfont = font.createfont(font.truetype_font, inputstream); awtfont = awtfont.derivefont(24f); font = new truetypefont(awtfont, fontas); } catch (exception e) { e.printstacktrace(); } } public static void main(string[] args) { new game(); } } artist's drawquad method
public static void drawquad(float x, float y, float width, float height) { glbegin(gl_quads); glcolor3d(0, 0, 1); glvertex2f(x, y); glvertex2f(x + width, y); glvertex2f(x + width, y + height); glvertex2f(x, y + height); glend(); }
after searching, found solution this stackoverflow post
not calling glenable(gl_blend) in initgl calling glenable(gl_blend) when draw text should make work.
glenable(gl_blend); font.drawstring(0, 0, "this text should appear"); gldisable(gl_blend);
Comments
Post a Comment