JOGL v2.6.0-rc-20250712
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 */
28package 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
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
98 gl.glLoadIdentity();
99 }
100
101 @Override
102 public void display(final GLAutoDrawable drawable) {
103 final GL2ES1 gl = drawable.getGL().getGL2ES1();
104
106
107 // draw a triangle filling the window
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}
abstract GL setGL(GL gl)
Sets the GL pipeline object for this GLContext.
Factory for pipelining GL instances.
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...
Provides access to the OpenGL Utility Library (GLU).
Definition: GLU.java:43
void gluOrtho2D(float left, float right, float bottom, float top)
Definition: GLU.java:1358
final void glVertex2f(final float x, final float y)
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.
final void glColor3f(final float x, final float y, final float z)
final void glEnd(final GL gl)
Tool to pipeline GL2ES2 into a fixed function emulation implementing GL2ES1.
static final GL2ES1 wrapFixedFuncEmul(final GL gl, final ShaderSelectionMode mode, final PMVMatrix pmvMatrix, final boolean force, final boolean verbose)
AUTO
Auto shader selection, based upon FFP states.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
GL2ES1 getGL2ES1()
Casts this object to the GL2ES1 interface.
GLContext getContext()
Returns the GLContext associated which this GL object.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
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
static final int GL_TRIANGLES
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TRIANGLES" with expre...
Definition: GL.java:145
static final int GL_VERSION
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_VERSION" with express...
Definition: GL.java:190
static final int GL_FLOAT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FLOAT" with expressio...
Definition: GL.java:786
static final int GL_COLOR_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_COLOR_BUFFER_BIT" wit...
Definition: GL.java:390
String glGetString(int name)
Entry point to C language function: const GLubyte * {@native glGetString}(GLenum name) Part of GL_...
static final int GL_RENDERER
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_RENDERER" with expres...
Definition: GL.java:662
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
static final int GL_VENDOR
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_VENDOR" with expressi...
Definition: GL.java:607
Subset of OpenGL fixed function pipeline's matrix operations.
static final int GL_PROJECTION
Matrix mode projection.
static final int GL_MODELVIEW
Matrix mode modelview.
void glLoadIdentity()
Load the current matrix with the identity matrix.
void glMatrixMode(int mode)
Sets the current matrix mode.