diff options
author | Kenneth Russel <[email protected]> | 2008-05-29 09:38:02 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2008-05-29 09:38:02 +0000 |
commit | d2cb0b7d199c2171a51a2ce03211fc5bf0047921 (patch) | |
tree | 84b2e95f4828190e707afe0d70b97fa05b20fe51 /src/demos/es1/RedSquare.java | |
parent | 5d94f5c240262c10504cad46ffe04c65bf7d8116 (diff) |
Rewrote to use minimal window abstraction for EGL. Not working yet.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/trunk@230 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src/demos/es1/RedSquare.java')
-rwxr-xr-x | src/demos/es1/RedSquare.java | 140 |
1 files changed, 46 insertions, 94 deletions
diff --git a/src/demos/es1/RedSquare.java b/src/demos/es1/RedSquare.java index 48ede76..1b2469b 100755 --- a/src/demos/es1/RedSquare.java +++ b/src/demos/es1/RedSquare.java @@ -3,34 +3,29 @@ package demos.es1; import java.nio.*; import javax.media.opengl.*; import javax.media.opengl.glu.*; -import com.sun.opengl.impl.egl.*; import com.sun.opengl.util.*; +import com.sun.javafx.newt.*; + public class RedSquare { public static void main(String[] args) { - System.out.println("Basic.main()"); + System.out.println("RedSquare.main()"); try { - System.out.println("GLDrawableFactory.getFactory()"); - EGLDrawableFactory factory = (EGLDrawableFactory) GLDrawableFactory.getFactory(); - - /* - - System.out.println("Testing getDirectBufferAddress"); - factory.testGetDirectBufferAddress(); - - */ - - System.out.println("EGLDrawableFactory.initialize()"); - factory.initialize(); - System.out.println("factory.createExternalGLContext()"); - GLContext context = factory.createExternalGLContext(); - // OpenGL context is current at this point - - // The following is a no-op that is only needed to get the - // Java-level GLContext object set up in thread-local storage - System.out.println("context.makeCurrent()"); + Window window = Window.create(); + + // Hook this into EGL + GLDrawableFactory.initialize(GLDrawableFactory.PROFILE_GLES1); + GLDrawableFactory factory = GLDrawableFactory.getFactory(); + GLCapabilities caps = new GLCapabilities(); + // For emulation library, use 16 bpp + caps.setRedBits(5); + caps.setGreenBits(5); + caps.setBlueBits(5); + caps.setDepthBits(16); + GLDrawable drawable = factory.getGLDrawable(new Long(window.getWindowHandle()), caps, null); + drawable.setRealized(true); + GLContext context = drawable.createContext(null); context.makeCurrent(); - context.setGL(new DebugGL(context.getGL())); GL gl = context.getGL(); GLU glu = new GLU(); @@ -44,8 +39,16 @@ public class RedSquare { // Size OpenGL to Video Surface int width = 800; int height = 480; + if (!window.setFullscreen(true)) { + window.setSize(width, height); + } + + // See how big it got + width = window.getWidth(); + height = window.getHeight(); + System.out.println("calling glViewport()"); - // gl.glViewport(0, 0, width, height); + gl.glViewport(0, 0, width, height); System.out.println("calling glMatrixMode()"); gl.glMatrixMode(GL.GL_PROJECTION); System.out.println("calling glLoadIdentity()"); @@ -58,67 +61,27 @@ public class RedSquare { System.out.println("Intialized matrices"); // Allocate vertex arrays - // FloatBuffer colors = BufferUtil.newFloatBuffer(12); - // FloatBuffer vertices = BufferUtil.newFloatBuffer(12); - // FloatBuffer normals = BufferUtil.newFloatBuffer(12); - // FloatBuffer colors = FloatBuffer.wrap(new float[12]); - // FloatBuffer vertices = FloatBuffer.wrap(new float[12]); - // FloatBuffer normals = FloatBuffer.wrap(new float[12]); + FloatBuffer colors = BufferUtil.newFloatBuffer(12); + FloatBuffer vertices = BufferUtil.newFloatBuffer(12); // Fill them up - // colors.put(0, 1); colors.put( 1, 0); colors.put( 2, 0); - // colors.put(3, 1); colors.put( 4, 0); colors.put( 5, 0); - // colors.put(6, 1); colors.put( 7, 0); colors.put( 8, 0); - // colors.put(9, 1); colors.put(10, 0); colors.put(11, 0); - // vertices.put(0, -2); vertices.put( 1, 2); vertices.put( 2, 0); - // vertices.put(3, 2); vertices.put( 4, 2); vertices.put( 5, 0); - // vertices.put(6, -2); vertices.put( 7, -2); vertices.put( 8, 0); - // vertices.put(9, 2); vertices.put(10, -2); vertices.put(11, 0); - // normals.put(0, 0); normals.put( 1, 0); normals.put( 2, 1); - // normals.put(3, 0); normals.put( 4, 0); normals.put( 5, 1); - // normals.put(6, 0); normals.put( 7, 0); normals.put( 8, 1); - // normals.put(9, 0); normals.put(10, 0); normals.put(11, 1); - - // FloatBuffer data = FloatBuffer.wrap(new float[24]); - FloatBuffer data = BufferUtil.newFloatBuffer(12 + 16); - // Vertices first - data.put(0, -2); data.put( 1, 2); data.put( 2, 0); - data.put(3, 2); data.put( 4, 2); data.put( 5, 0); - data.put(6, -2); data.put( 7, -2); data.put( 8, 0); - data.put(9, 2); data.put(10, -2); data.put(11, 0); - // Now colors - data.put(12, 1); data.put(13, 0); data.put(14, 0); data.put(15, 0); - data.put(16, 1); data.put(17, 0); data.put(18, 0); data.put(19, 0); - data.put(20, 1); data.put(21, 0); data.put(22, 0); data.put(23, 0); - data.put(24, 1); data.put(25, 0); data.put(26, 0); data.put(27, 0); - - System.out.println("Set up buffers"); - - int[] vbo = new int[1]; - gl.glGenBuffers(1, vbo, 0); - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[0]); - gl.glBufferData(GL.GL_ARRAY_BUFFER, (12 + 16) * BufferUtil.SIZEOF_FLOAT, data, GL.GL_STATIC_DRAW); - gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0); - // gl.glColorPointer(3, GL.GL_FLOAT, 0, 12 * BufferUtil.SIZEOF_FLOAT); + colors.put(0, 1); colors.put( 1, 0); colors.put( 2, 0); + colors.put(3, 1); colors.put( 4, 0); colors.put( 5, 0); + colors.put(6, 1); colors.put( 7, 0); colors.put( 8, 0); + colors.put(9, 1); colors.put(10, 0); colors.put(11, 0); + vertices.put(0, -2); vertices.put( 1, 2); vertices.put( 2, 0); + vertices.put(3, 2); vertices.put( 4, 2); vertices.put( 5, 0); + vertices.put(6, -2); vertices.put( 7, -2); vertices.put( 8, 0); + vertices.put(9, 2); vertices.put(10, -2); vertices.put(11, 0); + gl.glEnableClientState(GL.GL_VERTEX_ARRAY); - // gl.glEnableClientState(GL.GL_COLOR_ARRAY); - // System.out.println("Vertices' address: 0x" + Integer.toHexString(factory.getDirectBufferAddress(vertices))); - // System.out.println("Expected: 0x" + Integer.toHexString(vertices.arrayOffset)); - // System.out.println("Colors' address: 0x" + Integer.toHexString(factory.getDirectBufferAddress(colors))); - // System.out.println("Expected: 0x" + Integer.toHexString(colors.arrayOffset)); - // gl.glNormalPointer(GL.GL_FLOAT, 0, normals); - // gl.glEnableClientState(GL.GL_NORMAL_ARRAY); - // System.out.println("Normals' address: 0x" + Integer.toHexString(factory.getDirectBufferAddress(normals))); - // System.out.println("Expected: 0x" + Integer.toHexString(normals.arrayOffset)); - // System.out.println("Set up vertex, color and normal pointers"); - - System.out.println("Set up vertex and color pointers"); + gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertices); + gl.glEnableClientState(GL.GL_COLOR_ARRAY); + gl.glColorPointer(3, GL.GL_FLOAT, 0, colors); // OpenGL Render Settings gl.glClearColor(0, 0, 0, 1); - gl.glClearDepthf(1.0f); - gl.glEnable(GL.GL_DEPTH_TEST); - - System.out.println("Set up clear color and clear depth"); + // gl.glClearDepthf(1.0f); + // gl.glEnable(GL.GL_DEPTH_TEST); //---------------------------------------------------------------------- // Code for GLEventListener.display() @@ -129,34 +92,23 @@ public class RedSquare { while ((System.currentTimeMillis() - startTime) < 10000) { gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - System.out.println("Cleared buffers"); - // Set location in front of camera gl.glLoadIdentity(); gl.glTranslatef(0, 0, -10); - System.out.println("Translated"); - // Draw a square gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); - System.out.println("Drew arrays"); - - // FIXME -- need an external GLDrawable - factory.swapBuffers(); - - System.out.println("Swapped buffers"); + drawable.swapBuffers(); - // Process events - factory.processEvents(); + window.pumpMessages(); - // Sleep a bit try { - Thread.sleep(100); + Thread.sleep(10); } catch (InterruptedException e) { } } - } catch (GLException e) { + } catch (Exception e) { e.printStackTrace(); } |