Programming => OpenGL => Topic started by: j9263178 on March 26, 2020, 12:24:25

Title: Can't get EasyFont render on my lwjgl3 game
Post by: j9263178 on March 26, 2020, 12:24:25
The following demo works well on its own program
https://github.com/LWJGL/lwjgl3/blob/master/modules/samples/src/test/java/org/lwjgl/demo/stb/EasyFont.java (https://github.com/LWJGL/lwjgl3/blob/master/modules/samples/src/test/java/org/lwjgl/demo/stb/EasyFont.java)
but I just can't get it draw in my game.
I copied from line 53 to line 63 (make it a draw() method) to my game loop , and put other things( like those in front of the while loop in original code) in a init() method,
Code: [Select]
    public void init(){
        ByteBuffer charBuffer = BufferUtils.createByteBuffer(text.length() * 270);

        int quads = stb_easy_font_print(0, 0, getText(), null, charBuffer);

        glVertexPointer(2, GL_FLOAT, 16, charBuffer);

        glClearColor(43f / 255f, 43f / 255f, 43f / 255f, 0f); // BG color
        glColor3f(169f / 255f, 183f / 255f, 198f / 255f); // Text color


    public void draw(){
        float scaleFactor = 1.0f + getScale() * 0.25f;

        // Zoom
        glScalef(scaleFactor, scaleFactor, 1f);
        // Scroll
        glTranslatef(4.0f, 4.0f - getLineOffset() * getFontHeight(), 0f);

        glDrawArrays(GL_QUADS, 0, quads * 4);



but I just can't see any text in my game, is it because I am using a shader (I've tried unbind it but didn't work) or a camera (which relates to a "projection" Matrix4f uniform in shader) or a VBO?
or I need to to do some glEnable or glDisable stuff?
my game loop looks like this

Code: [Select]
mainCamera.getPosition().lerp(new Vector3f(0.64f*main.getPos().x,0.86f*main.getPos().y,0).mul(-1,new Vector3f()), 0.07f);
EasyFont.draw();  //much the same as in the while loop of original code
Title: Re: Can't get EasyFont render on my lwjgl3 game
Post by: abcdef on March 31, 2020, 15:21:35
Some suggestions

Use render doc to see what vertex were passed to the opengl driver.

Check the winding order

Check your project matrix maps to correct ndc coordinates.