As a continuation from my previous thread, i managed to get the time to have another look over it. So I started trimming it down to a bare minimum, and i’ve got to the point where it looks nigh on identical to the Gear demo, yet it still doesn’t render ???
If i add a mismatched .glBegin() at the bottom of the draw() method, it will render. Also, if i do this to make it render the lines, then they will shift and duplicate if the window is dragged around Anyone see my (probably basic) mistake?
package testPackage;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import net.java.games.jogl.*;
/**
* Vectrix
*
* @author John
*/
public class Vectrix implements GLEventListener
{
public static final Vectrix app = new Vectrix();
private Frame frame;
// private MouseHandler mouseHandler;
private Animator animator;
private GLCanvas canvas;
/**
*
*/
private Vectrix()
{
System.out.println("Vectrix instance created");
// Canvas setup
GLCapabilities caps = new GLCapabilities();
caps.setDoubleBuffered(true);
caps.setAlphaBits(8);
caps.setStencilBits(8);
canvas = GLDrawableFactory.getFactory().createGLCanvas(caps);
canvas.addGLEventListener(this);
// Frame setup
frame = new Frame("Vectrix");
frame.add(canvas);
frame.setSize(800, 600);
frame.addWindowListener( new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
animator.stop();
System.exit(0);
}
}
);
// Event handlers
animator = new Animator(canvas);
// mouseHandler = new MouseHandler();
// frame.addMouseListener(mouseHandler);
}
public void initialiseDisplay()
{
frame.show();
}
public void run()
{
animator.start();
}
public static void main(String[] args)
{
System.out.println("Vectrix starting...");
app.initialiseDisplay();
// Other loading/initialisation
// ..
// Start main game loop
app.run();
}
// GL Event Listener methods
// Called when GL has been initialised for the first time.
public void init(GLDrawable canvas)
{
System.out.println("Vectrix.init(): GL init event");
GL gl = canvas.getGL();
gl.glMatrixMode(GL.GL_PROJECTION_MATRIX);
gl.glLoadIdentity();
gl.glMatrixMode(GL.GL_TEXTURE);
gl.glLoadIdentity();
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
// gl.glFrontFace(GL.GL_CCW);
// gl.glEnable(GL.GL_CULL_FACE);
// gl.glEnable(GL.GL_DEPTH_TEST);
}
public void display(GLDrawable canvas)
{
GL gl = canvas.getGL();
GLU glu = canvas.getGLU();
gl.glClearColor(0.2f, 0.2f, 0.2f, 0.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);
// l/r t/b near/far
gl.glOrtho(0, 4, 0, 3, -8, 8);
// animate..
gl.glPushMatrix();
{
gl.glBegin(GL.GL_LINES);
{
int xMin = 0;
int xMax = 10;
gl.glColor3f(1f, 0f, 0f);
for (int x=xMin; x<=xMax; x++)
{
gl.glVertex3f(x, -1, 0f);
gl.glVertex3f(x, +1, 0f);
}
gl.glVertex3f(0f, 0f, 0f);
gl.glVertex3f(4f, 4f, 4f);
}
gl.glEnd();
}
gl.glPopMatrix();
gl.glBegin(GL.GL_LINES);// Mismatched begin causes drawing to work!
// gl.glEnd();
}
public void reshape(GLDrawable arg0, int arg1, int arg2, int arg3, int arg4)
{
}
public void displayChanged(GLDrawable arg0, boolean arg1, boolean arg2)
{
}
}
Thanks