PDA

View Full Version : text on new line ?



sonnik
04-07-2009, 08:13 AM
I have a couple of queries/difficulties...
1) I have been able to print text on the face of my cubes using textures and glCopyTexImage. But I want to be able to write text in different lines...for e.g. HELLO
WORLD
i want to split the text in different lines. How to do that?
Currently my text is always displayed only at the bottom of the cube and the string gets clipped if its too long.
Is there any way to print the long strings in separate lines and also be able to move them anywhere on the face?

CODE:

public void init(GLAutoDrawable drawable)
{
GL gl = drawable.getGL();
glut = new GLUT();

gl.glClearDepth( 1.0f );
gl.glClear( gl.GL_DEPTH_BUFFER_BIT );
gl.glEnable( gl.GL_DEPTH_TEST );
gl.glDepthFunc( gl.GL_LEQUAL );


gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
gl.glClear(gl.GL_COLOR_BUFFER_BIT);
gl.glShadeModel(GL.GL_SMOOTH);

gl.glEnable(GL.GL_TEXTURE_2D);
texture = genTexture(gl);
gl.glBindTexture(GL.GL_TEXTURE_2D, texture);

gl.glColor4f(1.0f,1.0f,1.0f,1.0f);
glut.glutBitmapString(GLUT.BITMAP_TIMES_ROMAN_24, "TEXT 1");

glut.glutBitmapString(GLUT.BITMAP_TIMES_ROMAN_24, "THIS TEXT on next line");

gl.glCopyTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, 0, 0, 128, 128, 0);
gl.glClearColor(0.0f, 1.0f, 1.0f, 0.0f);

gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);

}

ephtracy
04-08-2009, 07:24 AM
may use 'glRasterPos2i' to change the start point of your text

sonnik
04-08-2009, 08:32 AM
I did try that earlier but when I copy the text on the texture to put it on my cube, it does not work.

ephtracy
04-09-2009, 09:25 AM
if the text you are using are bitmaps, 'glRasterPos2i' should have worked.
or you may use 'glTranslatef' to reach your goal;

i suggest you draw the text first on the screen before copying it to texture, so you can see if your codes draw the texts as you expected.