Hello Guest

Display Text, Transform coordinates and more..

  • 8 Replies
  • 12057 Views
Display Text, Transform coordinates and more..
« on: November 10, 2005, 12:45:22 »
I am new to OpenGL and I'm really lost in space. I would like to use LWJGL but it's hard to understand.

Why is there no wrapper library for the OpenGL Bindings. I find it
very masochistic to program pure OpenGL (like glvertexf, glMatrix, ...)??

I figured out how to init a GLContext on a SWT Display and to draw
lines but:
- I couldn't figure out how to display 2D text in a specific font and rotate it.
- How to transform a screen coordinate to a OpenGL coordinate.

Regards
Michael

*

Offline hvor

  • *
  • 37
    • http://hvor.madpage.com
Display Text, Transform coordinates and more..
« Reply #1 on: November 10, 2005, 13:18:41 »
You should really try the NEHE tutorials, they covered lost of aspects of openGL programming, and most tutorials are ported to LWJGL (see the bottom of pages). Orto mode for drawing text included ;)

http://nehe.gamedev.net/lesson.asp?index=01

*

Offline napier

  • ***
  • 104
    • http://potatoland.org
Display Text, Transform coordinates and more..
« Reply #2 on: November 10, 2005, 16:36:28 »
There's a learning curve to OpenGL and LWJGL, but it's well worth the effort.  

As for text drawing, there are two threads in this forum that may help:

http://www.lwjgl.org/forum/viewtopic.php?t=895
http://www.lwjgl.org/forum/viewtopic.php?t=711

and to transform screen coordinates to a 3D world coords, you need to look at GLU.unproject().  I have utility functions that wrap this here:

http://potatoland.org/code/gl/GLApp.java

Look for "unproject"

and for demos that use these functions:  http://potatoland.org/code/gl
penGL/Java/LWJGL demos and code: http://potatoland.org/code/gl

Display Text, Transform coordinates and more..
« Reply #3 on: November 11, 2005, 13:22:47 »
I had a look at the examples but I was not able to transform the code to my needs. I don't need all the 3D Stuff. All I wanna do is drawing a 2D text in an arbitrary angle and using display coordinates of SWT.
(Like in Sun's 2D-Library).

Example:
/**
 * Print a outline text at screen (display) position x, y
 * This must be an outline text, so I can rotate it!!
 */
glDrawText(int x, int y, String text);

It seems to me, that drawing 3D-Objects is much easier than drawing a simple text!!

Michael

Display Text, Transform coordinates and more..
« Reply #4 on: November 11, 2005, 15:31:02 »
Try this one:

http://www.lwjgl.org/forum/viewtopic.php?t=1258

I tried to make it as simple as possible. You'll also need the Objects posted near the end of the thread.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

*

Offline napier

  • ***
  • 104
    • http://potatoland.org
Display Text, Transform coordinates and more..
« Reply #5 on: November 11, 2005, 15:49:44 »
If you want to address the screen using pixel coordinates you'll need to look into Ortho mode.  This flattens out the perspective so you have a coordinate system that exactly matches the screen pixel for pixel.

in GLApp.java the glPrint() function calls setOrthoOn, which switches to Ortho mode.  glTranslate() moves to the screen location where the text will be drawn.  You can then call glRotate to rotate the text around the Z axis.  Here's a snip of code from the glPrint() function with a glRotate call added:

 
Code: [Select]
           // enable the charset texture
             GL11.glBindTexture(GL11.GL_TEXTURE_2D, fontTextureHandle);
             // prepare to render in 2D
             setOrthoOn();
             // Position The Text (in pixels coords)
             GL11.glTranslatef(x, y, 0);  
             // Rotate 45 degrees around Z axis
             GL11.glRotatef(45, 0,0,1);  
             // draw the characters
             for(int i=0; i<msg.length(); i++) {  
                 GL11.glCallList(offset + msg.charAt(i));
             }
             // restore the original positions and views
             setOrthoOff();



You're right though, OpenGL is designed for drawing 3D shapes, not text, so you've started with one of the trickier areas.
penGL/Java/LWJGL demos and code: http://potatoland.org/code/gl

Display Text, Transform coordinates and more..
« Reply #6 on: November 13, 2005, 21:18:57 »
@napier
The hint with the glOrtho() was very usefull. Thanks.

@elias4444
I tried to print text with the FontTranslator class.
All I get is a filled rectangle but no text!
I used the windows font file arial.ttf (C:\Windows\Fonts).
Do I have to use a special font file or is there a OpenGL
setting missing?

Display Text, Transform coordinates and more..
« Reply #7 on: November 13, 2005, 21:39:50 »
I found the problem myself. GL_TEXTURE_2D was not enabled..

*

Offline hvor

  • *
  • 37
    • http://hvor.madpage.com
Re: Display Text, Transform coordinates and more..
« Reply #8 on: November 25, 2005, 09:06:54 »
Quote from: "mimhof"

Why is there no wrapper library for the OpenGL Bindings. I find it
very masochistic to program pure OpenGL (like glvertexf, glMatrix, ...)??
Michael

I just want to encourage you more. I begun with 3d programming in Java3d. Pretty sucessful, but after a while, you feel like something is missing. Funny parts are hiden to you. With LWJGL (openGL) you can do DIRECTLY whatever you want, and that is why i like it so much now ;)