JOGL: src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES1ImmModeSink.java Source File

JOGL v2.6.0 JOGL, High-Performance Graphics Binding for Java™ (public API).

DemoGL2ES1ImmModeSink.java
Go to the documentation of this file.
1/**
2 * Copyright 2012 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28 package com.jogamp.opengl.test.junit.jogl.util;
29
30import com.jogamp.opengl.GL;
31import com.jogamp.opengl.GL2ES1;
32import com.jogamp.opengl.GL2ES2;
33import com.jogamp.opengl.GLAutoDrawable;
34import com.jogamp.opengl.GLEventListener;
35import com.jogamp.opengl.GLPipelineFactory;
36import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
37import com.jogamp.opengl.glu.GLU;
38import com.jogamp.opengl.glu.gl2es1.GLUgl2es1;
39
40import com.jogamp.opengl.util.ImmModeSink;
41import com.jogamp.opengl.util.glsl.fixedfunc.FixedFuncUtil;
42import com.jogamp.opengl.util.glsl.fixedfunc.ShaderSelectionMode;
43
44class DemoGL2ES1ImmModeSink implements GLEventListener {
45 private boolean debugFFPEmu = false;
46 private boolean verboseFFPEmu = false;
47 private boolean traceFFPEmu = false;
48 private boolean forceFFPEmu = false;
49 final ImmModeSink ims;
50 final GLU glu;
51
52 DemoGL2ES1ImmModeSink(final boolean useVBO) {
53 ims = ImmModeSink.createFixed(3*3,
54 3, GL.GL_FLOAT, // vertex
55 3, GL.GL_FLOAT, // color
56 0, GL.GL_FLOAT, // normal
57 0, GL.GL_FLOAT, // texCoords
58 useVBO ? GL.GL_STATIC_DRAW : 0);
59 glu = new GLUgl2es1();
60 }
61
62 public void setForceFFPEmu(final boolean forceFFPEmu, final boolean verboseFFPEmu, final boolean debugFFPEmu, final boolean traceFFPEmu) {
63 this.forceFFPEmu = forceFFPEmu;
64 this.verboseFFPEmu = verboseFFPEmu;
65 this.debugFFPEmu = debugFFPEmu;
66 this.traceFFPEmu = traceFFPEmu;
67 }
68
69 @Override
70 public void init(final GLAutoDrawable drawable) {
71 GL _gl = drawable.getGL();
72 if(debugFFPEmu) {
73 // Debug ..
74 _gl = _gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Debug", GL2ES2.class, _gl, null) );
75 }
76 if(traceFFPEmu) {
77 // Trace ..
78 _gl = _gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Trace", GL2ES2.class, _gl, new Object[] { System.err } ) );
79 }
80 final GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(_gl, ShaderSelectionMode.AUTO, null, forceFFPEmu, verboseFFPEmu);
81
82 System.err.println("GL_VENDOR "+gl.glGetString(GL.GL_VENDOR));
83 System.err.println("GL_RENDERER "+gl.glGetString(GL.GL_RENDERER));
84 System.err.println("GL_VERSION "+gl.glGetString(GL.GL_VERSION));
85 }
86
87 @Override
88 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
89 final GL2ES1 gl = drawable.getGL().getGL2ES1();
90
91 gl.glMatrixMode( GLMatrixFunc.GL_PROJECTION );
92 gl.glLoadIdentity();
93
94 // coordinate system origin at lower left with width and height same as the window
95 glu.gluOrtho2D( 0.0f, width, 0.0f, height );
96
97 gl.glMatrixMode( GLMatrixFunc.GL_MODELVIEW );
98 gl.glLoadIdentity();
99 }
100
101 @Override
102 public void display(final GLAutoDrawable drawable) {
103 final GL2ES1 gl = drawable.getGL().getGL2ES1();
104
105 gl.glClear( GL.GL_COLOR_BUFFER_BIT );
106
107 // draw a triangle filling the window
108 ims.glBegin(GL.GL_TRIANGLES);
109 ims.glColor3f( 1, 0, 0 );
110 ims.glVertex2f( 0, 0 );
111 ims.glColor3f( 0, 1, 0 );
112 ims.glVertex2f( drawable.getSurfaceWidth(), 0 );
113 ims.glColor3f( 0, 0, 1 );
114 ims.glVertex2f( drawable.getSurfaceWidth() / 2f, drawable.getSurfaceHeight() );
115 ims.glEnd(gl, true);
116 }
117
118 @Override
119 public void dispose(final GLAutoDrawable drawable) {
120 }
121}
com.jogamp.opengl.GLContext.setGL
abstract GL setGL(GL gl)
Sets the GL pipeline object for this GLContext.
com.jogamp.opengl.GLPipelineFactory
Factory for pipelining GL instances.
Definition: GLPipelineFactory.java:49
com.jogamp.opengl.GLPipelineFactory.create
static final GL create(final String pipelineClazzBaseName, final Class<?> reqInterface, final GL downstream, final Object[] additionalArgs)
Creates a pipelined GL instance using the given downstream downstream and optional arguments addition...
Definition: GLPipelineFactory.java:91
com.jogamp.opengl.glu.GLU
Provides access to the OpenGL Utility Library (GLU).
Definition: GLU.java:43
com.jogamp.opengl.glu.GLU.gluOrtho2D
void gluOrtho2D(float left, float right, float bottom, float top)
Definition: GLU.java:1358
com.jogamp.opengl.glu.gl2es1.GLUgl2es1
Definition: GLUgl2es1.java:27
com.jogamp.opengl.util.ImmModeSink
Definition: ImmModeSink.java:52
com.jogamp.opengl.util.ImmModeSink.glVertex2f
final void glVertex2f(final float x, final float y)
Definition: ImmModeSink.java:277
com.jogamp.opengl.util.ImmModeSink.createFixed
static ImmModeSink createFixed(final int initialElementCount, final int vComps, final int vDataType, final int cComps, final int cDataType, final int nComps, final int nDataType, final int tComps, final int tDataType, final int glBufferUsage)
Uses a GL2ES1, or ES2 fixed function emulation immediate mode sink.
Definition: ImmModeSink.java:86
com.jogamp.opengl.util.ImmModeSink.glBegin
void glBegin(int mode)
Definition: ImmModeSink.java:216
com.jogamp.opengl.util.ImmModeSink.glColor3f
final void glColor3f(final float x, final float y, final float z)
Definition: ImmModeSink.java:289
com.jogamp.opengl.util.ImmModeSink.glEnd
final void glEnd(final GL gl)
Definition: ImmModeSink.java:233
com.jogamp.opengl.util.glsl.fixedfunc.FixedFuncUtil
Tool to pipeline GL2ES2 into a fixed function emulation implementing GL2ES1.
Definition: FixedFuncUtil.java:25
com.jogamp.opengl.util.glsl.fixedfunc.FixedFuncUtil.wrapFixedFuncEmul
static final GL2ES1 wrapFixedFuncEmul(final GL gl, final ShaderSelectionMode mode, final PMVMatrix pmvMatrix, final boolean force, final boolean verbose)
Definition: FixedFuncUtil.java:41
com.jogamp.opengl.util.glsl.fixedfunc.ShaderSelectionMode
Shader selection mode.
Definition: ShaderSelectionMode.java:12
com.jogamp.opengl.util.glsl.fixedfunc.ShaderSelectionMode.AUTO
AUTO
Auto shader selection, based upon FFP states.
Definition: ShaderSelectionMode.java:14
com.jogamp.opengl.GL2ES1
Definition: GL2ES1.java:27
com.jogamp.opengl.GL2ES2
Definition: GL2ES2.java:29
com.jogamp.opengl.GLAutoDrawable
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
Definition: GLAutoDrawable.java:146
com.jogamp.opengl.GLAutoDrawable.getGL
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
com.jogamp.opengl.GLBase.getGL2ES1
GL2ES1 getGL2ES1()
Casts this object to the GL2ES1 interface.
com.jogamp.opengl.GLBase.getContext
GLContext getContext()
Returns the GLContext associated which this GL object.
com.jogamp.opengl.GLDrawable.getSurfaceWidth
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
com.jogamp.opengl.GLDrawable.getSurfaceHeight
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
com.jogamp.opengl.GLEventListener
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
Definition: GLEventListener.java:47
com.jogamp.opengl.GL
Definition: GL.java:25
com.jogamp.opengl.GL.GL_STATIC_DRAW
static final int GL_STATIC_DRAW
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_STATI...
Definition: GL.java:673
com.jogamp.opengl.GL.GL_TRIANGLES
static final int GL_TRIANGLES
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TRIANGLES" with expression '0x0004',...
Definition: GL.java:145
com.jogamp.opengl.GL.GL_VERSION
static final int GL_VERSION
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_VERSION" with expression '0x1F02',...
Definition: GL.java:190
com.jogamp.opengl.GL.GL_FLOAT
static final int GL_FLOAT
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FLOAT" with expression '0x1406',...
Definition: GL.java:786
com.jogamp.opengl.GL.GL_COLOR_BUFFER_BIT
static final int GL_COLOR_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_COLOR_BUFFER_BIT" with expression '0x...
Definition: GL.java:390
com.jogamp.opengl.GL.glGetString
String glGetString(int name)
Entry point to C language function: const GLubyte * {@native glGetString}(GLenum name) Part of GL_...
com.jogamp.opengl.GL.GL_RENDERER
static final int GL_RENDERER
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_RENDERER" with expression '0x1F01',...
Definition: GL.java:662
com.jogamp.opengl.GL.glClear
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
com.jogamp.opengl.GL.GL_VENDOR
static final int GL_VENDOR
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_VENDOR" with expression '0x1F00',...
Definition: GL.java:607
com.jogamp.opengl.fixedfunc.GLMatrixFunc
Subset of OpenGL fixed function pipeline's matrix operations.
Definition: GLMatrixFunc.java:39
com.jogamp.opengl.fixedfunc.GLMatrixFunc.GL_PROJECTION
static final int GL_PROJECTION
Matrix mode projection.
Definition: GLMatrixFunc.java:45
com.jogamp.opengl.fixedfunc.GLMatrixFunc.GL_MODELVIEW
static final int GL_MODELVIEW
Matrix mode modelview.
Definition: GLMatrixFunc.java:43
com.jogamp.opengl.fixedfunc.GLMatrixFunc.glLoadIdentity
void glLoadIdentity()
Load the current matrix with the identity matrix.
com.jogamp.opengl.fixedfunc.GLMatrixFunc.glMatrixMode
void glMatrixMode(int mode)
Sets the current matrix mode.