1 /** 2 * Copyright 2010 JogAmp Community. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, are 5 * permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this list of 8 * conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * 24 * The views and conclusions contained in the software and documentation are those of the 25 * authors and should not be interpreted as representing official policies, either expressed 26 * or implied, of JogAmp Community. 27 */ 28 29 package com.jogamp.opengl.test.junit.graph.demos; 30 31 import java.util.ArrayList; 32 import java.util.List; 33 34 import com.jogamp.opengl.GL; 35 import com.jogamp.opengl.GL2ES2; 36 import com.jogamp.opengl.GLAutoDrawable; 37 import com.jogamp.opengl.fixedfunc.GLMatrixFunc; 38 39 import com.jogamp.graph.curve.OutlineShape; 40 import com.jogamp.graph.curve.opengl.GLRegion; 41 import com.jogamp.graph.curve.opengl.RenderState; 42 import com.jogamp.graph.curve.opengl.RegionRenderer; 43 import com.jogamp.opengl.util.PMVMatrix; 44 45 /** Demonstrate the rendering of multiple OutlineShapes 46 * into one region 47 * 48 */ 49 public class GPURegionGLListener02 extends GPURendererListenerBase01 { 50 List<OutlineShape> outlineShapes = new ArrayList<OutlineShape>(); 51 GPURegionGLListener02(final RenderState rs, final int renderModes, final int sampleCount, final boolean debug, final boolean trace)52 public GPURegionGLListener02 (final RenderState rs, final int renderModes, final int sampleCount, final boolean debug, final boolean trace) { 53 super(RegionRenderer.create(rs, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable), renderModes, debug, trace); 54 rs.setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED); 55 setMatrix(-20, 00, -50, 0f, sampleCount); 56 } 57 createTestOutline()58 private void createTestOutline(){ 59 float offset = 0; 60 OutlineShape shape = new OutlineShape(getRenderer().getRenderState().getVertexFactory()); 61 outlineShapes.add(shape); 62 shape.addVertex(0.0f,-10.0f,true); 63 shape.addVertex(15.0f,-10.0f, true); 64 shape.addVertex(10.0f,5.0f, false); 65 shape.addVertex(15.0f,10.0f, true); 66 shape.addVertex(6.0f,15.0f, false); 67 shape.addVertex(5.0f,8.0f, false); 68 shape.addVertex(0.0f,10.0f,true); 69 shape.closeLastOutline(true); 70 shape.addEmptyOutline(); 71 shape.addVertex(5.0f,-5.0f,true); 72 shape.addVertex(10.0f,-5.0f, false); 73 shape.addVertex(10.0f,0.0f, true); 74 shape.addVertex(5.0f,0.0f, false); 75 shape.closeLastOutline(true); 76 77 /** Same shape as above but without any off-curve vertices */ 78 shape = new OutlineShape(getRenderer().getRenderState().getVertexFactory()); 79 outlineShapes.add(shape); 80 offset = 30; 81 shape.addVertex(offset+0.0f,-10.0f, true); 82 shape.addVertex(offset+17.0f,-10.0f, true); 83 shape.addVertex(offset+11.0f,5.0f, true); 84 shape.addVertex(offset+16.0f,10.0f, true); 85 shape.addVertex(offset+7.0f,15.0f, true); 86 shape.addVertex(offset+6.0f,8.0f, true); 87 shape.addVertex(offset+0.0f,10.0f, true); 88 shape.closeLastOutline(true); 89 shape.addEmptyOutline(); 90 shape.addVertex(offset+5.0f,0.0f, true); 91 shape.addVertex(offset+5.0f,-5.0f, true); 92 shape.addVertex(offset+10.0f,-5.0f, true); 93 shape.addVertex(offset+10.0f,0.0f, true); 94 shape.closeLastOutline(true); 95 96 region = GLRegion.create(getRenderModes(), null); 97 region.addOutlineShapes(outlineShapes, null, null); 98 } 99 init(final GLAutoDrawable drawable)100 public void init(final GLAutoDrawable drawable) { 101 super.init(drawable); 102 103 final GL2ES2 gl = drawable.getGL().getGL2ES2(); 104 105 final RenderState rs = getRenderer().getRenderState(); 106 107 gl.setSwapInterval(1); 108 gl.glEnable(GL.GL_DEPTH_TEST); 109 gl.glEnable(GL.GL_BLEND); 110 rs.setColorStatic(0.0f, 0.0f, 0.0f, 1.0f); 111 112 createTestOutline(); 113 } 114 display(final GLAutoDrawable drawable)115 public void display(final GLAutoDrawable drawable) { 116 final GL2ES2 gl = drawable.getGL().getGL2ES2(); 117 118 gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 119 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); 120 121 final RegionRenderer regionRenderer = getRenderer(); 122 123 final PMVMatrix pmv = regionRenderer.getMatrix(); 124 pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); 125 pmv.glLoadIdentity(); 126 pmv.glTranslatef(getXTran(), getYTran(), getZTran()); 127 pmv.glRotatef(getAngle(), 0, 1, 0); 128 if( weight != regionRenderer.getRenderState().getWeight() ) { 129 regionRenderer.getRenderState().setWeight(weight); 130 } 131 region.draw(gl, regionRenderer, getSampleCount()); 132 133 } 134 } 135