PDA

View Full Version : Why canīt I print a GL_POINTS?



marce
07-09-2009, 04:09 PM
I am trying to print a point using GL_POINTS, but the point is not beeing printed.

When I try to output a GL_QUAD, then it works, but not GL_POINTS. What am a doing wrong?

The reshape() method contains these two lines:

...
gl.glLoadIdentity();
glu.gluOrtho2D(0.0, 500.0, 0.0, 300.0);

my display() function contains this:

GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();

gl.glColor3f(1.5f, 1.5f, 1.5f);
gl.glPointSize(5.0f);
gl.glBegin(GL.GL_POINTS);
gl.glVertex2i(20, 150);
gl.glEnd();

Have I missed something?

ZbuffeR
07-10-2009, 05:44 AM
gl.glPointSize(5.0f); -> try without point size, check you see a normal 1 pixel point.
beware from the screen edges, points are clipped before being sized, so stay far from the edges.

marce
07-10-2009, 06:00 AM
I have tested that but it still doesnīt work.

Here is the whole code. It works with QUADS but not with POINTS. No point is beeing printed.

Can you see any error in the code?


import com.sun.opengl.util.Animator;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.*;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;


public class SimpleJOGL implements GLEventListener {


static Frame frame;

public static void main(String[] args) {
frame = new Frame("OpenGL Application");
GLCanvas canvas = new GLCanvas();

canvas.addGLEventListener(new SimpleJOGL());
frame.add(canvas);
frame.setSize(640, 480);

final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {

public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
// Center frame
frame.setLocationRelativeTo(null);
frame.setVisible(true);
animator.start();
canvas.requestFocus();
}

public void init(GLAutoDrawable drawable) {
// Use debug pipeline
// drawable.setGL(new DebugGL(drawable.getGL()));

GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClear(GL.GL_DEPTH_BUFFER_BIT);

System.err.println("INIT GL IS: " + gl.getClass().getName());

// Enable VSync
gl.setSwapInterval(1);

// Setup the drawing area and shading mode
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glShadeModel(GL.GL_SMOOTH); // try setting this to GL_FLAT and see what happens.
drawable.addKeyListener(new KeyListener());

}

public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
GL gl = drawable.getGL();
GLU glu = new GLU();

if (height <= 0) { // avoid a divide by zero error!

height = 1;
}
final float h = (float) width / (float) height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glMatrixMode(GL.GL_MODELVIEW);

gl.glLoadIdentity();
glu.gluOrtho2D(0.0, 500.0, 0.0, 300.0);


}

public void display(GLAutoDrawable drawable) {

GL gl = drawable.getGL();

// Clear the drawing area
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
// Reset the current matrix to the "identity"
gl.glLoadIdentity();

gl.glColor3f(1.5f, 1.5f, 1.5f);
gl.glPointSize(50.0f);
gl.glBegin(GL.GL_POINTS);
gl.glVertex2i(20, 150);
gl.glEnd();


// Flush all drawing operations to the graphics card
gl.glFlush();
}

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

private class KeyListener extends KeyAdapter
{
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode() == KeyEvent.VK_ESCAPE)
{
System.exit(0);
}
}



}