LWJGL 3 text positioning help

Started by GiantNuker, September 28, 2017, 23:50:17

Previous topic - Next topic

GiantNuker

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
I am new to LWJGL and I probably need help. ???

Please help me! :)

spasi

Quote from: GiantNuker on September 28, 2017, 23:50:17I 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.

GiantNuker

Quote from: spasi on September 29, 2017, 13:20:47
Quote from: GiantNuker on September 28, 2017, 23:50:17I 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.

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);
	}
I am new to LWJGL and I probably need help. ???

Please help me! :)

GiantNuker

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! :)

spasi

Quote from: GiantNuker on September 29, 2017, 17:35:04Problem 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.

Quote from: GiantNuker on September 29, 2017, 23:08:07And how do I use STBTruetype?

See the corresponding demo.