diff options
Diffstat (limited to 'src/test')
33 files changed, 1928 insertions, 1380 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java index e9609ca9c..de5fe8eb2 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java @@ -44,7 +44,7 @@ import org.junit.runners.MethodSorters; import com.jogamp.common.os.Platform; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.graph.geom.SVertex; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.graph.demos.GPURegionGLListener01; import com.jogamp.opengl.test.junit.graph.demos.GPURegionGLListener02; @@ -59,8 +59,8 @@ public class TestRegionRendererNEWT01 extends UITestCase { public static void main(String args[]) throws IOException { String tstname = TestRegionRendererNEWT01.class.getName(); org.junit.runner.JUnitCore.main(tstname); - } - + } + static void destroyWindow(GLWindow window) { if(null!=window) { window.destroy(); @@ -80,46 +80,75 @@ public class TestRegionRendererNEWT01 extends UITestCase { return window; } - @Test - public void testRegionRendererR2T01() throws InterruptedException { + // @Test + public void test00RegionRendererNONE01() throws InterruptedException { + GLProfile glp = GLProfile.get(GLProfile.GL2ES2); + GLCapabilities caps = new GLCapabilities(glp); + // caps.setOnscreen(false); + caps.setAlphaBits(4); + + GLWindow window = createWindow("shape-vbaa0-msaa0", caps, 800, 400); + RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); + + GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, 0, 0, false, false); + demo01Listener.attachInputListenerTo(window); + window.addGLEventListener(demo01Listener); + + RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion01"); + window.addGLEventListener(listener); + + listener.setTech(-20, 0, -300, 0f, 2); + window.display(); + + listener.setTech(-20, 0, -150, 0f, 3); + window.display(); + + listener.setTech(-20, 0, -50, 0f, 4); + window.display(); + + destroyWindow(window); + } + + // @Test + public void test01RegionRendererNONE02() throws InterruptedException { if(Platform.CPUFamily.X86 != Platform.CPU_ARCH.family) { // FIXME - // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise). + // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise). + // FIXME: Also the GLSL code for VARIABLE_CURVE is not fit for mobile yet! System.err.println("disabled on non desktop (x86) arch for now .."); return; } - GLProfile glp = GLProfile.getGL2ES2(); - + GLProfile glp = GLProfile.get(GLProfile.GL2ES2); GLCapabilities caps = new GLCapabilities(glp); - //caps.setOnscreen(false); - caps.setAlphaBits(4); + caps.setAlphaBits(4); - GLWindow window = createWindow("shape-vbaa1-msaa0", caps, 800,400); + GLWindow window = createWindow("shape-vbaa0-msaa0", caps, 800, 400); RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); - GPURegionGLListener02 demo02Listener = new GPURegionGLListener02 (rs, Region.VBAA_RENDERING_BIT, 1140, false, false); - demo02Listener.attachInputListenerTo(window); - window.addGLEventListener(demo02Listener); - - RegionGLListener listener = new RegionGLListener(demo02Listener, window.getTitle(), "GPURegionNewtDemo02"); + + GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, Region.VARIABLE_CURVE_WEIGHT_BIT, 0, false, false); + demo01Listener.attachInputListenerTo(window); + window.addGLEventListener(demo01Listener); + + RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion02"); window.addGLEventListener(listener); - - listener.setTech(-20, 00, 0f, -300, 400); + + listener.setTech(-20, 0, -300, 0f, 2); window.display(); - - listener.setTech(-20, 00, 0f, -150, 800); + + listener.setTech(-20, 0, -150, 0f, 3); window.display(); - - listener.setTech(-20, 00, 0f, -50, 1000); + + listener.setTech(-20, 0, -50, 0f, 4); window.display(); - destroyWindow(window); + destroyWindow(window); } - + @Test - public void testRegionRendererMSAA01() throws InterruptedException { + public void test10RegionRendererMSAA01() throws InterruptedException { GLProfile glp = GLProfile.get(GLProfile.GL2ES2); GLCapabilities caps = new GLCapabilities(glp); // caps.setOnscreen(false); - caps.setAlphaBits(4); + caps.setAlphaBits(4); caps.setSampleBuffers(true); caps.setNumSamples(4); @@ -127,26 +156,26 @@ public class TestRegionRendererNEWT01 extends UITestCase { RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, 0, 0, false, false); - demo01Listener.attachInputListenerTo(window); + demo01Listener.attachInputListenerTo(window); window.addGLEventListener(demo01Listener); - + RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion01"); window.addGLEventListener(listener); - - listener.setTech(-20, 00, 0f, -300, 400); + + listener.setTech(-20, 00, -300, 0f, 2); window.display(); - - listener.setTech(-20, 00, 0f, -150, 800); + + listener.setTech(-20, 00, -150, 0f, 3); window.display(); - - listener.setTech(-20, 00, 0f, -50, 1000); + + listener.setTech(-20, 00, -50, 0f, 4); window.display(); - - destroyWindow(window); + + destroyWindow(window); } - - @Test - public void testRegionRendererMSAA02() throws InterruptedException { + + // @Test + public void test11RegionRendererMSAA02() throws InterruptedException { if(Platform.CPUFamily.X86 != Platform.CPU_ARCH.family) { // FIXME // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise). // FIXME: Also the GLSL code for VARIABLE_CURVE is not fit for mobile yet! @@ -155,7 +184,7 @@ public class TestRegionRendererNEWT01 extends UITestCase { } GLProfile glp = GLProfile.get(GLProfile.GL2ES2); GLCapabilities caps = new GLCapabilities(glp); - caps.setAlphaBits(4); + caps.setAlphaBits(4); caps.setSampleBuffers(true); caps.setNumSamples(4); @@ -163,43 +192,77 @@ public class TestRegionRendererNEWT01 extends UITestCase { RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, Region.VARIABLE_CURVE_WEIGHT_BIT, 0, false, false); - demo01Listener.attachInputListenerTo(window); + demo01Listener.attachInputListenerTo(window); window.addGLEventListener(demo01Listener); - + RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion02"); window.addGLEventListener(listener); - - listener.setTech(-20, 00, 0f, -300, 400); + + listener.setTech(-20, 00, -300, 0f, 2); window.display(); - - listener.setTech(-20, 00, 0f, -150, 800); + + listener.setTech(-20, 00, -150, 0f, 3); window.display(); - - listener.setTech(-20, 00, 0f, -50, 1000); + + listener.setTech(-20, 00, -50, 0f, 4); window.display(); - - destroyWindow(window); + + destroyWindow(window); } - + + @Test + public void test20RegionRendererR2T01() throws InterruptedException { + if(Platform.CPUFamily.X86 != Platform.CPU_ARCH.family) { // FIXME + // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise). + System.err.println("disabled on non desktop (x86) arch for now .."); + return; + } + GLProfile glp = GLProfile.getGL2ES2(); + + GLCapabilities caps = new GLCapabilities(glp); + //caps.setOnscreen(false); + caps.setAlphaBits(4); + + GLWindow window = createWindow("shape-vbaa1-msaa0", caps, 800,400); + RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); + GPURegionGLListener02 demo02Listener = new GPURegionGLListener02 (rs, Region.VBAA_RENDERING_BIT, 4, false, false); + demo02Listener.attachInputListenerTo(window); + window.addGLEventListener(demo02Listener); + + RegionGLListener listener = new RegionGLListener(demo02Listener, window.getTitle(), "GPURegionNewtDemo02"); + window.addGLEventListener(listener); + + listener.setTech(-20, 00, -300, 0f, 2); + window.display(); + + listener.setTech(-20, 00, -150, 0f, 3); + window.display(); + + listener.setTech(-20, 00, -50, 0f, 4); + window.display(); + + destroyWindow(window); + } + private class RegionGLListener implements GLEventListener { String winTitle; String name; GPURegionRendererListenerBase01 impl; - + public RegionGLListener(GPURegionRendererListenerBase01 impl, String title, String name) { this.impl = impl; this.winTitle = title; this.name = name; } - - public void setTech(float xt, float yt, float angle, int zoom, int fboSize){ - impl.setMatrix(xt, yt, angle, zoom, fboSize); + + public void setTech(float xt, float yt, int zt, float angle, int sampleCount){ + impl.setMatrix(xt, yt, zt, angle, sampleCount); } public void init(GLAutoDrawable drawable) { impl.init(drawable); } - + public void display(GLAutoDrawable drawable) { impl.display(drawable); @@ -214,12 +277,12 @@ public class TestRegionRendererNEWT01 extends UITestCase { public void dispose(GLAutoDrawable drawable) { impl.dispose(drawable); - + } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { impl.reshape(drawable, x, y, width, height); - + } } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java index f675e42cd..905483e7f 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java @@ -29,33 +29,36 @@ package com.jogamp.opengl.test.junit.graph; import java.io.File; import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAnimatorControl; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLCapabilitiesImmutable; -import javax.media.opengl.GLEventListener; import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; import javax.media.opengl.GLRunnable; import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; import org.junit.FixMethodOrder; +import org.junit.Test; import org.junit.runners.MethodSorters; +import com.jogamp.common.os.Platform; +import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.GLRegion; +import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.curve.opengl.TextRenderer; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; -import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.graph.geom.SVertex; +import com.jogamp.newt.MonitorDevice; +import com.jogamp.newt.Window; import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.math.geom.AABBox; +import com.jogamp.opengl.test.junit.util.MiscUtils; import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.util.GLReadBufferUtil; import com.jogamp.opengl.util.glsl.ShaderState; @@ -64,42 +67,86 @@ import com.jogamp.opengl.util.glsl.ShaderState; public class TestTextRendererNEWT00 extends UITestCase { static final boolean DEBUG = false; static final boolean TRACE = false; - static long duration = 100; // ms - - static final float[] textPosition = new float[] {0,0,0}; - static final int[] texSize = new int[] { 0 }; - static final int fontSize = 24; - static Font font; - - @BeforeClass - public static void setup() throws IOException { - font = FontFactory.get(FontFactory.UBUNTU).getDefault(); - } - + static long Duration = 2000; // ms + static boolean WaitStartEnd = false; + static boolean TextAnim = false; + static int SceneMSAASamples = 4; + static int GraphVBAASamples = 4; + static int GraphMSAASamples = 4; + static int SwapInterval = 0; + + static String fontFileName = null; + static int fontSet = 0; + static int fontFamily = 0; + static int fontStylebits = 0; + static float fontSizeFixed = 14f; + static int atoi(String a) { try { return Integer.parseInt(a); } catch (Exception ex) { throw new RuntimeException(ex); } } - + public static void main(String args[]) throws IOException { for(int i=0; i<args.length; i++) { if(args[i].equals("-time")) { i++; - duration = atoi(args[i]); + Duration = atoi(args[i]); + } else if(args[i].equals("-fontFile")) { + i++; + fontFileName = args[i]; + } else if(args[i].equals("-fontSet")) { + i++; + fontSet = atoi(args[i]); + } else if(args[i].equals("-fontFamily")) { + i++; + fontFamily = atoi(args[i]); + } else if(args[i].equals("-fontStyle")) { + i++; + fontStylebits = atoi(args[i]); + } else if(args[i].equals("-fontSize")) { + i++; + fontSizeFixed = atoi(args[i]); + } else if(args[i].equals("-smsaa")) { + i++; + SceneMSAASamples = atoi(args[i]); + GraphMSAASamples = 0; + GraphVBAASamples = 0; + } else if(args[i].equals("-gmsaa")) { + i++; + SceneMSAASamples = 0; + GraphMSAASamples = atoi(args[i]); + GraphVBAASamples = 0; + } else if(args[i].equals("-gvbaa")) { + i++; + SceneMSAASamples = 0; + GraphMSAASamples = 0; + GraphVBAASamples = atoi(args[i]); + } else if(args[i].equals("-textAnim")) { + TextAnim = true; + } else if(args[i].equals("-vsync")) { + i++; + SwapInterval = MiscUtils.atoi(args[i], SwapInterval); + } else if(args[i].equals("-wait")) { + WaitStartEnd = true; } } + System.err.println("Font [set "+fontSet+", family "+fontFamily+", style "+fontStylebits+", size "+fontSizeFixed+"], fontFileName "+fontFileName); + System.err.println("Scene MSAA Samples "+SceneMSAASamples); + System.err.println("Graph MSAA Samples "+GraphMSAASamples); + System.err.println("Graph VBAA Samples "+GraphVBAASamples); + System.err.println("swapInterval "+SwapInterval); String tstname = TestTextRendererNEWT00.class.getName(); org.junit.runner.JUnitCore.main(tstname); - } - + } + static void sleep() { try { - System.err.println("** new frame ** (sleep: "+duration+"ms)"); - Thread.sleep(duration); + System.err.println("** new frame ** (sleep: "+Duration+"ms)"); + Thread.sleep(Duration); } catch (InterruptedException ie) {} } - + static void destroyWindow(GLWindow window) { if(null!=window) { window.destroy(); @@ -118,122 +165,232 @@ public class TestTextRendererNEWT00 extends UITestCase { return window; } - + @Test - public void testTextRendererMSAA01() throws InterruptedException { + public void test01SceneMSAA01() throws InterruptedException { + if( SceneMSAASamples > 0 ) { + testImpl(SceneMSAASamples, 0, 0); + } + } + @Test + public void test02GraphMSAA01() throws InterruptedException { + if( GraphMSAASamples > 0 ) { + testImpl(0, GraphMSAASamples, 0); + } + } + @Test + public void test03GraphVBAA01() throws InterruptedException { + if( GraphVBAASamples > 0 ) { + testImpl(0, 0, GraphVBAASamples); + } + } + + public void testImpl(final int sceneMSAASamples, final int graphMSAASamples, final int graphVBAASamples) throws InterruptedException { GLProfile glp = GLProfile.get(GLProfile.GL2ES2); GLCapabilities caps = new GLCapabilities(glp); - caps.setAlphaBits(4); - caps.setSampleBuffers(true); - caps.setNumSamples(4); - System.err.println("Requested: "+caps); + caps.setAlphaBits(4); + if( 0 < sceneMSAASamples ) { + caps.setSampleBuffers(true); + caps.setNumSamples(sceneMSAASamples); + } + System.err.println("Requested: "+caps+", graph[msaaSamples "+graphMSAASamples+", vbaaSamples "+graphVBAASamples+"]"); - GLWindow window = createWindow("text-vbaa0-msaa1", caps, 800, 400); + GLWindow window = createWindow("text-gvbaa"+graphVBAASamples+"-gmsaa"+graphMSAASamples+"-smsaa"+sceneMSAASamples, caps, 1024, 640); window.display(); System.err.println("Chosen: "+window.getChosenGLCapabilities()); - + if( WaitStartEnd ) { + UITestCase.waitForKey("Start"); + } + final RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); - final TextRendererListener textGLListener = new TextRendererListener(rs); - final TextRenderer renderer = textGLListener.getRenderer(); + final int rendererMode, sampleCount; + if( graphVBAASamples > 0 ) { + rendererMode = Region.VBAA_RENDERING_BIT; + sampleCount = graphVBAASamples; + } else if ( graphMSAASamples > 0 ) { + rendererMode = Region.MSAA_RENDERING_BIT; + sampleCount = graphMSAASamples; + } else { + rendererMode = 0; + sampleCount = 0; + } + final TextRendererGLEL textGLListener = new TextRendererGLEL(rs, rendererMode, sampleCount); + System.err.println(textGLListener.getFontInfo()); + window.addGLEventListener(textGLListener); + Animator anim = new Animator(); + anim.add(window); + anim.start(); + anim.setUpdateFPSFrames(60, null); + sleep(); window.invoke(true, new GLRunnable() { @Override public boolean run(GLAutoDrawable drawable) { - int c=0; - renderString(drawable, renderer, "GlueGen", c++, -1, -1000); - renderString(drawable, renderer, "JOAL", c++, -1, -1000); - renderString(drawable, renderer, "JOGL", c++, -1, -1000); - renderString(drawable, renderer, "JOCL", c++, -1, -1000); try { textGLListener.printScreen(drawable, "./", "TestTextRendererNEWT00-snap"+screenshot_num, false); + screenshot_num++; } catch (Exception e) { e.printStackTrace(); } return true; - } + } }); - sleep(); - - destroyWindow(window); - } - int screenshot_num = 0; - - int lastRow = -1; - - void renderString(GLAutoDrawable drawable, TextRenderer renderer, String text, int column, int row, int z0) { - final GL2ES2 gl = drawable.getGL().getGL2ES2(); - final int height = drawable.getHeight(); - - int dx = 0; - int dy = height; - if(0>row) { - row = lastRow + 1; + anim.stop(); + if( WaitStartEnd ) { + UITestCase.waitForKey("Stop"); } - AABBox textBox = font.getStringBounds(text, fontSize); - dx += font.getAdvanceWidth('X', fontSize) * column; - dy -= (int)textBox.getHeight() * ( row + 1 ); - renderer.resetModelview(null); - renderer.translate(gl, dx, dy, z0); - renderer.drawString3D(gl, font, text, textPosition, fontSize, texSize); - - lastRow = row; + destroyWindow(window); } - - public class TextRendererListener implements GLEventListener { - private GLReadBufferUtil screenshot; - private TextRenderer renderer; - - public TextRendererListener(RenderState rs) { + int screenshot_num = 0; + + static final String textX2 = + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec sapien tellus. \n"+ + "Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel urna. Mauris ultricies \n"+ + "quam iaculis urna cursus ornare. Nullam ut felis a ante ultrices ultricies nec a elit. \n"+ + "In hac habitasse platea dictumst. Vivamus et mi a quam lacinia pharetra at venenatis est.\n"+ + "Morbi quis bibendum nibh. Donec lectus orci, sagittis in consequat nec, volutpat nec nisi.\n"+ + "Donec ut dolor et nulla tristique varius. In nulla magna, fermentum id tempus quis, semper \n"+ + "in lorem. Maecenas in ipsum ac justo scelerisque sollicitudin. Quisque sit amet neque lorem,\n" + + "-------Press H to change text---------\n"; + + private final class TextRendererGLEL extends TextRendererGLELBase { + private final GLReadBufferUtil screenshot; + private final GLRegion regionFPS, regionFPSAnim; + final Font font; + final float fontSizeMin, fontSizeMax; + private long t0; + float fontSizeAnim, fontSizeDelta; + float dpiH; + + TextRendererGLEL(final RenderState rs, final int renderModes, final int sampleCount) { + super(renderModes, new int[] { sampleCount }); + setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable); + setRenderState(rs); + + regionFPS = GLRegion.create(renderModes); + regionFPSAnim = GLRegion.create(renderModes); + if( null != fontFileName ) { + Font _font = null; + try { + _font = FontFactory.get(getClass(), fontFileName, false); + } catch (IOException e) { + e.printStackTrace(); + } + font = _font; + } else { + font = getFont(fontSet, fontFamily, fontStylebits); + } + + staticRGBAColor[0] = 0.0f; + staticRGBAColor[1] = 0.0f; + staticRGBAColor[2] = 0.0f; + staticRGBAColor[3] = 1.0f; + this.screenshot = new GLReadBufferUtil(false, false); - this.renderer = TextRenderer.create(rs, 0); + // fontSizeMin = Math.max(8, fontSizeFixed-5); + fontSizeMin = fontSizeFixed; + fontSizeMax = fontSizeFixed+8; + fontSizeAnim = fontSizeFixed; + fontSizeDelta = 0.01f; + } + + @Override + public void init(GLAutoDrawable drawable) { + super.init(drawable); + drawable.getGL().setSwapInterval(SwapInterval); + t0 = Platform.currentTimeMillis(); + + final Window win = (Window)drawable.getUpstreamWidget(); + final MonitorDevice monitor = win.getMainMonitor(); + final float[] pixelsPerMM = new float[2]; + monitor.getPixelsPerMM(pixelsPerMM); + final float[] dotsPerInch = new float[] { pixelsPerMM[0]*25.4f, pixelsPerMM[1]*25.4f }; + dpiH = dotsPerInch[1]; + System.err.println(getFontInfo()); + System.err.println("fontSize "+fontSizeFixed+", dotsPerMM "+pixelsPerMM[0]+"x"+pixelsPerMM[1]+", dpi "+dotsPerInch[0]+"x"+dotsPerInch[1]+", pixelSize "+font.getPixelSize(fontSizeFixed, dotsPerInch[1] /* dpi display */)); } - - public final TextRenderer getRenderer() { return renderer; } - + + @Override + public void dispose(GLAutoDrawable drawable) { + final GL2ES2 gl = drawable.getGL().getGL2ES2(); + screenshot.dispose(gl); + regionFPS.destroy(gl, renderer); + regionFPSAnim.destroy(gl, renderer); + super.dispose(drawable); + } + public void printScreen(GLAutoDrawable drawable, String dir, String objName, boolean exportAlpha) throws GLException, IOException { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - pw.printf("%s-%03dx%03d-T%04d", objName, drawable.getWidth(), drawable.getHeight(), texSize[0]); - - final String filename = dir + sw +".png"; + final String modeS = Region.getRenderModeString(renderer.getRenderModes()); + final String bname = String.format("%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d", objName, + drawable.getChosenGLCapabilities().getNumSamples(), + TestTextRendererNEWT00.fontSizeFixed, drawable.getWidth(), drawable.getHeight(), modeS, vbaaSampleCount[0]); + final String filename = dir + bname +".png"; if(screenshot.readPixels(drawable.getGL(), false)) { screenshot.write(new File(filename)); } } - - public void init(GLAutoDrawable drawable) { - final GL2ES2 gl = drawable.getGL().getGL2ES2(); - gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - renderer.init(gl); - renderer.setAlpha(gl, 1.0f); - renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); - } - - public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) { - final GL2ES2 gl = drawable.getGL().getGL2ES2(); - - gl.glViewport(xstart, ystart, width, height); - // renderer.reshapePerspective(gl, 45.0f, width, height, 0.1f, 1000.0f); - renderer.reshapeOrtho(gl, width, height, 0.1f, 1000.0f); + + String getFontInfo() { + final float unitsPerEM_Inv = font.getMetrics().getScale(1f); + final float unitsPerEM = 1f / unitsPerEM_Inv; + return String.format("Font %s%n %s%nunitsPerEM %f (upem)", + font.getFullFamilyName(null).toString(), + font.getName(Font.NAME_UNIQUNAME), + unitsPerEM); } - + + @Override public void display(GLAutoDrawable drawable) { - final GL2ES2 gl = drawable.getGL().getGL2ES2(); + final GL2ES2 gl = drawable.getGL().getGL2ES2(); + + gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - - renderString(drawable, renderer, "012345678901234567890123456789", 0, 0, -1000); - renderString(drawable, renderer, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000); - renderString(drawable, renderer, "Hello World", 0, -1, -1000); - renderString(drawable, renderer, "4567890123456", 4, -1, -1000); - renderString(drawable, renderer, "I like JogAmp", 4, -1, -1000); - } - - public void dispose(GLAutoDrawable drawable) { - final GL2ES2 gl = drawable.getGL().getGL2ES2(); - screenshot.dispose(gl); - renderer.destroy(gl); - } - } + + final GLAnimatorControl anim = drawable.getAnimator(); + final float lfps = null != anim ? anim.getLastFPS() : 0f; + final float tfps = null != anim ? anim.getTotalFPS() : 0f; + + // Note: MODELVIEW is from [ 0 .. height ] + + final long t1 = Platform.currentTimeMillis(); + + // final float fontSize = TestTextRendererNEWT00.fontSize; + + fontSizeAnim += fontSizeDelta; + if( fontSizeMin >= fontSizeAnim || fontSizeAnim >= fontSizeMax ) { + fontSizeDelta *= -1f; + } + + final float pixelSize = font.getPixelSize(fontSizeFixed, dpiH); + final float pixelSizeAnim = font.getPixelSize(fontSizeAnim, dpiH); + + final String modeS = Region.getRenderModeString(renderer.getRenderModes()); + final String text1 = String.format("%03.1f/%03.1f fps, vsync %d, elapsed %4.1f s, fontSize %2.2f, msaa %d, %s-samples %d", + lfps, tfps, gl.getSwapInterval(), (t1-t0)/1000.0, fontSizeFixed, + drawable.getChosenGLCapabilities().getNumSamples(), modeS, vbaaSampleCount[0]); + final String text1A = String.format("%03.1f/%03.1f fps, vsync %d, elapsed %4.1f s, fontSize %2.2f, msaa %d, %s-samples %d", + lfps, tfps, gl.getSwapInterval(), (t1-t0)/1000.0, fontSizeAnim, + drawable.getChosenGLCapabilities().getNumSamples(), modeS, vbaaSampleCount[0]); + + if( false ) { + // renderString(drawable, font, pixelSize, getFontInfo(), 0, 0, 0, 0, -1000f, true); + renderString(drawable, font, pixelSize, textX2, 0, 0, 0, 0, -1000f, true); + // renderString(drawable, font, pixelSize, text1, 0, 0, 0, -1000f, regionFPS); // no-cache + } else { + renderString(drawable, font, pixelSize, getFontInfo(), 0, 0, 0, 0, -1000, true); + renderString(drawable, font, pixelSize, "012345678901234567890123456789", 0, 0, 0, -1000, true); + renderString(drawable, font, pixelSize, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, 0, 0, -1000, true); + renderString(drawable, font, pixelSize, "Hello World", 0, 0, 0, -1000, true); + renderString(drawable, font, pixelSize, "4567890123456", 4, 0, 0, -1000, true); + renderString(drawable, font, pixelSize, "I like JogAmp", 4, 0, 0, -1000, true); + renderString(drawable, font, pixelSize, "Hello World", 0, 0, 0, -1000, true); + renderString(drawable, font, pixelSize, textX2, 0, 0, 0, -1000, true); + renderString(drawable, font, pixelSize, text1, 0, 0, 0, -1000, regionFPS); // no-cache + if( TextAnim ) { + renderString(drawable, font, pixelSizeAnim, text1A, 0, 0, 0, -1000, regionFPSAnim); // no-cache + } + } + } }; } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java index 75a672a5b..a8044463d 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java @@ -45,9 +45,9 @@ import org.junit.runners.MethodSorters; import com.jogamp.common.os.Platform; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.curve.opengl.TextRenderer; +import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.font.FontFactory; -import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.graph.geom.SVertex; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.graph.demos.GPUTextRendererListenerBase01; import com.jogamp.opengl.test.junit.util.UITestCase; @@ -65,7 +65,7 @@ public class TestTextRendererNEWT01 extends UITestCase { return Integer.parseInt(a); } catch (Exception ex) { throw new RuntimeException(ex); } } - + public static void main(String args[]) throws IOException { for(int i=0; i<args.length; i++) { if(args[i].equals("-time")) { @@ -75,15 +75,15 @@ public class TestTextRendererNEWT01 extends UITestCase { } String tstname = TestTextRendererNEWT01.class.getName(); org.junit.runner.JUnitCore.main(tstname); - } - + } + static void sleep() { try { System.err.println("** new frame ** (sleep: "+duration+"ms)"); Thread.sleep(duration); } catch (InterruptedException ie) {} } - + static void destroyWindow(GLWindow window) { if(null!=window) { window.destroy(); @@ -111,56 +111,56 @@ public class TestTextRendererNEWT01 extends UITestCase { return; } GLProfile glp = GLProfile.getGL2ES2(); - + GLCapabilities caps = new GLCapabilities(glp); - caps.setAlphaBits(4); + caps.setAlphaBits(4); System.err.println("Requested: "+caps); GLWindow window = createWindow("text-vbaa1-msaa0", caps, 800,400); window.display(); System.err.println("Chosen: "+window.getChosenGLCapabilities()); - + RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); TextGLListener textGLListener = new TextGLListener(rs, Region.VBAA_RENDERING_BIT, DEBUG, TRACE); textGLListener.attachInputListenerTo(window); window.addGLEventListener(textGLListener); - + if(textGLListener.setFontSet(FontFactory.UBUNTU, 0, 0)) { - textGLListener.setTech(-400, -30, 0f, -1000, window.getWidth()*2); + textGLListener.setTech(-400, -30, 0f, -1000, 2); window.display(); sleep(); - - textGLListener.setTech(-400, -30, 0, -380, window.getWidth()*3); + + textGLListener.setTech(-400, -30, 0f, -380, 3); window.display(); sleep(); - - textGLListener.setTech(-400, -20, 0, -80, window.getWidth()*4); + + textGLListener.setTech(-400, -20, 0f, -80, 4); window.display(); sleep(); } if(textGLListener.setFontSet(FontFactory.JAVA, 0, 0)) { - textGLListener.setTech(-400, -30, 0f, -1000, window.getWidth()*2); + textGLListener.setTech(-400, -30, 0f, -1000, 2); window.display(); sleep(); - - textGLListener.setTech(-400, -30, 0, -380, window.getWidth()*3); + + textGLListener.setTech(-400, -30, 0f, -380, 3); window.display(); sleep(); - - textGLListener.setTech(-400, -20, 0, -80, window.getWidth()*4); + + textGLListener.setTech(-400, -20, 0f, -80, 4); window.display(); sleep(); } - - destroyWindow(window); + + destroyWindow(window); } - + @Test public void testTextRendererMSAA01() throws InterruptedException { GLProfile glp = GLProfile.get(GLProfile.GL2ES2); GLCapabilities caps = new GLCapabilities(glp); - caps.setAlphaBits(4); + caps.setAlphaBits(4); caps.setSampleBuffers(true); caps.setNumSamples(4); System.err.println("Requested: "+caps); @@ -168,22 +168,22 @@ public class TestTextRendererNEWT01 extends UITestCase { GLWindow window = createWindow("text-vbaa0-msaa1", caps, 800, 400); window.display(); System.err.println("Chosen: "+window.getChosenGLCapabilities()); - + RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); TextGLListener textGLListener = new TextGLListener(rs, 0, DEBUG, TRACE); textGLListener.attachInputListenerTo(window); window.addGLEventListener(textGLListener); - + if(textGLListener.setFontSet(FontFactory.UBUNTU, 0, 0)) { textGLListener.setTech(-400, -30, 0f, -1000, 0); window.display(); sleep(); - - textGLListener.setTech(-400, -30, 0, -380, 0); + + textGLListener.setTech(-400, -30, 0, -380, 0); window.display(); sleep(); - - textGLListener.setTech(-400, -20, 0, -80, 0); + + textGLListener.setTech(-400, -20, 0, -80, 0); window.display(); sleep(); } @@ -192,47 +192,47 @@ public class TestTextRendererNEWT01 extends UITestCase { textGLListener.setTech(-400, -30, 0f, -1000, 0); window.display(); sleep(); - - textGLListener.setTech(-400, -30, 0, -380, 0); + + textGLListener.setTech(-400, -30, 0, -380, 0); window.display(); sleep(); - - textGLListener.setTech(-400, -20, 0, -80, 0); + + textGLListener.setTech(-400, -20, 0, -80, 0); window.display(); sleep(); } - - destroyWindow(window); + + destroyWindow(window); } - + private class TextGLListener extends GPUTextRendererListenerBase01 { String winTitle; - + public TextGLListener(RenderState rs, int type, boolean debug, boolean trace) { - super(rs, type, debug, trace); + super(rs, type, 4, true, debug, trace); } - + public void attachInputListenerTo(GLWindow window) { super.attachInputListenerTo(window); winTitle = window.getTitle(); } - public void setTech(float xt, float yt, float angle, int zoom, int fboSize){ - setMatrix(xt, yt, angle, zoom, fboSize); + public void setTech(float xt, float yt, float angle, int zoom, int sampleCount){ + setMatrix(xt, yt, zoom, angle, sampleCount); } public void init(GLAutoDrawable drawable) { super.init(drawable); - + GL2ES2 gl = drawable.getGL().getGL2ES2(); gl.setSwapInterval(1); gl.glEnable(GL.GL_DEPTH_TEST); - - final TextRenderer textRenderer = (TextRenderer) getRenderer(); - - textRenderer.setAlpha(gl, 1.0f); - textRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); + + final RegionRenderer renderer = getRenderer(); + + renderer.setAlpha(gl, 1.0f); + renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); } - + public void display(GLAutoDrawable drawable) { super.display(drawable); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java index bfa942cc1..d109ba1cc 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java @@ -42,10 +42,11 @@ import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.curve.opengl.TextRenderer; +import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.graph.curve.opengl.TextRegionUtil; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; -import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.graph.geom.SVertex; import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.opengl.test.junit.util.NEWTGLContext; import com.jogamp.opengl.test.junit.util.UITestCase; @@ -60,9 +61,9 @@ public class TestTextRendererNEWT10 extends UITestCase { static boolean forceES2 = false; static boolean forceGL3 = false; static boolean mainRun = false; - - static final float[] textPosition = new float[] {0,0,0}; - static final int[] texSize = new int[] { 0 }; + static boolean useMSAA = true; + + static final int[] texSize = new int[] { 0 }; static final int fontSize = 24; static Font font; @@ -70,19 +71,21 @@ public class TestTextRendererNEWT10 extends UITestCase { public static void setup() throws IOException { font = FontFactory.get(FontFactory.UBUNTU).getDefault(); } - + static int atoi(String a) { try { return Integer.parseInt(a); } catch (Exception ex) { throw new RuntimeException(ex); } } - + public static void main(String args[]) throws IOException { mainRun = true; for(int i=0; i<args.length; i++) { if(args[i].equals("-time")) { i++; duration = atoi(args[i]); + } else if(args[i].equals("-noMSAA")) { + useMSAA = false; } else if(args[i].equals("-es2")) { forceES2 = true; } else if(args[i].equals("-gl3")) { @@ -91,17 +94,26 @@ public class TestTextRendererNEWT10 extends UITestCase { } String tstname = TestTextRendererNEWT10.class.getName(); org.junit.runner.JUnitCore.main(tstname); - } - + } + static void sleep() { try { System.err.println("** new frame ** (sleep: "+duration+"ms)"); Thread.sleep(duration); } catch (InterruptedException ie) {} } - + + // @Test + public void test00TextRendererNONE01() throws InterruptedException { + testTextRendererImpl(0); + } + @Test public void testTextRendererMSAA01() throws InterruptedException { + testTextRendererImpl(4); + } + + void testTextRendererImpl(int sampleCount) throws InterruptedException { final GLProfile glp; if(forceGL3) { glp = GLProfile.get(GLProfile.GL3); @@ -111,76 +123,77 @@ public class TestTextRendererNEWT10 extends UITestCase { glp = GLProfile.getGL2ES2(); } final GLCapabilities caps = new GLCapabilities( glp ); - caps.setAlphaBits(4); - caps.setSampleBuffers(true); - caps.setNumSamples(4); + caps.setAlphaBits(4); + if( 0 < sampleCount ) { + caps.setSampleBuffers(true); + caps.setNumSamples(sampleCount); + } System.err.println("Requested: "+caps); final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow(caps, 800, 400, true); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL2ES2 gl = winctx.context.getGL().getGL2ES2(); - System.err.println(winctx.context); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); System.err.println("Chosen: "+winctx.window.getChosenCapabilities()); - + final RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); - final TextRenderer renderer = TextRenderer.create(rs, 0); + final RegionRenderer renderer = RegionRenderer.create(rs, 0, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable); + final TextRegionUtil textRenderUtil = new TextRegionUtil(renderer); // init gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); renderer.init(gl); renderer.setAlpha(gl, 1.0f); - renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); + renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); // reshape - gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight()); + gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight()); // renderer.reshapePerspective(gl, 45.0f, drawable.getWidth(), drawable.getHeight(), 0.1f, 1000.0f); renderer.reshapeOrtho(gl, drawable.getWidth(), drawable.getHeight(), 0.1f, 1000.0f); // display - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - renderString(drawable, gl, renderer, "012345678901234567890123456789", 0, 0, -1000); - renderString(drawable, gl, renderer, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000); - renderString(drawable, gl, renderer, "Hello World", 0, -1, -1000); - renderString(drawable, gl, renderer, "4567890123456", 4, -1, -1000); - renderString(drawable, gl, renderer, "I like JogAmp", 4, -1, -1000); - + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + renderString(drawable, gl, textRenderUtil, "012345678901234567890123456789", 0, 0, -1000); + renderString(drawable, gl, textRenderUtil, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000); + renderString(drawable, gl, textRenderUtil, "Hello World", 0, -1, -1000); + renderString(drawable, gl, textRenderUtil, "4567890123456", 4, -1, -1000); + renderString(drawable, gl, textRenderUtil, "I like JogAmp", 4, -1, -1000); + int c = 0; - renderString(drawable, gl, renderer, "GlueGen", c++, -1, -1000); - renderString(drawable, gl, renderer, "JOAL", c++, -1, -1000); - renderString(drawable, gl, renderer, "JOGL", c++, -1, -1000); - renderString(drawable, gl, renderer, "JOCL", c++, -1, -1000); - + renderString(drawable, gl, textRenderUtil, "GlueGen", c++, -1, -1000); + renderString(drawable, gl, textRenderUtil, "JOAL", c++, -1, -1000); + renderString(drawable, gl, textRenderUtil, "JOGL", c++, -1, -1000); + renderString(drawable, gl, textRenderUtil, "JOCL", c++, -1, -1000); + drawable.swapBuffers(); - sleep(); + sleep(); // dispose renderer.destroy(gl); - + NEWTGLContext.destroyWindow(winctx); - } - int screenshot_num = 0; - + } + int lastRow = -1; - - void renderString(GLDrawable drawable, GL2ES2 gl, TextRenderer renderer, String text, int column, int row, int z0) { + + void renderString(GLDrawable drawable, GL2ES2 gl, TextRegionUtil textRenderUtil, String text, int column, int row, int z0) { final int height = drawable.getHeight(); - + int dx = 0; - int dy = height; + int dy = height; if(0>row) { row = lastRow + 1; } AABBox textBox = font.getStringBounds(text, fontSize); dx += font.getAdvanceWidth('X', fontSize) * column; dy -= (int)textBox.getHeight() * ( row + 1 ); - renderer.resetModelview(null); - renderer.translate(gl, dx, dy, z0); - renderer.drawString3D(gl, font, text, textPosition, fontSize, texSize); - + textRenderUtil.renderer.resetModelview(null); + textRenderUtil.renderer.translate(gl, dx, dy, z0); + textRenderUtil.drawString3D(gl, font, fontSize, text, texSize); + lastRow = row; - } + } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java b/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java index 1282d5d97..4b89a85fb 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java @@ -34,22 +34,71 @@ import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; import javax.media.opengl.fixedfunc.GLMatrixFunc; +import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.curve.opengl.TextRenderer; +import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.graph.curve.opengl.TextRegionUtil; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; -import com.jogamp.graph.geom.opengl.SVertex; -import com.jogamp.opengl.math.geom.AABBox; +import com.jogamp.graph.font.FontSet; +import com.jogamp.graph.geom.SVertex; +import com.jogamp.newt.Window; import com.jogamp.opengl.util.PMVMatrix; import com.jogamp.opengl.util.glsl.ShaderState; public abstract class TextRendererGLELBase implements GLEventListener { - protected final float[] textPosition = new float[] {0,0,0}; - protected final int[] texSize = new int[] { 0 }; + public final int usrRenderModes; + + protected final int[] vbaaSampleCount; protected final float[] staticRGBAColor = new float[] { 1f, 1f, 1f, 1f }; - protected final Font font; - protected final int usrRenderModes; + private boolean exclusivePMVMatrix = true; + private PMVMatrix sharedPMVMatrix = null; + private RenderState rs = null; + private RegionRenderer.GLCallback enableCallback=null, disableCallback=null; + protected RegionRenderer renderer = null; + protected TextRegionUtil textRenderUtil = null; + + /** scale pixel, default is 1f */ + protected float pixelScale = 1.0f; + + /** dpi display resolution, queried at {@link #init(GLAutoDrawable)} if NEWT, otherwise 96. */ + protected float dpiH = 96; + + boolean flipVerticalInGLOrientation = false; + + /** + * @param fontSet e.g. default is {@link FontFactory#UBUNTU} + * @param fontFamily e.g. default is {@link FontSet#FAMILY_REGULAR} + * @param fontStylebits e.g. default is {@link FontSet#STYLE_NONE} + * @return the resulting font. + */ + public static Font getFont(final int fontSet, final int fontFamily, final int fontStylebits) { + try { + return FontFactory.get(fontSet).get(fontFamily, fontStylebits); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** + * @param renderModes + * @param sampleCount desired multisampling sample count for msaa-rendering. + * @see #setRendererCallbacks(com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback) + */ + public TextRendererGLELBase(final int renderModes, int[] sampleCount) { + this.usrRenderModes = renderModes; + this.vbaaSampleCount = sampleCount; + } + + /** + * <p> + * Must be called before {@link #init(GLAutoDrawable)}. + * </p> + * @param rs + */ + public void setRenderState(RenderState rs) { this.rs = rs; } /** * In exclusive mode, impl. uses a pixelScale of 1f and orthogonal PMV on window dimensions @@ -58,54 +107,49 @@ public abstract class TextRendererGLELBase implements GLEventListener { * In non-exclusive mode, i.e. shared w/ custom PMV (within another 3d scene), * it uses the custom pixelScale and renderString uses normalized 'height', i.e. '1'. * </p> + * <p> + * Must be called before {@link #init(GLAutoDrawable)}. + * </p> */ - protected boolean exclusivePMVMatrix = true; - protected PMVMatrix usrPMVMatrix = null; - protected RenderState rs = null; - protected TextRenderer renderer = null; - - /** font size in pixels, default is 24 */ - protected int fontSize = 24; - /** scale pixel, default is 1f */ - protected float pixelScale = 1.0f; - protected int texSizeScale = 2; - - boolean flipVerticalInGLOrientation = false; + public void setSharedPMVMatrix(PMVMatrix pmv) { + this.sharedPMVMatrix = pmv; + } - public TextRendererGLELBase(final int renderModes) { - usrRenderModes = renderModes; - { - Font _font = null; - try { - _font = FontFactory.get(FontFactory.UBUNTU).getDefault(); - } catch (IOException e) { - e.printStackTrace(); - } - this.font = _font; - } + /** + * See {@link RegionRenderer#create(RenderState, int, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback)}. + * <p> + * Must be called before {@link #init(GLAutoDrawable)}. + * </p> + */ + public void setRendererCallbacks(RegionRenderer.GLCallback enable, RegionRenderer.GLCallback disable) { + this.enableCallback = enable; + this.disableCallback = disable; } public void setFlipVerticalInGLOrientation(boolean v) { flipVerticalInGLOrientation=v; } - public final TextRenderer getRenderer() { return renderer; } + public final RegionRenderer getRenderer() { return renderer; } + public final TextRegionUtil getTextRenderUtil() { return textRenderUtil; } @Override public void init(GLAutoDrawable drawable) { - if( null != font ) { - exclusivePMVMatrix = null == usrPMVMatrix; - this.rs = RenderState.createRenderState(new ShaderState(), SVertex.factory(), usrPMVMatrix); - this.renderer = TextRenderer.create(rs, usrRenderModes); - if( 0 == usrRenderModes ) { - texSizeScale = 0; - } - final GL2ES2 gl = drawable.getGL().getGL2ES2(); - renderer.init(gl); - renderer.setAlpha(gl, staticRGBAColor[3]); - renderer.setColorStatic(gl, staticRGBAColor[0], staticRGBAColor[1], staticRGBAColor[2]); - final ShaderState st = rs.getShaderState(); - st.useProgram(gl, false); - } else { - this.rs = null; - this.renderer = null; + if( null == this.rs ) { + exclusivePMVMatrix = null == sharedPMVMatrix; + this.rs = RenderState.createRenderState(new ShaderState(), SVertex.factory(), sharedPMVMatrix); + } + this.renderer = RegionRenderer.create(rs, usrRenderModes, enableCallback, disableCallback); + this.textRenderUtil = new TextRegionUtil(renderer); + final GL2ES2 gl = drawable.getGL().getGL2ES2(); + renderer.init(gl); + renderer.setAlpha(gl, staticRGBAColor[3]); + renderer.setColorStatic(gl, staticRGBAColor[0], staticRGBAColor[1], staticRGBAColor[2]); + final ShaderState st = rs.getShaderState(); + st.useProgram(gl, false); + + final Object upObj = drawable.getUpstreamWidget(); + if( upObj instanceof Window ) { + final float[] pixelsPerMM = new float[2]; + ((Window)upObj).getMainMonitor().getPixelsPerMM(pixelsPerMM); + dpiH = pixelsPerMM[1]*25.4f; } } @@ -123,7 +167,6 @@ public abstract class TextRendererGLELBase implements GLEventListener { renderer.reshapeNotify(gl, width, height); } st.useProgram(gl, false); - texSize[0] = width * texSizeScale; } } @@ -140,13 +183,63 @@ public abstract class TextRendererGLELBase implements GLEventListener { int lastRow = -1; - public void renderString(GLAutoDrawable drawable, String text, int column, float tx, float ty, float tz) { + /** + * + * @param drawable + * @param font + * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. + * @param text + * @param column + * @param tx + * @param ty + * @param tz + * @param cacheRegion + */ + public void renderString(GLAutoDrawable drawable, + Font font, float pixelSize, String text, + int column, float tx, float ty, float tz, boolean cacheRegion) { final int row = lastRow + 1; - renderString(drawable, text, column, row, tx, ty, tz); - lastRow = row; + renderStringImpl(drawable, font, pixelSize, text, column, row, tx, ty, tz, cacheRegion, null); } - public void renderString(GLAutoDrawable drawable, String text, int column, int row, float tx, float ty, float tz) { + public void renderString(GLAutoDrawable drawable, + Font font, float pixelSize, String text, + int column, float tx, float ty, float tz, GLRegion region) { + final int row = lastRow + 1; + renderStringImpl(drawable, font, pixelSize, text, column, row, tx, ty, tz, false, region); + } + + /** + * + * @param drawable + * @param font + * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. + * @param text + * @param column + * @param row + * @param tx + * @param ty + * @param tz + * @param cacheRegion + */ + public void renderString(GLAutoDrawable drawable, + Font font, float pixelSize, String text, + int column, int row, + float tx, float ty, float tz, boolean cacheRegion) { + renderStringImpl(drawable, font, pixelSize, text, column, row, tx, ty, tz, cacheRegion, null); + } + + public void renderString(GLAutoDrawable drawable, + Font font, float pixelSize, String text, + int column, int row, + float tx, float ty, float tz, GLRegion region) { + renderStringImpl(drawable, font, pixelSize, text, column, row, tx, ty, tz, false, region); + } + + private void renderStringImpl(GLAutoDrawable drawable, + Font font, float pixelSize, String text, + int column, int row, + float tx, float ty, float tz, boolean cacheRegion, GLRegion region) { if( null != renderer ) { final GL2ES2 gl = drawable.getGL().getGL2ES2(); @@ -159,12 +252,11 @@ public abstract class TextRendererGLELBase implements GLEventListener { final int height = drawable.getHeight(); dy = height-ty; } + final int newLineCount = text.length() - text.replace("\n", "").length(); + final float lineHeight = font.getLineHeight(pixelSize); + dx += pixelScale * font.getAdvanceWidth('X', pixelSize) * column; + dy -= pixelScale * lineHeight * ( row + 1 ); - final AABBox textBox = font.getStringBounds(text, fontSize); - dx += pixelScale * font.getAdvanceWidth('X', fontSize) * column; - dy -= pixelScale * (int)textBox.getHeight() * ( row + 1 ); - - final ShaderState st = rs.getShaderState(); final PMVMatrix pmvMatrix = rs.pmvMatrix(); pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); if( !exclusivePMVMatrix ) { @@ -172,24 +264,27 @@ public abstract class TextRendererGLELBase implements GLEventListener { } else { pmvMatrix.glLoadIdentity(); } - - st.useProgram(gl, true); - gl.glEnable(GL2ES2.GL_BLEND); pmvMatrix.glTranslatef(dx, dy, tz); if( flipVerticalInGLOrientation && drawable.isGLOriented() ) { pmvMatrix.glScalef(pixelScale, -1f*pixelScale, 1f); } else if( 1f != pixelScale ) { pmvMatrix.glScalef(pixelScale, pixelScale, 1f); } + renderer.enable(gl, true); renderer.updateMatrix(gl); - renderer.drawString3D(gl, font, text, textPosition, fontSize, texSize); - st.useProgram(gl, false); - gl.glDisable(GL2ES2.GL_BLEND); + if( cacheRegion ) { + textRenderUtil.drawString3D(gl, font, pixelSize, text, vbaaSampleCount); + } else if( null != region ) { + TextRegionUtil.drawString3D(region, renderer, gl, font, pixelSize, text, vbaaSampleCount); + } else { + TextRegionUtil.drawString3D(renderer, gl, font, pixelSize, text, vbaaSampleCount); + } + renderer.enable(gl, false); if( !exclusivePMVMatrix ) { pmvMatrix.glPopMatrix(); } - lastRow = -1; + lastRow = row + newLineCount; } } -}
\ No newline at end of file +} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java index 46557e8c8..6dd86e10c 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener01.java @@ -31,26 +31,27 @@ package com.jogamp.opengl.test.junit.graph.demos; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; import javax.media.opengl.GLAutoDrawable; + import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.curve.opengl.GLRegion; -import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.curve.opengl.RenderState; +import com.jogamp.graph.curve.opengl.RegionRenderer; /** Demonstrate the rendering of multiple outlines into one region/OutlineShape * These Outlines are not necessary connected or contained. * The output of this demo shows two identical shapes but the left one - * has some vertices with off-curve flag set to true, and the right allt he vertices - * are on the curve. Demos the Res. Independent Nurbs based Curve rendering + * has some vertices with off-curve flag set to true, and the right allt he vertices + * are on the curve. Demos the Res. Independent Nurbs based Curve rendering * */ public class GPURegionGLListener01 extends GPURegionRendererListenerBase01 { OutlineShape outlineShape = null; - - public GPURegionGLListener01 (RenderState rs, int renderModes, int fbosize, boolean debug, boolean trace) { + + public GPURegionGLListener01 (RenderState rs, int renderModes, int sampleCount, boolean debug, boolean trace) { super(rs, renderModes, debug, trace); - setMatrix(-20, 00, 0f, -50, fbosize); + setMatrix(-20, 00, -50, 0f, sampleCount); } - + private void createTestOutline(){ float offset = 0; outlineShape = new OutlineShape(getRenderer().getRenderState().getVertexFactory()); @@ -61,14 +62,14 @@ public class GPURegionGLListener01 extends GPURegionRendererListenerBase01 { outlineShape.addVertex(6.0f,15.0f, false); outlineShape.addVertex(5.0f,8.0f, false); outlineShape.addVertex(0.0f,10.0f,true); - outlineShape.closeLastOutline(); + outlineShape.closeLastOutline(true); outlineShape.addEmptyOutline(); outlineShape.addVertex(5.0f,-5.0f,true); outlineShape.addVertex(10.0f,-5.0f, false); outlineShape.addVertex(10.0f,0.0f, true); outlineShape.addVertex(5.0f,0.0f, false); - outlineShape.closeLastOutline(); - + outlineShape.closeLastOutline(true); + /** Same shape as above but without any off-curve vertices */ offset = 30; outlineShape.addEmptyOutline(); @@ -79,30 +80,31 @@ public class GPURegionGLListener01 extends GPURegionRendererListenerBase01 { outlineShape.addVertex(offset+7.0f,15.0f, true); outlineShape.addVertex(offset+6.0f,8.0f, true); outlineShape.addVertex(offset+0.0f,10.0f, true); - outlineShape.closeLastOutline(); + outlineShape.closeLastOutline(true); outlineShape.addEmptyOutline(); outlineShape.addVertex(offset+5.0f,0.0f, true); outlineShape.addVertex(offset+5.0f,-5.0f, true); outlineShape.addVertex(offset+10.0f,-5.0f, true); outlineShape.addVertex(offset+10.0f,0.0f, true); - outlineShape.closeLastOutline(); - - region = GLRegion.create(outlineShape, getRenderModes()); + outlineShape.closeLastOutline(true); + + region = GLRegion.create(getRenderModes()); + region.addOutlineShape(outlineShape, null); } public void init(GLAutoDrawable drawable) { super.init(drawable); - + GL2ES2 gl = drawable.getGL().getGL2ES2(); - final RegionRenderer regionRenderer = (RegionRenderer) getRenderer(); + final RegionRenderer regionRenderer = getRenderer(); gl.setSwapInterval(1); gl.glEnable(GL2ES2.GL_DEPTH_TEST); gl.glEnable(GL2ES2.GL_BLEND); regionRenderer.setAlpha(gl, 1.0f); regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); - + createTestOutline(); } @@ -112,14 +114,14 @@ public class GPURegionGLListener01 extends GPURegionRendererListenerBase01 { gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - final RegionRenderer regionRenderer = (RegionRenderer) getRenderer(); - + final RegionRenderer regionRenderer = getRenderer(); + regionRenderer.resetModelview(null); - regionRenderer.translate(null, getXTran(), getYTran(), getZoom()); + regionRenderer.translate(null, getXTran(), getYTran(), getZTran()); regionRenderer.rotate(gl, getAngle(), 0, 1, 0); if( weight != regionRenderer.getWeight()) { regionRenderer.setWeight(gl, weight); } - regionRenderer.draw(gl, region, getPosition(), getTexSize()); - } + region.draw(gl, regionRenderer, getSampleCount()); + } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java index 525c5e648..d0afc8ad0 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionGLListener02.java @@ -28,79 +28,85 @@ package com.jogamp.opengl.test.junit.graph.demos; +import java.util.ArrayList; +import java.util.List; + import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; import javax.media.opengl.GLAutoDrawable; import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.curve.opengl.GLRegion; -import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.curve.opengl.RenderState; +import com.jogamp.graph.curve.opengl.RegionRenderer; /** Demonstrate the rendering of multiple OutlineShapes * into one region * */ public class GPURegionGLListener02 extends GPURegionRendererListenerBase01 { - OutlineShape[] outlineShapes = new OutlineShape[2]; + List<OutlineShape> outlineShapes = new ArrayList<OutlineShape>(); - public GPURegionGLListener02 (RenderState rs, int renderModes, int fbosize, boolean debug, boolean trace) { + public GPURegionGLListener02 (RenderState rs, int renderModes, int sampleCount, boolean debug, boolean trace) { super(rs, renderModes, debug, trace); - setMatrix(-20, 00, 0f, -50, fbosize); + setMatrix(-20, 00, -50, 0f, sampleCount); } - + private void createTestOutline(){ float offset = 0; - outlineShapes[0] = new OutlineShape(getRenderer().getRenderState().getVertexFactory()); - outlineShapes[0].addVertex(0.0f,-10.0f,true); - outlineShapes[0].addVertex(15.0f,-10.0f, true); - outlineShapes[0].addVertex(10.0f,5.0f, false); - outlineShapes[0].addVertex(15.0f,10.0f, true); - outlineShapes[0].addVertex(6.0f,15.0f, false); - outlineShapes[0].addVertex(5.0f,8.0f, false); - outlineShapes[0].addVertex(0.0f,10.0f,true); - outlineShapes[0].closeLastOutline(); - outlineShapes[0].addEmptyOutline(); - outlineShapes[0].addVertex(5.0f,-5.0f,true); - outlineShapes[0].addVertex(10.0f,-5.0f, false); - outlineShapes[0].addVertex(10.0f,0.0f, true); - outlineShapes[0].addVertex(5.0f,0.0f, false); - outlineShapes[0].closeLastOutline(); - + OutlineShape shape = new OutlineShape(getRenderer().getRenderState().getVertexFactory()); + outlineShapes.add(shape); + shape.addVertex(0.0f,-10.0f,true); + shape.addVertex(15.0f,-10.0f, true); + shape.addVertex(10.0f,5.0f, false); + shape.addVertex(15.0f,10.0f, true); + shape.addVertex(6.0f,15.0f, false); + shape.addVertex(5.0f,8.0f, false); + shape.addVertex(0.0f,10.0f,true); + shape.closeLastOutline(true); + shape.addEmptyOutline(); + shape.addVertex(5.0f,-5.0f,true); + shape.addVertex(10.0f,-5.0f, false); + shape.addVertex(10.0f,0.0f, true); + shape.addVertex(5.0f,0.0f, false); + shape.closeLastOutline(true); + /** Same shape as above but without any off-curve vertices */ - outlineShapes[1] = new OutlineShape(getRenderer().getRenderState().getVertexFactory()); + shape = new OutlineShape(getRenderer().getRenderState().getVertexFactory()); + outlineShapes.add(shape); offset = 30; - outlineShapes[1].addVertex(offset+0.0f,-10.0f, true); - outlineShapes[1].addVertex(offset+17.0f,-10.0f, true); - outlineShapes[1].addVertex(offset+11.0f,5.0f, true); - outlineShapes[1].addVertex(offset+16.0f,10.0f, true); - outlineShapes[1].addVertex(offset+7.0f,15.0f, true); - outlineShapes[1].addVertex(offset+6.0f,8.0f, true); - outlineShapes[1].addVertex(offset+0.0f,10.0f, true); - outlineShapes[1].closeLastOutline(); - outlineShapes[1].addEmptyOutline(); - outlineShapes[1].addVertex(offset+5.0f,0.0f, true); - outlineShapes[1].addVertex(offset+5.0f,-5.0f, true); - outlineShapes[1].addVertex(offset+10.0f,-5.0f, true); - outlineShapes[1].addVertex(offset+10.0f,0.0f, true); - outlineShapes[1].closeLastOutline(); - - region = GLRegion.create(outlineShapes, getRenderModes()); + shape.addVertex(offset+0.0f,-10.0f, true); + shape.addVertex(offset+17.0f,-10.0f, true); + shape.addVertex(offset+11.0f,5.0f, true); + shape.addVertex(offset+16.0f,10.0f, true); + shape.addVertex(offset+7.0f,15.0f, true); + shape.addVertex(offset+6.0f,8.0f, true); + shape.addVertex(offset+0.0f,10.0f, true); + shape.closeLastOutline(true); + shape.addEmptyOutline(); + shape.addVertex(offset+5.0f,0.0f, true); + shape.addVertex(offset+5.0f,-5.0f, true); + shape.addVertex(offset+10.0f,-5.0f, true); + shape.addVertex(offset+10.0f,0.0f, true); + shape.closeLastOutline(true); + + region = GLRegion.create(getRenderModes()); + region.addOutlineShapes(outlineShapes, null); } public void init(GLAutoDrawable drawable) { super.init(drawable); - + GL2ES2 gl = drawable.getGL().getGL2ES2(); - final RegionRenderer regionRenderer = (RegionRenderer) getRenderer(); + final RegionRenderer regionRenderer = getRenderer(); gl.setSwapInterval(1); gl.glEnable(GL2ES2.GL_DEPTH_TEST); gl.glEnable(GL2ES2.GL_BLEND); regionRenderer.setAlpha(gl, 1.0f); regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); - + createTestOutline(); } @@ -110,15 +116,15 @@ public class GPURegionGLListener02 extends GPURegionRendererListenerBase01 { gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - final RegionRenderer regionRenderer = (RegionRenderer) getRenderer(); - + final RegionRenderer regionRenderer = getRenderer(); + regionRenderer.resetModelview(null); - regionRenderer.translate(null, getXTran(), getYTran(), getZoom()); + regionRenderer.translate(null, getXTran(), getYTran(), getZTran()); regionRenderer.rotate(gl, getAngle(), 0, 1, 0); if( weight != regionRenderer.getWeight()) { regionRenderer.setWeight(gl, weight); } - regionRenderer.draw(gl, region, getPosition(), getTexSize()); - - } + region.draw(gl, regionRenderer, getSampleCount()); + + } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java index 160dc0ffe..c6c4b62ce 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java @@ -28,13 +28,12 @@ package com.jogamp.opengl.test.junit.graph.demos; -import javax.media.opengl.FPSCounter; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.graph.geom.SVertex; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.WindowAdapter; @@ -46,14 +45,14 @@ import com.jogamp.opengl.util.glsl.ShaderState; /** Demonstrate the rendering of multiple outlines into one region/OutlineShape * These Outlines are not necessary connected or contained. * The output of this demo shows two identical shapes but the left one - * has some vertices with off-curve flag set to true, and the right allt he vertices - * are on the curve. Demos the Res. Independent Nurbs based Curve rendering + * has some vertices with off-curve flag set to true, and the right allt he vertices + * are on the curve. Demos the Res. Independent Nurbs based Curve rendering * */ public class GPURegionNewtDemo01 { static final boolean DEBUG = false; static final boolean TRACE = false; - + public static void main(String[] args) { GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); @@ -61,25 +60,23 @@ public class GPURegionNewtDemo01 { caps.setSampleBuffers(true); caps.setNumSamples(4); // 2 samples is not enough .. System.out.println("Requested: " + caps); - + final GLWindow window = GLWindow.create(caps); window.setPosition(10, 10); window.setSize(800, 400); window.setTitle("GPU Curve Region Newt Demo 01 - vbaa0 msaa1"); - + RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); GPURegionGLListener01 regionGLListener = new GPURegionGLListener01 (rs, Region.VARIABLE_CURVE_WEIGHT_BIT, 0, DEBUG, TRACE); - regionGLListener.attachInputListenerTo(window); + regionGLListener.attachInputListenerTo(window); window.addGLEventListener(regionGLListener); - - window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); window.setVisible(true); //FPSAnimator animator = new FPSAnimator(60); final Animator animator = new Animator(); - animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); + animator.setUpdateFPSFrames(60, System.err); animator.add(window); - + window.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent arg0) { if(arg0.getKeyCode() == KeyEvent.VK_F4) { @@ -92,7 +89,7 @@ public class GPURegionNewtDemo01 { animator.stop(); } }); - + animator.start(); - } + } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java index e7b5c73c5..e7bd59aeb 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java @@ -28,13 +28,12 @@ package com.jogamp.opengl.test.junit.graph.demos; -import javax.media.opengl.FPSCounter; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.graph.geom.SVertex; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.WindowAdapter; @@ -50,31 +49,29 @@ import com.jogamp.opengl.util.glsl.ShaderState; public class GPURegionNewtDemo02 { static final boolean DEBUG = false; static final boolean TRACE = false; - + public static void main(String[] args) { GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); - caps.setAlphaBits(4); + caps.setAlphaBits(4); System.out.println("Requested: " + caps); - + final GLWindow window = GLWindow.create(caps); window.setPosition(10, 10); window.setSize(800, 400); window.setTitle("GPU Curve Region Newt Demo 02 - vbaa1 msaa0"); - + RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); - GPURegionGLListener02 regionGLListener = new GPURegionGLListener02 (rs, Region.VBAA_RENDERING_BIT|Region.VARIABLE_CURVE_WEIGHT_BIT, 1140, DEBUG, TRACE); - regionGLListener.attachInputListenerTo(window); + GPURegionGLListener02 regionGLListener = new GPURegionGLListener02 (rs, Region.VBAA_RENDERING_BIT|Region.VARIABLE_CURVE_WEIGHT_BIT, 4, DEBUG, TRACE); + regionGLListener.attachInputListenerTo(window); window.addGLEventListener(regionGLListener); - - window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); window.setVisible(true); //FPSAnimator animator = new FPSAnimator(60); final Animator animator = new Animator(); - animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); + animator.setUpdateFPSFrames(60, System.err); animator.add(window); - + window.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent arg0) { if(arg0.getKeyCode() == KeyEvent.VK_F4) { @@ -87,7 +84,7 @@ public class GPURegionNewtDemo02 { animator.stop(); } }); - + animator.start(); - } + } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionRendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionRendererListenerBase01.java index 8439d1fff..9ececa082 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionRendererListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionRendererListenerBase01.java @@ -37,7 +37,7 @@ import com.jogamp.graph.curve.opengl.RenderState; * - 1/2: zoom in/out * - 3/4: font +/- * - 6/7: 2nd pass texture size - * - 0/9: rotate + * - 0/9: rotate * - s: toogle draw 'font set' * - f: toggle draw fps * - v: toggle v-sync @@ -47,6 +47,6 @@ public abstract class GPURegionRendererListenerBase01 extends GPURendererListene OutlineShape outlineShape = null; public GPURegionRendererListenerBase01(RenderState rs, int renderModes, boolean debug, boolean trace) { - super(RegionRenderer.create(rs, renderModes), renderModes, debug, trace); - } -}
\ No newline at end of file + super(RegionRenderer.create(rs, renderModes, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable), renderModes, debug, trace); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java index 4ebb937a0..d5247eb51 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java @@ -42,10 +42,9 @@ import javax.media.opengl.GLException; import javax.media.opengl.GLPipelineFactory; import javax.media.opengl.GLRunnable; - import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.GLRegion; -import com.jogamp.graph.curve.opengl.Renderer; +import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.KeyListener; import com.jogamp.newt.opengl.GLWindow; @@ -56,60 +55,64 @@ import com.jogamp.opengl.util.GLReadBufferUtil; * Action Keys: * - 1/2: zoom in/out * - 6/7: 2nd pass texture size - * - 0/9: rotate + * - 0/9: rotate * - Q/W: change weight * - v: toggle v-sync * - s: screenshot */ public abstract class GPURendererListenerBase01 implements GLEventListener { - private GLReadBufferUtil screenshot; - private Renderer renderer; - private int renderModes; - private boolean debug; - private boolean trace; - + private final RegionRenderer renderer; + private final int renderModes; + private final boolean debug; + private final boolean trace; + protected GLRegion region; + private final GLReadBufferUtil screenshot; + private KeyAction keyAction; - + private volatile GLAutoDrawable autoDrawable = null; - + private final float[] position = new float[] {0,0,0}; + + protected final float zNear = 0.1f, zFar = 7000f; private float xTran = -10; - private float yTran = 10; + private float yTran = 10; private float ang = 0f; - private float zoom = -70f; - private int[] texSize = new int[] { 400 }; + private float zTran = -70f; + private final int[] sampleCount = new int[] { 4 }; protected volatile float weight = 1.0f; boolean ignoreInput = false; - public GPURendererListenerBase01(Renderer renderer, int renderModes, boolean debug, boolean trace) { + public GPURendererListenerBase01(RegionRenderer renderer, int renderModes, boolean debug, boolean trace) { this.renderer = renderer; this.renderModes = renderModes; this.debug = debug; this.trace = trace; this.screenshot = new GLReadBufferUtil(false, false); } - - public final Renderer getRenderer() { return renderer; } + + public final RegionRenderer getRenderer() { return renderer; } public final int getRenderModes() { return renderModes; } - public final float getZoom() { return zoom; } + public final float getZTran() { return zTran; } public final float getXTran() { return xTran; } public final float getYTran() { return yTran; } public final float getAngle() { return ang; } - public final int[] getTexSize() { return texSize; } + public final int[] getSampleCount() { return sampleCount; } public final float[] getPosition() { return position; } - public void setMatrix(float xtrans, float ytrans, float angle, int zoom, int fbosize) { + public void setMatrix(float xtrans, float ytrans, int zTran, float angle, int sampleCount) { this.xTran = xtrans; - this.yTran = ytrans; - this.ang = angle; - this.zoom = zoom; - this.texSize[0] = fbosize; + this.yTran = ytrans; + this.zTran = zTran; + this.ang = angle; + this.sampleCount[0] = sampleCount; } - + + @Override public void init(GLAutoDrawable drawable) { autoDrawable = drawable; GL2ES2 gl = drawable.getGL().getGL2ES2(); @@ -125,32 +128,34 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); getRenderer().init(gl); } - + + @Override public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) { GL2ES2 gl = drawable.getGL().getGL2ES2(); - - gl.glViewport(xstart, ystart, width, height); - renderer.reshapePerspective(gl, 45.0f, width, height, 0.1f, 7000.0f); - + + gl.glViewport(xstart, ystart, width, height); + renderer.reshapePerspective(gl, 45.0f, width, height, zNear, zFar); + dumpMatrix(); - System.err.println("Reshape: "+renderer.getRenderState()); + // System.err.println("Reshape: "+renderer.getRenderState()); } - + + @Override public void dispose(GLAutoDrawable drawable) { autoDrawable = null; GL2ES2 gl = drawable.getGL().getGL2ES2(); if(null != region) { - region.destroy(gl, renderer.getRenderState()); + region.destroy(gl, renderer); } screenshot.dispose(gl); renderer.destroy(gl); - } - + } + public void zoom(int v){ - zoom += v; + zTran += v; dumpMatrix(); } - + public void move(float x, float y){ xTran += x; yTran += y; @@ -162,43 +167,43 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { dumpMatrix(); } public void editGlobalWeight(float delta) { - if( !Renderer.isWeightValid(weight+delta) ) { + if( !RegionRenderer.isWeightValid(weight+delta) ) { return; } weight += delta; System.err.println("Global Weight: "+ weight); } - + void dumpMatrix() { - System.err.println("Matrix: " + xTran + "/" + yTran + " x"+zoom + " @"+ang); + System.err.println("Matrix: " + xTran + " / " + yTran + " / "+zTran + " @ "+ang); } - - /** Attach the input listener to the window */ + + /** Attach the input listener to the window */ public void attachInputListenerTo(GLWindow window) { if ( null == keyAction ) { keyAction = new KeyAction(); - window.addKeyListener(keyAction); + window.addKeyListener(keyAction); } } - + public void detachInputListenerFrom(GLWindow window) { if ( null == keyAction ) { return; } window.removeKeyListener(keyAction); } - + public void printScreen(GLAutoDrawable drawable, String dir, String tech, String objName, boolean exportAlpha) throws GLException, IOException { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); - pw.printf("-%03dx%03d-Z%04d-T%04d-%s", drawable.getWidth(), drawable.getHeight(), (int)Math.abs(zoom), texSize[0], objName); - + pw.printf("-%03dx%03d-Z%04d-S%02d-%s", drawable.getWidth(), drawable.getHeight(), (int)Math.abs(zTran), sampleCount[0], objName); + final String filename = dir + tech + sw +".png"; if(screenshot.readPixels(drawable.getGL(), false)) { screenshot.write(new File(filename)); } } - + int screenshot_num = 0; public void setIgnoreInput(boolean v) { @@ -207,13 +212,14 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { public boolean getIgnoreInput() { return ignoreInput; } - + public class KeyAction implements KeyListener { + @Override public void keyPressed(KeyEvent arg0) { if(ignoreInput) { return; } - + if(arg0.getKeyCode() == KeyEvent.VK_1){ zoom(10); } @@ -227,25 +233,25 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { move(0, 1); } else if(arg0.getKeyCode() == KeyEvent.VK_LEFT){ - move(1, 0); + move(-1, 0); } else if(arg0.getKeyCode() == KeyEvent.VK_RIGHT){ - move(-1, 0); + move(1, 0); } else if(arg0.getKeyCode() == KeyEvent.VK_6){ - texSize[0] -= 10; - System.err.println("Tex Size: " + texSize[0]); + sampleCount[0] -= 1; + System.err.println("Sample Count: " + sampleCount[0]); } else if(arg0.getKeyCode() == KeyEvent.VK_7){ - texSize[0] += 10; - System.err.println("Tex Size: " + texSize[0]); - } + sampleCount[0] += 1; + System.err.println("Sample Count: " + sampleCount[0]); + } else if(arg0.getKeyCode() == KeyEvent.VK_0){ rotate(1); } else if(arg0.getKeyCode() == KeyEvent.VK_9){ rotate(-1); - } + } else if(arg0.getKeyCode() == KeyEvent.VK_Q){ editGlobalWeight(-0.1f); } @@ -255,9 +261,10 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { else if(arg0.getKeyCode() == KeyEvent.VK_V) { if(null != autoDrawable) { autoDrawable.invoke(false, new GLRunnable() { + @Override public boolean run(GLAutoDrawable drawable) { GL gl = drawable.getGL(); - int i = gl.getSwapInterval(); + int i = gl.getSwapInterval(); i = i==0 ? 1 : 0; gl.setSwapInterval(i); final GLAnimatorControl a = drawable.getAnimator(); @@ -271,28 +278,31 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { return true; } }); - } + } } else if(arg0.getKeyCode() == KeyEvent.VK_S){ rotate(-1); if(null != autoDrawable) { autoDrawable.invoke(false, new GLRunnable() { + @Override public boolean run(GLAutoDrawable drawable) { try { - final String type = Region.isVBAA(renderModes) ? "vbaa0-msaa1" : "vbaa1-msaa0" + ( Region.isNonUniformWeight(renderModes) ? "-vc" : "-uc" ) ; + final String modeS = Region.getRenderModeString(renderer.getRenderModes()); + final String type = modeS + ( Region.isNonUniformWeight(renderModes) ? "-vc" : "-uc" ) ; printScreen(drawable, "./", "demo-"+type, "snap"+screenshot_num, false); screenshot_num++; } catch (GLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); - } + } return true; } }); - } - } + } + } } + @Override public void keyReleased(KeyEvent arg0) {} } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java index 5c7d15ad1..29b897d0e 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java @@ -32,40 +32,33 @@ import javax.media.opengl.GL2ES2; import javax.media.opengl.GLAutoDrawable; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.curve.opengl.TextRenderer; -import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.util.glsl.ShaderState; public class GPUTextGLListener0A extends GPUTextRendererListenerBase01 { - - public GPUTextGLListener0A() { - this( RenderState.createRenderState(new ShaderState(), SVertex.factory()), 0, 0, false, false ) ; - } - - public GPUTextGLListener0A(RenderState rs, int numpass, int fbosize, boolean debug, boolean trace) { - super(rs, numpass, debug, trace); - setMatrix(-400, -30, 0f, -500, fbosize); + + public GPUTextGLListener0A(RenderState rs, int renderModes, int sampleCount, boolean blending, boolean debug, boolean trace) { + super(rs, renderModes, sampleCount, blending, debug, trace); } - + public void init(GLAutoDrawable drawable) { if(drawable instanceof GLWindow) { final GLWindow glw = (GLWindow) drawable; attachInputListenerTo(glw); - } + } super.init(drawable); - + GL2ES2 gl = drawable.getGL().getGL2ES2(); - - final TextRenderer textRenderer = (TextRenderer) getRenderer(); - + + final RegionRenderer renderer = getRenderer(); + gl.setSwapInterval(1); gl.glEnable(GL2ES2.GL_DEPTH_TEST); gl.glEnable(GL2ES2.GL_BLEND); - textRenderer.setAlpha(gl, 1.0f); - textRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); + renderer.setAlpha(gl, 1.0f); + renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); } - + public void dispose(GLAutoDrawable drawable) { if(drawable instanceof GLWindow) { final GLWindow glw = (GLWindow) drawable; diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java index d257f78fc..de06310d7 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java @@ -28,14 +28,11 @@ package com.jogamp.opengl.test.junit.graph.demos; -import javax.media.opengl.FPSCounter; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; - -import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.graph.geom.SVertex; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.WindowAdapter; @@ -47,7 +44,7 @@ import com.jogamp.opengl.util.glsl.ShaderState; public class GPUTextNewtDemo01 { static final boolean DEBUG = false; static final boolean TRACE = false; - + public static void main(String[] args) { GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); @@ -55,21 +52,20 @@ public class GPUTextNewtDemo01 { caps.setSampleBuffers(true); caps.setNumSamples(4); // 2 samples is not enough .. System.out.println("Requested: "+caps); - - final GLWindow window = GLWindow.create(caps); + + final GLWindow window = GLWindow.create(caps); window.setPosition(10, 10); window.setSize(800, 400); - window.setTitle("GPU Text Newt Demo 01 - vbaa0 msaa1"); - + window.setTitle("GPU Text Newt Demo 01 - smsaa1"); + final RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); - GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, 0, 0, DEBUG, TRACE); + GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, 0, 0, true, DEBUG, TRACE); window.addGLEventListener(textGLListener); - window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); - + final Animator animator = new Animator(); - animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); + animator.setUpdateFPSFrames(60, System.err); animator.add(window); - + window.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent arg0) { if(arg0.getKeyCode() == KeyEvent.VK_F4) { @@ -82,9 +78,9 @@ public class GPUTextNewtDemo01 { animator.stop(); } }); - + window.setVisible(true); // FPSAnimator animator = new FPSAnimator(10); animator.start(); - } + } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java index 1b71cd781..3dc03788b 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java @@ -27,13 +27,12 @@ */ package com.jogamp.opengl.test.junit.graph.demos; -import javax.media.opengl.FPSCounter; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.graph.geom.SVertex; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.WindowAdapter; @@ -45,42 +44,50 @@ import com.jogamp.opengl.util.glsl.ShaderState; public class GPUTextNewtDemo02 { /** * FIXME: - * + * * If DEBUG is enabled: - * - * Caused by: javax.media.opengl.GLException: Thread[main-Display-X11_:0.0-1-EDT-1,5,main] glGetError() returned the following error codes after a call to glFramebufferRenderbuffer(<int> 0x8D40, <int> 0x1902, <int> 0x8D41, <int> 0x1): GL_INVALID_ENUM ( 1280 0x500), + * + * Caused by: javax.media.opengl.GLException: Thread[main-Display-X11_:0.0-1-EDT-1,5,main] glGetError() returned the following error codes after a call to glFramebufferRenderbuffer(<int> 0x8D40, <int> 0x1902, <int> 0x8D41, <int> 0x1): GL_INVALID_ENUM ( 1280 0x500), * at javax.media.opengl.DebugGL4bc.checkGLGetError(DebugGL4bc.java:33961) * at javax.media.opengl.DebugGL4bc.glFramebufferRenderbuffer(DebugGL4bc.java:33077) * at jogamp.graph.curve.opengl.VBORegion2PGL3.initFBOTexture(VBORegion2PGL3.java:295) */ static final boolean DEBUG = false; static final boolean TRACE = false; - + public static void main(String[] args) { - GLProfile glp = GLProfile.getGL2ES2(); - + boolean alpha = true; + boolean blending = true; + for(int i=0; i<args.length; i++) { + if(args[i].equals("-noblend")) { + blending = false; + } else if(args[i].equals("-noalpha")) { + alpha = false; + } + } + + final GLProfile glp = GLProfile.getGL2ES2(); + GLCapabilities caps = new GLCapabilities(glp); - caps.setAlphaBits(4); + caps.setAlphaBits( alpha ? 4 : 0 ); System.out.println("Requested: "+caps); - + final GLWindow window = GLWindow.create(caps); - + window.setPosition(10, 10); - window.setSize(800, 400); - window.setTitle("GPU Text Newt Demo 02 - vbaa1 msaa0"); - + window.setSize(800, 400); + window.setTitle("GPU Text Newt Demo 02 - gvbaa4 gmsaa0"); + RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); - GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, Region.VBAA_RENDERING_BIT, window.getWidth()*3, DEBUG, TRACE); + GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, Region.VBAA_RENDERING_BIT, 4, blending, DEBUG, TRACE); // ((TextRenderer)textGLListener.getRenderer()).setCacheLimit(32); window.addGLEventListener(textGLListener); - - window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); window.setVisible(true); // FPSAnimator animator = new FPSAnimator(60); final Animator animator = new Animator(); - animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); + animator.setUpdateFPSFrames(60, System.err); animator.add(window); - + window.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent arg0) { if(arg0.getKeyCode() == KeyEvent.VK_F4) { @@ -93,7 +100,7 @@ public class GPUTextNewtDemo02 { animator.stop(); } }); - + animator.start(); - } + } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo03.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo03.java new file mode 100644 index 000000000..9174d69af --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo03.java @@ -0,0 +1,96 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.opengl.test.junit.graph.demos; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.RenderState; +import com.jogamp.graph.geom.SVertex; +import com.jogamp.newt.event.KeyAdapter; +import com.jogamp.newt.event.KeyEvent; +import com.jogamp.newt.event.WindowAdapter; +import com.jogamp.newt.event.WindowEvent; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.glsl.ShaderState; + +public class GPUTextNewtDemo03 { + /** + * FIXME: + * + * If DEBUG is enabled: + * + * Caused by: javax.media.opengl.GLException: Thread[main-Display-X11_:0.0-1-EDT-1,5,main] glGetError() returned the following error codes after a call to glFramebufferRenderbuffer(<int> 0x8D40, <int> 0x1902, <int> 0x8D41, <int> 0x1): GL_INVALID_ENUM ( 1280 0x500), + * at javax.media.opengl.DebugGL4bc.checkGLGetError(DebugGL4bc.java:33961) + * at javax.media.opengl.DebugGL4bc.glFramebufferRenderbuffer(DebugGL4bc.java:33077) + * at jogamp.graph.curve.opengl.VBORegion2PGL3.initFBOTexture(VBORegion2PGL3.java:295) + */ + static final boolean DEBUG = false; + static final boolean TRACE = false; + + public static void main(String[] args) { + GLProfile glp = GLProfile.getGL2ES2(); + + GLCapabilities caps = new GLCapabilities(glp); + caps.setAlphaBits(4); + System.out.println("Requested: "+caps); + + final GLWindow window = GLWindow.create(caps); + + window.setPosition(10, 10); + window.setSize(800, 400); + window.setTitle("GPU Text Newt Demo 03 - gvbaa0 gmsaa4"); + + RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); + GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, Region.MSAA_RENDERING_BIT, 4, true, DEBUG, TRACE); + // ((TextRenderer)textGLListener.getRenderer()).setCacheLimit(32); + window.addGLEventListener(textGLListener); + window.setVisible(true); + // FPSAnimator animator = new FPSAnimator(60); + final Animator animator = new Animator(); + animator.setUpdateFPSFrames(60, System.err); + animator.add(window); + + window.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent arg0) { + if(arg0.getKeyCode() == KeyEvent.VK_F4) { + window.destroy(); + } + } + }); + window.addWindowListener(new WindowAdapter() { + public void windowDestroyed(WindowEvent e) { + animator.stop(); + } + }); + + animator.start(); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java index 1dc104cbb..d77b0032d 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java @@ -35,14 +35,19 @@ import javax.media.opengl.GLAnimatorControl; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLException; +import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.GLRegion; +import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.curve.opengl.TextRenderer; +import com.jogamp.graph.curve.opengl.TextRegionUtil; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; +import com.jogamp.newt.Window; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.KeyListener; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.math.geom.AABBox; +import com.jogamp.opengl.util.PMVMatrix; /** * @@ -52,7 +57,7 @@ import com.jogamp.opengl.math.geom.AABBox; * - 0/9: rotate * - v: toggle v-sync * - s: screenshot - * + * * Additional Keys: * - 3/4: font +/- * - h: toogle draw 'font set' @@ -61,145 +66,248 @@ import com.jogamp.opengl.math.geom.AABBox; * - i: live input text input (CR ends it, backspace supported) */ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerBase01 { + public final TextRegionUtil textRegionUtil; + private final GLRegion regionFPS; + private final boolean useBlending; int fontSet = FontFactory.UBUNTU; Font font; - + int headType = 0; - boolean drawFPS = false; - final int fontSizeFixed = 6; - int fontSize = 40; + boolean drawFPS = true; + final float fontSizeFName = 8f; + final float fontSizeFPS = 10f; + final int[] sampleCountFPS = new int[] { 8 }; + float fontSizeHead = 12f; + float fontSizeBottom = 16f; + float dpiH = 96; final int fontSizeModulo = 100; String fontName; AABBox fontNameBox; String headtext; AABBox headbox; - + static final String text1 = "abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]"; static final String text2 = "The quick brown fox jumps over the lazy dog"; - static final String textX = + static final String textX = "JOGAMP graph demo using Resolution Independent NURBS\n"+ "JOGAMP JOGL - OpenGL ES2 profile\n"+ "Press 1/2 to zoom in/out the below text\n"+ + "Press 3/4 to incr/decs font size (alt: head, w/o bottom)\n"+ "Press 6/7 to edit texture size if using VBAA\n"+ "Press 0/9 to rotate the below string\n"+ "Press v to toggle vsync\n"+ "Press i for live input text input (CR ends it, backspace supported)\n"+ - "Press f to toggle fps. H for different text, space for font type\n"; - - static final String textX2 = + "Press f to toggle fps. H for different text, space for font type\n"; + + static final String textX2 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec sapien tellus. \n"+ "Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel urna. Mauris ultricies \n"+ "quam iaculis urna cursus ornare. Nullam ut felis a ante ultrices ultricies nec a elit. \n"+ - "In hac habitasse platea dictumst. Vivamus et mi a quam lacinia pharetra at venenatis est.\n"+ + "In hac habitasse platea dictumst. Vivamus et mi a quam lacinia pharetra at venenatis est.\n"+ "Morbi quis bibendum nibh. Donec lectus orci, sagittis in consequat nec, volutpat nec nisi.\n"+ "Donec ut dolor et nulla tristique varius. In nulla magna, fermentum id tempus quis, semper \n"+ "in lorem. Maecenas in ipsum ac justo scelerisque sollicitudin. Quisque sit amet neque lorem,\n" + - "-------Press H to change text---------\n"; - + "-------Press H to change text---------"; + StringBuilder userString = new StringBuilder(); boolean userInput = false; - - public GPUTextRendererListenerBase01(RenderState rs, int modes, boolean debug, boolean trace) { - super(TextRenderer.create(rs, modes), modes, debug, trace); + public GPUTextRendererListenerBase01(RenderState rs, int renderModes, int sampleCount, boolean blending, boolean debug, boolean trace) { + // NOTE_ALPHA_BLENDING: We use alpha-blending + super(RegionRenderer.create(rs, renderModes, + blending ? RegionRenderer.defaultBlendEnable : null, + blending ? RegionRenderer.defaultBlendDisable : null), + renderModes, debug, trace); + this.useBlending = blending; + this.textRegionUtil = new TextRegionUtil(this.getRenderer()); + this.regionFPS = GLRegion.create(renderModes); try { this.font = FontFactory.get(fontSet).getDefault(); dumpFontNames(); - + this.fontName = font.toString(); - this.fontNameBox = font.getStringBounds(fontName, fontSizeFixed*2); - switchHeadBox(); } catch (IOException ioe) { System.err.println("Catched: "+ioe.getMessage()); ioe.printStackTrace(); } + setMatrix(0, 0, 0, 0f, sampleCount); } void dumpFontNames() { System.err.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); System.err.println(font.getAllNames(null, "\n")); - System.err.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + System.err.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); } - + void switchHeadBox() { - headType = ( headType + 1 ) % 4 ; + headType = ( headType + 1 ) % 4 ; switch(headType) { case 0: headtext = null; break; - + case 1: headtext= textX2; break; case 2: headtext= textX; break; - + default: - headtext = text1; + headtext = text1; } if(null != headtext) { - headbox = font.getStringBounds(headtext, fontSizeFixed*3); + headbox = font.getStringBounds(headtext, font.getPixelSize(fontSizeHead, dpiH)); + } + } + + @Override + public void init(GLAutoDrawable drawable) { + super.init(drawable); + final Object upObj = drawable.getUpstreamWidget(); + if( upObj instanceof Window ) { + final float[] pixelsPerMM = new float[2]; + ((Window)upObj).getMainMonitor().getPixelsPerMM(pixelsPerMM); + dpiH = pixelsPerMM[1]*25.4f; } + fontNameBox = font.getStringBounds(fontName, font.getPixelSize(fontSizeFName, dpiH)); + switchHeadBox(); + } + @Override + public void dispose(GLAutoDrawable drawable) { + regionFPS.destroy(drawable.getGL().getGL2ES2(), getRenderer()); + super.dispose(drawable); + } + + public static void mapWin2ObjectCoords(final PMVMatrix pmv, final int[] view, + final float zNear, final float zFar, + float orthoX, float orthoY, float orthoDist, + final float[] winZ, final float[] objPos) { + winZ[0] = (1f/zNear-1f/orthoDist)/(1f/zNear-1f/zFar); + pmv.gluUnProject(orthoX, orthoY, winZ[0], view, 0, objPos, 0); + } + public static void translateOrtho(final String msg, + final PMVMatrix pmv, final int[] view, + final float zNear, final float zFar, + float orthoX, float orthoY, float orthoDist, + final float[] winZ, final float[] objPos) { + mapWin2ObjectCoords(pmv, view, zNear, zFar, orthoX, orthoY, orthoDist, winZ, objPos); + pmv.glTranslatef(objPos[0], objPos[1], objPos[2]); + /** + System.err.printf("XXX %7s: [%5.1f, %5.1f, [%5.1f -> %5.1f]] --> [%8.3f, %8.3f, %8.3f]%n", + msg, orthoX, orthoY, orthoDist, winZ[0], objPos[0], objPos[1], objPos[2]); */ + } + + @Override public void display(GLAutoDrawable drawable) { final int width = drawable.getWidth(); final int height = drawable.getHeight(); GL2ES2 gl = drawable.getGL().getGL2ES2(); - - gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Demo02 needs to have this set here as well .. hmm ? + + gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - final TextRenderer textRenderer = (TextRenderer) getRenderer(); - textRenderer.reshapeOrtho(null, width, height, 0.1f, 7000.0f); - textRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); - final GLAnimatorControl animator = drawable.getAnimator(); - final boolean _drawFPS = drawFPS && null != animator && animator.getTotalFPSFrames()>10; - - if(_drawFPS) { - final float fps = animator.getTotalFPS(); - final String fpsS = String.valueOf(fps); - final int fpsSp = fpsS.indexOf('.'); - textRenderer.resetModelview(null); - textRenderer.translate(gl, fontSizeFixed, fontSizeFixed, -6000); - textRenderer.drawString3D(gl, font, fpsS.substring(0, fpsSp+2)+" fps", getPosition(), fontSizeFixed*3, getTexSize()); + final float zDistance0 = 500f; + final float zDistance1 = 400f; + final float[] objPos = new float[3]; + final float[] winZ = new float[1]; + final int[] view = new int[] { 0, 0, drawable.getWidth(), drawable.getHeight() }; + + final RegionRenderer renderer = getRenderer(); + final PMVMatrix pmv = renderer.getMatrix(); + renderer.resetModelview(null); + renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); + if( useBlending ) { + // NOTE_ALPHA_BLENDING: + // Due to alpha blending and VBAA, we need a background in text color + // otherwise blending will amplify 'white'! + gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + } + + final float pixelSizeFName = font.getPixelSize(fontSizeFName, dpiH); + final float pixelSizeHead = font.getPixelSize(fontSizeHead, dpiH); + final float pixelSizeBottom = font.getPixelSize(fontSizeBottom, dpiH); + + if( drawFPS ) { + final float pixelSizeFPS = font.getPixelSize(fontSizeFPS, dpiH); + final float lfps, tfps, td; + final GLAnimatorControl animator = drawable.getAnimator(); + if( null != animator ) { + lfps = animator.getLastFPS(); + tfps = animator.getTotalFPS(); + td = animator.getTotalFPSDuration()/1000f; + } else { + lfps = 0f; + tfps = 0f; + td = 0f; + } + final String modeS = Region.getRenderModeString(renderer.getRenderModes()); + final String text = String.format("%03.1f/%03.1f fps, v-sync %d, fontSize [head %.1f, bottom %.1f], %s-samples [%d, this %d], td %4.1f, blend %b, alpha-bits %d", + lfps, tfps, gl.getSwapInterval(), fontSizeHead, fontSizeBottom, modeS, getSampleCount()[0], sampleCountFPS[0], td, + useBlending, drawable.getChosenGLCapabilities().getAlphaBits()); + + // bottom, half line up + renderer.resetModelview(null); + translateOrtho("fpstxt", pmv, view, zNear, zFar, 0, pixelSizeFPS/2, zDistance0, winZ, objPos); + renderer.updateMatrix(gl); + + // No cache, keep region alive! + TextRegionUtil.drawString3D(regionFPS, renderer, gl, font, pixelSizeFPS, text, sampleCountFPS); + } + + float dx = width-fontNameBox.getWidth()-2f; + float dy = height - 10f; + + renderer.resetModelview(null); + translateOrtho("fontxt", pmv, view, zNear, zFar, dx, dy, zDistance0, winZ, objPos); + renderer.updateMatrix(gl); + textRegionUtil.drawString3D(gl, font, pixelSizeFName, fontName, getSampleCount()); + + dx = 10f; + dy += -fontNameBox.getHeight() - 10f; + + if(null != headtext) { + renderer.resetModelview(null); + translateOrtho("headtx", pmv, view, zNear, zFar, dx, dy, zDistance0, winZ, objPos); + renderer.updateMatrix(gl); + textRegionUtil.drawString3D(gl, font, pixelSizeHead, headtext, getSampleCount()); } - - int dx = width-(int)fontNameBox.getWidth()-2 ; - int dy = height - 10; - - textRenderer.resetModelview(null); - textRenderer.translate(gl, dx, dy, -6000); - textRenderer.drawString3D(gl, font, fontName, getPosition(), fontSizeFixed*2, getTexSize()); - - dx = 10; - dy += -(int)fontNameBox.getHeight() - 10; - - if(null != headtext) { - textRenderer.resetModelview(null); - textRenderer.translate(gl, dx, dy, -6000); - textRenderer.drawString3D(gl, font, headtext, getPosition(), fontSizeFixed*3, getTexSize()); + + dy += -headbox.getHeight() - font.getLineHeight(pixelSizeBottom); + + renderer.resetModelview(null); + translateOrtho("Bottom", pmv, view, zNear, zFar, dx, dy, zDistance1, winZ, objPos); + renderer.translate(null, getXTran(), getYTran(), getZTran()); + renderer.rotate(gl, getAngle(), 0, 1, 0); + renderer.setColorStatic(gl, 1.0f, 0.0f, 0.0f); + if( useBlending ) { + // NOTE_ALPHA_BLENDING: + // Due to alpha blending and VBAA, we need a background in text color + // otherwise blending will amplify 'white'! + gl.glClearColor(1.0f, 0.0f, 0.0f, 0.0f); } - - textRenderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f); - textRenderer.resetModelview(null); - textRenderer.translate(null, getXTran(), getYTran(), getZoom()); - textRenderer.rotate(gl, getAngle(), 0, 1, 0); - textRenderer.setColorStatic(gl, 1.0f, 0.0f, 0.0f); if(!userInput) { - textRenderer.drawString3D(gl, font, text2, getPosition(), fontSize, getTexSize()); + textRegionUtil.drawString3D(gl, font, pixelSizeBottom, text2, getSampleCount()); } else { - textRenderer.drawString3D(gl, font, userString.toString(), getPosition(), fontSize, getTexSize()); + textRegionUtil.drawString3D(gl, font, pixelSizeBottom, userString.toString(), getSampleCount()); } - } - - public void fontIncr(int v) { - fontSize = Math.abs((fontSize + v) % fontSizeModulo) ; + } + + public void fontBottomIncr(int v) { + fontSizeBottom = Math.abs((fontSizeBottom + v) % fontSizeModulo) ; dumpMatrix(true); } - public boolean nextFontSet() { + public void fontHeadIncr(int v) { + fontSizeHead = Math.abs((fontSizeHead + v) % fontSizeModulo) ; + if(null != headtext) { + headbox = font.getStringBounds(headtext, font.getPixelSize(fontSizeHead, dpiH)); + } + } + + public boolean nextFontSet() { try { int set = ( fontSet == FontFactory.UBUNTU ) ? FontFactory.JAVA : FontFactory.UBUNTU ; Font _font = FontFactory.get(set).getDefault(); @@ -207,7 +315,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB fontSet = set; font = _font; fontName = font.getFullFamilyName(null).toString(); - fontNameBox = font.getStringBounds(fontName, fontSizeFixed*3); + fontNameBox = font.getStringBounds(fontName, font.getPixelSize(fontSizeFName, dpiH)); dumpFontNames(); return true; } @@ -216,7 +324,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB } return false; } - + public boolean setFontSet(int set, int family, int stylebits) { try { Font _font = FontFactory.get(set).get(family, stylebits); @@ -224,7 +332,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB fontSet = set; font = _font; fontName = font.getFullFamilyName(null).toString(); - fontNameBox = font.getStringBounds(fontName, fontSizeFixed*3); + fontNameBox = font.getStringBounds(fontName, font.getPixelSize(fontSizeFName, dpiH)); dumpFontNames(); return true; } @@ -233,25 +341,25 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB } return false; } - + public boolean isUserInputMode() { return userInput; } - + void dumpMatrix(boolean bbox) { - System.err.println("Matrix: " + getXTran() + "/" + getYTran() + " x"+getZoom() + " @"+getAngle() +" fontSize "+fontSize); + System.err.println("Matrix: " + getXTran() + "/" + getYTran() + " x"+getZTran() + " @"+getAngle() +" fontSize "+fontSizeBottom); if(bbox) { - System.err.println("bbox: "+font.getStringBounds(text2, fontSize)); + System.err.println("bbox: "+font.getStringBounds(text2, font.getPixelSize(fontSizeBottom, dpiH))); } } - + KeyAction keyAction = null; - + @Override public void attachInputListenerTo(GLWindow window) { if ( null == keyAction ) { keyAction = new KeyAction(); window.addKeyListener(keyAction); - super.attachInputListenerTo(window); - } + super.attachInputListenerTo(window); + } } @Override @@ -262,31 +370,42 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB } window.removeKeyListener(keyAction); } - + public void printScreen(GLAutoDrawable drawable, String dir, String tech, boolean exportAlpha) throws GLException, IOException { - final String fn = font.getFullFamilyName(null).toString(); + final String fn = font.getFullFamilyName(null).toString(); printScreen(drawable, dir, tech, fn.replace(' ', '_'), exportAlpha); } - + + float fontHeadScale = 1f; + public class KeyAction implements KeyListener { + @Override public void keyPressed(KeyEvent e) { if(userInput) { return; } - final short s = e.getKeySymbol(); + final short s = e.getKeySymbol(); if(s == KeyEvent.VK_3) { - fontIncr(10); + if( e.isAltDown() ) { + fontHeadIncr(1); + } else { + fontBottomIncr(1); + } } else if(s == KeyEvent.VK_4) { - fontIncr(-10); + if( e.isAltDown() ) { + fontHeadIncr(-1); + } else { + fontBottomIncr(-1); + } } else if(s == KeyEvent.VK_H) { switchHeadBox(); - } + } else if(s == KeyEvent.VK_F) { - drawFPS = !drawFPS; - } - else if(s == KeyEvent.VK_SPACE) { + drawFPS = !drawFPS; + } + else if(s == KeyEvent.VK_SPACE) { nextFontSet(); } else if(s == KeyEvent.VK_I) { @@ -294,12 +413,13 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB setIgnoreInput(true); } } - + + @Override public void keyReleased(KeyEvent e) { if( !e.isPrintableKey() || e.isAutoRepeat() ) { return; - } - if(userInput) { + } + if(userInput) { final short k = e.getKeySymbol(); if( KeyEvent.VK_ENTER == k ) { userInput = false; @@ -308,7 +428,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB userString.deleteCharAt(userString.length()-1); } else { final char c = e.getKeyChar(); - if( font.isPrintableChar( c ) ) { + if( font.isPrintableChar( c ) ) { userString.append(c); } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java index 59ce28408..aef3ab4bd 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java @@ -11,76 +11,76 @@ import javax.media.opengl.GLPipelineFactory; import javax.media.opengl.GLRunnable; import com.jogamp.graph.curve.Region; -import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.curve.opengl.RenderState; +import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; -import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.graph.geom.SVertex; +import com.jogamp.newt.Window; import com.jogamp.newt.event.MouseAdapter; import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.graph.demos.ui.Label; import com.jogamp.opengl.test.junit.graph.demos.ui.RIButton; import com.jogamp.opengl.test.junit.graph.demos.ui.SceneUIController; -import com.jogamp.opengl.test.junit.graph.demos.ui.opengl.UIRegion; import com.jogamp.opengl.util.glsl.ShaderState; public class GPUUISceneGLListener0A implements GLEventListener { private boolean debug = false; - private boolean trace = false; - + private boolean trace = false; + private final int renderModes; - private final int[] texSize = new int[1]; - private final int renderModes2; - private final int[] texSize2 = new int[1]; - private RegionRenderer regionRenderer; - private RenderState rs; - + private final int[] sampleCount = new int[1]; + private final int[] texSize2 = new int[1]; + private final RenderState rs; + private final boolean useBlending; + private final SceneUIController sceneUIController; + protected final float zNear = 0.1f, zFar = 7000f; + + private RegionRenderer renderer; + int fontSet = FontFactory.UBUNTU; Font font; - final int fontSizeFixed = 6; - + final float fontSizeFixed = 6; + float dpiH = 96; + private float xTran = 0; - private float yTran = 0; + private float yTran = 0; private float ang = 0f; private float zoom = -200f; - private float zoomText = 1f; + private final float zoomText = 1f; private int currentText = 0; - + private Label[] labels = null; private String[] strings = null; - private UIRegion[] labelRegions; - private UIRegion fpsRegion = null; - private UIRegion jogampRegion = null; private RIButton[] buttons = null; - - private int numSelectable = 6; - - private SceneUIController sceneUIController = null; + private Label jogampLabel = null; + private Label fpsLabel = null; + private final int numSelectable = 6; + private MultiTouchListener multiTouchListener = null; private boolean showFPS = false; private GLAutoDrawable cDrawable; - private float fps = 0; - - private String jogamp = "JogAmp - Jogl Graph Module Demo"; - private float angText = 0; - + + private final String jogamp = "JogAmp - Jogl Graph Module Demo"; + private final float angText = 0; + public GPUUISceneGLListener0A() { this(0); } - + public GPUUISceneGLListener0A(int renderModes) { this(RenderState.createRenderState(new ShaderState(), SVertex.factory()), renderModes, false, false); } - + public GPUUISceneGLListener0A(RenderState rs, int renderModes, boolean debug, boolean trace) { this.rs = rs; this.renderModes = renderModes; - this.texSize[0] = Region.isVBAA(renderModes) ? 400 : 0; - this.renderModes2 = 0; + this.sampleCount[0] = 4; this.texSize2[0] = 0; - + this.useBlending = true; + this.debug = debug; this.trace = trace; try { @@ -89,19 +89,18 @@ public class GPUUISceneGLListener0A implements GLEventListener { System.err.println("Catched: "+ioe.getMessage()); ioe.printStackTrace(); } - labelRegions = new UIRegion[3]; sceneUIController = new SceneUIController(); } - + private void initButtons(int width, int height) { buttons = new RIButton[numSelectable]; int xaxis = -110; float xSize = 40f; float ySize = 16f; - + int start = 50; int diff = (int)ySize + 5; - + buttons[0] = new RIButton(SVertex.factory(), font, "Next Text", xSize, ySize){ public void onClick() { currentText = (currentText+1)%3; @@ -109,9 +108,9 @@ public class GPUUISceneGLListener0A implements GLEventListener { public void onPressed() { } public void onRelease() { } }; - - buttons[0].setPosition(xaxis,start,0); - + + buttons[0].translate(xaxis,start); + buttons[1] = new RIButton(SVertex.factory(), font, "Show FPS", xSize, ySize){ public void onClick() { final GLAnimatorControl a = cDrawable.getAnimator(); @@ -120,12 +119,10 @@ public class GPUUISceneGLListener0A implements GLEventListener { } showFPS = !showFPS; } - public void onPressed() { } - public void onRelease() { } }; - buttons[1].setPosition(xaxis,start - diff,0); + buttons[1].translate(xaxis,start - diff); buttons[1].setToggleable(true); - + buttons[2] = new RIButton(SVertex.factory(), font, "v-sync", xSize, ySize){ public void onClick() { cDrawable.invoke(false, new GLRunnable() { @@ -140,72 +137,68 @@ public class GPUUISceneGLListener0A implements GLEventListener { } }); } - public void onPressed() { } - public void onRelease() { } }; - buttons[2].setPosition(xaxis,start-diff*2,0); + buttons[2].translate(xaxis,start-diff*2); buttons[2].setToggleable(true); - + buttons[3] = new RIButton(SVertex.factory(), font, "Tilt +Y", xSize, ySize) { - public void onClick() { + public void onClick() { ang+=10; } - public void onPressed() { - - } - public void onRelease() { } }; - buttons[3].setPosition(xaxis,start-diff*3,0); - + buttons[3].translate(xaxis,start-diff*3); + buttons[4] = new RIButton(SVertex.factory(), font, "Tilt -Y", xSize, ySize){ public void onClick() { ang-=10; } - public void onPressed() { } - public void onRelease() { } }; - buttons[4].setPosition(xaxis,start-diff*4,0); - + buttons[4].translate(xaxis,start-diff*4); + buttons[5] = new RIButton(SVertex.factory(), font, "Quit", xSize, ySize){ public void onClick() { cDrawable.destroy(); } - public void onPressed() { } - public void onRelease() { } }; - buttons[5].setPosition(xaxis,start-diff*5,0); - buttons[5].setButtonColor(0.8f, 0.0f, 0.0f); + buttons[5].translate(xaxis,start-diff*5); + buttons[5].setColor(0.8f, 0.0f, 0.0f); buttons[5].setLabelColor(1.0f, 1.0f, 1.0f); - - buttons[5].setButtonSelectedColor(0.8f, 0.8f, 0.8f); + + buttons[5].setSelectedColor(0.8f, 0.8f, 0.8f); buttons[5].setLabelSelectedColor(0.8f, 0.0f, 0.0f); } - + private void initTexts() { strings = new String[3]; - + strings[0] = "abcdefghijklmn\nopqrstuvwxyz\nABCDEFGHIJKL\nMNOPQRSTUVWXYZ\n0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]"; strings[1] = "The quick brown fox\njumps over the lazy\ndog"; - - strings[2] = + + strings[2] = "Lorem ipsum dolor sit amet, consectetur\n"+ "Ut purus odio, rhoncus sit amet com\n"+ "quam iaculis urna cursus ornare. Nullam\n"+ - "In hac habitasse platea dictumst. Vivam\n"+ + "In hac habitasse platea dictumst. Vivam\n"+ "Morbi quis bibendum nibh. Donec lectus\n"+ "Donec ut dolor et nulla tristique variu\n"+ "in lorem. Maecenas in ipsum ac justo sc\n"; - + labels = new Label[3]; } public void init(GLAutoDrawable drawable) { + final Object upObj = drawable.getUpstreamWidget(); + if( upObj instanceof Window ) { + final float[] pixelsPerMM = new float[2]; + ((Window)upObj).getMainMonitor().getPixelsPerMM(pixelsPerMM); + dpiH = pixelsPerMM[1]*25.4f; + } if(drawable instanceof GLWindow) { System.err.println("GPUUISceneGLListener0A: init (1)"); final GLWindow glw = (GLWindow) drawable; attachInputListenerTo(glw); } else { - System.err.println("GPUUISceneGLListener0A: init (0)"); + System.err.println("GPUUISceneGLListener0A: init (0)"); } final int width = drawable.getWidth(); final int height = drawable.getHeight(); @@ -217,46 +210,42 @@ public class GPUUISceneGLListener0A implements GLEventListener { if(trace) { gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, gl, new Object[] { System.err } ) ).getGL2ES2(); } - + try { font = FontFactory.get(fontSet).getDefault(); } catch (IOException ioe) { System.err.println("Catched: "+ioe.getMessage()); ioe.printStackTrace(); } - - regionRenderer = RegionRenderer.create(rs, renderModes); - + + renderer = RegionRenderer.create(rs, renderModes, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable); + gl.glEnable(GL2ES2.GL_DEPTH_TEST); gl.glEnable(GL2ES2.GL_BLEND); - - regionRenderer.init(gl); - regionRenderer.setAlpha(gl, 1.0f); - regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); - + + renderer.init(gl); + renderer.setAlpha(gl, 1.0f); + renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); + initTexts(); initButtons(width, height); - - sceneUIController.setRenderer(regionRenderer, rs, renderModes, texSize); + + sceneUIController.setRenderer(renderer, renderModes, sampleCount); sceneUIController.addShape(buttons[0]); sceneUIController.addShape(buttons[1]); sceneUIController.addShape(buttons[2]); sceneUIController.addShape(buttons[3]); sceneUIController.addShape(buttons[4]); sceneUIController.addShape(buttons[5]); - drawable.addGLEventListener(sceneUIController); - - Label jlabel = new Label(SVertex.factory(), font, fontSizeFixed, jogamp){ - public void onClick() { } - public void onPressed() { } - public void onRelease() { } - }; - - jogampRegion = new UIRegion(jlabel); + sceneUIController.init(drawable); + + final float pixelSizeFixed = font.getPixelSize(fontSizeFixed, dpiH); + jogampLabel = new Label(SVertex.factory(), font, pixelSizeFixed, jogamp); + final GLAnimatorControl a = drawable.getAnimator(); if( null != a ) { a.resetFPSCounter(); - } + } } public void dispose(GLAutoDrawable drawable) { @@ -265,95 +254,87 @@ public class GPUUISceneGLListener0A implements GLEventListener { final GLWindow glw = (GLWindow) drawable; detachInputListenerFrom(glw); } else { - System.err.println("GPUUISceneGLListener0A: dispose (0)"); + System.err.println("GPUUISceneGLListener0A: dispose (0)"); } - // sceneUIController will remove itself from the drawable! - + sceneUIController.dispose(drawable); + GL2ES2 gl = drawable.getGL().getGL2ES2(); - regionRenderer.destroy(gl); + renderer.destroy(gl); } public void display(GLAutoDrawable drawable) { // System.err.println("GPUUISceneGLListener0A: display"); - final int width = drawable.getWidth(); - final int height = drawable.getHeight(); GL2ES2 gl = drawable.getGL().getGL2ES2(); - + gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - - regionRenderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f); + + renderer.resetModelview(null); sceneUIController.setTranslate(xTran, yTran, zoom); sceneUIController.setRotation(0, ang, 0); - - renderScene(drawable); - } - - private void renderScene(GLAutoDrawable drawable) { - GL2ES2 gl = drawable.getGL().getGL2ES2(); - - regionRenderer.resetModelview(null); - regionRenderer.translate(null, xTran-50, yTran+43, zoom); - regionRenderer.translate(gl, 0, 30, 0); - regionRenderer.scale(null, zoomText, zoomText, 1); - regionRenderer.scale(gl, 1.5f, 1.5f, 1.0f); - regionRenderer.rotate(gl, angText , 0, 1, 0); - regionRenderer.setColorStatic(gl, 0.0f, 1.0f, 0.0f); - regionRenderer.draw(gl, jogampRegion.getRegion(gl, rs, 0), new float[]{0,0,0}, null); - - if(null == labelRegions[currentText]) { - if( null == labels[currentText]) { - labels[currentText] = new Label(SVertex.factory(), font, fontSizeFixed, strings[currentText]){ - public void onClick() { } - public void onPressed() { } - public void onRelease() { } - }; - } - labelRegions[currentText] = new UIRegion(labels[currentText]); + sceneUIController.display(drawable); + + final float pixelSizeFixed = font.getPixelSize(fontSizeFixed, dpiH); + + renderer.resetModelview(null); + renderer.translate(null, xTran-50, yTran+43, zoom); + renderer.translate(gl, 0, 30, 0); + renderer.scale(null, zoomText, zoomText, 1); + renderer.scale(gl, 1.5f, 1.5f, 1.0f); + renderer.rotate(gl, angText , 0, 1, 0); + renderer.setColorStatic(gl, 0.0f, 1.0f, 0.0f); + jogampLabel.drawShape(gl, renderer, sampleCount, false); + if(null == labels[currentText]) { + labels[currentText] = new Label(SVertex.factory(), font, pixelSizeFixed, strings[currentText]); } - - regionRenderer.resetModelview(null); - regionRenderer.translate(null, xTran-50, yTran, zoom); - regionRenderer.translate(gl, 0, 30, 0); - regionRenderer.scale(null, zoomText, zoomText, 1); - regionRenderer.scale(gl, 1.5f, 1.5f, 1.0f); - regionRenderer.rotate(gl, zoomText, 0, 1, 0); - - regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); - regionRenderer.draw(gl, labelRegions[currentText].getRegion(gl, rs, renderModes2), new float[]{0,0,0}, texSize2); - - final GLAnimatorControl animator = drawable.getAnimator(); - final boolean _drawFPS = showFPS && null != animator; - - if(_drawFPS && fps != animator.getTotalFPS()) { - if(null != fpsRegion) { - fpsRegion.destroy(gl, rs); + + renderer.resetModelview(null); + renderer.translate(null, xTran-50, yTran, zoom); + renderer.translate(gl, 0, 30, 0); + renderer.scale(null, zoomText, zoomText, 1); + renderer.scale(gl, 1.5f, 1.5f, 1.0f); + renderer.rotate(gl, zoomText, 0, 1, 0); + + renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); + labels[currentText].drawShape(gl, renderer, sampleCount, false); + + if( showFPS ) { + final float lfps, tfps, td; + final GLAnimatorControl animator = drawable.getAnimator(); + if( null != animator ) { + lfps = animator.getLastFPS(); + tfps = animator.getTotalFPS(); + td = animator.getTotalFPSDuration()/1000f; + } else { + lfps = 0f; + tfps = 0f; + td = 0f; + } + final String modeS = Region.getRenderModeString(renderer.getRenderModes()); + final String text = String.format("%03.1f/%03.1f fps, v-sync %d, fontSize %.1f, %s-samples %d, td %4.1f, blend %b, alpha-bits %d", + lfps, tfps, gl.getSwapInterval(), fontSizeFixed, modeS, sampleCount[0], td, + useBlending, drawable.getChosenGLCapabilities().getAlphaBits()); + if(null != fpsLabel) { + fpsLabel.clear(gl, renderer); + fpsLabel.setText(text); + fpsLabel.setPixelSize(pixelSizeFixed); + } else { + fpsLabel = new Label(renderer.getRenderState().getVertexFactory(), font, pixelSizeFixed, text); } - fps = animator.getTotalFPS(); - final String fpsS = String.valueOf(fps); - final int fpsSp = fpsS.indexOf('.'); - - Label fpsLabel = new Label(SVertex.factory(), font, fontSizeFixed, fpsS.substring(0, fpsSp+2)+" fps"){ - public void onClick() { } - public void onPressed() { } - public void onRelease() { } - }; - fpsRegion = new UIRegion(fpsLabel); - } - if(showFPS && null != fpsRegion) { - regionRenderer.translate(gl, 0, -60, 0); - regionRenderer.scale(null, zoomText, zoomText, 1); - regionRenderer.draw(gl, fpsRegion.getRegion(gl, rs, 0), new float[]{0,0,0}, null); + renderer.translate(gl, 0, -60, 0); + renderer.scale(null, zoomText, zoomText, 1); + fpsLabel.drawShape(gl, renderer, sampleCount, false); } } - + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { System.err.println("GPUUISceneGLListener0A: reshape"); GL2ES2 gl = drawable.getGL().getGL2ES2(); - - gl.glViewport(x, y, width, height); - regionRenderer.reshapePerspective(gl, 45.0f, width, height, 5f, 70.0f); + + gl.glViewport(x, y, width, height); + renderer.reshapePerspective(gl, 45.0f, width, height, zNear, zFar); + sceneUIController.reshape(drawable, x, y, width, height); } public void attachInputListenerTo(GLWindow window) { @@ -363,23 +344,23 @@ public class GPUUISceneGLListener0A implements GLEventListener { sceneUIController.attachInputListenerTo(window); } } - + public void detachInputListenerFrom(GLWindow window) { if ( null != multiTouchListener ) { window.removeMouseListener(multiTouchListener); sceneUIController.detachInputListenerFrom(window); } } - + private class MultiTouchListener extends MouseAdapter { int lx = 0; int ly = 0; - + boolean first = false; - + @Override public void mousePressed(MouseEvent e) { - first = true; + first = true; } @Override @@ -399,9 +380,9 @@ public class GPUUISceneGLListener0A implements GLEventListener { } int nv = Math.abs(e.getY(0)-e.getY(1)); int dy = nv - lx; - + zoom += 2 * Math.signum(dy); - + lx = nv; } else { // 1 pointer drag @@ -413,7 +394,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { } int nx = e.getX(); int ny = e.getY(); - int dx = nx - lx; + int dx = nx - lx; int dy = ny - ly; if(Math.abs(dx) > Math.abs(dy)){ xTran += Math.signum(dx); @@ -425,7 +406,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { ly = ny; } } - + @Override public void mouseWheelMoved(MouseEvent e) { if( !e.isShiftDown() ) { @@ -433,4 +414,4 @@ public class GPUUISceneGLListener0A implements GLEventListener { } } } -}
\ No newline at end of file +}
\ No newline at end of file diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java index 0563ab2cf..17b9642d9 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java @@ -4,7 +4,7 @@ import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.graph.geom.SVertex; import com.jogamp.newt.event.WindowAdapter; import com.jogamp.newt.event.WindowEvent; import com.jogamp.newt.opengl.GLWindow; diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java index 4c8da139e..a4673f0c5 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java @@ -5,7 +5,7 @@ import javax.media.opengl.GLProfile; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.graph.geom.SVertex; import com.jogamp.newt.event.WindowAdapter; import com.jogamp.newt.event.WindowEvent; import com.jogamp.newt.opengl.GLWindow; diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/MSAATool.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/MSAATool.java index 4cddb1340..ea593ec7d 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/MSAATool.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/MSAATool.java @@ -45,27 +45,27 @@ public class MSAATool { } catch (Exception e) { System.err.println("Catched Exception: "+e.getMessage()); // e.printStackTrace(); - } + } return isEnabled; } public static void dump(GLAutoDrawable drawable) { float[] vf = new float[] { 0f }; byte[] vb = new byte[] { 0 }; int[] vi = new int[] { 0, 0 }; - + System.out.println("GL MSAA SETUP:"); GL2ES2 gl = drawable.getGL().getGL2ES2(); GLCapabilitiesImmutable caps = drawable.getChosenGLCapabilities(); - System.out.println(" Caps realised "+caps); + System.out.println(" Caps realised "+caps); System.out.println(" Caps sample buffers "+caps.getSampleBuffers()+", samples "+caps.getNumSamples()); - + System.out.println(" GL MULTISAMPLE "+glIsEnabled(gl, GL2ES2.GL_MULTISAMPLE)); - // sample buffers min 0, same as GLX_SAMPLE_BUFFERS_ARB or WGL_SAMPLE_BUFFERS_ARB + // sample buffers min 0, same as GLX_SAMPLE_BUFFERS_ARB or WGL_SAMPLE_BUFFERS_ARB gl.glGetIntegerv(GL2GL3.GL_SAMPLE_BUFFERS, vi, 0); // samples min 0 gl.glGetIntegerv(GL2GL3.GL_SAMPLES, vi, 1); System.out.println(" GL SAMPLE_BUFFERS "+vi[0]+", SAMPLES "+vi[1]); - + System.out.println("GL CSAA SETUP:"); // default FALSE System.out.println(" GL SAMPLE COVERAGE "+glIsEnabled(gl, GL2GL3.GL_SAMPLE_COVERAGE)); @@ -76,8 +76,21 @@ public class MSAATool { // default FALSE, value 1, invert false gl.glGetFloatv(GL2GL3.GL_SAMPLE_COVERAGE_VALUE, vf, 0); gl.glGetBooleanv(GL2GL3.GL_SAMPLE_COVERAGE_INVERT, vb, 0); - System.out.println(" GL SAMPLE_COVERAGE "+glIsEnabled(gl, GL2GL3.GL_SAMPLE_COVERAGE) + + System.out.println(" GL SAMPLE_COVERAGE "+glIsEnabled(gl, GL2GL3.GL_SAMPLE_COVERAGE) + ": SAMPLE_COVERAGE_VALUE "+vf[0]+ - ", SAMPLE_COVERAGE_INVERT "+vb[0]); + ", SAMPLE_COVERAGE_INVERT "+vb[0]); + dumpBlend(gl); + } + public static void dumpBlend(GL gl) { + int[] vi = new int[] { 0, 0, 0, 0 }; + gl.glGetIntegerv(GL.GL_BLEND, vi, 0); + gl.glGetIntegerv(GL.GL_BLEND_SRC_ALPHA, vi, 1); + gl.glGetIntegerv(GL.GL_BLEND_SRC_RGB, vi, 2); + gl.glGetIntegerv(GL.GL_BLEND_DST_RGB, vi, 3); + final boolean blendEnabled = vi[0] == GL.GL_TRUE; + System.out.println("GL_BLEND "+blendEnabled+"/"+glIsEnabled(gl, GL.GL_BLEND) + + " GL_SRC_ALPHA 0x"+Integer.toHexString(vi[1])+ + " GL_SRC_RGB 0x"+Integer.toHexString(vi[2])+ + " GL_DST_RGB 0x"+Integer.toHexString(vi[3])); } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java index 4fef2d8c2..6275f25d2 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java @@ -29,77 +29,83 @@ package com.jogamp.opengl.test.junit.graph.demos.ui; import javax.media.opengl.GL2ES2; -import jogamp.graph.curve.text.GlyphString; +import jogamp.graph.geom.plane.AffineTransform; +import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.curve.opengl.RegionRenderer; -import com.jogamp.graph.curve.opengl.RenderState; +import com.jogamp.graph.curve.opengl.TextRegionUtil; import com.jogamp.graph.font.Font; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Vertex.Factory; +import com.jogamp.opengl.math.geom.AABBox; -public abstract class Label extends UIShape implements UITextShape { +public class Label extends UIShape { protected Font font; - protected int size; + protected float pixelSize; protected String text; - protected GlyphString glyphString; - - public Label(Factory<? extends Vertex> factory, Font font, int size, String text) { + + public Label(Factory<? extends Vertex> factory, Font font, float pixelSize, String text) { super(factory); this.font = font; - this.size = size; + this.pixelSize = pixelSize; this.text = text; } - - public GlyphString getGlyphString() { - return glyphString; - } - + public String getText() { return text; } - + public void setText(String text) { this.text = text; - dirty |= DIRTY_SHAPE; + dirty |= DIRTY_SHAPE | DIRTY_REGION; } - + public Font getFont() { return font; } public void setFont(Font font) { this.font = font; - dirty |= DIRTY_SHAPE; + dirty |= DIRTY_SHAPE | DIRTY_REGION; } - public int getSize() { - return size; + public float getPixelSize() { + return pixelSize; } - public void setSize(int size) { - this.size = size; - dirty |= DIRTY_SHAPE; + public void setPixelSize(float pixelSize) { + this.pixelSize = pixelSize; + dirty |= DIRTY_SHAPE | DIRTY_REGION; } - public String toString(){ - return "Label [" + font.toString() + ", size " + size + ", " + getText() + "]"; + @Override + protected void clearImpl(GL2ES2 gl, RegionRenderer renderer) { } @Override - protected void clearImpl() { - if(null != glyphString) { - glyphString.destroy(null, null); - } + protected void destroyImpl(GL2ES2 gl, RegionRenderer renderer) { } - + + private final TextRegionUtil.ShapeVisitor shapeVisitor = new TextRegionUtil.ShapeVisitor() { + final float[] tmp = new float[3]; + @Override + public void visit(OutlineShape shape, AffineTransform t) { + shapes.add(new TransformedShape(shape, new AffineTransform(t))); + final AABBox sbox = shape.getBounds(); + t.transform(sbox.getLow(), tmp); + box.resize(tmp, 0); + t.transform(sbox.getHigh(), tmp); + box.resize(tmp, 0); + } + }; + @Override - protected void createShape() { - clearImpl(); - glyphString = GlyphString.createString(shape, getVertexFactory(), font, size, text); + protected void createShape(GL2ES2 gl, RegionRenderer renderer) { + TextRegionUtil.processString(shapeVisitor, new AffineTransform(renderer.getRenderState().getVertexFactory()), font, pixelSize, text); } @Override - public void render(GL2ES2 gl, RenderState rs, RegionRenderer renderer, - int renderModes, int[/*1*/] texSize, boolean selection) { + public String toString(){ + return "Label [" + font.toString() + ", size " + pixelSize + ", " + getText() + "]"; } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java index 12c90f87d..df0e504c6 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java @@ -29,40 +29,35 @@ package com.jogamp.opengl.test.junit.graph.demos.ui; import javax.media.opengl.GL2ES2; +import jogamp.graph.geom.plane.AffineTransform; + +import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.curve.opengl.RegionRenderer; -import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.graph.font.Font; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Vertex.Factory; import com.jogamp.opengl.math.geom.AABBox; -import com.jogamp.opengl.test.junit.graph.demos.ui.opengl.UIRegion; -/** GPU based resolution independent Button impl +/** + * GPU based resolution independent Button impl */ public abstract class RIButton extends UIShape { private float width, height; - private Label label; + private final Label label; private float spacing = 4.0f; private float corner = 1.0f; private float labelZOffset = -0.05f; - - private float[] buttonColor = {0.6f, 0.6f, 0.6f}; - private float[] buttonSelectedColor = {0.8f,0.8f,0.8f}; - private float[] labelColor = {1.0f, 1.0f, 1.0f}; - private float[] labelSelectedColor = {0.1f, 0.1f, 0.1f}; - - + public RIButton(Factory<? extends Vertex> factory, Font labelFont, String labelText, float width, float height) { super(factory); - + // FIXME: Determine font size - PMV Matrix relation ? // this.label = new Label(factory, labelFont, (int)(height - 2f * spacing), labelText); - this.label = new Label(factory, labelFont, 10, labelText){ - public void onClick() { } - public void onPressed() { } - public void onRelease() { } - }; - + this.label = new Label(factory, labelFont, 10, labelText); + this.label.setSelectedColor(this.color[0], this.color[1], this.color[2]); + this.label.setColor(0.9f, 0.9f, 0.9f); + this.label.setSelectedColor(1f, 1f, 1f); + this.width = width; this.height = height; } @@ -75,63 +70,77 @@ public abstract class RIButton extends UIShape { public void setDimension(int width, int height) { this.width = width; this.height = height; - dirty |= DIRTY_SHAPE; + dirty |= DIRTY_SHAPE | DIRTY_REGION; + } + + @Override + protected void clearImpl(GL2ES2 gl, RegionRenderer renderer) { + label.clear(gl, renderer); } - + @Override - protected void clearImpl() { - label.clear(); + protected void destroyImpl(GL2ES2 gl, RegionRenderer renderer) { + label.destroy(gl, renderer); } - + @Override - protected void createShape() { - // FIXME: Only possible if all data (color) is - // is incl. in Outline Shape. - // Until then - draw each separately! - //shape.addOutlinShape( label.getShape() ); - label.updateShape(); - - final AABBox lbox = label.getBounds(); + public void drawShape(GL2ES2 gl, RegionRenderer renderer, int[] sampleCount, boolean select) { + gl.glEnable(GL2ES2.GL_POLYGON_OFFSET_FILL); + gl.glPolygonOffset(0.0f, 1f); + super.drawShape(gl, renderer, sampleCount, select); + gl.glDisable(GL2ES2.GL_POLYGON_OFFSET_FILL); + + label.drawShape(gl, renderer, sampleCount, select); + } + + @Override + protected void createShape(GL2ES2 gl, RegionRenderer renderer) { + label.createShape(gl, renderer); + box.resize(label.getBounds()); + + final float sx = getWidth() / ( 2f*spacing + box.getWidth() ); + final float sy = getHeight() / ( 2f*spacing + box.getHeight() ); + scale(sx, sy, 1); + + final OutlineShape shape = new OutlineShape(renderer.getRenderState().getVertexFactory()); if(corner == 0.0f) { - createSharpOutline(lbox); + createSharpOutline(shape, box); } else { - createCurvedOutline(lbox); + createCurvedOutline(shape, box); } - float sx = getWidth() / ( 2f*spacing + lbox.getWidth() ); - float sy = getHeight() / ( 2f*spacing + lbox.getHeight() ); - - setScale(sx, sy, 1); + box.resize(shape.getBounds()); + shapes.add(new TransformedShape(shape, new AffineTransform(renderer.getRenderState().getVertexFactory()))); + System.err.println("XXX.UIShape.RIButton: Added Shape: "+shape+", "+box); } - - - private void createSharpOutline(AABBox lbox) { + private void createSharpOutline(OutlineShape shape, AABBox lbox) { float th = (2f*spacing) + lbox.getHeight(); float tw = (2f*spacing) + lbox.getWidth(); - + float minX = lbox.getMinX()-spacing; float minY = lbox.getMinY()-spacing; float minZ = labelZOffset; - + shape.addVertex(minX, minY, minZ, true); shape.addVertex(minX+tw, minY, minZ, true); shape.addVertex(minX+tw, minY + th, minZ, true); shape.addVertex(minX, minY + th, minZ, true); - shape.closeLastOutline(); + shape.closeLastOutline(true); } - - private void createCurvedOutline(AABBox lbox){ - float th = 2.0f*spacing + lbox.getHeight(); - float tw = 2.0f*spacing + lbox.getWidth(); - - float cw = 0.5f*corner*Math.min(tw, th); - float ch = 0.5f*corner*Math.min(tw, th); - + private void createCurvedOutline(OutlineShape shape, AABBox lbox){ + final float th = 2.0f*spacing + lbox.getHeight(); + final float tw = 2.0f*spacing + lbox.getWidth(); + final float cw = 0.5f*corner*Math.min(tw, th); + final float ch = 0.5f*corner*Math.min(tw, th); + float minX = lbox.getMinX()-spacing; float minY = lbox.getMinY()-spacing; float minZ = labelZOffset; + shape.addVertex(minX, minY + ch, minZ, true); shape.addVertex(minX, minY, minZ, false); + shape.addVertex(minX + cw, minY, minZ, true); + shape.addVertex(minX + tw - cw, minY, minZ, true); shape.addVertex(minX + tw, minY, minZ, false); shape.addVertex(minX + tw, minY + ch, minZ, true); @@ -141,9 +150,9 @@ public abstract class RIButton extends UIShape { shape.addVertex(minX + cw, minY + th, minZ, true); shape.addVertex(minX, minY + th, minZ, false); shape.addVertex(minX, minY + th - ch, minZ, true); - shape.closeLastOutline(); + shape.closeLastOutline(true); } - + public void setCorner(float corner) { if(corner > 1.0f){ this.corner = 1.0f; @@ -154,16 +163,16 @@ public abstract class RIButton extends UIShape { else{ this.corner = corner; } - dirty |= DIRTY_SHAPE; + dirty |= DIRTY_SHAPE | DIRTY_REGION; } - + public float getLabelZOffset() { return labelZOffset; } public void setLabelZOffset(float labelZOffset) { this.labelZOffset = -labelZOffset; - dirty |= DIRTY_SHAPE; + dirty |= DIRTY_SHAPE | DIRTY_REGION; } public float getSpacing() { return spacing; @@ -176,91 +185,19 @@ public abstract class RIButton extends UIShape { else{ this.spacing = spacing; } - dirty |= DIRTY_SHAPE; - } - - public float[] getButtonColor() { - return buttonColor; - } - - public void setButtonColor(float r, float g, float b) { - this.buttonColor = new float[3]; - this.buttonColor[0] = r; - this.buttonColor[1] = g; - this.buttonColor[2] = b; + dirty |= DIRTY_SHAPE | DIRTY_REGION; } public float[] getLabelColor() { - return labelColor; + return label.getColor(); } - - private UIRegion buttonRegion = null; - private UIRegion labelRegion = null; - private boolean toggle =false; - private boolean toggleable = false; - public void render(GL2ES2 gl, RenderState rs, RegionRenderer renderer, int renderModes, int[/*1*/] texSize, boolean selection) { - if(null == buttonRegion) { - buttonRegion = new UIRegion(this); - labelRegion = new UIRegion(getLabel()); - } - - gl.glEnable(GL2ES2.GL_POLYGON_OFFSET_FILL); - gl.glPolygonOffset(0.0f, 1f); - - float[] bColor = buttonColor; - if(isPressed() || toggle){ - bColor = buttonSelectedColor; - } - if(!selection){ - renderer.setColorStatic(gl, bColor[0], bColor[1], bColor[2]); - } - renderer.draw(gl, buttonRegion.getRegion(gl, rs, renderModes), getPosition(), texSize); - gl.glDisable(GL2ES2.GL_POLYGON_OFFSET_FILL); - - float[] lColor = labelColor; - if(isPressed() || toggle ){ - lColor = labelSelectedColor; - } - if(!selection){ - renderer.setColorStatic(gl, lColor[0], lColor[1], lColor[2]); - } - renderer.draw(gl, labelRegion.getRegion(gl, rs, renderModes), getPosition(), texSize); - } - public void setPressed(boolean b) { - super.setPressed(b); - if(isToggleable() && b) { - toggle = !toggle; - } - } - public void setLabelColor(float r, float g, float b) { - this.labelColor = new float[3]; - this.labelColor[0] = r; - this.labelColor[1] = g; - this.labelColor[2] = b; - } - - public void setButtonSelectedColor(float r, float g, float b){ - this.buttonSelectedColor = new float[3]; - this.buttonSelectedColor[0] = r; - this.buttonSelectedColor[1] = g; - this.buttonSelectedColor[2] = b; - } - - public void setLabelSelectedColor(float r, float g, float b){ - this.labelSelectedColor = new float[3]; - this.labelSelectedColor[0] = r; - this.labelSelectedColor[1] = g; - this.labelSelectedColor[2] = b; + label.setColor(r, g, b); } - public boolean isToggleable() { - return toggleable; - } - - public void setToggleable(boolean toggleable) { - this.toggleable = toggleable; + public void setLabelSelectedColor(float r, float g, float b){ + label.setSelectedColor(r, g, b); } public String toString() { diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java index 616dd9b98..77195646d 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java @@ -10,52 +10,56 @@ import javax.media.opengl.GL2ES2; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLRunnable; +import javax.media.opengl.fixedfunc.GLMatrixFunc; + +import jogamp.graph.geom.plane.AffineTransform; import com.jogamp.common.nio.Buffers; import com.jogamp.graph.curve.opengl.RegionRenderer; -import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.event.MouseListener; import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.util.PMVMatrix; public class SceneUIController implements GLEventListener{ - private ArrayList<UIShape> shapes = new ArrayList<UIShape>(); + private final ArrayList<UIShape> shapes = new ArrayList<UIShape>(); private int count = 0; - private int renderModes; - private int[] texSize; - private RegionRenderer renderer = null; - private RenderState rs = null; + private int renderModes; + private int[] sampleCount; + private RegionRenderer renderer; + + private final float[] translate = new float[3]; + private final float[] scale = new float[3]; + private final float[] rotation = new float[3]; - private float[] translate = new float[3]; - private float[] scale = new float[3]; - private float[] rotation = new float[3]; + private final float[] sceneClearColor = new float[]{0,0,0,0}; - private float[] sceneClearColor = new float[]{0,0,0,1}; - private int activeId = -1; - + private SBCMouseListener sbcMouseListener = null; - + private GLAutoDrawable cDrawable = null; public SceneUIController() { + this(null, 0, null); } - - public void setRenderer(RegionRenderer renderer, RenderState rs, int renderModes, int[] texSize) { + + public SceneUIController(RegionRenderer renderer, int renderModes, int[] sampleCount) { this.renderer = renderer; - this.rs = rs; this.renderModes = renderModes; - this.texSize = texSize; + this.sampleCount = sampleCount; + setScale(1f, 1f, 1f); + setTranslate(0f, 0f, 0f); + setRotation(0f, 0f, 0f); } - - public SceneUIController(RegionRenderer renderer, RenderState rs, int renderModes, int[] texSize) { + + public void setRenderer(RegionRenderer renderer, int renderModes, int[] sampleCount) { this.renderer = renderer; - this.rs = rs; this.renderModes = renderModes; - this.texSize = texSize; + this.sampleCount = sampleCount; } - + public void attachInputListenerTo(GLWindow window) { if(null == sbcMouseListener) { sbcMouseListener = new SBCMouseListener(); @@ -68,7 +72,7 @@ public class SceneUIController implements GLEventListener{ window.removeMouseListener(sbcMouseListener); } } - + public ArrayList<UIShape> getShapes() { return shapes; } @@ -83,7 +87,7 @@ public class SceneUIController implements GLEventListener{ count--; } } - + public void init(GLAutoDrawable drawable) { System.err.println("SceneUIController: init"); cDrawable = drawable; @@ -94,20 +98,15 @@ public class SceneUIController implements GLEventListener{ final int height = drawable.getHeight(); GL2ES2 gl = drawable.getGL().getGL2ES2(); - render(gl, width, height, renderModes, texSize, false); + render(gl, width, height, renderModes, sampleCount, false); } - + public void dispose(GLAutoDrawable drawable) { System.err.println("SceneUIController: dispose"); cDrawable = null; - drawable.removeGLEventListener(this); } - public void reshape(GLAutoDrawable drawable, int x, int y, int width, - int height) { - System.err.println("SceneUIController: reshape"); - GL2ES2 gl = drawable.getGL().getGL2ES2(); - renderer.reshapePerspective(gl, 45.0f, width, height, 5f, 70.0f); + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { } public UIShape getShape(GLAutoDrawable drawable,int x, int y) { @@ -120,13 +119,13 @@ public class SceneUIController implements GLEventListener{ return null; return shapes.get(index); } - + public UIShape getActiveUI() { if(activeId == -1) return null; return shapes.get(activeId); } - + public void release() { activeId = -1; } @@ -152,27 +151,30 @@ public class SceneUIController implements GLEventListener{ return index; } - private void render(GL2ES2 gl, int width, int height, int renderModes, int[/*1*/] texSize, boolean select) { - renderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f); - + private void render(GL2ES2 gl, int width, int height, int renderModes, int[/*1*/] sampleCount, boolean select) { for(int index=0; index < count;index++){ if(select) { float color= index+1; renderer.setColorStatic(gl, color/(count+2), color/(count+2), color/(count+2)); } - float[] s = shapes.get(index).getScale(); - float[] p = shapes.get(index).getPosition(); - renderer.resetModelview(null); - renderer.translate(null, translate[0]+p[0], translate[1]+p[1], translate[2]+p[2]); - renderer.scale(gl, s[0], s[1], s[2]); - renderer.rotate(gl, rotation[0], 1, 0, 0); - renderer.rotate(gl, rotation[1], 0, 1, 0); - renderer.rotate(gl, rotation[2], 0, 0, 1); - - shapes.get(index).render(gl, rs, renderer, renderModes, texSize, select); - renderer.rotate(gl, -rotation[0], 1, 0, 0); - renderer.rotate(gl, -rotation[1], 0, 1, 0); - renderer.rotate(gl, -rotation[2], 0, 0, 1); + final UIShape uiShape = shapes.get(index); + uiShape.validate(gl, renderer); + final AffineTransform t = uiShape.getTransform(); + + final PMVMatrix pmv = renderer.getMatrix(); + pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + pmv.glPushMatrix(); + pmv.glLoadIdentity(); + System.err.printf("SceneUICtrl.render.1.0: translate.0: %f, %f, %f%n", translate[0], translate[1], translate[2]); + System.err.printf("SceneUICtrl.render.1.0: translate.1: %f, %f%n", t.getTranslateX(), t.getTranslateY()); + pmv.glTranslatef(translate[0]+t.getTranslateX(), translate[1]+t.getTranslateY(), translate[2]); + pmv.glScalef(scale[0]*t.getScaleX(), scale[1]*t.getScaleY(), scale[2]); + pmv.glRotatef(rotation[0], 1, 0, 0); + pmv.glRotatef(rotation[1], 0, 1, 0); + pmv.glRotatef(rotation[2], 0, 0, 1); + renderer.updateMatrix(gl); + uiShape.drawShape(gl, renderer, sampleCount, select); + pmv.glPopMatrix(); } } @@ -203,11 +205,11 @@ public class SceneUIController implements GLEventListener{ this.sceneClearColor[2] = b; this.sceneClearColor[3] = a; } - + private class SBCMouseListener implements MouseListener { int mouseX = -1; int mouseY = -1; - + public void mouseClicked(MouseEvent e) { UIShape uiShape = getActiveUI(); if(uiShape != null){ @@ -221,7 +223,7 @@ public class SceneUIController implements GLEventListener{ } mouseX = e.getX(); mouseY = e.getY(); - + GLRunnable runnable = new GLRunnable() { public boolean run(GLAutoDrawable drawable) { UIShape s = getShape(drawable, mouseX, mouseY); @@ -235,16 +237,16 @@ public class SceneUIController implements GLEventListener{ } }; cDrawable.invoke(true, runnable); - + UIShape uiShape = getActiveUI(); - + if(uiShape != null) { uiShape.setPressed(true); uiShape.onPressed(); } } - public void mouseReleased(MouseEvent e) { + public void mouseReleased(MouseEvent e) { UIShape uiShape = getActiveUI(); if(uiShape != null){ uiShape.setPressed(false); @@ -257,6 +259,6 @@ public class SceneUIController implements GLEventListener{ public void mouseExited(MouseEvent e) { } public void mouseDragged(MouseEvent e) { } public void mouseWheelMoved(MouseEvent e) { } - + } }
\ No newline at end of file diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java index da94f6a7c..587b9b3dc 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java @@ -34,18 +34,19 @@ import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; import javax.media.opengl.GLAutoDrawable; -import com.jogamp.graph.curve.opengl.RegionRenderer; +import jogamp.graph.geom.plane.AffineTransform; + import com.jogamp.graph.curve.opengl.RenderState; +import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; -import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.graph.geom.SVertex; import com.jogamp.opengl.test.junit.graph.demos.MSAATool; -import com.jogamp.opengl.test.junit.graph.demos.ui.opengl.UIRegion; public class UIGLListener01 extends UIListenerBase01 { - + public UIGLListener01 (RenderState rs, boolean debug, boolean trace) { - super(RegionRenderer.create(rs, 0), debug, trace); + super(RegionRenderer.create(rs, 0, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable), debug, trace); setMatrix(-20, 00, 0f, -50); try { final Font font = FontFactory.get(FontFactory.UBUNTU).getDefault(); @@ -56,9 +57,9 @@ public class UIGLListener01 extends UIListenerBase01 { } public void onRelease() { } - + }; - button.setPosition(2,1,0); + button.translate(2,1); /** Button defaults ! button.setLabelColor(1.0f,1.0f,1.0f); button.setButtonColor(0.6f,0.6f,0.6f); @@ -69,24 +70,21 @@ public class UIGLListener01 extends UIListenerBase01 { } catch (IOException ex) { System.err.println("Catched: "+ex.getMessage()); ex.printStackTrace(); - } + } } - + public void init(GLAutoDrawable drawable) { super.init(drawable); - + GL2ES2 gl = drawable.getGL().getGL2ES2(); gl.setSwapInterval(1); gl.glEnable(GL2ES2.GL_DEPTH_TEST); gl.glEnable(GL2ES2.GL_POLYGON_OFFSET_FILL); - + MSAATool.dump(drawable); } - UIRegion regionButton; - UIRegion regionLabel; - public void display(GLAutoDrawable drawable) { GL2ES2 gl = drawable.getGL().getGL2ES2(); @@ -94,37 +92,21 @@ public class UIGLListener01 extends UIListenerBase01 { gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); final RegionRenderer regionRenderer = getRegionRenderer(); - final RenderState rs = regionRenderer.getRenderState(); - + regionRenderer.resetModelview(null); - + regionRenderer.translate(null, getXTran(), getYTran(), getZoom()); regionRenderer.rotate(gl, getAngle(), 0, 1, 0); - - final float[] bColor = button.getButtonColor(); - final float[] lColor = button.getLabelColor(); - if(null == regionButton) { - regionButton = new UIRegion(button); - regionLabel = new UIRegion(button.getLabel()); - } - - regionRenderer.setColorStatic(gl, bColor[0], bColor[1], bColor[2]); - regionRenderer.draw(gl, regionButton.getRegion(gl, rs, 0), getPosition(), null); -// regionRenderer.translate(gl, button.getPosition()[0], button.getPosition()[1], button.getPosition()[2]); - regionRenderer.setColorStatic(gl, lColor[0], lColor[1], lColor[2]); - regionRenderer.draw(gl, regionLabel.getRegion(gl, rs, 0), getPosition(), null); - } - + + final int[] sampleCount = { 4 }; + final AffineTransform t = button.getTransform(); + regionRenderer.translate(gl, t.getTranslateX(), t.getTranslateY(), 0); + button.drawShape(gl, regionRenderer, sampleCount, false); + } + public void dispose(GLAutoDrawable drawable) { GL2ES2 gl = drawable.getGL().getGL2ES2(); - if(null != regionButton) { - regionButton.destroy(gl, getRegionRenderer().getRenderState()); - regionButton = null; - } - if(null != regionLabel) { - regionLabel.destroy(gl, getRegionRenderer().getRenderState()); - regionButton = null; - } + button.destroy(gl, getRegionRenderer()); super.dispose(drawable); } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java index 0577c5ff0..031d43e79 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java @@ -28,12 +28,11 @@ package com.jogamp.opengl.test.junit.graph.demos.ui; -import javax.media.opengl.FPSCounter; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.graph.geom.SVertex; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.WindowAdapter; @@ -45,14 +44,14 @@ import com.jogamp.opengl.util.glsl.ShaderState; /** Demonstrate the rendering of multiple outlines into one region/OutlineShape * These Outlines are not necessary connected or contained. * The output of this demo shows two identical shapes but the left one - * has some vertices with off-curve flag set to true, and the right allt he vertices - * are on the curve. Demos the Res. Independent Nurbs based Curve rendering + * has some vertices with off-curve flag set to true, and the right allt he vertices + * are on the curve. Demos the Res. Independent Nurbs based Curve rendering * */ public class UINewtDemo01 { static final boolean DEBUG = false; static final boolean TRACE = false; - + public static void main(String[] args) { GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); @@ -60,23 +59,21 @@ public class UINewtDemo01 { caps.setSampleBuffers(true); caps.setNumSamples(4); System.out.println("Requested: " + caps); - + final GLWindow window = GLWindow.create(caps); window.setPosition(10, 10); window.setSize(800, 400); window.setTitle("GPU UI Newt Demo 01"); RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); UIGLListener01 uiGLListener = new UIGLListener01 (rs, DEBUG, TRACE); - uiGLListener.attachInputListenerTo(window); + uiGLListener.attachInputListenerTo(window); window.addGLEventListener(uiGLListener); - - window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); window.setVisible(true); final Animator animator = new Animator(); - animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); + animator.setUpdateFPSFrames(60, System.err); animator.add(window); - + window.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent arg0) { if(arg0.getKeyCode() == KeyEvent.VK_F4) { @@ -89,7 +86,7 @@ public class UINewtDemo01 { animator.stop(); } }); - + animator.start(); - } + } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java index c38f8f75c..5a7b147d5 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java @@ -27,104 +27,253 @@ */ package com.jogamp.opengl.test.junit.graph.demos.ui; +import java.util.ArrayList; + import javax.media.opengl.GL2ES2; +import jogamp.graph.geom.plane.AffineTransform; + import com.jogamp.graph.curve.OutlineShape; +import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RegionRenderer; -import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Vertex.Factory; import com.jogamp.opengl.math.geom.AABBox; public abstract class UIShape { private final Factory<? extends Vertex> vertexFactory; - protected OutlineShape shape; - - protected static final int DIRTY_SHAPE = 1 << 0 ; - protected int dirty = DIRTY_SHAPE; - + + public class TransformedShape { + public final OutlineShape shape; + public final AffineTransform t; + + public TransformedShape(final OutlineShape shape, final AffineTransform t) { + this.shape = shape; + this.t = t; + } + } + protected final ArrayList<TransformedShape> shapes; + + protected static final int DIRTY_SHAPE = 1 << 0 ; + protected static final int DIRTY_POSITION = 1 << 1 ; + protected static final int DIRTY_REGION = 1 << 2 ; + protected int dirty = DIRTY_SHAPE | DIRTY_POSITION | DIRTY_REGION; + + protected final AABBox box; + protected final AffineTransform transform; + private GLRegion region = null; + + protected final float[] color = {0.6f, 0.6f, 0.6f}; + protected final float[] selectedColor = {0.8f, 0.8f, 0.8f}; + private boolean down = false; + private boolean toggle =false; + private boolean toggleable = false; public UIShape(Factory<? extends Vertex> factory) { this.vertexFactory = factory; - this.shape = new OutlineShape(factory); - } - - public void clear() { - clearImpl(); - shape.clear(); - } - - public abstract void render(GL2ES2 gl, RenderState rs, RegionRenderer renderer, int renderModes, int[/*1*/] texSize, boolean selection); - - protected boolean positionDirty = false; - - private float[] position = new float[]{0,0,0}; - private float[] scale = new float[]{1.0f,1.0f,1.0f}; - public void setScale(float x, float y, float z){ - scale[0] = x; - scale[1] = y; - scale[2] = z; - } - - public void setPosition(float x, float y, float z) { - this.position[0] = x; - this.position[1] = y; - this.position[2] = z; - positionDirty = true; - } - - private void updatePosition () { - float minX = shape.getBounds().getLow()[0]; - float minY = shape.getBounds().getLow()[1]; - float minZ = shape.getBounds().getLow()[2]; - System.out.println("Position was: " + (position[0]) + " " + (position[1]) + " " + (position[2])); - System.out.println("Position became: " + (position[0] - minX) + " " + (position[1] - minY) + " " + (position[2] - minZ)); - setPosition(position[0] - minX, position[1] - minY, position[2] - minZ); - positionDirty = false; - } - - public float[] getScale() { return scale; } - public float[] getPosition() { return position; } - - protected abstract void clearImpl(); - - protected abstract void createShape(); - - public boolean updateShape() { - if( isShapeDirty() ) { - shape.clear(); - createShape(); - if(positionDirty){ - updatePosition(); + this.shapes = new ArrayList<TransformedShape>(); + this.box = new AABBox(); + this.transform = new AffineTransform(factory); + } + + public final Vertex.Factory<? extends Vertex> getVertexFactory() { return vertexFactory; } + + /** + * Clears all data and reset all states as if this instance was newly created + * @param gl TODO + * @param renderer TODO\ + */ + public void clear(GL2ES2 gl, RegionRenderer renderer) { + clearImpl(gl, renderer); + shapes.clear(); + transform.setToIdentity(); + box.reset(); + dirty = DIRTY_SHAPE | DIRTY_POSITION | DIRTY_REGION; + } + + /** + * Destroys all data + * @param gl + * @param renderer + */ + public void destroy(GL2ES2 gl, RegionRenderer renderer) { + destroyImpl(gl, renderer); + shapes.clear(); + transform.setToIdentity(); + box.reset(); + dirty = DIRTY_SHAPE | DIRTY_POSITION | DIRTY_REGION; + } + + public final void translate(float tx, float ty) { + transform.translate(tx, ty); + dirty |= DIRTY_POSITION; + } + + public final void scale(float sx, float sy, float sz) { + transform.scale(sx, sy); + } + + public final AffineTransform getTransform() { + if( !isShapeDirty() ) { + validatePosition(); + } + return transform; + } + + public final boolean isShapeDirty() { + return 0 != ( dirty & DIRTY_SHAPE ) ; + } + + public final boolean isPositionDirty() { + return 0 != ( dirty & DIRTY_POSITION ) ; + } + + public final boolean isRegionDirty() { + return 0 != ( dirty & DIRTY_REGION ) ; + } + + public ArrayList<TransformedShape> getShapes() { return shapes; } + + public final AABBox getBounds() { return box; } + + public GLRegion getRegion(GL2ES2 gl, RegionRenderer renderer) { + validate(gl, renderer); + if( isRegionDirty() ) { + if( null == region ) { + region = GLRegion.create(renderer.getRenderModes()); + } else { + region.clear(gl, renderer); } + addToRegion(region); + dirty &= ~DIRTY_REGION; + System.err.println("XXX.UIShape: updated: "+region); + } + return region; + } + + /** + * Renders {@link OutlineShape} using local {@link GLRegion} which might be cached or updated. + * <p> + * No matrix operations (translate, scale, ..) are performed. + * </p> + * @param gl + * @param renderer + * @param sampleCount + * @param select + */ + public void drawShape(GL2ES2 gl, RegionRenderer renderer, int[] sampleCount, boolean select) { + float[] _color = color; + if( isPressed() || toggle ){ + _color = selectedColor; + } + if(!select){ + /** + if( useBlending ) { + // NOTE_ALPHA_BLENDING: + // Due to alpha blending and VBAA, we need a background in text color + // otherwise blending will amplify 'white'! + gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + } */ + renderer.setColorStatic(gl, _color[0], _color[1], _color[2]); + } + getRegion(gl, renderer).draw(gl, renderer, sampleCount); + } + + public final boolean validate(GL2ES2 gl, RegionRenderer renderer) { + if( !validateShape(gl, renderer) ) { + return validatePosition(); + } + return true; + } + private final boolean validateShape(GL2ES2 gl, RegionRenderer renderer) { + if( isShapeDirty() ) { + shapes.clear(); + box.reset(); + createShape(gl, renderer); dirty &= ~DIRTY_SHAPE; + dirty |= DIRTY_REGION; + validatePosition(); return true; } return false; } - - public final Vertex.Factory<? extends Vertex> getVertexFactory() { return vertexFactory; } - public AABBox getBounds() { return shape.getBounds(); } - - public OutlineShape getShape() { - updateShape(); - return shape; + private final boolean validatePosition () { + if( isPositionDirty() && !isShapeDirty() ) { + // Subtract the bbox minx/miny from position, i.e. the shape's offset. + final AABBox box = getBounds(); + final float minX = box.getMinX(); + final float minY = box.getMinY(); + System.err.println("XXX.UIShape: Position pre: " + transform.getTranslateX() + " " + transform.getTranslateY() + ", sbox "+box); + translate(-minX, -minY); + System.err.println("XXX.UIShape: Position post: " + transform.getTranslateX() + " " + transform.getTranslateY() + ", sbox "+box); + dirty &= ~DIRTY_POSITION; + return true; + } + return false; } - - public boolean isShapeDirty() { - return 0 != ( dirty & DIRTY_SHAPE ) ; - } - + + private final void addToRegion(Region region) { + final int shapeCount = shapes.size(); + for(int i=0; i<shapeCount; i++) { + final TransformedShape tshape = shapes.get(i); + region.addOutlineShape(tshape.shape, tshape.t); + } + } + + public float[] getColor() { + return color; + } + + public void setColor(float r, float g, float b) { + this.color[0] = r; + this.color[1] = g; + this.color[2] = b; + } + public void setSelectedColor(float r, float g, float b){ + this.selectedColor[0] = r; + this.selectedColor[1] = g; + this.selectedColor[2] = b; + } + + // + // Input + // + public void setPressed(boolean b) { this.down = b; + if(isToggleable() && b) { + toggle = !toggle; + } } - + public boolean isPressed() { return this.down; } - - public abstract void onClick(); - public abstract void onPressed(); - public abstract void onRelease(); + + public boolean isToggleable() { + return toggleable; + } + + public void setToggleable(boolean toggleable) { + this.toggleable = toggleable; + } + + public void onClick() { } + public void onPressed() { } + public void onRelease() { } + + // + // + // + + protected abstract void clearImpl(GL2ES2 gl, RegionRenderer renderer); + protected abstract void destroyImpl(GL2ES2 gl, RegionRenderer renderer); + protected abstract void createShape(GL2ES2 gl, RegionRenderer renderer); + + // + // + // + } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITextShape.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITextShape.java deleted file mode 100644 index ee79d9a0b..000000000 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITextShape.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package com.jogamp.opengl.test.junit.graph.demos.ui; - -import jogamp.graph.curve.text.GlyphString; - -/** - * Marker interface to mark a UIShape implementation for text usage - */ -public interface UITextShape { - GlyphString getGlyphString(); -} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/opengl/UIRegion.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/opengl/UIRegion.java deleted file mode 100644 index 88271095c..000000000 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/opengl/UIRegion.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package com.jogamp.opengl.test.junit.graph.demos.ui.opengl; - -import javax.media.opengl.GL2ES2; - -import com.jogamp.graph.curve.opengl.GLRegion; -import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.opengl.test.junit.graph.demos.ui.UIShape; -import com.jogamp.opengl.test.junit.graph.demos.ui.UITextShape; - -public class UIRegion { - protected static final int DIRTY_REGION = 1 << 0 ; - protected int dirty = DIRTY_REGION; - - private UIShape uiShape; - private GLRegion region; - - public UIRegion(UIShape uis) { - this.uiShape = uis; - } - - public boolean updateRegion(GL2ES2 gl, RenderState rs, int renderModes) { - if( uiShape.updateShape() || isRegionDirty() ) { - destroy(gl, rs); - if(uiShape instanceof UITextShape) { - region = ((UITextShape)uiShape).getGlyphString().createRegion(gl, renderModes); - } else { - region = GLRegion.create(uiShape.getShape(), renderModes); - } - dirty &= ~DIRTY_REGION; - return true; - } - return false; - } - - public GLRegion getRegion(GL2ES2 gl, RenderState rs, int renderModes) { - updateRegion(gl, rs, renderModes); - return region; - } - - public boolean isRegionDirty() { - return 0 != ( dirty & DIRTY_REGION ) ; - } - - public void destroy(GL2ES2 gl, RenderState rs) { - if(null != region) { - region.destroy(gl, rs); - region = null; - } - } -} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/GLReadBuffer00Base.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/GLReadBuffer00Base.java index 43f8b89bd..d556f2963 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/GLReadBuffer00Base.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/GLReadBuffer00Base.java @@ -41,6 +41,9 @@ import org.junit.Test; import org.junit.runners.MethodSorters; import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.GLRegion; +import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.graph.font.Font; import com.jogamp.opengl.test.junit.graph.TextRendererGLELBase; import com.jogamp.opengl.test.junit.util.UITestCase; @@ -51,15 +54,16 @@ import com.jogamp.opengl.test.junit.util.UITestCase; public abstract class GLReadBuffer00Base extends UITestCase { public static class TextRendererGLEL extends TextRendererGLELBase { + final Font font = getFont(0, 0, 0); public int frameNo = 0; public int userCounter = 0; + private final GLRegion regionFPS; public TextRendererGLEL() { // FIXME: Graph TextRenderer does not AA well w/o MSAA and FBO - super(Region.VBAA_RENDERING_BIT); - texSizeScale = 2; - - fontSize = 24; + super(Region.VBAA_RENDERING_BIT, new int[] { 4 }); + this.setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable); + regionFPS = GLRegion.create(usrRenderModes); staticRGBAColor[0] = 1.0f; staticRGBAColor[1] = 1.0f; @@ -68,11 +72,19 @@ public abstract class GLReadBuffer00Base extends UITestCase { } @Override + public void dispose(GLAutoDrawable drawable) { + regionFPS.destroy(drawable.getGL().getGL2ES2(), renderer); + super.dispose(drawable); + } + + @Override public void display(GLAutoDrawable drawable) { final String text = String.format("Frame %04d (%03d): %04dx%04d", frameNo, userCounter, drawable.getWidth(), drawable.getHeight()); System.err.println("TextRendererGLEL.display: "+text); if( null != renderer ) { - renderString(drawable, text, 0 /* col */, 0 /* row */, 0, 0, -1); + final float pixelSize = font.getPixelSize(14f, dpiH); + drawable.getGL().glClearColor(1f, 1f, 1f, 0f); + renderString(drawable, font, pixelSize, text, 0 /* col */, 0 /* row */, 0, 0, -1, regionFPS); } else { System.err.println(text); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java index b02238c2b..79e0655e3 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java @@ -305,14 +305,6 @@ public class TextureSequenceCubeES2 implements GLEventListener { gl.glViewport(0, 0, width, height); - if(innerCube) { - // Clear background to white - gl.glClearColor(1.0f, 1.0f, 1.0f, 0.4f); - } else { - // Clear background to blue - gl.glClearColor(0.0f, 0.0f, 1.0f, 1.0f); - } - if(!innerCube) { // lights on } else { @@ -370,6 +362,13 @@ public class TextureSequenceCubeES2 implements GLEventListener { public void display(GLAutoDrawable drawable) { GL2ES2 gl = drawable.getGL().getGL2ES2(); + if(innerCube) { + // Clear background to white + gl.glClearColor(1.0f, 1.0f, 1.0f, 0.4f); + } else { + // Clear background to blue + gl.glClearColor(0.0f, 0.0f, 1.0f, 1.0f); + } gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); if( null == st ) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java index b148ebabd..3aa400232 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java @@ -43,6 +43,7 @@ import javax.media.opengl.GLProfile; import com.jogamp.common.util.IOUtil; import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.font.Font; import com.jogamp.newt.Window; import com.jogamp.newt.event.KeyAdapter; @@ -156,24 +157,22 @@ public class MovieCube implements GLEventListener { resetGLState = true; } + final int[] textSampleCount = { 4 }; + private final class InfoTextRendererGLELBase extends TextRendererGLELBase { - static final float z_diff = 0.001f; - final float underlineSize; + private static final float z_diff = 0.001f; + private final Font font = getFont(0, 0, 0); + private final float fontSize = 12; + private final GLRegion regionFPS; + private float pixelSize, underlineSize; InfoTextRendererGLELBase() { // FIXME: Graph TextRenderer does not AA well w/o MSAA and FBO - super(Region.VBAA_RENDERING_BIT); - texSizeScale = 2; - - fontSize = 1; - pixelScale = 1.0f / ( fontSize * 20f ); - - // underlineSize: 'underline' amount of pixel below 0/0 (Note: lineGap is negative) - final Font.Metrics metrics = font.getMetrics(); - final float lineGap = metrics.getLineGap(fontSize); - final float descent = metrics.getDescent(fontSize); - underlineSize = descent - lineGap; - // System.err.println("XXX: fLG "+lineGap+", fDesc "+descent+", underlineSize "+underlineSize); + super(Region.VBAA_RENDERING_BIT, MovieCube.this.textSampleCount); + // NOTE_ALPHA_BLENDING: We go w/o alpha and blending! + // this.setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable); + regionFPS = GLRegion.create(usrRenderModes); + System.err.println("RegionFPS "+Region.getRenderModeString(usrRenderModes)+", sampleCount "+textSampleCount[0]+", class "+regionFPS.getClass().getName()); staticRGBAColor[0] = 0.0f; staticRGBAColor[1] = 0.0f; @@ -184,8 +183,23 @@ public class MovieCube implements GLEventListener { @Override public void init(GLAutoDrawable drawable) { // non-exclusive mode! - this.usrPMVMatrix = cube.pmvMatrix; + this.setSharedPMVMatrix(cube.pmvMatrix); super.init(drawable); + + pixelSize = font.getPixelSize(fontSize, dpiH); + pixelScale = 1.0f / ( pixelSize * 20f ); + // underlineSize: 'underline' amount of pixel below 0/0 (Note: lineGap is negative) + final Font.Metrics metrics = font.getMetrics(); + final float lineGap = metrics.getLineGap(pixelSize); + final float descent = metrics.getDescent(pixelSize); + underlineSize = descent - lineGap; + System.err.println("XXX: dpiH "+dpiH+", fontSize "+fontSize+", pixelSize "+pixelSize+", pixelScale "+pixelScale+", fLG "+lineGap+", fDesc "+descent+", underlineSize "+underlineSize); + } + + @Override + public void dispose(GLAutoDrawable drawable) { + regionFPS.destroy(drawable.getGL().getGL2ES2(), renderer); + super.dispose(drawable); } @Override @@ -215,9 +229,7 @@ public class MovieCube implements GLEventListener { "; underlineSize "+underlineSize+" "+(pixelScale*underlineSize)+ "; yoff "+yoff1+", yoff2 "+yoff2); */ - // FIXME: Graph TextRenderer does not scale well, i.e. text update per 1/10s cause too much recompute of regions! - // final String text1 = String.format("%03.1f/%03.1f s, %s (%01.2fx, vol %01.2f), a %01.2f, fps %02.1f -> %02.1f / %02.1f, v-sync %d", - final String text1 = String.format("%03.0f/%03.0f s, %s (%01.2fx, vol %01.2f), a %01.2f, fps %02.1f -> %02.1f / %02.1f, v-sync %d", + final String text1 = String.format("%03.1f/%03.1f s, %s (%01.2fx, vol %01.2f), a %01.2f, fps %02.1f -> %02.1f / %02.1f, v-sync %d", pts, mPlayer.getDuration() / 1000f, mPlayer.getState().toString().toLowerCase(), mPlayer.getPlaySpeed(), mPlayer.getAudioVolume(), aspect, mPlayer.getFramerate(), lfps, tfps, swapIntervalSet); @@ -227,10 +239,11 @@ public class MovieCube implements GLEventListener { mPlayer.getVID(), mPlayer.getVideoBitrate()/1000, mPlayer.getVideoCodec()); final String text4 = mPlayer.getURI().getRawPath(); if( displayOSD && null != renderer ) { - renderString(drawable, text1, 1 /* col */, -1 /* row */, -1+z_diff, yoff1, 1f+z_diff); - renderString(drawable, text2, 1 /* col */, 0 /* row */, -1+z_diff, yoff2, 1f+z_diff); - renderString(drawable, text3, 1 /* col */, 1 /* row */, -1+z_diff, yoff2, 1f+z_diff); - renderString(drawable, text4, 1 /* col */, 2 /* row */, -1+z_diff, yoff2, 1f+z_diff); + drawable.getGL().glClearColor(1.0f, 1.0f, 1.0f, 0.0f); + renderString(drawable, font, pixelSize, text1, 1 /* col */, -1 /* row */, -1+z_diff, yoff1, 1f+z_diff, regionFPS); // no-cache + renderString(drawable, font, pixelSize, text2, 1 /* col */, 0 /* row */, -1+z_diff, yoff2, 1f+z_diff, true); + renderString(drawable, font, pixelSize, text3, 1 /* col */, 1 /* row */, -1+z_diff, yoff2, 1f+z_diff, true); + renderString(drawable, font, pixelSize, text4, 1 /* col */, 2 /* row */, -1+z_diff, yoff2, 1f+z_diff, true); } } }; private final InfoTextRendererGLELBase textRendererGLEL = new InfoTextRendererGLELBase(); @@ -510,7 +523,9 @@ public class MovieCube implements GLEventListener { glp = GLProfile.getGL2ES2(); } System.err.println("GLProfile: "+glp); - final GLWindow window = GLWindow.create(new GLCapabilities(glp)); + final GLCapabilities caps = new GLCapabilities(glp); + // caps.setAlphaBits(4); // NOTE_ALPHA_BLENDING: We go w/o alpha and blending! + final GLWindow window = GLWindow.create(caps); final Animator anim = new Animator(window); window.addWindowListener(new WindowAdapter() { public void windowDestroyed(WindowEvent e) { @@ -519,6 +534,7 @@ public class MovieCube implements GLEventListener { }); window.setSize(width, height); window.setVisible(true); + System.err.println("Chosen: "+window.getChosenGLCapabilities()); anim.start(); mc.mPlayer.addEventListener(new GLMediaEventListener() { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java index 787dbab78..6cee4066b 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java @@ -49,6 +49,8 @@ import javax.media.opengl.fixedfunc.GLMatrixFunc; import com.jogamp.common.os.Platform; import com.jogamp.common.util.IOUtil; import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.GLRegion; +import com.jogamp.graph.font.Font; import com.jogamp.newt.Window; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; @@ -130,13 +132,20 @@ public class MovieSimple implements GLEventListener { defURI = _defURI; } + final int[] textSampleCount = { 4 }; + private final class InfoTextRendererGLELBase extends TextRendererGLELBase { + private final Font font = getFont(0, 0, 0); + private final float fontSize = 10f; + private final GLRegion regionFPS; + InfoTextRendererGLELBase() { // FIXME: Graph TextRenderer does not AA well w/o MSAA and FBO - super(Region.VBAA_RENDERING_BIT); - texSizeScale = 2; - - fontSize = 18; + super(Region.VBAA_RENDERING_BIT, textSampleCount); + // NOTE_ALPHA_BLENDING: We go w/o alpha and blending! + // this.setRendererCallbacks(RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable); + regionFPS = GLRegion.create(usrRenderModes); + System.err.println("RegionFPS "+Region.getRenderModeString(usrRenderModes)+", sampleCount "+textSampleCount[0]+", class "+regionFPS.getClass().getName()); staticRGBAColor[0] = 1.0f; staticRGBAColor[1] = 1.0f; @@ -145,6 +154,17 @@ public class MovieSimple implements GLEventListener { } @Override + public void init(GLAutoDrawable drawable) { + super.init(drawable); + } + + @Override + public void dispose(GLAutoDrawable drawable) { + regionFPS.destroy(drawable.getGL().getGL2ES2(), renderer); + super.dispose(drawable); + } + + @Override public void display(GLAutoDrawable drawable) { final GLAnimatorControl anim = drawable.getAnimator(); final float lfps = null != anim ? anim.getLastFPS() : 0f; @@ -158,9 +178,7 @@ public class MovieSimple implements GLEventListener { final float aspect = (float)mPlayer.getWidth() / (float)mPlayer.getHeight(); - // FIXME: Graph TextRenderer does not scale well, i.e. text update per 1/10s cause too much recompute of regions! - // final String text1 = String.format("%03.1f/%03.1f s, %s (%01.2fx, vol %01.2f), a %01.2f, fps %02.1f -> %02.1f / %02.1f, v-sync %d", - final String text1 = String.format("%03.0f/%03.0f s, %s (%01.2fx, vol %01.2f), a %01.2f, fps %02.1f -> %02.1f / %02.1f, v-sync %d", + final String text1 = String.format("%03.1f/%03.1f s, %s (%01.2fx, vol %01.2f), a %01.2f, fps %02.1f -> %02.1f / %02.1f, v-sync %d", pts, mPlayer.getDuration() / 1000f, mPlayer.getState().toString().toLowerCase(), mPlayer.getPlaySpeed(), mPlayer.getAudioVolume(), aspect, mPlayer.getFramerate(), lfps, tfps, swapIntervalSet); @@ -170,10 +188,12 @@ public class MovieSimple implements GLEventListener { mPlayer.getVID(), mPlayer.getVideoBitrate()/1000, mPlayer.getVideoCodec()); final String text4 = mPlayer.getURI().getRawPath(); if( displayOSD && null != renderer ) { - renderString(drawable, text1, 1 /* col */, 1 /* row */, 0, 0, -1); - renderString(drawable, text2, 1 /* col */, -4 /* row */, 0, height, -1); - renderString(drawable, text3, 1 /* col */, -3 /* row */, 0, height, -1); - renderString(drawable, text4, 1 /* col */, -2 /* row */, 0, height, -1); + // We share ClearColor w/ MovieSimple's init ! + final float pixelSize = font.getPixelSize(fontSize, dpiH); + renderString(drawable, font, pixelSize, text1, 1 /* col */, 1 /* row */, 0, 0, -1, regionFPS); // no-cache + renderString(drawable, font, pixelSize, text2, 1 /* col */, -4 /* row */, 0, height, -1, true); + renderString(drawable, font, pixelSize, text3, 1 /* col */, -3 /* row */, 0, height, -1, true); + renderString(drawable, font, pixelSize, text4, 1 /* col */, -2 /* row */, 0, height, -1, true); } } }; private final InfoTextRendererGLELBase textRendererGLEL = new InfoTextRendererGLELBase(); @@ -993,7 +1013,8 @@ public class MovieSimple implements GLEventListener { glp = GLProfile.getGL2ES2(); } System.err.println("GLProfile: "+glp); - GLCapabilities caps = new GLCapabilities(glp); + final GLCapabilities caps = new GLCapabilities(glp); + // caps.setAlphaBits(4); // NOTE_ALPHA_BLENDING: We go w/o alpha and blending! final MovieSimple[] mss = new MovieSimple[windowCount]; final GLWindow[] windows = new GLWindow[windowCount]; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java index 360f4e8d7..32bea649f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java @@ -29,7 +29,6 @@ package com.jogamp.opengl.test.junit.jogl.glsl; import com.jogamp.common.nio.Buffers; import com.jogamp.newt.MonitorDevice; -import com.jogamp.newt.MonitorMode; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.PMVMatrix; import com.jogamp.opengl.util.glsl.ShaderCode; @@ -43,7 +42,6 @@ import com.jogamp.opengl.test.junit.util.UITestCase; import java.io.IOException; import java.nio.FloatBuffer; -import javax.media.nativewindow.util.DimensionImmutable; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; import javax.media.opengl.GLCapabilities; @@ -73,9 +71,9 @@ public class TestRulerNEWT01 extends UITestCase { System.err.println(winctx.context); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - // test code .. + // test code .. final ShaderState st = new ShaderState(); - + final ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, RedSquareES2.class, "shader", "shader/bin", "default", true); final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, RedSquareES2.class, "shader", @@ -85,50 +83,47 @@ public class TestRulerNEWT01 extends UITestCase { final ShaderProgram sp0 = new ShaderProgram(); sp0.add(gl, vp0, System.err); - sp0.add(gl, fp0, System.err); - Assert.assertTrue(0 != sp0.program()); + sp0.add(gl, fp0, System.err); + Assert.assertTrue(0 != sp0.program()); Assert.assertTrue(!sp0.inUse()); Assert.assertTrue(!sp0.linked()); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - + st.attachShaderProgram(gl, sp0, true); - + final PMVMatrix pmvMatrix = new PMVMatrix(); final GLUniformData pmvMatrixUniform = new GLUniformData("gcu_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - st.ownUniform(pmvMatrixUniform); + st.ownUniform(pmvMatrixUniform); st.uniform(gl, pmvMatrixUniform); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - + final GLUniformData rulerColor= new GLUniformData("gcu_RulerColor", 3, Buffers.newDirectFloatBuffer(3)); final FloatBuffer rulerColorV = (FloatBuffer) rulerColor.getBuffer(); rulerColorV.put(0, 0.5f); rulerColorV.put(1, 0.5f); rulerColorV.put(2, 0.5f); - st.ownUniform(rulerColor); - st.uniform(gl, rulerColor); + st.ownUniform(rulerColor); + st.uniform(gl, rulerColor); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - + Assert.assertNotNull(winctx); Assert.assertNotNull(winctx.window); Assert.assertNotNull(winctx.window.getScreen()); - final MonitorDevice monitor = winctx.window.getMainMonitor(); - Assert.assertNotNull(monitor); - System.err.println(monitor); - final MonitorMode mmode = monitor.getCurrentMode(); - Assert.assertNotNull(mmode); - System.err.println(mmode); - final DimensionImmutable sdim = monitor.getSizeMM(); - final DimensionImmutable spix = mmode.getSurfaceSize().getResolution(); + final float[] ppmmStore = { 0f, 0f }; + { + final MonitorDevice monitor = winctx.window.getMainMonitor(); + Assert.assertNotNull(monitor); + System.err.println(monitor); + monitor.getPixelsPerMM(ppmmStore); + } final GLUniformData rulerPixFreq = new GLUniformData("gcu_RulerPixFreq", 2, Buffers.newDirectFloatBuffer(2)); final FloatBuffer rulerPixFreqV = (FloatBuffer) rulerPixFreq.getBuffer(); - rulerPixFreqV.put(0, (float)spix.getWidth() / (float)sdim.getWidth() * 10.0f); - rulerPixFreqV.put(1, (float)spix.getHeight() / (float)sdim.getHeight() * 10.0f); + rulerPixFreqV.put(0, ppmmStore[0] * 10.0f); + rulerPixFreqV.put(1, ppmmStore[1] * 10.0f); st.ownUniform(rulerPixFreq); - st.uniform(gl, rulerPixFreq); + st.uniform(gl, rulerPixFreq); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - System.err.println("Screen dim "+sdim); - System.err.println("Screen siz "+spix); System.err.println("Screen pixel/cm "+rulerPixFreqV.get(0)+", "+rulerPixFreqV.get(1)); final GLArrayDataServer vertices0 = GLArrayDataServer.createGLSL("gca_Vertices", 3, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); @@ -138,7 +133,7 @@ public class TestRulerNEWT01 extends UITestCase { vertices0.putf(1); vertices0.putf(0); vertices0.putf(0); vertices0.seal(gl, true); st.ownAttribute(vertices0, true); - + // misc GL setup gl.glClearColor(1, 1, 1, 1); gl.glEnable(GL2ES2.GL_DEPTH_TEST); @@ -154,29 +149,29 @@ public class TestRulerNEWT01 extends UITestCase { // pmvMatrix.glTranslatef(0, 0, -6); // pmvMatrix.glRotatef(45f, 1f, 0f, 0f); st.uniform(gl, pmvMatrixUniform); - gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight()); + gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight()); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - + for(int i=0; i<10; i++) { vertices0.enableBuffer(gl, true); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); + gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); vertices0.enableBuffer(gl, false); drawable.swapBuffers(); Thread.sleep(durationPerTest/10); } - + long t2 = System.nanoTime(); - + NEWTGLContext.destroyWindow(winctx); - + long t3 = System.nanoTime(); - - System.err.println("t1-t0: "+ (t1-t0)/1e6 +"ms"); - System.err.println("t3-t0: "+ (t3-t0)/1e6 +"ms"); - System.err.println("t3-t2: "+ (t3-t2)/1e6 +"ms"); + + System.err.println("t1-t0: "+ (t1-t0)/1e6 +"ms"); + System.err.println("t3-t0: "+ (t3-t0)/1e6 +"ms"); + System.err.println("t3-t2: "+ (t3-t2)/1e6 +"ms"); } - + public static void main(String args[]) throws IOException { System.err.println("main - start"); for(int i=0; i<args.length; i++) { @@ -187,6 +182,6 @@ public class TestRulerNEWT01 extends UITestCase { String tstname = TestRulerNEWT01.class.getName(); org.junit.runner.JUnitCore.main(tstname); System.err.println("main - end"); - } + } } |