28package com.jogamp.opengl.demos.es2;
30import com.jogamp.opengl.util.Animator;
31import com.jogamp.opengl.util.GLArrayDataServer;
32import com.jogamp.opengl.util.caps.NonFSAAGLCapsChooser;
33import com.jogamp.opengl.util.glsl.ShaderCode;
34import com.jogamp.opengl.util.glsl.ShaderProgram;
35import com.jogamp.opengl.util.glsl.ShaderState;
36import java.nio.FloatBuffer;
38import com.jogamp.common.util.VersionUtil;
39import com.jogamp.newt.event.WindowAdapter;
40import com.jogamp.newt.event.WindowEvent;
41import com.jogamp.newt.opengl.GLWindow;
42import com.jogamp.opengl.GL;
43import com.jogamp.opengl.GL2ES2;
44import com.jogamp.opengl.GLAutoDrawable;
45import com.jogamp.opengl.GLCapabilities;
46import com.jogamp.opengl.GLEventListener;
47import com.jogamp.opengl.GLUniformData;
48import com.jogamp.opengl.demos.util.CommandlineOptions;
54 private int swapInterval = 0;
55 private boolean verbose =
true;
58 private long millisOffset;
59 private int frameCount;
60 private float frameRate;
65 private float[] resolution;
70 private int fcount = 0, lastm = 0;
71 private final int fint = 1;
74 this.swapInterval = swapInterval;
78 this.swapInterval = 1;
85 System.err.println(Thread.currentThread()+
" LandscapeES2.init ...");
89 System.err.println(
"LandscapeES2 init on "+Thread.currentThread());
91 System.err.println(
"INIT GL IS: " + gl.getClass().getName());
107 shaderProg.
add(gl, vertShader, System.err);
108 shaderProg.
add(gl, fragShader, System.err);
114 resolutionUni =
new GLUniformData(
"iResolution", 3, FloatBuffer.wrap(resolution));
116 shaderState.
uniform(gl, resolutionUni);
122 vertices.
putf(-1.0f); vertices.
putf(-1.0f);
123 vertices.
putf(+1.0f); vertices.
putf(-1.0f);
124 vertices.
putf(-1.0f); vertices.
putf(+1.0f);
125 vertices.
putf(+1.0f); vertices.
putf(+1.0f);
126 vertices.
seal(gl,
true);
130 millisOffset = System.currentTimeMillis();
132 System.err.println(Thread.currentThread()+
" LandscapeES2.init FIN");
137 System.err.println(Thread.currentThread()+
" LandscapeES2.reshape "+x+
"/"+y+
" "+width+
"x"+height+
", swapInterval "+swapInterval+
", drawable 0x"+Long.toHexString(drawable.
getHandle()));
147 shaderState.
uniform(gl, resolutionUni);
154 System.err.println(Thread.currentThread()+
" LandscapeES2.dispose ... ");
160 System.err.println(Thread.currentThread()+
" LandscapeES2.dispose FIN");
172 timeUni.
setData((System.currentTimeMillis() - millisOffset) / 1000.0f);
173 shaderState.
uniform(gl, timeUni);
183 final int m = (int) (System.currentTimeMillis() - millisOffset);
184 if (m - lastm > 1000 * fint) {
185 frameRate = (float)(fcount) / fint;
190 System.out.println(
"FrameCount: " + frameCount +
" - " +
"FrameRate: " + frameRate);
194 boolean confinedFixedCenter =
false;
197 confinedFixedCenter = v;
200 public static void main(
final String[] args) {
203 System.err.println(options);
204 System.err.println(VersionUtil.getPlatformInfo());
208 System.out.println(
"Requested: " + reqCaps);
221 animator.
add(window);
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final void setTitle(final String title)
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
CapabilitiesChooser setCapabilitiesChooser(final CapabilitiesChooser chooser)
Set the CapabilitiesChooser to help determine the native visual type.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
final GLRendererQuirks getRendererQuirks()
Returns the instance of GLRendererQuirks, allowing one to determine workarounds.
final String getGLVersion()
Returns a valid OpenGL version string, ie
final StringBuilder toString(StringBuilder sb)
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.
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void setConfinedFixedCenter(final boolean v)
void setVerbose(final boolean v)
LandscapeES2(final int swapInterval)
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
static final int TARGET_FPS
static void main(final String[] args)
GLCapabilities getGLCaps()
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
void seal(final GL gl, final boolean seal)
Convenience method calling seal(boolean) and enableBuffer(GL, boolean).
void enableBuffer(final GL gl, final boolean enable)
Enables the buffer if enable is true, and transfers the data if required.
static GLArrayDataServer createGLSL(final String name, final int compsPerElement, final int dataType, final boolean normalized, final int initialElementCount, final int vboUsage)
Create a VBO, using a custom GLSL array attribute name and starting with a new created Buffer object ...
Custom GLCapabilitiesChooser, filtering out all full screen anti-aliasing (FSAA, multisample) capabil...
Convenient shader code class to use and instantiate vertex or fragment programs.
final int defaultShaderCustomization(final GL2ES2 gl, final boolean preludeVersion, final boolean addDefaultPrecision)
Default customization of this shader source code.
static ShaderCode create(final GL2ES2 gl, final int type, final int count, final Class<?> context, final String[] sourceFiles, final boolean mutableStringBuilder)
Creates a complete ShaderCode object while reading all shader source of sourceFiles,...
synchronized void add(final ShaderCode shaderCode)
Adds a new shader to this program.
ShaderState allows to sharing data between shader programs, while updating the attribute and uniform ...
void ownAttribute(final GLArrayData attribute, final boolean own)
Binds or unbinds the GLArrayData lifecycle to this ShaderState.
synchronized void useProgram(final GL2ES2 gl, final boolean on)
Turns the shader program on or off.
synchronized boolean attachShaderProgram(final GL2ES2 gl, final ShaderProgram prog, final boolean enable)
Attach or switch a shader program.
synchronized void destroy(final GL2ES2 gl)
Calls release(gl, true, true, true).
boolean uniform(final GL2ES2 gl, final GLUniformData data)
Set the uniform data, if it's location is valid, i.e.
void ownUniform(final GLUniformData uniform)
Bind the GLUniform lifecycle to this ShaderState.
static final int GL_VERTEX_SHADER
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_EXT_vertex_shader, GL_ARB_vertex_shader Alias for: GL_VERTEX_SH...
static final int GL_SHADING_LANGUAGE_VERSION
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_ARB_shading_language_100 Alias for: GL_SHADING_LANGUAGE_VERSION...
static final int GL_FRAGMENT_SHADER
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_ATI_fragment_shader, GL_ARB_fragment_shader Alias for: GL_FRAGM...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
boolean hasGLSL()
Indicates whether this GL object supports GLSL.
boolean hasBasicFBOSupport()
Returns true if basic FBO support is available, otherwise false.
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
GLProfile getGLProfile()
Returns the GLProfile associated with this GL object.
void setSwapInterval(int interval)
Set the swap interval of the current context and attached onscreen GLDrawable.
GLContext getContext()
Returns the GLContext associated which this GL object.
boolean isFunctionAvailable(String glFunctionName)
Returns true if the specified OpenGL core- or extension-function can be used successfully through thi...
boolean hasFullFBOSupport()
Returns true if full FBO support is available, otherwise false.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
long getHandle()
Returns the GL drawable handle, guaranteed to be valid after realization and while it's surface is be...
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.
void glDrawArrays(int mode, int first, int count)
Entry point to C language function: void {@native glDrawArrays}(GLenum mode, GLint first,...
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...
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...
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...
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...
static final int GL_TRIANGLE_STRIP
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TRIANGLE_STRIP" with ...
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...