28package com.jogamp.opengl.demos.graph.ui;
30import java.io.IOException;
32import com.jogamp.graph.curve.Region;
33import com.jogamp.graph.curve.opengl.GLRegion;
34import com.jogamp.graph.curve.opengl.RegionRenderer;
35import com.jogamp.graph.curve.opengl.TextRegionUtil;
36import com.jogamp.graph.font.Font;
37import com.jogamp.graph.font.Font.Glyph;
38import com.jogamp.graph.font.FontFactory;
39import com.jogamp.graph.font.FontSet;
40import com.jogamp.graph.ui.GraphShape;
41import com.jogamp.graph.ui.shapes.CrossHair;
42import com.jogamp.math.FloatUtil;
43import com.jogamp.math.Matrix4f;
44import com.jogamp.math.Recti;
45import com.jogamp.math.Vec2f;
46import com.jogamp.math.Vec2i;
47import com.jogamp.math.Vec3f;
48import com.jogamp.math.Vec4f;
49import com.jogamp.math.geom.AABBox;
50import com.jogamp.math.geom.plane.AffineTransform;
51import com.jogamp.math.util.PMVMatrix4f;
52import com.jogamp.newt.event.WindowAdapter;
53import com.jogamp.newt.event.WindowEvent;
54import com.jogamp.newt.opengl.GLWindow;
55import com.jogamp.opengl.GL;
56import com.jogamp.opengl.GL2ES2;
57import com.jogamp.opengl.GLAutoDrawable;
58import com.jogamp.opengl.GLCapabilities;
59import com.jogamp.opengl.GLEventListener;
60import com.jogamp.opengl.JoglVersion;
61import com.jogamp.opengl.demos.util.CommandlineOptions;
62import com.jogamp.opengl.demos.util.MiscUtils;
63import com.jogamp.opengl.util.Animator;
94 static final Vec4f text_color =
new Vec4f( 0, 1, 0, 1 );
96 static boolean projOrtho =
true;
97 static boolean projOrthoWin =
false;
98 static boolean textOnly =
false;
101 static final float normWidgetSize = 1/4f;
103 public static void main(
final String[] args)
throws IOException {
104 if( 0 != args.length ) {
105 final int[] idx = { 0 };
106 for(idx[0]=0; idx[0]<args.length; ++idx[0]) {
107 if( options.
parse(args, idx) ) {
109 }
else if(args[idx[0]].equals(
"-projPersp")) {
111 projOrthoWin =
false;
112 }
else if(args[idx[0]].equals(
"-projWin")) {
115 }
else if(args[idx[0]].equals(
"-texUnit")) {
118 }
else if(args[idx[0]].equals(
"-x")) {
121 }
else if(args[idx[0]].equals(
"-y")) {
124 }
else if(args[idx[0]].equals(
"-textOnly")) {
131 System.err.println(options);
132 System.err.println(
"Ortho Projection "+projOrtho+
", Ortho-Win "+projOrthoWin);
133 System.err.println(
"pass2TexUnit "+pass2TexUnit);
136 System.out.println(
"Requested: " + reqCaps);
160 public void windowDestroyNotify(
final WindowEvent e) {
166 animator.
add(window);
172 private final float angle;
173 private final float zNear;
174 private final float zFar;
175 private final float sceneDist;
178 private final Vec2f worldDim =
new Vec2f(1f, 1f);
180 private final Vec3f worldOrigin =
new Vec3f();
211 shape =
new CrossHair(options.
renderModes, normWidgetSize, normWidgetSize, normWidgetSize/100f);
215 System.err.println(
"Init: Shape "+shape);
220 if(
null == textRegion ) {
232 final float s = Math.min(worldDim.x(), worldDim.y());
238 final float ratio = (float)viewport.width()/(float)viewport.height();
240 worldDim.
setX( viewport.width() );
241 worldDim.
setY( worldDim.x() / ratio );
242 pmv.
orthoP(0, worldDim.x(), 0, worldDim.y(), zNear, zFar);
244 }
else if( projOrtho ) {
245 worldDim.
setY( worldDim.x() / ratio );
246 pmv.
orthoP(-worldDim.x()/2f, worldDim.x()/2f, -worldDim.y()/2f, worldDim.y()/2f, zNear, zFar);
253 winToPlaneCoord(pmv, viewport, zNear, zFar, viewport.x(), viewport.y(), -sceneDist, obj00Coord);
254 winToPlaneCoord(pmv, viewport, zNear, zFar, viewport.width(), viewport.height(), -sceneDist, obj11Coord);
257 planeBox.
setSize( obj00Coord, obj11Coord );
265 winToPlaneCoord(pmv, viewport, zNear, zFar, winOrigin.x(), winOrigin.y(), -sceneDist, worldOrigin);
267 final Matrix4f p = pmv.
getP();
268 final Matrix4f mv = pmv.
getMv();
269 System.err.println(
"Reshape VP: "+viewport);
270 System.err.println(
"Reshape P :"); System.err.println(p.toString());
271 System.err.println(
"Reshape Mv:"); System.err.println(mv.toString());
272 System.err.println(
"World Dim : "+worldDim);
273 System.err.println(
"Window Origin: "+winOrigin);
274 System.err.println(
"World Origin : "+worldOrigin);
276 pmv.
translateMv(worldOrigin.x(), worldOrigin.y(), 0);
279 final float zNear,
final float zFar,
280 final float winX,
final float winY,
final float objOrthoZ,
281 final Vec3f objPos) {
283 pmv.
mapWinToObj(winX, winY, winZ, viewport, objPos);
295 if( onceAtDisplay ) {
298 System.err.println(
"Display.0: P :"); System.err.println(p.
toString());
299 System.err.println(
"Display.0: Mv:"); System.err.println(mv.
toString());
302 renderer.
enable(gl,
true);
305 drawText(gl, pmv,
" Hello JogAmp Users!");
312 shape.
draw(gl, renderer);
313 if( onceAtDisplay ) {
316 System.err.println(
"Display.1: P :"); System.err.println(p.
toString());
317 System.err.println(
"Display.1: Mv:"); System.err.println(mv.
toString());
319 System.err.println(
"Display.1: Shape "+shape);
321 System.err.println(
"Display.1: Shape SurfacePort "+shapePort);
325 renderer.
enable(gl,
false);
326 onceAtDisplay =
false;
328 private void drawText(
final GL2ES2 gl,
final PMVMatrix4f pmv,
final String text) {
333 final float full_width_s = worldDim.x() / txt_box_em.
getWidth();
334 final float full_height_s = worldDim.y() / txt_box_em.
getHeight();
335 final float txt_scale = full_width_s < full_height_s ? full_width_s * normWidgetSize : full_height_s * normWidgetSize;
336 pmv.
scaleMv(txt_scale, txt_scale, 1f);
340 if( onceAtDisplay ) {
341 System.err.println(
"XXX: full_width: "+worldDim.x()+
" / "+txt_box_em.
getWidth()+
" -> "+full_width_s);
342 System.err.println(
"XXX: full_height: "+worldDim.y()+
" / "+txt_box_em.
getHeight()+
" -> "+full_height_s);
343 System.err.println(
"XXX: txt_scale: "+txt_scale);
344 System.err.println(
"XXX: txt_box_em "+txt_box_em);
345 System.err.println(
"XXX: txt_box_r "+txt_box_r);
347 System.err.println(
"Display.1: Shape TextPort "+textPort);
353 System.err.println(
"idx["+idx+
"]: "+glyph);
358 System.err.println(
"XXX: txt_box_r2 "+txt_box_r2);
360 final Glyph g = font.
getGlyph(
' ' );
361 System.err.println(
"XXX: space "+g);
364 final Glyph g = font.
getGlyph(
'\t' );
365 System.err.println(
"XXX: tab "+g);
369 private boolean onceAtDisplay =
true;
379 System.err.println(
"Destroyed");
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
static final int DEFAULT_TWO_PASS_TEXTURE_UNIT
static final int VBAA_RENDERING_BIT
Rendering-Mode bit for Region.
A GLRegion is the OGL binding of one or more OutlineShapes Defined by its vertices and generated tria...
final GLRegion clear(final GL2ES2 gl)
Clears all buffers, i.e.
final void destroy(final GL2ES2 gl)
Delete and clear the associated OGL objects.
static GLRegion create(final GLProfile glp, int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit, final int initialVerticesCount, final int initialIndicesCount)
Create a GLRegion using the passed render mode.
final void enable(final GL2ES2 gl, final boolean enable)
Enabling or disabling the RenderState's current shader program.
final PMVMatrix4f getMatrix()
Borrow the current PMVMatrix4f.
final void reshapeNotify(final int x, final int y, final int width, final int height)
No PMVMatrix4f operation is performed here.
final int setSampleCount(final int v)
Sets pass2 AA sample count clipped to the range [Region#MIN_AA_SAMPLE_COUNT..Region#MAX_AA_SAMPLE_COU...
static final GLCallback defaultBlendDisable
Default GL#GL_BLEND disable GLCallback, simply turning-off the GL#GL_BLEND state and turning-on depth...
final int setAAQuality(final int v)
Sets pass2 AA-quality rendering value clipped to the range [Region#MIN_AA_QUALITY....
static final GLCallback defaultBlendEnable
Default GL#GL_BLEND enable GLCallback, turning-off depth writing via GL#glDepthMask(boolean) if Rende...
final void init(final GL2ES2 gl)
Initialize shader and bindings for GPU based rendering bound to the given GL object's GLContext if no...
static RegionRenderer create()
Create a hardware accelerated RegionRenderer including its RenderState composition.
final Recti getViewport(final Recti target)
Copies the current Rect4i viewport in given target and returns it for chaining.
final void destroy(final GL2ES2 gl)
Deletes all ShaderPrograms and nullifies its references including RenderState#destroy(GL2ES2).
Text Type Rendering Utility Class adding the Font.Glyphs OutlineShape to a GLRegion.
AABBox drawString3D(final GL2ES2 gl, final RegionRenderer renderer, final Font font, final CharSequence str, final Vec4f rgbaColor)
Render the string in 3D space w.r.t.
The optional property jogamp.graph.font.ctor allows user to specify the FontConstructor implementatio...
static final FontSet get(final int font)
static final int UBUNTU
Ubuntu is the default font family, {@value}.
Graph based GLRegion Shape.
void setTextureUnit(final int pass2TexUnit)
Set the 2nd pass texture unit.
Shape setColor(final float r, final float g, final float b, final float a)
Set base color.
final Shape setScale(final Vec3f s)
Set scale factor to given scale.
void draw(final GL2ES2 gl, final RegionRenderer renderer)
Renders the shape.
final Recti getSurfacePort(final PMVMatrix4f pmv, final Recti viewport, final Recti surfacePort)
Retrieve surface (view) port of this shape, i.e.
final AABBox getBounds()
Returns the unscaled bounding AABBox for this shape, borrowing internal instance.
final void destroy(final GL2ES2 gl, final RegionRenderer renderer)
Destroys all data.
final void applyMatToMv(final PMVMatrix4f pmv)
Applies the internal Matrix4f to the given modelview matrix, i.e.
A GraphUI Crosshair GraphShape.
Basic Float math utility functions.
static float getOrthoWinZ(final float orthoZ, final float zNear, final float zFar)
Returns orthogonal distance (1f/zNear-1f/orthoZ) / (1f/zNear-1f/zFar);.
static final float QUARTER_PI
The value PI/4, i.e.
Basic 4x4 float matrix implementation using fields for intensive use-cases (host operations).
StringBuilder toString(final StringBuilder sb, final String rowPrefix, final String f)
Rectangle with x, y, width and height integer components.
2D Vector based upon two float components.
void set(final Vec2f o)
this = o, returns this.
2D Vector based upon two integer components.
3D Vector based upon three float components.
4D Vector based upon four float components.
Axis Aligned Bounding Box.
AABBox mapToWindow(final AABBox result, final Matrix4f mat4PMv, final Recti viewport, final boolean useCenterZ)
Assume this bounding box as being in object space and compute the window bounding box.
final AABBox setSize(final float[] low, final float[] high)
Set size of the AABBox specifying the coordinates of the low and high.
PMVMatrix4f implements the basic computer graphics Matrix4f pack using projection (P),...
final PMVMatrix4f translateMv(final float x, final float y, final float z)
Translate the modelview matrix.
final PMVMatrix4f scaleMv(final float x, final float y, final float z)
Scale the modelview matrix.
final PMVMatrix4f loadMvIdentity()
Load the modelview matrix with the values of the given Matrix4f.
final Matrix4f getMv()
Returns the modelview matrix (Mv).
final PMVMatrix4f translateP(final float x, final float y, final float z)
Translate the projection matrix.
final PMVMatrix4f perspectiveP(final float fovy_rad, final float aspect, final float zNear, final float zFar)
Multiply the projection matrix with the perspective/frustum matrix.
final Matrix4f getPMv()
Returns the pre-multiplied projection x modelview, P x Mv.
final void orthoP(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar)
Multiply the projection matrix with the orthogonal matrix.
final PMVMatrix4f loadPIdentity()
Load the projection matrix with the values of the given Matrix4f.
final Matrix4f getP()
Returns the projection matrix (P).
final PMVMatrix4f popMv()
Pop the modelview matrix from its stack.
final boolean mapWinToObj(final float winx, final float winy, final float winz, final Recti viewport, final Vec3f objPos)
Map window coordinates to object coordinates.
final PMVMatrix4f pushMv()
Push the modelview matrix to its stack, while preserving its values.
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final void setTitle(final String title)
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
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.
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 JoglVersion getInstance()
static StringBuilder getGLInfo(final GL gl, final StringBuilder sb)
StringBuilder toString(final GL gl, 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 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.
static void winToPlaneCoord(final PMVMatrix4f pmv, final Recti viewport, final float zNear, final float zFar, final float winX, final float winY, final float objOrthoZ, final Vec3f objPos)
Res independent Graph + GraphUI integration demo using a GraphUI Shape and Graph text rendering withi...
static void main(final String[] args)
GLCapabilities getGLCaps()
int graphAASamples
Sample count for Graph Region AA render-modes: Region#VBAA_RENDERING_BIT or Region#MSAA_RENDERING_BIT...
int graphAAQuality
Pass2 AA-quality rendering for Graph Region AA render-modes: VBAA_RENDERING_BIT.
void parse(final String[] args)
static int atoi(final String str, final int def)
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.
static final int FAMILY_LIGHT
Font family LIGHT, {@value}.
Font get(int family, int stylebits)
static final int STYLE_SERIF
SERIF style/family bit flag.
General purpose Font.Glyph visitor.
Interface wrapper for font implementation.
Glyph getGlyph(final String name)
Returns the Glyph mapped to given name.
String getFullFamilyName()
Shall return the family and subfamily name, separated a dash.
AABBox getGlyphBounds(final CharSequence string)
Try using getGlyphBounds(CharSequence, AffineTransform, AffineTransform) to reuse AffineTransform ins...
AABBox processString(final Font.GlyphVisitor visitor, final AffineTransform transform, final CharSequence string)
Try using processString(GlyphVisitor, AffineTransform, CharSequence, AffineTransform,...
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.
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
GLProfile getGLProfile()
Returns the GLProfile associated with this GL object.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
GLProfile getGLProfile()
Fetches the GLProfile for this drawable.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
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,...
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
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...