JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TextRendererGLEventListener01.java
Go to the documentation of this file.
1/**
2 * Copyright 2011 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.awt.text;
30
31import java.awt.Font;
32import java.io.OutputStream;
33import java.io.PrintStream;
34
35import com.jogamp.opengl.util.awt.TextRenderer;
36
37import com.jogamp.opengl.GL2ES1;
38import com.jogamp.opengl.GL2;
39import com.jogamp.opengl.GLAutoDrawable;
40import com.jogamp.opengl.GLEventListener;
41import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
42import com.jogamp.opengl.glu.GLU;
43
44import org.junit.Assert;
45
46/*
47 * Unit tests for Bug464
48 * GLEventListener for unit test TestAWTTextRendererUseVertexArrayBug464. The display
49 * method renders the String "ABC123#+?" to the lower left corner of the canvas.
50 *
51 * The testNumber variable is used to switch between 2D- and 3D-textrendering in the display
52 * method.
53 * The disallowedMethodCalls variable is used to log VBO-related glFunction calls during
54 * the execution of the test.
55 *
56 * Other classes related to this test:
57 * TestAWTTextRendererUseVertexArrayBug464
58 * TextRendererTraceGL2Mock01
59 */
60
62 private final GLU glu = new GLU();
63 private TextRenderer renderer;
64 private String text;
65 private String disallowedMethodCalls;
66 private final int testNumber;
67
68 public TextRendererGLEventListener01(final int testNumber) {
69 this.disallowedMethodCalls = "";
70 this.testNumber = testNumber;
71 }
72
73 public void init(final GLAutoDrawable drawable) {
74 renderer = new TextRenderer(new Font("SansSerif", Font.BOLD, 36));
75 renderer.setUseVertexArrays(false);
76 Assert.assertNotNull(renderer);
77 Assert.assertFalse(renderer.getUseVertexArrays());
78
79 text = "ABC123#+?";
80
81 final PrintStream nullStream = new PrintStream(new OutputStream(){ public void write(final int b){}});
82 drawable.setGL(new TextRendererTraceGL2Mock01(drawable.getGL().getGL2(), nullStream, this));
83 }
84
85 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
86 final GL2 gl = drawable.getGL().getGL2();
88 gl.glLoadIdentity();
89 glu.gluOrtho2D(0, 1, 0, 1);
91 gl.glLoadIdentity();
92 }
93
94 public void dispose(final GLAutoDrawable drawable) {
95 renderer.dispose();
96 }
97
98 public void display(final GLAutoDrawable drawable) {
99 if (disallowedMethodCalls.equals("")) {
100 if (testNumber == 1) {
101 renderer.beginRendering(drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
102 renderer.setColor(1.0f, 1.0f, 1.0f, 1.0f);
103 renderer.draw(text, 0, 0);
104 renderer.endRendering();
105 }
106 if (testNumber == 2) {
107 renderer.begin3DRendering();
108 renderer.setColor(1.0f, 1.0f, 1.0f, 1.0f);
109 renderer.draw3D(text, 0, 0, 0, 0.002f);
110 renderer.end3DRendering();
111 }
112 }
113 }
114
115 public void disallowedMethodCalled (final String method) {
116 if (!disallowedMethodCalls.equals("")) {
117 disallowedMethodCalls += ", ";
118 }
119 disallowedMethodCalls += method;
120 }
121
122 public String getDisallowedMethodCalls() {
123 return this.disallowedMethodCalls;
124 }
125}
126
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 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.
Renders bitmapped Java 2D text into an OpenGL window with high performance, full Unicode support,...
void beginRendering(final int width, final int height)
Begins rendering with this TextRenderer into the current OpenGL drawable, pushing the projection and ...
void endRendering()
Ends a render cycle with this TextRenderer.
void draw(final CharSequence str, final int x, final int y)
Draws the supplied CharSequence at the desired location using the renderer's current color.
void begin3DRendering()
Begins rendering of 2D text in 3D with this TextRenderer into the current OpenGL drawable.
void setColor(final Color color)
Changes the current color of this TextRenderer to the supplied one.
void draw3D(final CharSequence str, final float x, final float y, final float z, final float scaleFactor)
Draws the supplied CharSequence at the desired 3D location using the renderer's current color.
void setUseVertexArrays(final boolean useVertexArrays)
Sets whether vertex arrays are being used internally for rendering, or whether text is rendered using...
void end3DRendering()
Ends a 3D render cycle with this TextRenderer.
void dispose()
Disposes of all resources this TextRenderer is using.
final boolean getUseVertexArrays()
Indicates whether vertex arrays are being used internally for rendering, or whether text is rendered ...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
GL setGL(GL gl)
Sets the GL pipeline object this GLAutoDrawable uses.
GL2 getGL2()
Casts this object to the GL2 interface.
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.
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.