I created a small test app to see if I wanted to start using JOGL and for some reason my cube and triangle are red. Even if specify a color for them, they stay red. I am wondering if I am doing something wrong.
package com.gthought.swing.gl;
import net.java.games.jogl.*;
import javax.swing.*;
import java.awt.*;
public class JOGLTest extends JFrame
{
public JOGLTest()
{
super("JOGL Test");
this.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas( new GLCapabilities());
canvas.addGLEventListener( new MyCanvas());
this.getContentPane().setLayout( new BorderLayout());
this.getContentPane().add( canvas, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
JButton button1 = new JButton("Add");
buttonPanel.setLayout( new FlowLayout(FlowLayout.LEADING) );
buttonPanel.add(button1);
this.getContentPane().add( buttonPanel, BorderLayout.SOUTH);
this.setBounds( 5, 5, 640, 480);
}
public static void main(String[] args)
{
new JOGLTest().setVisible( true );
}
class MyCanvas implements GLEventListener
{
public void display(GLDrawable glDraw)
{
GL gl = glDraw.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(-1.5f,0.0f,-6.0f);
gl.glBegin(GL.GL_TRIANGLES);
gl.glVertex3f( 0.0f, 1.0f, 0.0f);
gl.glVertex3f(-1.0f,-1.0f, 0.0f);
gl.glVertex3f( 1.0f,-1.0f, 0.0f);
gl.glEnd();
gl.glTranslatef(3.0f,0.0f,0.0f);
gl.glBegin(GL.GL_QUADS);
gl.glVertex3f(-1.0f, 1.0f, 0.0f);
gl.glVertex3f( 1.0f, 1.0f, 0.0f);
gl.glVertex3f( 1.0f,-1.0f, 0.0f);
gl.glVertex3f(-1.0f,-1.0f, 0.0f);
gl.glEnd();
}
public void init(GLDrawable glDraw)
{
GL gl = glDraw.getGL();
gl.glShadeModel(GL.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClearDepth(1.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
}
public void reshape(GLDrawable glDraw, int x, int y, int w, int h)
{
GL gl = glDraw.getGL();
GLU glu = glDraw.getGLU();
gl.glViewport ( 0, 0, w, h );
gl.glMatrixMode ( GL.GL_PROJECTION );
gl.glLoadIdentity ( );
if ( h==0 )
{
glu.gluPerspective ( 80, ( float ) w, 1.0, 5000.0 );
}
else
{
glu.gluPerspective ( 80, ( float ) w / ( float ) h, 1.0, 5000.0 );
}
gl.glMatrixMode ( GL.GL_MODELVIEW );
gl.glLoadIdentity ( );
}
public void displayChanged(GLDrawable glDraw, boolean modeChanged, boolean deviceChanged) {}
}
}
Thanks for any help.