JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
Issue344Base.java
Go to the documentation of this file.
1package com.jogamp.opengl.test.bugs;
2
3import java.awt.BorderLayout;
4import java.awt.Font;
5import java.awt.Frame;
6import java.awt.event.*;
7import java.awt.geom.*;
8
9import com.jogamp.common.util.InterruptSource;
10import com.jogamp.opengl.GL;
11import com.jogamp.opengl.GL2;
12import com.jogamp.opengl.GLAutoDrawable;
13import com.jogamp.opengl.GLEventListener;
14import com.jogamp.opengl.awt.GLCanvas;
15import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
16import com.jogamp.opengl.glu.*;
17
18import com.jogamp.opengl.util.awt.TextRenderer;
19
20/** Test Code adapted from TextCube.java (in JOGL demos)
21 *
22 * @author spiraljetty
23 * @author kbr
24 */
25
26public abstract class Issue344Base implements GLEventListener
27{
28 GLU glu = new GLU();
29 TextRenderer renderer;
30
31 float textScaleFactor;
32 Font font;
33 boolean useMipMaps;
34
35 protected Issue344Base() {
36 font = new Font("default", Font.PLAIN, 200);
37 useMipMaps = true; //false
38 }
39
40 protected abstract String getText();
41
42 protected void run(final String[] args) {
43 final Frame frame = new Frame(getClass().getName());
44 frame.setLayout(new BorderLayout());
45
46 final GLCanvas canvas = new GLCanvas();
47 canvas.addGLEventListener(this);
48 frame.add(canvas, BorderLayout.CENTER);
49
50 frame.setSize(512, 512);
51 frame.addWindowListener(new WindowAdapter() {
52 public void windowClosing(final WindowEvent e) {
53 new InterruptSource.Thread(null, new Runnable() {
54 public void run() {
55 System.exit(0);
56 }
57 }).start();
58 }
59 });
60 try {
61 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
62 public void run() {
63 frame.setVisible(true);
64 } } );
65 } catch(final Exception ex) {
66 throw new RuntimeException(ex);
67 }
68 }
69
70 public void init(final GLAutoDrawable drawable)
71 {
72 final GL2 gl = drawable.getGL().getGL2();
73
75
76 renderer = new TextRenderer(font, useMipMaps);
77
78 final Rectangle2D bounds = renderer.getBounds(getText());
79 final float w = (float) bounds.getWidth();
80 // final float h = (float) bounds.getHeight();
81 textScaleFactor = 2.0f / (w * 1.1f);
82 gl.setSwapInterval(0);
83 }
84
85 public void display(final GLAutoDrawable drawable)
86 {
87 final GL2 gl = drawable.getGL().getGL2();
89
91 gl.glLoadIdentity();
92 glu.gluLookAt(0, 0, 10,
93 0, 0, 0,
94 0, 1, 0);
95
96 renderer.begin3DRendering();
97 final Rectangle2D bounds = renderer.getBounds(getText());
98 final float w = (float) bounds.getWidth();
99 final float h = (float) bounds.getHeight();
100 renderer.draw3D(getText(),
101 w / -2.0f * textScaleFactor,
102 h / -2.0f * textScaleFactor,
103 3f,
104 textScaleFactor);
105
106 renderer.end3DRendering();
107 }
108
109 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height)
110 {
111 final GL2 gl = drawable.getGL().getGL2();
113 gl.glLoadIdentity();
114 glu.gluPerspective(15, (float) width / (float) height, 5, 15);
115 }
116
117 public void dispose(final GLAutoDrawable drawable) {}
118}
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
Provides access to the OpenGL Utility Library (GLU).
Definition: GLU.java:43
void gluLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
Definition: GLU.java:1366
void gluPerspective(float fovy, float aspect, float zNear, float zFar)
Definition: GLU.java:1362
Test Code adapted from TextCube.java (in JOGL demos)
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 display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
Renders bitmapped Java 2D text into an OpenGL window with high performance, full Unicode support,...
void begin3DRendering()
Begins rendering of 2D text in 3D with this TextRenderer into the current OpenGL drawable.
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 end3DRendering()
Ends a 3D render cycle with this TextRenderer.
Rectangle2D getBounds(final String str)
Returns the bounding rectangle of the given String, assuming it was rendered at the origin.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void setSwapInterval(int interval)
Set the swap interval of the current context and attached onscreen GLDrawable.
GL2 getGL2()
Casts this object to the GL2 interface.
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...
Definition: GL.java:390
void glEnable(int cap)
Entry point to C language function: void {@native glEnable}(GLenum cap) Part of GL_ES_VERSION_2_0,...
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...
Definition: GL.java:43
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...
Definition: GL.java:738
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.