JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
Gears.java
Go to the documentation of this file.
1
2package com.jogamp.opengl.test.junit.jogl.demos.gl2;
3
4import com.jogamp.opengl.GL;
5import com.jogamp.opengl.GL2;
6import com.jogamp.opengl.GL2ES3;
7import com.jogamp.opengl.GL2GL3;
8import com.jogamp.opengl.GLAutoDrawable;
9import com.jogamp.opengl.GLEventListener;
10import com.jogamp.opengl.GLProfile;
11import com.jogamp.opengl.fixedfunc.GLLightingFunc;
12import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
13
14import com.jogamp.newt.Window;
15import com.jogamp.newt.event.InputEvent;
16import com.jogamp.newt.event.KeyAdapter;
17import com.jogamp.newt.event.KeyEvent;
18import com.jogamp.newt.event.KeyListener;
19import com.jogamp.newt.event.MouseAdapter;
20import com.jogamp.newt.event.MouseEvent;
21import com.jogamp.newt.event.MouseListener;
22import com.jogamp.newt.event.awt.AWTKeyAdapter;
23import com.jogamp.newt.event.awt.AWTMouseAdapter;
24import com.jogamp.opengl.GLRendererQuirks;
25import com.jogamp.opengl.JoglVersion;
26import com.jogamp.opengl.util.TileRendererBase;
27
28/**
29 * Gears.java <BR>
30 * author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel) <P>
31 *
32 * This version is equal to Brian Paul's version 1.2 1999/10/21
33 */
34public class Gears implements GLEventListener, TileRendererBase.TileRendererListener {
35 private float view_rotx = 20.0f, view_roty = 30.0f;
36 private final float view_rotz = 0.0f;
37 private int gear1=0, gear2=0, gear3=0;
38 private Gears sharedGears = null;
39 private Object syncObjects = null;
40 private float angle = 0.0f;
41 private boolean doRotate = true;
42 private final int swapInterval;
43 private final MouseListener gearsMouse = new GearsMouseAdapter();
44 private final KeyListener gearsKeys = new GearsKeyAdapter();
45 private TileRendererBase tileRendererInUse = null;
46 private boolean doRotateBeforePrinting;
47 private boolean verbose = true;
48 private boolean flipVerticalInGLOrientation = false;
49 private volatile boolean isInit = false;
50
51 // private boolean mouseRButtonDown = false;
52 private int prevMouseX, prevMouseY;
53
54 public Gears(final int swapInterval) {
55 this.swapInterval = swapInterval;
56 }
57
58 public Gears() {
59 this.swapInterval = 1;
60 }
61
62 @Override
64 tileRendererInUse = tr;
65 doRotateBeforePrinting = doRotate;
66 setDoRotation(false);
67 }
68 @Override
70 tileRendererInUse = null;
71 setDoRotation(doRotateBeforePrinting);
72 }
73 @Override
74 public void startTileRendering(final TileRendererBase tr) {
75 System.err.println("Gears.startTileRendering: "+tr);
76 }
77 @Override
78 public void endTileRendering(final TileRendererBase tr) {
79 System.err.println("Gears.endTileRendering: "+tr);
80 }
81
82 public void setDoRotation(final boolean rotate) { doRotate = rotate; }
83 public void setVerbose(final boolean v) { verbose = v; }
84 public void setFlipVerticalInGLOrientation(final boolean v) { flipVerticalInGLOrientation=v; }
85
86 public void setSharedGears(final Gears shared) {
87 sharedGears = shared;
88 }
89
90 /**
91 * @return display list gear1
92 */
93 public int getGear1() { return gear1; }
94
95 /**
96 * @return display list gear2
97 */
98 public int getGear2() { return gear2; }
99
100 /**
101 * @return display list gear3
102 */
103 public int getGear3() { return gear3; }
104
105 @Override
106 public void init(final GLAutoDrawable drawable) {
107 final GL2 gl = drawable.getGL().getGL2();
108
109 if( init(gl) ) {
110 final Object upstreamWidget = drawable.getUpstreamWidget();
111 if (upstreamWidget instanceof Window) {
112 final Window window = (Window) upstreamWidget;
113 window.addMouseListener(gearsMouse);
114 window.addKeyListener(gearsKeys);
115 } else if (GLProfile.isAWTAvailable() && upstreamWidget instanceof java.awt.Component) {
116 final java.awt.Component comp = (java.awt.Component) upstreamWidget;
117 new AWTMouseAdapter(gearsMouse, drawable).addTo(comp);
118 new AWTKeyAdapter(gearsKeys, drawable).addTo(comp);
119 }
120 } else {
121 drawable.setGLEventListenerInitState(this, false);
122 }
123 }
124
125 boolean enableCullFace = false;
126
127 private void enableStates(final GL gl, final boolean enable) {
129 if( enable ) {
130 if( enableCullFace ) {
132 }
133 gl.glEnable(GLLightingFunc.GL_LIGHTING);
134 gl.glEnable(GLLightingFunc.GL_LIGHT0);
136 gl.glDepthFunc(GL.GL_LESS); // default
137 gl.glEnable(GLLightingFunc.GL_NORMALIZE);
138 if( msaa ) {
140 }
141 } else {
142 if( enableCullFace ) {
144 }
145 gl.glDisable(GLLightingFunc.GL_LIGHTING);
146 gl.glDisable(GLLightingFunc.GL_LIGHT0);
148 gl.glDisable(GLLightingFunc.GL_NORMALIZE);
149 if( msaa ) {
151 }
152 }
153 }
154
155 public boolean init(final GL2 gl) {
156 if(null != sharedGears && !sharedGears.isInit() ) {
157 if(verbose) {
158 System.err.println(Thread.currentThread()+" GearsES1.init.0: pending shared Gears .. re-init later XXXXX");
159 }
160 return false;
161 }
162 final float lightPos[] = { 5.0f, 5.0f, 10.0f, 0.0f };
163 final float red[] = { 0.8f, 0.1f, 0.0f, 0.7f };
164 final float green[] = { 0.0f, 0.8f, 0.2f, 0.7f };
165 final float blue[] = { 0.2f, 0.2f, 1.0f, 0.7f };
166
167 System.err.println(Thread.currentThread()+" Gears.init: tileRendererInUse "+tileRendererInUse);
168 if(verbose) {
169 System.err.println("GearsES2 init on "+Thread.currentThread());
170 System.err.println("Chosen GLCapabilities: " + gl.getContext().getGLDrawable().getChosenGLCapabilities());
171 System.err.println("INIT GL IS: " + gl.getClass().getName());
172 System.err.println(JoglVersion.getGLStrings(gl, null, false).toString());
173 }
174
176 if( ! ( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ) ) {
177 // Only possible if we do not flip the projection matrix
178 enableCullFace = true;
179 } else {
180 enableCullFace = false;
181 }
182 enableStates(gl, true);
183
184 /* make the gears */
185 if( null != sharedGears ) {
186 gear1 = sharedGears.getGear1();
187 gear2 = sharedGears.getGear2();
188 gear3 = sharedGears.getGear3();
189 if(verbose) {
190 System.err.println("gear1 list reused: "+gear1);
191 System.err.println("gear2 list reused: "+gear2);
192 System.err.println("gear3 list reused: "+gear3);
193 }
195 syncObjects = sharedGears;
196 if(verbose) {
197 System.err.println("Shared Gears: Synchronized Objects due to quirk "+GLRendererQuirks.toString(GLRendererQuirks.NeedSharedObjectSync));
198 }
199 } else {
200 syncObjects = new Object();
201 if(verbose) {
202 System.err.println("Shared Gears: Unsynchronized Objects");
203 }
204 }
205 } else {
206 gear1 = gl.glGenLists(1);
207 gl.glNewList(gear1, GL2.GL_COMPILE);
209 gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f);
210 gl.glEndList();
211 if(verbose) {
212 System.err.println("gear1 list created: "+gear1);
213 }
214
215 gear2 = gl.glGenLists(1);
216 gl.glNewList(gear2, GL2.GL_COMPILE);
218 gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f);
219 gl.glEndList();
220 if(verbose) {
221 System.err.println("gear2 list created: "+gear2);
222 }
223
224 gear3 = gl.glGenLists(1);
225 gl.glNewList(gear3, GL2.GL_COMPILE);
227 gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f);
228 gl.glEndList();
229 if(verbose) {
230 System.err.println("gear3 list created: "+gear3);
231 }
232
233 syncObjects = new Object();
234 }
235
236 enableStates(gl, false);
237
238 isInit = true;
239 return true;
240 }
241
242 public final boolean isInit() { return isInit; }
243
244 @Override
245 public void reshape(final GLAutoDrawable glad, final int x, final int y, final int width, final int height) {
246 if( !isInit ) { return; }
247 final GL2 gl = glad.getGL().getGL2();
248 gl.setSwapInterval(swapInterval);
249 reshape(gl, x, y, width, height, width, height);
250 }
251
252 @Override
253 public void reshapeTile(final TileRendererBase tr,
254 final int tileX, final int tileY, final int tileWidth, final int tileHeight,
255 final int imageWidth, final int imageHeight) {
256 if( !isInit ) { return; }
257 final GL2 gl = tr.getAttachedDrawable().getGL().getGL2();
258 gl.setSwapInterval(0);
259 reshape(gl, tileX, tileY, tileWidth, tileHeight, imageWidth, imageHeight);
260 }
261
262 public void reshape(final GL2 gl, final int tileX, final int tileY, final int tileWidth, final int tileHeight, final int imageWidth, final int imageHeight) {
263 if(verbose) {
264 System.err.println(Thread.currentThread()+" Gears.reshape "+tileX+"/"+tileY+" "+tileWidth+"x"+tileHeight+" of "+imageWidth+"x"+imageHeight+", swapInterval "+swapInterval+", drawable 0x"+Long.toHexString(gl.getContext().getGLDrawable().getHandle())+", tileRendererInUse "+tileRendererInUse);
265 }
266
267 // compute projection parameters 'normal'
268 float left, right, bottom, top;
269 if( imageHeight > imageWidth ) {
270 final float a = (float)imageHeight / (float)imageWidth;
271 left = -1.0f;
272 right = 1.0f;
273 bottom = -a;
274 top = a;
275 } else {
276 final float a = (float)imageWidth / (float)imageHeight;
277 left = -a;
278 right = a;
279 bottom = -1.0f;
280 top = 1.0f;
281 }
282 final float w = right - left;
283 final float h = top - bottom;
284
285 // compute projection parameters 'tiled'
286 final float l = left + tileX * w / imageWidth;
287 final float r = l + tileWidth * w / imageWidth;
288
289 final float b = bottom + tileY * h / imageHeight;
290 final float t = b + tileHeight * h / imageHeight;
291
292 final float _w = r - l;
293 final float _h = t - b;
294 if(verbose) {
295 System.err.println(">> Gears angle "+angle+", [l "+left+", r "+right+", b "+bottom+", t "+top+"] "+w+"x"+h+" -> [l "+l+", r "+r+", b "+b+", t "+t+"] "+_w+"x"+_h+", v-flip "+flipVerticalInGLOrientation);
296 }
297
299 gl.glLoadIdentity();
300 if( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ) {
301 gl.glScalef(1f, -1f, 1f);
302 }
303 gl.glFrustum(l, r, b, t, 5.0f, 60.0f);
304
306 gl.glLoadIdentity();
307 gl.glTranslatef(0.0f, 0.0f, -40.0f);
308 }
309
310 @Override
311 public void dispose(final GLAutoDrawable drawable) {
312 if( !isInit ) { return; }
313 isInit = false;
314 if(verbose) {
315 System.err.println(Thread.currentThread()+" Gears.dispose: tileRendererInUse "+tileRendererInUse);
316 }
317 try {
318 final Object upstreamWidget = drawable.getUpstreamWidget();
319 if (upstreamWidget instanceof Window) {
320 final Window window = (Window) upstreamWidget;
321 window.removeMouseListener(gearsMouse);
322 window.removeKeyListener(gearsKeys);
323 }
324 } catch (final Exception e) { System.err.println("Caught: "); e.printStackTrace(); }
325 gear1 = 0;
326 gear2 = 0;
327 gear3 = 0;
328 sharedGears = null;
329 syncObjects = null;
330 }
331
332 @Override
333 public void display(final GLAutoDrawable drawable) {
334 if( !isInit ) { return; }
335
336 // Get the GL corresponding to the drawable we are animating
337 final GL2 gl = drawable.getGL().getGL2();
338
339 enableStates(gl, true);
340
341 if( null == tileRendererInUse ) {
342 gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
343 } else {
344 gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
345 }
346
347 // Special handling for the case where the GLJPanel is translucent
348 // and wants to be composited with other Java 2D content
349 if (GLProfile.isAWTAvailable() &&
350 (drawable instanceof com.jogamp.opengl.awt.GLJPanel) &&
351 !((com.jogamp.opengl.awt.GLJPanel) drawable).isOpaque() &&
352 ((com.jogamp.opengl.awt.GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) {
354 } else {
356 }
357 displayImpl(gl);
358
359 enableStates(gl, false);
360 }
361
362 public void display(final GL2 gl) {
363 if( !isInit ) { return; }
364 enableStates(gl, true);
365
366 if( null == tileRendererInUse ) {
367 gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
368 } else {
369 gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
370 }
372 displayImpl(gl);
373
374 enableStates(gl, false);
375 }
376
377 private void displayImpl(final GL2 gl) {
378 if( doRotate ) {
379 // Turn the gears' teeth
380 angle += 0.5f;
381 }
382 // Rotate the entire assembly of gears based on how the user
383 // dragged the mouse around
384 gl.glPushMatrix();
385 gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
386 gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
387 gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
388
389 // Place the first gear and call its display list
390 synchronized ( syncObjects ) {
391 gl.glPushMatrix();
392 gl.glTranslatef(-3.0f, -2.0f, 0.0f);
393 gl.glRotatef(angle, 0.0f, 0.0f, 1.0f);
394 gl.glCallList(gear1);
395 gl.glPopMatrix();
396
397 // Place the second gear and call its display list
398 gl.glPushMatrix();
399 gl.glTranslatef(3.1f, -2.0f, 0.0f);
400 gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
401 gl.glCallList(gear2);
402 gl.glPopMatrix();
403
404 // Place the third gear and call its display list
405 gl.glPushMatrix();
406 gl.glTranslatef(-3.1f, 4.2f, 0.0f);
407 gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
408 gl.glCallList(gear3);
409 gl.glPopMatrix();
410 }
411
412 // Remember that every push needs a pop; this one is paired with
413 // rotating the entire gear assembly
414 gl.glPopMatrix();
415 }
416
417 public static void gear(final GL2 gl,
418 final float inner_radius,
419 final float outer_radius,
420 final float width,
421 final int teeth,
422 final float tooth_depth)
423 {
424 int i;
425 float r0, r1, r2;
426 float angle, da;
427 float u, v, len;
428
429 r0 = inner_radius;
430 r1 = outer_radius - tooth_depth / 2.0f;
431 r2 = outer_radius + tooth_depth / 2.0f;
432
433 da = 2.0f * (float) Math.PI / teeth / 4.0f;
434
436
437 gl.glNormal3f(0.0f, 0.0f, 1.0f);
438
439 /* draw front face */
441 for (i = 0; i <= teeth; i++)
442 {
443 angle = i * 2.0f * (float) Math.PI / teeth;
444 gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f);
445 gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f);
446 if(i < teeth)
447 {
448 gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f);
449 gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f);
450 }
451 }
452 gl.glEnd();
453
454 /* draw front sides of teeth */
456 for (i = 0; i < teeth; i++)
457 {
458 angle = i * 2.0f * (float) Math.PI / teeth;
459 gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f);
460 gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f);
461 gl.glVertex3f(r2 * (float)Math.cos(angle + 2.0f * da), r2 * (float)Math.sin(angle + 2.0f * da), width * 0.5f);
462 gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f);
463 }
464 gl.glEnd();
465
466 /* draw back face */
468 for (i = 0; i <= teeth; i++)
469 {
470 angle = i * 2.0f * (float) Math.PI / teeth;
471 gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f);
472 gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f);
473 gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f);
474 gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f);
475 }
476 gl.glEnd();
477
478 /* draw back sides of teeth */
480 for (i = 0; i < teeth; i++)
481 {
482 angle = i * 2.0f * (float) Math.PI / teeth;
483 gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f);
484 gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f);
485 gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f);
486 gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f);
487 }
488 gl.glEnd();
489
490 /* draw outward faces of teeth */
492 for (i = 0; i < teeth; i++)
493 {
494 angle = i * 2.0f * (float) Math.PI / teeth;
495 gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f);
496 gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f);
497 u = r2 * (float)Math.cos(angle + da) - r1 * (float)Math.cos(angle);
498 v = r2 * (float)Math.sin(angle + da) - r1 * (float)Math.sin(angle);
499 len = (float)Math.sqrt(u * u + v * v);
500 u /= len;
501 v /= len;
502 gl.glNormal3f(v, -u, 0.0f);
503 gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f);
504 gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f);
505 gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f);
506 gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), width * 0.5f);
507 gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f);
508 u = r1 * (float)Math.cos(angle + 3 * da) - r2 * (float)Math.cos(angle + 2 * da);
509 v = r1 * (float)Math.sin(angle + 3 * da) - r2 * (float)Math.sin(angle + 2 * da);
510 gl.glNormal3f(v, -u, 0.0f);
511 gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), width * 0.5f);
512 gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f);
513 gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f);
514 }
515 gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), width * 0.5f);
516 gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), -width * 0.5f);
517 gl.glEnd();
518
520
521 /* draw inside radius cylinder */
523 for (i = 0; i <= teeth; i++)
524 {
525 angle = i * 2.0f * (float) Math.PI / teeth;
526 gl.glNormal3f(-(float)Math.cos(angle), -(float)Math.sin(angle), 0.0f);
527 gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f);
528 gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f);
529 }
530 gl.glEnd();
531 }
532
533 class GearsKeyAdapter extends KeyAdapter {
534 public void keyPressed(final KeyEvent e) {
535 final int kc = e.getKeyCode();
536 if(KeyEvent.VK_LEFT == kc) {
537 view_roty -= 1;
538 } else if(KeyEvent.VK_RIGHT == kc) {
539 view_roty += 1;
540 } else if(KeyEvent.VK_UP == kc) {
541 view_rotx -= 1;
542 } else if(KeyEvent.VK_DOWN == kc) {
543 view_rotx += 1;
544 }
545 }
546 }
547
548 class GearsMouseAdapter extends MouseAdapter {
549 public void mousePressed(final MouseEvent e) {
550 prevMouseX = e.getX();
551 prevMouseY = e.getY();
552 if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) {
553 // mouseRButtonDown = true;
554 }
555 }
556
557 public void mouseReleased(final MouseEvent e) {
558 if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) {
559 // mouseRButtonDown = false;
560 }
561 }
562
563 public void mouseDragged(final MouseEvent e) {
564 final int x = e.getX();
565 final int y = e.getY();
566 int width=0, height=0;
567 final Object source = e.getSource();
568 if(source instanceof Window) {
569 final Window window = (Window) source;
570 width=window.getSurfaceWidth();
571 height=window.getSurfaceHeight();
572 } else if (source instanceof GLAutoDrawable) {
573 final GLAutoDrawable glad = (GLAutoDrawable) source;
574 width = glad.getSurfaceWidth();
575 height = glad.getSurfaceHeight();
576 } else if (GLProfile.isAWTAvailable() && source instanceof java.awt.Component) {
577 final java.awt.Component comp = (java.awt.Component) source;
578 width=comp.getWidth(); // FIXME HiDPI: May need to convert window units -> pixel units!
579 height=comp.getHeight();
580 } else {
581 throw new RuntimeException("Event source neither Window nor Component: "+source);
582 }
583 final float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)width);
584 final float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)height);
585
586 prevMouseX = x;
587 prevMouseY = y;
588
589 view_rotx += thetaX;
590 view_roty += thetaY;
591 }
592 }
593}
static final short VK_LEFT
Constant for the cursor- or numerical-pad left arrow key.
Definition: KeyEvent.java:811
final short getKeyCode()
Returns the virtual key code using a fixed mapping to the US keyboard layout.
Definition: KeyEvent.java:195
AWT: printable: PRESSED (t0), TYPED (t0), RELEASED (t1) non-printable: PRESSED (t0),...
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
abstract GLDrawable getGLDrawable()
Returns the write-drawable this context uses for framebuffer operations.
final boolean hasRendererQuirk(final int quirk)
Returns true if the quirk exist in getRendererQuirks(), otherwise false.
Definition: GLContext.java:304
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
GLRendererQuirks contains information of known bugs of various GL renderer.
static final int NeedSharedObjectSync
Need GL objects (VBO, ..) to be synchronized when utilized concurrently from multiple threads via a s...
final StringBuilder toString(StringBuilder sb)
static StringBuilder getGLStrings(final GL gl, final StringBuilder sb)
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
Definition: Gears.java:34
void reshape(final GL2 gl, final int tileX, final int tileY, final int tileWidth, final int tileHeight, final int imageWidth, final int imageHeight)
Definition: Gears.java:262
void reshapeTile(final TileRendererBase tr, final int tileX, final int tileY, final int tileWidth, final int tileHeight, final int imageWidth, final int imageHeight)
Called by the TileRendererBase during tile-rendering via an attached GLAutoDrawable's GLAutoDrawable#...
Definition: Gears.java:253
void removeTileRendererNotify(final TileRendererBase tr)
The owning GLAutoDrawable is detached from the given TileRendererBase instance.
Definition: Gears.java:69
void setDoRotation(final boolean rotate)
Definition: Gears.java:82
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
Definition: Gears.java:311
void reshape(final GLAutoDrawable glad, 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.
Definition: Gears.java:245
void addTileRendererNotify(final TileRendererBase tr)
The owning GLAutoDrawable is attached to the given TileRendererBase instance.
Definition: Gears.java:63
static void gear(final GL2 gl, final float inner_radius, final float outer_radius, final float width, final int teeth, final float tooth_depth)
Definition: Gears.java:417
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
Definition: Gears.java:106
void startTileRendering(final TileRendererBase tr)
Called by the TileRendererBase during tile-rendering after TileRendererBase#beginTile(GL) and before ...
Definition: Gears.java:74
void setFlipVerticalInGLOrientation(final boolean v)
Definition: Gears.java:84
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
Definition: Gears.java:333
void endTileRendering(final TileRendererBase tr)
Called by the TileRenderer during tile-rendering after TileRendererBase#endTile(GL) and GLAutoDrawabl...
Definition: Gears.java:78
A fairly direct port of Brian Paul's tile rendering library, found at http://www.mesa3d....
final GLAutoDrawable getAttachedDrawable()
Returns a previously attached GLAutoDrawable, null if none is attached.
Specifying NEWT's Window functionality:
Definition: Window.java:115
void addKeyListener(KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
void removeKeyListener(KeyListener l)
void addMouseListener(MouseListener l)
Appends the given MouseListener to the end of the list.
void removeMouseListener(MouseListener l)
Removes the given MouseListener from the list.
Listener for KeyEvents.
void glNormal3f(float nx, float ny, float nz)
Entry point to C language function: void {@native glNormal3f}(GLfloat nx, GLfloat ny,...
void glFrustum(double left, double right, double bottom, double top, double zNear, double zFar)
static final int GL_QUADS
GL_ES_VERSION_3_2, GL_VERSION_1_1, GL_VERSION_1_0, GL_OES_tessellation_shader, GL_EXT_tessellation_sh...
Definition: GL2ES3.java:734
int glGenLists(int range)
Entry point to C language function: GLuint {@native glGenLists}(GLsizei range) Part of GL_VERSION_...
void glCallList(int list)
Entry point to C language function: void {@native glCallList}(GLuint list) Part of GL_VERSION_1_0
void glBegin(int mode)
Entry point to C language function: void {@native glBegin}(GLenum mode) Part of GL_VERSION_1_0
void glEndList()
Entry point to C language function: void {@native glEndList}() Part of GL_VERSION_1_0
void glVertex3f(float x, float y, float z)
Entry point to C language function: void {@native glVertex3f}(GLfloat x, GLfloat y,...
static final int GL_COMPILE
GL_VERSION_1_0 Define "GL_COMPILE" with expression '0x1300', CType: int
Definition: GL2.java:1875
void glEnd()
Entry point to C language function: void {@native glEnd}() Part of GL_VERSION_1_0
static final int GL_QUAD_STRIP
GL_VERSION_1_0 Define "GL_QUAD_STRIP" with expression '0x0008', CType: int
Definition: GL2.java:2548
void glNewList(int list, int mode)
Entry point to C language function: void {@native glNewList}(GLuint list, GLenum mode) Part of GL_...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void setGLEventListenerInitState(GLEventListener listener, boolean initialized)
Sets the given listener's initialized state.
Object getUpstreamWidget()
Method may return the upstream UI toolkit object holding this GLAutoDrawable instance,...
void setSwapInterval(int interval)
Set the swap interval of the current context and attached onscreen GLDrawable.
GLContext getContext()
Returns the GLContext associated which this GL object.
GL2 getGL2()
Casts this object to the GL2 interface.
boolean getSampleBuffers()
Returns whether sample buffers for full-scene antialiasing (FSAA) should be allocated for this drawab...
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
long getHandle()
Returns the GL drawable handle, guaranteed to be valid after realization and while it's surface is be...
boolean isGLOriented()
Returns true if the drawable is rendered in OpenGL's coordinate system, origin at bottom left.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
static final int GL_MULTISAMPLE
Common in ES1, GL2 and GL3.
Definition: GL.java:1249
void glDisable(int cap)
Entry point to C language function: void {@native glDisable}(GLenum cap) Part of GL_ES_VERSION_2_0...
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 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_FRONT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FRONT" with expressio...
Definition: GL.java:597
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
static final int GL_LESS
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_LESS" with expression...
Definition: GL.java:134
static final int GL_CULL_FACE
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_CULL_FACE" with expre...
Definition: GL.java:720
void glDepthFunc(int func)
Entry point to C language function: void {@native glDepthFunc}(GLenum func) Part of GL_ES_VERSION_...
void glMaterialfv(int face, int pname, java.nio.FloatBuffer params)
void glLightfv(int light, int pname, java.nio.FloatBuffer params)
Subset of OpenGL fixed function pipeline's matrix operations.
static final int GL_PROJECTION
Matrix mode projection.
void glPushMatrix()
Push the current matrix to it's stack, while preserving it's values.
void glPopMatrix()
Pop the current matrix from it's stack.
void glTranslatef(float x, float y, float z)
Translate the current matrix.
void glRotatef(float angle, float x, float y, float z)
Rotate the current matrix.
static final int GL_MODELVIEW
Matrix mode modelview.
void glScalef(float x, float y, float z)
Scale the current matrix.
void glLoadIdentity()
Load the current matrix with the identity matrix.
void glMatrixMode(int mode)
Sets the current matrix mode.