Hello Guest

LWJGL 3 text positioning help

  • 4 Replies
  • 4722 Views
*

Offline GiantNuker

  • *
  • 4
  • I am new to LWJGL and I probably need help
LWJGL 3 text positioning help
« on: September 28, 2017, 23:50:17 »
EDIT: forget the rest of of this post Issue is herehttp://forum.lwjgl.org/index.php?topic=6610.msg34982#msg34982(or scroll down to my next post)

I am having trouble rendering text, what is wrong with my method? ??? ??? ???


public static void drawString(String text) {
      ByteBuffer charBuffer = BufferUtils.createByteBuffer(text.length() * 270);
      int d = STBEasyFont.stb_easy_font_print(10, 10, text, null, charBuffer);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, 7);
      FloatBuffer b = charBuffer.asFloatBuffer();
      float[] f = new float[text.length() * 270];
      int i = 0;
      while (b.hasRemaining()) {
         f = b.get();
         i++;
      }
      int four = 0;
      for(int z = 0; z < f.length; z+= 16){
         if (f[z] == 0) break;
         if (four == 0)GL11.glBegin(GL11.GL_QUADS);
         float[] xb = new float[4], yb = new float[4];
         //for (i = 0; i < 4; i++) {
            float x = 0, y = 0;
            for (int j = 0; j < 2; j++) {
               if (j == 0) x = f[z + j];
               else if (j == 1) y = f[z + j];
               
            }
         //}
         GL11.glVertex2d(x, y);
         four++;
         if (four == 4) {
            four = 0;
            GL11.glEnd();
         }
      }
   }

Any help would be GREATLY APPRECIATED ;D
« Last Edit: September 29, 2017, 22:05:38 by GiantNuker »
I am new to LWJGL and I probably need help. ???

Please help me! :)

*

Offline spasi

  • *****
  • 2258
    • WebHotelier
Re: LWJGL 3 STBEasyFont help
« Reply #1 on: September 29, 2017, 13:20:47 »
I am having trouble rendering text, what is wrong with my method? ??? ??? ???

Everything, except the first two lines maybe. :)

See the EasyFont demo in the lwjgl3 repository for a working example.

*

Offline GiantNuker

  • *
  • 4
  • I am new to LWJGL and I probably need help
Re: LWJGL 3 STBEasyFont help
« Reply #2 on: September 29, 2017, 17:35:04 »
I am having trouble rendering text, what is wrong with my method? ??? ??? ???

Everything, except the first two lines maybe. :)

See the EasyFont demo in the lwjgl3 repository for a working example.

New Problem: Now parts of text don't show, and are in weird positions.Problem is, based on where it is set to render, it renders in a position that is a multiple(I think), but ONLY when scale is more than 1.0 and the position is more than (0, 0), the offset increases more the farther out you go.

Code: [Select]
public static void drawString(String text, ScreenPos2D pos, double scale) {
ByteBuffer charBuffer = BufferUtils.createByteBuffer(text.length() * 270);

        int quads = stb_easy_font_print((float)pos.x, (float)pos.y, text, 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

        //glfwPollEvents();

        //glClear(GL_COLOR_BUFFER_BIT);

        glPushMatrix();
        // Zoom
        glScaled(scale, scale, 1f);
        // Scroll
        glTranslatef(4.0f, 4.0f - 0/*getLineOffset()*/ * STBEasyFont.stb_easy_font_height(text), 0f);

        glDrawArrays(GL_QUADS, 0, quads * 4);

        glPopMatrix();

glDisableClientState(GL_VERTEX_ARRAY);
}
« Last Edit: September 29, 2017, 22:04:14 by GiantNuker »
I am new to LWJGL and I probably need help. ???

Please help me! :)

*

Offline GiantNuker

  • *
  • 4
  • I am new to LWJGL and I probably need help
Re: LWJGL 3 text positioning help
« Reply #3 on: September 29, 2017, 23:08:07 »
And how do I use STBTruetype?

I'm not getting anything from the demo.
I am new to LWJGL and I probably need help. ???

Please help me! :)

*

Offline spasi

  • *****
  • 2258
    • WebHotelier
Re: LWJGL 3 STBEasyFont help
« Reply #4 on: October 01, 2017, 16:27:50 »
Problem is, based on where it is set to render, it renders in a position that is a multiple(I think), but ONLY when scale is more than 1.0 and the position is more than (0, 0), the offset increases more the farther out you go.

That's because the EasyFont demo scales the entire viewport. If you'd like to change the font size instead, do the translation first and then the glScale.

And how do I use STBTruetype?

See the corresponding demo.