JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
Bug816AppletGLCanvas01.java
Go to the documentation of this file.
1/**
2 * Copyright 2013 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 */
28package com.jogamp.opengl.test.junit.jogl.demos.es2.awt;
29
30import java.applet.Applet;
31import java.awt.Color;
32import java.awt.event.WindowAdapter;
33import java.awt.event.WindowEvent;
34
35import com.jogamp.opengl.GL;
36import com.jogamp.opengl.GLAutoDrawable;
37import com.jogamp.opengl.GLCapabilities;
38import com.jogamp.opengl.GLCapabilitiesImmutable;
39import com.jogamp.opengl.GLEventListener;
40import com.jogamp.opengl.GLProfile;
41import com.jogamp.opengl.awt.GLCanvas;
42import javax.swing.JFrame;
43import javax.swing.JPanel;
44
45/**
46 * Bug 816: OSX CALayer Positioning Bug.
47 * <p>
48 * Diff. OSX CALayer positioning w/ java6, [7uxx..7u40[, and >= 7u40
49 * </p>
50 * <p>
51 * Test simply positions a GLCanvas via setBounds(..) within it's Applet.
52 * </p>
53 */
54@SuppressWarnings("serial")
55public class Bug816AppletGLCanvas01 extends Applet implements GLEventListener {
56
58 }
59
60 public static JFrame frame;
61 public static JPanel appletHolder;
62 public static boolean isApplet = true;
63
64 static public void main(final String args[]) {
65 Applet myApplet = null;
66 isApplet = false;
67
68 myApplet = new Bug816AppletGLCanvas01();
69 appletStarter(myApplet, "Bug861AppletGLCanvasTest01", 800, 600);
70 }
71
72 static public void appletStarter(final Applet des, final String frameName, final int width, final int height) {
73 appletHolder = new JPanel();
74 if (frame != null) {
75 frame.dispose();
76 frame = null;
77 }
78 frame = new JFrame(frameName);
79 frame.setVisible(false);
80 frame.getContentPane().add(appletHolder);
81
82 appletHolder.setLayout(null);
83 des.setBounds(0, 0, width, height);
84 appletHolder.add(des);
85
86 frame.setVisible(true);
87 final int frameBorderSize = appletHolder.getLocationOnScreen().x - frame.getLocationOnScreen().x;
88 final int titleBarHeight = appletHolder.getLocationOnScreen().y - frame.getLocationOnScreen().y;
89 final int frameWidth = width + 2 * frameBorderSize;
90 final int frameHeight = height + titleBarHeight + frameBorderSize;
91 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
92 frame.setSize(frameWidth, frameHeight);
93 frame.setVisible(true);
94 des.init();
95 frame.addWindowListener(new WindowAdapter() {
96 public void windowClosing(final WindowEvent e) {
97 System.exit(0);
98 }
99 });
100 }
101
102 public void init() {
103 initOpenGLAWT();
104 }
105
106 public void initOpenGLAWT() {
107 setBackground(Color.gray);
108 setLayout(null);
109
110 final GLProfile glp = GLProfile.getDefault();
111 final GLCapabilities caps = new GLCapabilities(glp);
112 final GLCanvas canvas = new GLCanvas(caps);
113 canvas.setBounds(50, 50, 200, 450);
114 canvas.addGLEventListener(this);
115 add(canvas);
116 }
117
118 public void init(final GLAutoDrawable gLAutoDrawable) {
119 final GL gl = gLAutoDrawable.getGL();
120 gl.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
122 gLAutoDrawable.swapBuffers();
123 }
124
125 public void dispose(final GLAutoDrawable glad) {
126 }
127
128 public void display(final GLAutoDrawable glad) {
129 }
130
131 public void reshape(final GLAutoDrawable glad, final int i, final int i1, final int i2, final int i3) {
132 }
133
134}
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
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
void init(final GLAutoDrawable gLAutoDrawable)
Called by the drawable immediately after the OpenGL context is initialized.
static void appletStarter(final Applet des, final String frameName, final int width, final int height)
void dispose(final GLAutoDrawable glad)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void reshape(final GLAutoDrawable glad, final int i, final int i1, final int i2, final int i3)
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.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void swapBuffers()
Swaps the front and back buffers of 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...
Definition: GL.java:390
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_...