28package com.jogamp.opengl.test.junit.jogl.demos.gl2.awt;
30import java.awt.ComponentOrientation;
31import java.awt.Dimension;
32import java.awt.GridLayout;
33import java.awt.event.WindowAdapter;
34import java.awt.event.WindowEvent;
35import java.io.InputStream;
36import java.nio.ByteBuffer;
37import java.nio.ByteOrder;
38import java.nio.FloatBuffer;
40import com.jogamp.opengl.GL;
41import com.jogamp.opengl.GL2;
42import com.jogamp.opengl.GL2ES1;
43import com.jogamp.opengl.GL2GL3;
44import com.jogamp.opengl.GLAutoDrawable;
45import com.jogamp.opengl.GLEventListener;
46import com.jogamp.opengl.awt.GLCanvas;
47import com.jogamp.opengl.awt.GLJPanel;
48import com.jogamp.opengl.fixedfunc.GLLightingFunc;
49import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
50import com.jogamp.opengl.fixedfunc.GLPointerFunc;
51import javax.swing.JApplet;
52import javax.swing.JLabel;
53import javax.swing.JPanel;
54import javax.swing.JFrame;
55import javax.swing.SwingConstants;
57import com.jogamp.common.util.VersionUtil;
58import com.jogamp.opengl.JoglVersion;
59import com.jogamp.opengl.util.Animator;
60import com.jogamp.opengl.util.texture.Texture;
61import com.jogamp.opengl.util.texture.TextureIO;
75 private static final long serialVersionUID = 1L;
85 static public void main(
final String args[]) {
92 frame =
new JFrame(
"Bug818GLJPanelApplet");
93 frame.getContentPane().add(myApplet);
95 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
96 frame.addWindowListener(
new WindowAdapter() {
97 public void windowClosing(
final WindowEvent e) {
103 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
108 frame.setVisible(
true);
110 }
catch(
final Throwable throwable ) {
111 throwable.printStackTrace();
121 final JPanel panel =
new JPanel();
122 panel.setLayout(
new GridLayout(2, 2));
123 System.err.println(
"Pre Orientation L2R: "+panel.getComponentOrientation().isLeftToRight());
124 panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
125 System.err.println(
"Post Orientation L2R: "+panel.getComponentOrientation().isLeftToRight());
126 setContentPane(panel);
127 panel.add(
new JLabel(
"GLJPanel", SwingConstants.CENTER));
128 panel.add(
new JLabel(
"GLCanvas", SwingConstants.CENTER));
132 animatorPanel =
new Animator(gljPanel);
133 gljPanel.setPreferredSize(
new Dimension(300, 300));
138 animatorCanvas =
new Animator(glCanvas);
139 glCanvas.setPreferredSize(
new Dimension(300, 300));
146 animatorCanvas.
start();
148 animatorPanel.
start();
155 animatorCanvas.
stop();
156 animatorPanel.
stop();
167 private static final float[] VERTEX_DATA = {
174 private static final float[] TEXCOORD_DATA = {
181 private final FloatBuffer vertexBuf;
183 private final FloatBuffer texCoordBuf;
185 private int vertexVBO;
187 private int texCoordVBO;
189 private float rotateT = 0.0f;
191 private final boolean canvas;
195 JOGLQuad(
final boolean canvas) {
197 this.canvas = canvas;
199 ByteBuffer bb = ByteBuffer.allocateDirect(VERTEX_DATA.length * 4);
200 bb.order(ByteOrder.nativeOrder());
201 vertexBuf = bb.asFloatBuffer();
202 vertexBuf.put(VERTEX_DATA);
205 bb = ByteBuffer.allocateDirect(TEXCOORD_DATA.length * 4);
206 bb.order(ByteOrder.nativeOrder());
207 texCoordBuf = bb.asFloatBuffer();
208 texCoordBuf.put(TEXCOORD_DATA);
209 texCoordBuf.rewind();
217 System.err.println(VersionUtil.getPlatformInfo());
227 final int[] tmp =
new int[2];
230 texCoordVBO = tmp[1];
239 final InputStream stream = getClass().getClassLoader().getResourceAsStream(
"com/jogamp/opengl/test/junit/jogl/util/texture/test-ntscN_3-01-160x90-90pct-yuv444-base.jpg");
240 texture = TextureIO.newTexture(stream,
true, TextureIO.JPG);
241 }
catch (
final Exception exc) {
242 exc.printStackTrace(System.err);
250 final int[] tmp =
new int[] {vertexVBO, texCoordVBO};
255 public void reshape(
final GLAutoDrawable gLDrawable,
final int x,
final int y,
final int width,
final int height) {
258 final float aspect = (float) width / (
float) height;
261 final float fh = 0.5f;
262 final float fw = fh * aspect;
263 gl.glFrustumf(-fw, fw, -fh, fh, 1.0f, 1000.0f);
264 gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
269 public void display(
final GLAutoDrawable gLDrawable) {
271 final GL2 gl = gLDrawable.getGL().getGL2();
273 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
275 gl.glTranslatef(0.0f, 0.0f, -5.0f);
278 gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
279 gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
280 gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);
284 gl.glColor3f(0.2f, 0.2f, 1.0f);
286 gl.glColor3f(1.0f, 0.2f, 0.2f);
289 if (texture !=
null) {
293 System.err.println(
"no texture");
297 gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
298 gl.glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
299 gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexVBO);
300 gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0);
301 gl.glBindBuffer(GL.GL_ARRAY_BUFFER, texCoordVBO);
302 gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, 0);
303 gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
304 gl.glDrawArrays(GL2GL3.GL_QUADS, 0, 4);
305 gl.glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
306 gl.glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
308 if (texture !=
null) {
static StringBuilder getGLInfo(final GL gl, final StringBuilder sb)
A heavyweight AWT component which provides OpenGL rendering support.
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
A lightweight Swing component which provides OpenGL rendering support.
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Bug 818: OSX GLJPanel [and GLCanvas] Crash.
static void main(final String args[])
static JPanel appletHolder
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.
Represents an OpenGL texture object.
void bind(final GL gl)
Binds this texture to the given GL context.
void disable(final GL gl)
Disables this texture's target (e.g., GL_TEXTURE_2D) in the given GL state.
void enable(final GL gl)
Enables this texture's target (e.g., GL_TEXTURE_2D) in the given GL context's state.
static final int GL_PERSPECTIVE_CORRECTION_HINT
GL_VERSION_ES_1_0, GL_VERSION_1_0 Define "GL_PERSPECTIVE_CORRECTION_HINT" with expression '0x0C50',...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
GL getGL()
Casts this object to the GL interface.
void glClearDepth(double depth)
Aliased entrypoint of void {@native glClearDepth}(GLclampd depth); and void {@native glClearDepthf...
GL2 getGL2()
Casts this object to the GL2 interface.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void glGenBuffers(int n, IntBuffer buffers)
Entry point to C language function: void {@native glGenBuffers}(GLsizei n, GLuint * buffers) Part ...
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...
void glClearColor(float red, float green, float blue, float alpha)
Entry point to C language function: void {@native glClearColor}(GLfloat red, GLfloat green,...
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...
void glHint(int target, int mode)
Entry point to C language function: void {@native glHint}(GLenum target, GLenum mode) Part of GL_E...
static final int GL_NICEST
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_NICEST" with expressi...
void glDepthFunc(int func)
Entry point to C language function: void {@native glDepthFunc}(GLenum func) Part of GL_ES_VERSION_...
static final int GL_LEQUAL
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_LEQUAL" with expressi...
void glBindBuffer(int target, int buffer)
Entry point to C language function: void {@native glBindBuffer}(GLenum target, GLuint buffer) Part...
void glBufferData(int target, long size, Buffer data, int usage)
Entry point to C language function: void {@native glBufferData}(GLenum target, GLsizeiptr size,...
static final int GL_ARRAY_BUFFER
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_ARRAY...
void glShadeModel(int mode)
void glMatrixMode(int mode)
Sets the current matrix mode.