4 Replies Latest reply: Mar 12, 2010 2:12 AM by 843853 RSS

    no primitive is displayed on canvas

    843853
      I am using jogl to draw primitives to a canvas which I added to the content pane of a JFrame. The JFrame gets displayed but no primitive is drawn on th canvas. Here is the source code
      import java.awt.*;
      import java.awt.color.*;
      import java.awt.event.*;
      // Needed for ByteBuffers
      import java.nio.*;
      
      // The main JOGL import
      import net.java.games.jogl.*;
      
      // Needed for special type of empty ByteBuffer
      // used of Vertex Buffer Objects
      import net.java.games.jogl.util.*;
      
      
      public class Winta implements GLEventListener
      {
      
      
           Winta()    // sorry for using the name of my gf as a class name
           {                     
                Frame frame =  new Frame("GL TRial");
                GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
                canvas.addGLEventListener(this);
                frame.setSize(500, 400);
                frame.addWindowListener(new WindowAdapter()
                {
                     public void windowClosing(WindowEvent e)
                     {                    
                          System.exit(0);
                     }
                });
                frame.setBackground(Color.red);
           
                frame.add(canvas, BorderLayout.CENTER);
           
                frame.setVisible(true);
      
           }
      
           public static void main(String[] args)
           {
                new Winta();
      
           }
      
      
           public void display(GLDrawable drawable)
           {
                GL gl = drawable.getGL();
                GLU glu = drawable.getGLU();
                //gl.glClearColor(0f, 0f, 0f, 0f);
                gl.glColor3f(0, 0, 0);
                //gl.glClear(GL.GL_COLOR_BUFFER_BIT);
      
                drawSomeLines(gl);
           }
      
           public void displayChanged(GLDrawable gLDrawable, boolean modeChanged, boolean deviceChanged)
           {
           }
      
           public void init(GLDrawable drawable)
           {
                GL gl = drawable.getGL();
                //gl.glClearColor(0f, 0f, 0f, 1f); // Black Background
                gl.glColor3f(1f, 1, 1);
                gl.glPointSize(4.0f);
      
           }
           
           public void reshape(GLDrawable gLDrawable, int x, int y, int width, int height)
      
           {
           
           }
                
           protected void drawSomeLines(GL gl)
           {
                gl.glBegin(GL.GL_LINE_LOOP);
                     //gl.glColor3f(0f, 0f, 0.0f); 
                     gl.glVertex2f(50, 300);
                     gl.glVertex2f(75, 450);
                     gl.glVertex2f(60, 310);
                     gl.glVertex2f(85, 460);               
                gl.glEnd();
                gl.glFlush();
           }
      }
                
      well, you may see some lines of code that I commented out. It means I was desperately trying each combination.

      I have set the back ground of the frame to 'red' just to see what is going on. As it turns out, I see the red frame for a fraction of a second it then becomes black with no line or what so ever.

      Thanks in advance for your help.