public class Main extends JFrame {
GLJPanel panel;
public Main() {
this.setBounds(100, 100, 500, 500);
JP jp = new JP();
getContentPane().add(jp);
jp.addGLEventListener(new DrawListener());
setVisible(true);
}
class JP extends GLJPanel {
public JP() {
super(new GLCapabilities());
this.setSize(500,500);
}
public void paintComponent(Graphics g) {
//g.setColor(new Color(0xFFFFFF));
g.drawString("some words", 30, 30);
}
}
public static void main(String[] args) {
Main m = new Main();
}
}
class DrawListener implements GLEventListener {
public void init(GLAutoDrawable gld) {
GL gl = gld.getGL();
GLU glu = new GLU();
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.glViewport(0, 0, 500, 300);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluOrtho2D(0.0, 500.0, 0.0, 300.0);
}
public void display(GLAutoDrawable drawable) {
float red = 0.0f;
float green = 0.0f;
float blue = 0.0f;
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glPointSize(5.0f);
for (int i = 0; i < 50; i++) {
red -= .09f;
green -= .12f;
blue -= .15f;
if (red < 0.15)
red = 1.0f;
if (green < 0.15)
green = 1.0f;
if (blue < 0.15)
blue = 1.0f;
gl.glColor3f(red, green, blue);
gl.glBegin(GL.GL_POINTS);
gl.glVertex2i((i * 10), 150);
gl.glEnd();
}
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged,
boolean deviceChanged) {
}
}
Please help me and let me understand what’s the correctly code structure, as the above code, it doesn’t work on drawing string and rendering 3D together. if I eliminate draw string, then render 3D is well.
I have no idea why.
thanks in advance.