28package com.jogamp.opengl.demos.es2;
30import java.nio.FloatBuffer;
32import com.jogamp.common.nio.Buffers;
33import com.jogamp.common.util.VersionUtil;
34import com.jogamp.math.FloatUtil;
35import com.jogamp.newt.event.WindowAdapter;
36import com.jogamp.newt.event.WindowEvent;
37import com.jogamp.newt.opengl.GLWindow;
38import com.jogamp.opengl.util.Animator;
39import com.jogamp.opengl.util.GLArrayDataServer;
40import com.jogamp.opengl.util.PMVMatrix;
41import com.jogamp.opengl.util.caps.NonFSAAGLCapsChooser;
42import com.jogamp.opengl.util.glsl.ShaderCode;
43import com.jogamp.opengl.util.glsl.ShaderProgram;
44import com.jogamp.opengl.util.glsl.ShaderState;
46import com.jogamp.opengl.GL;
47import com.jogamp.opengl.GL2ES1;
48import com.jogamp.opengl.GL2ES2;
49import com.jogamp.opengl.GL2GL3;
50import com.jogamp.opengl.GLAutoDrawable;
51import com.jogamp.opengl.GLCapabilities;
52import com.jogamp.opengl.GLProfile;
53import com.jogamp.opengl.GLUniformData;
54import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
55import com.jogamp.opengl.demos.PointsDemo;
56import com.jogamp.opengl.demos.util.CommandlineOptions;
64 private int swapInterval = 0;
67 private static final String mgl_PointParams =
"mgl_PointParams";
70 private final FloatBuffer pointParams = Buffers.newDirectFloatBuffer(
new float[] { 1.0f, 0.0f, 0.0f, 4096.0f, 1.0f, 0.0f, 0.0f, 1.0f });
73 this.swapInterval = swapInterval;
77 this.swapInterval = 1;
82 pointParams.put(1, v ? 1.0f : 0.0f);
86 public void setPointParams(
final float minSize,
final float maxSize,
final float distAttenConst,
final float distAttenLinear,
final float distAttenQuadratic,
final float fadeThreshold) {
87 pointParams.put(2, minSize);
88 pointParams.put(3, maxSize);
89 pointParams.put(4+0, distAttenConst);
90 pointParams.put(4+1, distAttenLinear);
91 pointParams.put(4+2, distAttenQuadratic);
92 pointParams.put(4+3, fadeThreshold);
108 "shader/bin",
"PointsShader",
true);
110 "shader/bin",
"PointsShader",
true);
114 sp0.
add(gl, vp0, System.err);
115 sp0.
add(gl, fp0, System.err);
126 st.
uniform(gl, pmvMatrixUniform);
130 final GLUniformData colorStaticUniform =
new GLUniformData(
"mgl_ColorStatic", 4, Buffers.newDirectFloatBuffer(
new float[] { 1.0f, 1.0f, 1.0f, 1.0f }) );
131 st.
uniform(gl, colorStaticUniform);
137 for(
int i=0; i<edge; i++) {
138 for(
int j=0; j<edge; j++) {
139 final float x = -3+j*0.7f;
140 final float y = -3+i*0.7f;
141 final float p = (i*edge+j)*0.5f;
147 vertices.
seal(gl,
true);
150 pointSizes.
seal(gl,
true);
168 st.
uniform(gl, pmvMatrixUniform);
185 gl.glEnable ( GL.GL_BLEND );
212 st.
uniform(gl, pmvMatrixUniform);
224 public static void main(
final String[] args) {
227 System.err.println(options);
228 System.err.println(VersionUtil.getPlatformInfo());
232 System.out.println(
"Requested: " + reqCaps);
245 animator.
add(window);
Basic Float math utility functions.
static final float QUARTER_PI
The value PI/4, i.e.
final SyncMatrices4f getSyncPMv()
Returns SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
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.
static void main(final String[] args)
PointsDemoES2(final int swapInterval)
void dispose(final GLAutoDrawable glad)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void setPointParams(final float minSize, final float maxSize, final float distAttenConst, final float distAttenLinear, final float distAttenQuadratic, final float fadeThreshold)
void setSmoothPoints(final boolean v)
void init(final GLAutoDrawable glad)
Called by the drawable immediately after the OpenGL context is initialized.
void reshape(final GLAutoDrawable glad, 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 display(final GLAutoDrawable glad)
Called by the drawable to initiate OpenGL rendering by the client.
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 ...
PMVMatrix implements a subset of the fixed function pipeline GLMatrixFunc using PMVMatrix4f.
final void glTranslatef(final float x, final float y, final float z)
Translate the current matrix.
final void glMatrixMode(final int matrixName)
Sets the current matrix mode.
final void gluPerspective(final float fovy_rad, final float aspect, final float zNear, final float zFar)
Multiply the current matrix with the perspective/frustum matrix.
final void glLoadIdentity()
Load the current matrix with the identity matrix.
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.
void setVerbose(final boolean v)
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.
GLUniformData getUniform(final String name)
Get the uniform data, previously set.
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_POINT_SPRITE
GL_VERSION_2_0, GL_ARB_point_sprite, GL_NV_point_sprite, GL_OES_point_sprite Alias for: GL_POINT_SPRI...
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...
static final int GL_VERTEX_PROGRAM_POINT_SIZE
GL_VERSION_2_0, GL_ARB_vertex_program, GL_NV_vertex_program Alias for: GL_VERTEX_PROGRAM_POINT_SIZE_A...
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 isGL2GL3()
Indicates whether this GL object conforms to a GL2GL3 compatible profile.
boolean isGL2ES1()
Indicates whether this GL object conforms to a GL2ES1 compatible profile.
boolean hasGLSL()
Indicates whether this GL object supports GLSL.
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.
boolean isFunctionAvailable(String glFunctionName)
Returns true if the specified OpenGL core- or extension-function can be used successfully through thi...
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...
void glDisable(int cap)
Entry point to C language function: void {@native glDisable}(GLenum cap) Part of GL_ES_VERSION_2_0...
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...
void glClearColor(float red, float green, float blue, float alpha)
Entry point to C language function: void {@native glClearColor}(GLfloat red, GLfloat green,...
static final int GL_SRC_ALPHA
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_SRC_ALPHA" with expre...
static final int GL_POINTS
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_POINTS" with expressi...
void glEnable(int cap)
Entry point to C language function: void {@native glEnable}(GLenum cap) Part of GL_ES_VERSION_2_0,...
String glGetString(int name)
Entry point to C language function: const GLubyte * {@native glGetString}(GLenum name) Part of GL_...
static final int GL_DEPTH_TEST
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_TEST" with expr...
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...
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...
static final int GL_DEPTH_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_BUFFER_BIT" wit...
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.