JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
DemoGL2ES1TextureImmModeSink.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.jogl.util;
30
31import java.io.InputStream;
32import java.net.URLConnection;
33
34import com.jogamp.common.util.IOUtil;
35import com.jogamp.opengl.test.junit.jogl.demos.TextureDraw01Accessor;
36import com.jogamp.opengl.test.junit.jogl.util.texture.PNGTstFiles;
37import com.jogamp.opengl.util.ImmModeSink;
38import com.jogamp.opengl.util.glsl.fixedfunc.FixedFuncUtil;
39import com.jogamp.opengl.util.glsl.fixedfunc.ShaderSelectionMode;
40import com.jogamp.opengl.util.texture.Texture;
41import com.jogamp.opengl.util.texture.TextureCoords;
42import com.jogamp.opengl.util.texture.TextureData;
43import com.jogamp.opengl.util.texture.TextureIO;
44
45import com.jogamp.opengl.GL;
46import com.jogamp.opengl.GL2ES1;
47import com.jogamp.opengl.GL2ES2;
48import com.jogamp.opengl.GLAutoDrawable;
49import com.jogamp.opengl.GLEventListener;
50import com.jogamp.opengl.GLPipelineFactory;
51import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
52import com.jogamp.opengl.glu.GLU;
53
55 private boolean debugFFPEmu = false;
56 private boolean verboseFFPEmu = false;
57 private boolean traceFFPEmu = false;
58 private boolean forceFFPEmu = false;
59 private final ImmModeSink ims;
60 private final GLU glu = new GLU();
61 private TextureData textureData;
62 private Texture texture;
63 boolean keepTextureBound;
64
67 this.keepTextureBound = false;
68 }
69
70 public void setForceFFPEmu(final boolean forceFFPEmu, final boolean verboseFFPEmu, final boolean debugFFPEmu, final boolean traceFFPEmu) {
71 this.forceFFPEmu = forceFFPEmu;
72 this.verboseFFPEmu = verboseFFPEmu;
73 this.debugFFPEmu = debugFFPEmu;
74 this.traceFFPEmu = traceFFPEmu;
75 }
76
77
78 @Override
79 public void setKeepTextureBound(final boolean v) {
80 this.keepTextureBound = v;
81 }
82 @Override
83 public Texture getTexture( ) {
84 return this.texture;
85 }
86
87 @Override
88 public void init(final GLAutoDrawable drawable) {
89 GL _gl = drawable.getGL();
90 if(debugFFPEmu) {
91 // Debug ..
92 _gl = _gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Debug", GL2ES2.class, _gl, null) );
93 }
94 if(traceFFPEmu) {
95 // Trace ..
96 _gl = _gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Trace", GL2ES2.class, _gl, new Object[] { System.err } ) );
97 }
98 final GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(_gl, ShaderSelectionMode.AUTO, null, forceFFPEmu, verboseFFPEmu);
99
100 final URLConnection testTextureUrlConn = IOUtil.getResource("test-ntscP_3-01-160x90.png", PNGTstFiles.class.getClassLoader(), PNGTstFiles.class);
101 try {
102 final InputStream testTextureStream = testTextureUrlConn.getInputStream();
103 textureData = TextureIO.newTextureData(gl.getGLProfile(), testTextureStream , false /* mipmap */, TextureIO.PNG);
104 texture = TextureIO.newTexture(gl, textureData);
105 if( keepTextureBound && null != texture ) {
106 texture.enable(gl);
107 texture.bind(gl);
108 }
109 } catch (final Exception e) {
110 e.printStackTrace();
111 }
112 }
113
114 @Override
115 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
116 final GL2ES1 gl = drawable.getGL().getGL2ES1();
118 gl.glLoadIdentity();
119 glu.gluOrtho2D(0, 1, 0, 1);
121 gl.glLoadIdentity();
122 }
123
124 @Override
125 public void dispose(final GLAutoDrawable drawable) {
126 final GL2ES1 gl = drawable.getGL().getGL2ES1();
127 if(null!=texture) {
128 texture.disable(gl);
129 texture.destroy(gl);
130 }
131 if(null!=textureData) {
132 textureData.destroy();
133 }
134 }
135
136 @Override
137 public void display(final GLAutoDrawable drawable) {
138 final GL2ES1 gl = drawable.getGL().getGL2ES1();
139
140 // draw one quad with the texture
141 if(null!=texture) {
142 if( !keepTextureBound ) {
143 texture.enable(gl);
144 texture.bind(gl);
145 }
146 // gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
147 final TextureCoords coords = texture.getImageTexCoords();
149 ims.glTexCoord2f(coords.left(), coords.bottom());
150 ims.glVertex3f(0, 0, 0);
151 ims.glTexCoord2f(coords.right(), coords.bottom());
152 ims.glVertex3f(1, 0, 0);
153 ims.glTexCoord2f(coords.right(), coords.top());
154 ims.glVertex3f(1, 1, 0);
155 ims.glTexCoord2f(coords.left(), coords.top());
156 ims.glVertex3f(0, 1, 0);
157 ims.glEnd(gl);
158 if( !keepTextureBound ) {
159 texture.disable(gl);
160 }
161 }
162 }
163}
164
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
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void setForceFFPEmu(final boolean forceFFPEmu, final boolean verboseFFPEmu, final boolean debugFFPEmu, final boolean traceFFPEmu)
void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height)
Called by the drawable during the first repaint after the component has been resized.
final void glVertex3f(final float x, final float y, final float z)
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 glTexCoord2f(final float x, final float y)
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)
Specifies texture coordinates for a rectangular area of a texture.
Represents the data for an OpenGL texture.
static final String PNG
Constant which can be used as a file suffix to indicate a PNG file, value {@value}.
Definition: TextureIO.java:171
static TextureData newTextureData(final GLProfile glp, final File file, final boolean mipmap, String fileSuffix)
Creates a TextureData from the given file.
Definition: TextureIO.java:233
static Texture newTexture(final TextureData data)
Creates an OpenGL texture object from the specified TextureData using the current OpenGL context.
Definition: TextureIO.java:459
Represents an OpenGL texture object.
Definition: Texture.java:173
TextureCoords getImageTexCoords()
Returns the set of texture coordinates corresponding to the entire image.
Definition: Texture.java:480
void bind(final GL gl)
Binds this texture to the given GL context.
Definition: Texture.java:377
void disable(final GL gl)
Disables this texture's target (e.g., GL_TEXTURE_2D) in the given GL state.
Definition: Texture.java:357
void enable(final GL gl)
Enables this texture's target (e.g., GL_TEXTURE_2D) in the given GL context's state.
Definition: Texture.java:330
void destroy(final GL gl)
Destroys and nulls the underlying native texture used by this Texture instance if owned,...
Definition: Texture.java:388
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.
GLProfile getGLProfile()
Returns the GLProfile associated with this GL object.
GLContext getContext()
Returns the GLContext associated which this GL object.
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_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
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.