Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need 3d text support similar to glutBitmapString #4

Closed
jzy3d opened this issue Nov 25, 2020 · 1 comment
Closed

Need 3d text support similar to glutBitmapString #4

jzy3d opened this issue Nov 25, 2020 · 1 comment

Comments

@jzy3d
Copy link
Owner

jzy3d commented Nov 25, 2020

No description provided.

@jzy3d
Copy link
Owner Author

jzy3d commented Nov 25, 2020

Available as of 2.5, based on AWT drawString method, which is applied on top of the image containing the complete OpenGL scene. This is hence not a real OpenGL implementation of text management, but it provides a simple an easy way to quickly draw text with a larger font support than the one provided by OpenGL1.

See these two new methods in GLUT

/**
   * Print string at the specified 2d position.
   * 
   * This method is not following exactly the GLUT interface. 
   * Printing text in OpenGL usually requires such code :
   * 
   * <pre><code>
   * gl.glColor3f(r, g, b);
   * gl.glRasterPos3f(x, y, z);
   * glut.glutBitmapString(font, string);
   * </code></pre>
   * 
   * In our case, one need to first perform model-to-screen projection to get
   * x,y coordinates, and then call glutBitmapString. 
   * 
   * @see {@link #glutBitmapString(Font, String, float, float, float, float, float, float) to avoid doing the model-to-screen projection.
   */
  public void glutBitmapString(Font font, String string, float x, float y) {
	  JavaGL.appendTextToDraw(font, string, (int)x, (int)y);
  }
  
  /**
   * Print string at the specified 3d position.
   * 
   * This method is not following exactly the GLUT interface. 
   * Printing text in OpenGL usually requires such code :
   * 
   * <pre><code>
   * gl.glColor3f(r, g, b);
   * gl.glRasterPos3f(x, y, z);
   * glut.glutBitmapString(int font, string);
   * </code></pre>
   * 
   * Here we provide a convenient function that does all in one pass
   * <pre><code>
   * glut.glutBitmapString(java.awt.Font, java.lang.String, x, y, z, r, g, b);
   * </code></pre>
   * 
   * Behind the scene it makes the model-to-screen conversion and then
   * provide all data to {@link GL#appendTextToDraw(Font, String, int, int, float, float, float)}
   * that will handle the text rendering in {@link GL#glFlush()}
   */
  public void glutBitmapString(Font font, String string, float x, float y, float z, float r, float g, float b) {
	  double[] win = modelToScreen(x, y, z);
	  
	  double winX = win[0];
	  double winY = JavaGL.Context.Viewport.Height - win[1];
	  
	  JavaGL.appendTextToDraw(font, string, (int)winX, (int)winY, r, g, b);
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant