Can't get EasyFont render on my lwjgl3 game

Started by j9263178, March 26, 2020, 12:24:25

Previous topic - Next topic

j9263178

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
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,
    public void init(){
        ByteBuffer charBuffer = BufferUtils.createByteBuffer(text.length() * 270);

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

        glEnableClientState(GL_VERTEX_ARRAY);
        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;

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

        glDrawArrays(GL_QUADS, 0, quads * 4);

        glPopMatrix();

    }


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

glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 
shader.bind();
mainCamera.getPosition().lerp(new Vector3f(0.64f*main.getPos().x,0.86f*main.getPos().y,0).mul(-1,new Vector3f()), 0.07f);
onEntitiesDraw();
input.update();
EasyFont.draw();  //much the same as in the while loop of original code
glfwSwapBuffers(window);
glfwPollEvents();

abcdef

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.