problem overlay Java2D on jogl Canvas

classic Classic list List threaded Threaded
2 messages Options
jak
Reply | Threaded
Open this post in threaded view
|

problem overlay Java2D on jogl Canvas

jak
Hi, I have a problem. I want to overlay on a triangle a java2d text or something to draw, but now it isn't work. Here is my code:

public final class myclass extends otherclass implements GLEventListener{
 
  private final Color TRANSPARENT_BLACK = new Color(0.0f, 0.0f, 0.0f, 0.0f);
  private Overlay overlay;
  // World view.
  private GLCanvas world;
 
  @Override
  public void init(GLAutoDrawable drawable)
  {
    // TODO Auto-generated method stub
    final GL2 gl = drawable.getGL().getGL2();
    this.overlay = new Overlay(drawable);
   
  }
  @Override
  public void dispose(GLAutoDrawable drawable)
  {
    // TODO Auto-generated method stub
    this.overlay = null;
  }
  @Override
  public void display(GLAutoDrawable drawable){
 
    final GL2 gl = drawable.getGL().getGL2();
    Graphics2D g2d = this.overlay.createGraphics();
   
    gl.glLoadIdentity();
    gl.glTranslatef(-1.5f,0.0f,-6.0f);
    gl.glBegin(GL2.GL_TRIANGLES);
    gl.glColor3f(0,1,1);
    gl.glVertex3f(0.0f,1.0f,0.0f);
    gl.glColor3f(0,1,0);
    gl.glVertex3f(-1.0f, -1.0f, 0.0f);
    gl.glColor3f(1,1,0);
    gl.glVertex3f(1.0f,-1.0f,0.0f);  
    gl.glFlush();
   
 
    g2d.setColor(Color.RED);
    g2d.setComposite(AlphaComposite.Src);
    g2d.drawString("something", 25, 120);
    g2d.fillRect(30, 20, 50, 50);
    this.overlay.drawAll();
    g2d.dispose();
  }
  @Override
  public void reshape(GLAutoDrawable drawable, int x, int y, int width,
      int height)
  {
    // TODO Auto-generated method stub
    final GL2 gl = drawable.getGL().getGL2();
    /*
    if(height<=0) height = 1;
    final float h = (float) width/(float)height;
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    this.glu.gluPerspective(45.0f,h,1.0,20.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
    */
  }
public static void main(String[] args){
  int windowSize = 600;
  final JFrame frame = new JFrame ("my jogl pj");
 
  GLCapabilities capabilities = new GLCapabilities (null);  
  final GLCanvas glcanvas = new GLCanvas(capabilities);
 
  myclass r = new myclass();
  glcanvas.addGLEventListener(r);
  glcanvas.setSize(600,600);

  frame.setSize(windowSize, windowSize);
  frame.add(glcanvas);
  myclass myobj = new myclass();
  final Animator animator = new Animator(glcanvas);
 
  frame.addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosing(WindowEvent e) {
        new Thread(new Runnable() {
            @Override
            public void run() {
              animator.stop();
              System.exit(0);
            }
          }).start();
      }
    });
  frame.setVisible(true);
  animator.start();
 }//-- fine main

}
Reply | Threaded
Open this post in threaded view
|

Re: problem overlay Java2D on jogl Canvas

gouessej
Administrator
Hi

Rather use JOGL build-in text renderers or any third party libraries supporting text rendering.
Julien Gouesse | Personal blog | Website