From: Danny Y. <on...@ya...> - 2003-02-20 06:26:30
|
I've been going through the tutorials in the Red book, and everything works great under GL4Java, but now I'm stuck on Vertex Arrays. I've been trying to use glArrayElement and glDrawElements, but I can't see anything on my GLAnimCanvas. (Oh, by the way, does anyone know where to get the source code for the Red book.the ftp site listed in the cover doesn't work.) Here's the code below: import gl4java.*; import gl4java.drawable.*; import gl4java.utils.glut.*; public class VertexArray implements GLEventListener { private GLFunc gl; private GLUFunc glu; private GLContext glj; private GLDrawable gldrawable; private GLUTFunc glut; static int[] vertices = { 25, 25, 100, 325, 175, 25, 175, 325, 250, 25, 325, 325 }; static float[] colors = { 1.0f, 0.2f, 0.2f, 0.2f, 0.2f, 1.0f, 0.8f, 1.0f, 0.2f, 0.75f, 0.75f, 0.75f, 0.35f, 0.35f, 0.35f, 0.5f, 0.5f, 0.5f }; public VertexArray() { } public void init(GLDrawable drawable) { gl = drawable.getGL(); glu = drawable.getGLU(); glj = drawable.getGLContext(); gldrawable = drawable; glut = new GLUTFuncLightImpl(gl, glu); glj.gljCheckGL(); } public void preDisplay(GLDrawable drawable) { } public void display(GLDrawable drawable) { gl.glClearColor(1.0f, 0.0f, 0.0f, 0.0f); gl.glClear(GL_COLOR_BUFFER_BIT); gl.glLoadIdentity(); gl.glColor3d(1.0,1.0,1.0); gl.glEnableClientState(GL_VERTEX_ARRAY); gl.glEnableClientState(GL_COLOR_ARRAY); gl.glVertexPointer(2, GL_INT, 0, vertices); gl.glColorPointer(3,GL_FLOAT,0,colors); gl.glBegin(GL_TRIANGLES); gl.glArrayElement(0); gl.glArrayElement(1); gl.glArrayElement(2); gl.glEnd(); gl.glFlush(); } public void postDisplay(GLDrawable drawable) { } public void cleanup(GLDrawable drawable) { } public void reshape(GLDrawable drawable, int x, int y) { gl.glViewport(0,0,x,y ); gl.glMatrixMode(GL_PROJECTION); gl.glLoadIdentity(); glu.gluOrtho2D(0.0, (double) x, 0.0, (double) y); } public static void main(String[] args){ rtfm.opengl.FuGLAnimFrame frame = new rtfm.opengl.FuGLAnimFrame(new VertexArray(), 500,500,"Opengl Test"); } } |