gray output

hi y’all

Everything is set up and everything works, but when I execute my code all I get is a gray screen, allthough no errors were given and my code seems right…

(here is my code)

public class probeersel extends JFrame {

/** Creates a new instance of probeersel */
public probeersel() {

super(“JOGL-probeersel”);

// Move to here:
setSize(800, 600);
//centerWindow(this);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

GLCapabilities caps = new GLCapabilities();
caps.setDoubleBuffered(true);
caps.setHardwareAccelerated(true);

GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(caps);
canvas.addGLEventListener(new tekening3D());

// Not needed:
canvas.setSize(800, 600);

getContentPane().add(canvas, BorderLayout.CENTER);

}    

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    
    probeersel app = new probeersel();

    //show what we've done
    app.setVisible(true);

    
}

}

class tekening3D implements GLEventListener {

public void init(GLDrawable drawable) {

    GL gl = drawable.getGL();
    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    gl.glColor3i(0, 0, 0);
    gl.glPointSize(4.0f);
    
}

public void display(GLDrawable drawable) {
    
    GL gl = drawable.getGL();     
    gl.glBegin( GL.GL_LINES );
    gl.glVertex2i(50, 200);
    gl.glVertex2i(75, 250);
    gl.glVertex2i(60, 200);
    gl.glVertex2i(85, 250);
    gl.glEnd();
    
}

public void reshape(GLDrawable drawable, int x, int y, int width, int height) {}

public void displayChanged(GLDrawable drawable,
                       boolean modeChanged,
                       boolean deviceChanged) {}

}

Hi,

Change your display() method in tekening3D to something like

public void display(GLDrawable drawable) { 
  GL gl = drawable.getGL();      
  gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);
  gl.glBegin( GL.GL_LINES ); 
  gl.glVertex2i(0, 0); 
  gl.glVertex2i(1, 1); 
  gl.glVertex2i(0, 1); 
  gl.glVertex2i(1, 0); 
  gl.glEnd(); 
} 

and you will see the difference.

Yuri

Thanks for your help Yuri

I got rid of the gray background thing, now the next issue is that nothing appears on that nice white background. Whatever I try to draw on it, nothing appears on the screen except for a white canvas…

thanks in advance!

public class probeersel extends JFrame {

/** Creates a new instance of probeersel */
public probeersel() {

super(“JOGL-probeersel”);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

GLCapabilities caps = new GLCapabilities();
caps.setDoubleBuffered(true);
caps.setHardwareAccelerated(true);

GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(caps);
canvas.addGLEventListener(new tekening3D());

// Not needed:
canvas.setSize(800, 600);

getContentPane().add(canvas, BorderLayout.CENTER);
setSize(800, 600);

}    

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    
    probeersel app = new probeersel();

    //show what we've done
    app.setVisible(true);

    
}

}

class tekening3D implements GLEventListener {

public void init(GLDrawable drawable) {

    GL gl = drawable.getGL();
    gl.glMatrixMode( GL.GL_PROJECTION );
    gl.glLoadIdentity();
    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    gl.glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
    gl.glColor3i(0, 0, 0);
    gl.glPointSize(4.0f);
    
}

public void display(GLDrawable drawable) {
    
    GL gl = drawable.getGL();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);
    gl.glBegin( GL.GL_TRIANGLES );
    gl.glVertex2i(50, 200);
    gl.glVertex2i(75, 250);
    gl.glVertex2i(60, 200);
    gl.glEnd();
    gl.glFlush();
    
}

public void reshape(GLDrawable drawable, int x, int y, int width, int height) {}

public void displayChanged(GLDrawable drawable,
                       boolean modeChanged,
                       boolean deviceChanged) {}

}

A quick look over suggests you’re drawing totally off screen. Stick in your screen width and height for glOrtho if you want to draw with pixel values. Something like:
glOrtho(0, 800, 0, 600, -1, 1);
(disclaimer: order of parameters may vary, check your documentation. May contain nuts.)

Hi,

[quote]you’re drawing totally off screen.
[/quote]
…and if you have copied my code of suggested display method, you would see nice diagonal lines crossing upper right quarter of the canvas.

Anyway, Orangy Tang is right - you have to set up your projection and model-view matrices and take care of the coordinate system you are specifying vertices in.

Yuri

thank you guys for all your help, I’m off developing my openGL skills ;D