Hi,
I have a couple of queries/difficulties…
-
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?
-
Can I make the display function independent of the other graphics code?
-
Can I make the glTranslate and gl Rotate functions dynamic to take random co-ordinates during run time?
Below is my init() and display() methods:
public void init(GLAutoDrawable drawable)
{
GL gl = drawable.getGL();
glut = new GLUT();
gl.glShadeModel(GL.GL_SMOOTH);
gl.glClearColor(0.8f, 0.7f, 0.5f, 0.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
gl.glEnable(GL.GL_TEXTURE_2D);
texture = genTexture(gl);
gl.glBindTexture(GL.GL_TEXTURE_2D, texture);
// gl.glRasterPos2f
glut.glutBitmapString(GLUT.BITMAP_TIMES_ROMAN_24, “MY TEXT”);
gl.glCopyTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, -1, 0, 128, 128, 0);
gl.glClearColor(0.0f, 0.0f, 0.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);
}
public void display(GLAutoDrawable drawable)
{
GL gl = drawable.getGL();
GLU glu = new GLU();
GLUT glut = new GLUT();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glEnable(GL.GL_CULL_FACE);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, -3.0f, -19.0f); // Translate Into The Screen along z axis 12.0 Units
gl.glRotatef(rotqube/5,0.0f,1.0f,0.0f); // Rotate The cube around the Y axis
//gl.glRotatef(180, 0.0f,1.0f,0.0f);
gl.glScalef(1.0f, 1.0f, 1.0f); // CHANGE TO SEE THE DIAGRAM PROPER !!!
Drawcube(drawable); // Lower left class – derived class1
DrawDivideLines(drawable);
gl.glBegin(GL.GL_LINES);
//gl.glColor4f(1.0f,1.0f,1.0f,1);
gl.glVertex3f(0,2,0); // line connecting inherited class
gl.glVertex3f(0,9,0);
gl.glEnd();
gl.glBegin(GL.GL_TRIANGLES);
gl.glColor4f(0.0f,0.0f,1.0f,1);
gl.glVertex3f(0.3f,9,0);
gl.glVertex3f(-0.3f,9,0);
gl.glVertex3f(0,10,0);
gl.glEnd();
gl.glTranslatef(0.0f,12.0f,0.0f);
Drawcube(drawable); // Upper Left class – super class
DrawDivideLines(drawable);
gl.glTranslatef(-2.36f,0.0f,0.0f); // translate outside the cube to draw diamond shape
gl.glRotatef(45,0.0f,0.0f,1.0f); // rotate to make the cube look like a diamond
Drawsmallcube(drawable); // draw diamond
gl.glRotatef(-45,0.0f,0.0f,1.0f); // rotate to come back to original position
gl.glTranslatef(-0.35f,0.0f,0.0f); // come to the lower tip of the diamond
gl.glBegin(GL.GL_LINES);
//gl.glColor3f(1.0f,1.0f,1.0f);
gl.glVertex3f(0,0,0);
gl.glVertex3f(-3,0,0);
gl.glEnd();
gl.glTranslatef(-5.0f,0.0f,0.0f);
Drawcube(drawable); // Upper right class
DrawDivideLines(drawable);
gl.glTranslatef(0.0f,-12.0f,0.0f);
Drawcube(drawable); // Lower right class
DrawDivideLines(drawable);
gl.glEnable (GL.GL_LINE_STIPPLE);
gl.glLineStipple(1,(short) 170);
gl.glBegin(GL.GL_LINES);
//gl.glColor3f(1.0f,1.0f,1.0f);
gl.glVertex3f(0,2,0); // vertical line from lower right cube(inheritance)
gl.glVertex3f(0,5,0);
gl.glEnd();
gl.glBegin(GL.GL_LINES);
//gl.glColor3f(1.0f,1.0f,1.0f);
gl.glVertex3f(0,5,0); // horizontal line from lower right cube (inheritance)
gl.glVertex3f(6.5f,5,0);
gl.glEnd();
gl.glBegin(GL.GL_LINES);
//gl.glColor3f(1.0f,1.0f,1.0f);
gl.glVertex3f(6.5f,5,0); // horizontal line from lower right cube (inheritance)
gl.glVertex3f(6.5f,9,0);
gl.glEnd();
gl.glDisable(GL.GL_LINE_STIPPLE);
gl.glTranslatef(6.5f,0.0f,0.0f);
gl.glBegin(GL.GL_TRIANGLES);
gl.glColor3f(0.0f,0.0f,1.0f);
gl.glVertex3f(0.3f,9,0);
gl.glVertex3f(-0.3f,9,0);
gl.glVertex3f(0,10,0);
gl.glEnd();
gl.glTranslatef(-6.5f,12.0f,8.0f);
Drawcube(drawable);
DrawDivideLines(drawable);
gl.glBegin(GL.GL_LINES);
//gl.glColor3f(1.0f,1.0f,1.0f);
gl.glVertex3f(0,0,-2);
gl.glVertex3f(0,0,-6);
gl.glEnd();
rotqube++;
if (rotqube/30 >= 360.f)
rotqube = 0.0f;
}
PLEASE HELP!!