JOGL v2.6.0-rc-20250822
JOGL, High-Performance Graphics Binding for Java™ (public API).
GearsFBO02.java
Go to the documentation of this file.
1/**
2 * Copyright 2011-2025 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.demos.es2;
29
30import java.nio.FloatBuffer;
31
32import com.jogamp.opengl.GL;
33import com.jogamp.opengl.GL2ES2;
34import com.jogamp.opengl.GL2ES3;
35import com.jogamp.opengl.GL2GL3;
36import com.jogamp.opengl.GL4;
37import com.jogamp.opengl.GLAutoDrawable;
38import com.jogamp.opengl.GLCapabilities;
39import com.jogamp.opengl.GLEventListener;
40import com.jogamp.opengl.GLException;
41import com.jogamp.opengl.GLProfile;
42import com.jogamp.opengl.GLUniformData;
43import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
44import com.jogamp.common.util.VersionUtil;
45import com.jogamp.math.Recti;
46import com.jogamp.newt.event.WindowAdapter;
47import com.jogamp.newt.event.WindowEvent;
48import com.jogamp.newt.opengl.GLWindow;
49import com.jogamp.opengl.demos.util.CommandlineOptions;
50import com.jogamp.opengl.demos.util.MiscUtils;
51import com.jogamp.opengl.util.Animator;
52import com.jogamp.opengl.util.GLArrayDataServer;
53import com.jogamp.opengl.util.PMVMatrix;
54import com.jogamp.opengl.util.caps.NonFSAAGLCapsChooser;
55import com.jogamp.opengl.util.glsl.ShaderCode;
56import com.jogamp.opengl.util.glsl.ShaderProgram;
57import com.jogamp.opengl.util.glsl.ShaderState;
58
59/**
60 * FBO demo using a texture attachment for color- and combined depth + stencil-buffer.
61 * - The color-buffer texture is visualized.
62 * - The depth-buffer texture portion is visualized non-linear and linear.
63 * - The stencil-buffer texture portion is visualized.
64 *
65 * The FBO programming is done `manually` w/o FBObject.
66 *
67 * This demo required GL4 (core).
68 *
69 * We split viewport in 4 parts
70 * - bottom-left: original
71 * - bottom-right: depth-buffer
72 * - top-right: stencil-buffer
73 */
74public class GearsFBO02 implements GLEventListener {
75 private final GearsES2 demo;
76 private final GLEventListener demo2;
77 private final int swapInterval;
78
79 private final ShaderState st;
80 private final PMVMatrix pmvMatrix;
81
82 private ShaderProgram sp0;
83 private GLUniformData pmvMatrixUniform;
84 private GLArrayDataServer interleavedVBO;
85 private final GLUniformData texUnit0, texUnit1;
86 private GLUniformData texType;
87
88 public GearsFBO02(final int demo2Type, final int swapInterval) {
89 this.demo = new GearsES2(0);
90 switch(demo2Type) {
91 case 1: demo2 = new RedSquareES2(0); break;
92 case 2: demo2 = new LandscapeES2(0); break;
93 default: demo2 = null; break;
94 }
95 this.swapInterval = swapInterval;
96 texUnit0 = new GLUniformData("mgl_Texture0", 0);
97 texUnit1 = new GLUniformData("mgl_Texture1", 1);
98
99 st = new ShaderState();
100 // st.setVerbose(true);
101 pmvMatrix = new PMVMatrix();
102 }
103
104 @Override
105 public void init(final GLAutoDrawable drawable) {
106 System.err.println("Init: Chosen Caps: "+drawable.getChosenGLCapabilities());
107 final GL4 gl = drawable.getGL().getGL4();
108
109 demo.init(drawable);
110 if (null != demo2) {
111 demo2.init(drawable);
112 demo.setScale(2.0f);
113 demo.setRotX(0.0f);
114 demo.setRotY(0.0f);
115 }
116
117 final ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, GearsFBO02.class, "shader",
118 "shader/bin", "texture01_xxx", true);
119 final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, GearsFBO02.class, "shader",
120 "shader/bin", "texture01_customtex", true);
121 vp0.defaultShaderCustomization(gl, true, true);
122 fp0.defaultShaderCustomization(gl, true, true);
123
124 sp0 = new ShaderProgram();
125 sp0.add(gl, vp0, System.err);
126 sp0.add(gl, fp0, System.err);
127 st.attachShaderProgram(gl, sp0, true);
128
129 pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.getSyncPMv());
130 st.ownUniform(pmvMatrixUniform);
131 st.uniform(gl, pmvMatrixUniform);
132
133 interleavedVBO = GLArrayDataServer.createGLSLInterleaved(3+4+2, GL.GL_FLOAT, false, 3*4, GL.GL_STATIC_DRAW);
134 {
135 interleavedVBO.addGLSLSubArray("mgl_Vertex", 3, GL.GL_ARRAY_BUFFER);
136 interleavedVBO.addGLSLSubArray("mgl_Color", 4, GL.GL_ARRAY_BUFFER);
137 //interleavedVBO.addGLSLSubArray("mgl_Normal", 3, GL.GL_ARRAY_BUFFER);
138 interleavedVBO.addGLSLSubArray("mgl_MultiTexCoord", 2, GL.GL_ARRAY_BUFFER);
139
140 final FloatBuffer ib = (FloatBuffer)interleavedVBO.getBuffer();
141
142 for(int i=0; i<4; i++) {
143 ib.put(s_quadVertices, i*3, 3);
144 ib.put(s_quadColors, i*4, 4);
145 //ib.put(s_cubeNormals, i*3, 3);
146 ib.put(s_quadTexCoords, i*2, 2);
147 }
148 }
149 interleavedVBO.seal(gl, true);
150 interleavedVBO.enableBuffer(gl, false);
151 st.ownAttribute(interleavedVBO, true);
152
153 texType = new GLUniformData("mgl_TexType", 1);
154 st.ownUniform(texType);
155 st.uniform(gl, texType);
156 st.ownUniform(texUnit0);
157 st.uniform(gl, texUnit0);
158 st.ownUniform(texUnit1);
159 st.uniform(gl, texUnit1);
160
161 st.useProgram(gl, false);
162
163 viewport.set(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
164 initFBO(gl, viewport.width()/2, viewport.height()/2);
165
167 }
168
169 Recti viewport = new Recti();
170 private int fboID, fboWidth, fboHeight;
171 private int colorTexID, depthStencilTexID, stencilViewID; // via textures
172 private int depthStencilRenderID; // via renderbuffer
173 private final boolean useDepthStencilTexture = true;
174 private final int colorAttachmentPoint = 0;
175
176 private void initTexParam(final GL2ES2 gl) {
181 }
182 private void initFBO(final GL4 gl, final int width, final int height) {
183 // Generate a Framebuffer
184 final int tmp[] = { 0, 0 };
185
186 colorTexID=0;
187 depthStencilTexID=0;
188 stencilViewID=0;
189 depthStencilRenderID=0;
190 fboWidth = 0;
191 fboHeight = 0;
192
193 gl.glGenTextures(1, tmp, 0);
194 colorTexID = tmp[0];
195 if (0 == colorTexID) {
196 throw new GLException("XXX");
197 }
198
199 if( useDepthStencilTexture ) {
200 gl.glGenTextures(2, tmp, 0);
201 depthStencilTexID = tmp[0];
202 stencilViewID = tmp[1];
203 if (0 == depthStencilTexID || 0 == stencilViewID) {
204 throw new GLException("XXX");
205 }
206 } else {
207 gl.glGenRenderbuffers(1, tmp, 0);
208 depthStencilRenderID = tmp[0];
209 if (0 == depthStencilRenderID) {
210 throw new GLException("XXX");
211 }
212 }
213
214 gl.glGenFramebuffers(1, tmp, 0);
215 fboID = tmp[0];
216 if (0 == fboID) {
217 throw new GLException("XXX");
218 }
219 gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fboID);
220
221 // color tex
222 {
223 final boolean alpha=true;
224 final int iFormat, dataFormat, dataType;
225 if(gl.isGLES3()) {
226 iFormat = alpha ? GL.GL_RGBA8 : GL.GL_RGB8;
227 dataFormat = alpha ? GL.GL_RGBA : GL.GL_RGB;
228 dataType = GL.GL_UNSIGNED_BYTE;
229 } else if(gl.isGLES()) {
230 iFormat = alpha ? GL.GL_RGBA : GL.GL_RGB;
231 dataFormat = alpha ? GL.GL_RGBA : GL.GL_RGB;
232 dataType = GL.GL_UNSIGNED_BYTE;
233 } else {
234 iFormat = alpha ? GL.GL_RGBA8 : GL.GL_RGB8;
235 // textureInternalFormat = alpha ? GL.GL_RGBA : GL.GL_RGB;
236 // textureInternalFormat = alpha ? 4 : 3;
237 dataFormat = alpha ? GL.GL_BGRA : GL.GL_RGB;
238 dataType = alpha ? GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV : GL.GL_UNSIGNED_BYTE;
239 }
240 gl.glBindTexture(GL.GL_TEXTURE_2D, colorTexID);
241 gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, iFormat, width, height, 0, dataFormat, dataType, null);
242 initTexParam(gl);
243 // gl.glFramebufferTexture(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0, colorTexID, 0);
244 gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0 + colorAttachmentPoint, GL.GL_TEXTURE_2D, colorTexID, 0);
245 }
246
247 if( useDepthStencilTexture ) {
248 gl.glActiveTexture(GL.GL_TEXTURE0 + texUnit0.intValue());
249 gl.glBindTexture(GL.GL_TEXTURE_2D, depthStencilTexID);
250 gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_DEPTH24_STENCIL8, width, height, 0, GL.GL_DEPTH_STENCIL, GL.GL_UNSIGNED_INT_24_8, null);
251 gl.glTexStorage2D(GL.GL_TEXTURE_2D, 1, GL.GL_DEPTH24_STENCIL8, width, height);
252 // conform to GL_TEXTURE_IMMUTABLE_FORMAT
253 gl.glTextureView(stencilViewID, GL.GL_TEXTURE_2D, depthStencilTexID, GL.GL_DEPTH24_STENCIL8, 0, 1, 0, 1);
254 // float zBits = texture2D(tex.uv).r; //access the 24 first bit
255 initTexParam(gl);
256 gl.glTexParameteri (GL.GL_TEXTURE_2D, GL2ES3.GL_DEPTH_STENCIL_TEXTURE_MODE, GL2ES2.GL_DEPTH_COMPONENT);
257
258 gl.glActiveTexture(GL.GL_TEXTURE0 + texUnit1.intValue());
259 gl.glBindTexture(GL.GL_TEXTURE_2D, stencilViewID);
260 initTexParam(gl);
261 gl.glTexParameteri (GL.GL_TEXTURE_2D, GL2ES3.GL_DEPTH_STENCIL_TEXTURE_MODE, GL2ES2.GL_STENCIL_INDEX);
262
263 // gl.glFramebufferTexture(GL.GL_FRAMEBUFFER, GL2ES3.GL_DEPTH_STENCIL_ATTACHMENT, depthStencilTexID, 0);
264 gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL2ES3.GL_DEPTH_STENCIL_ATTACHMENT, GL.GL_TEXTURE_2D, depthStencilTexID, 0);
265 } else {
266 gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, depthStencilRenderID);
267 gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, GL.GL_DEPTH24_STENCIL8, width, height);
268 gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL2ES3.GL_DEPTH_STENCIL_ATTACHMENT, GL.GL_RENDERBUFFER, depthStencilRenderID);
269 }
270 gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0);
271 final int fboStatus = gl.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER);
272 if( GL.GL_FRAMEBUFFER_COMPLETE != fboStatus ) {
273 throw new GLException("FBO not complete, but 0x"+Integer.toHexString(fboStatus));
274 }
275 fboWidth = width;
276 fboHeight = height;
277 }
278 private void disposeFBO(final GL gl) {
279 gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fboID);
280 gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0 + colorAttachmentPoint, GL.GL_TEXTURE_2D, 0, 0);
281 if( useDepthStencilTexture ) {
282 gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_TEXTURE_2D, 0, 0);
283 } else {
284 gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_RENDERBUFFER, 0);
285 }
286 gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_STENCIL_ATTACHMENT, GL.GL_RENDERBUFFER, 0);
287 gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
288 {
289 final int tmp[] = { colorTexID };
290 gl.glDeleteTextures(1, tmp, 0);
291 }
292 if( useDepthStencilTexture ) {
293 final int tmp[] = { depthStencilTexID, stencilViewID };
294 gl.glDeleteTextures(2, tmp, 0);
295 } else {
296 final int tmp[] = { depthStencilRenderID };
297 gl.glDeleteRenderbuffers(1, tmp, 0);
298 }
299 colorTexID=0;
300 depthStencilTexID=0;
301 stencilViewID=0;
302 depthStencilRenderID=0;
303 fboWidth = 0;
304 fboHeight = 0;
305
306 gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0);
307 {
308 final int tmp[] = { fboID };
309 gl.glDeleteFramebuffers(1, tmp, 0);
310 fboID = 0;
311 }
312 }
313 private void resetFBOs(final GL4 gl, final int width, final int height) {
314 if( fboWidth != width || fboHeight != height ) {
315 disposeFBO(gl);
316 initFBO(gl, width, height);
317 }
318 }
319 private void resetStencil(final GL2ES2 gl) {
320 // default
321 gl.glStencilFunc(GL.GL_ALWAYS, 0, 0xFF); // default: ALWAYS, 0, 1s
322 gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP); // default: KEEP, KEEP, KEEP
323 gl.glStencilMask(0xFF); // default: 1s
324 }
325
326 @Override
327 public void dispose(final GLAutoDrawable drawable) {
328 final GL2ES2 gl = drawable.getGL().getGL2ES2();
329 demo.dispose(drawable);
330 disposeFBO(gl);
331 st.destroy(gl);
332
333 sp0 = null;
334 pmvMatrixUniform = null;
335 interleavedVBO = null;
336 }
337
338 @Override
339 public void display(final GLAutoDrawable drawable) {
340 final GL2ES2 gl = drawable.getGL().getGL2ES2();
341
342 {
343 gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
345 }
346
347 {
348 // demo writes to stencil (gears)
349 gl.glViewport(viewport.x(), viewport.y(), fboWidth, fboHeight);
351
353 gl.glStencilFunc(GL.GL_ALWAYS, 1, 0xFF); // default: ALWAYS, 0, 1s
354 gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_REPLACE); // default: KEEP, KEEP, KEEP
355 gl.glStencilMask(0xFF); // default: 1s
356
357 demo.setClearBuffers(true);
358 demo.setClearStencilBuffer(true);
359 demo.display(drawable);
360 resetStencil(gl);
362 gl.glFinish();
363 }
364
365 {
366 // only draw on non '1' stencil (demo or demo2)
367 gl.glViewport(viewport.x(), viewport.y(), fboWidth, fboHeight);
369
370 gl.glStencilFunc(GL.GL_NOTEQUAL, 0, 0xFF); // default: ALWAYS, 0, 1s
371 gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_REPLACE); // default: KEEP, KEEP, KEEP
372 gl.glStencilMask(0x00); // no stencil write
373 if( null != demo2 ) {
374 demo2.display(drawable);
375 } else {
376 demo.setClearBuffers(false);
377 demo.setClearStencilBuffer(false);
378 demo.setGearsColor(-1, 1.0f, 0.8431f, 0.0f, 0.7f);
379 demo.setScale(0.5f);
380 final float panX = -1.4f, panY = -1.0f, panZ = 2.0f;
381 demo.addPanning(panX, panY, panZ);
382 demo.display(drawable);
383 demo.setScale(1.0f);
384 demo.addPanning(-panX, -panY, -panZ);
385 demo.resetGearsColor();
386 }
387 resetStencil(gl);
389 gl.glFinish();
390 }
391 st.useProgram(gl, true);
392 {
393 // FBO color-buffer
394 gl.glViewport(viewport.x(), viewport.y(), fboWidth, fboHeight);
395 texType.setData(0);
396 st.uniform(gl, texType);
397
398 gl.glActiveTexture(GL.GL_TEXTURE0 + texUnit0.intValue());
399 {
400 gl.glBindTexture(GL.GL_TEXTURE_2D, colorTexID);
401 if( !gl.isGLcore() ) {
403 }
404 }
405 interleavedVBO.enableBuffer(gl, true);
406
408
409 interleavedVBO.enableBuffer(gl, false);
410
412
413 gl.glViewport(viewport.x(), viewport.y(), viewport.width(), viewport.height());
414 }
415 {
416 // FBO depth-buffer
417 gl.glViewport(viewport.x()+fboWidth, viewport.y(), fboWidth, fboHeight);
418
419 texType.setData(1);
420 st.uniform(gl, texType);
421
422 gl.glActiveTexture(GL.GL_TEXTURE0 + texUnit0.intValue());
423 {
424 gl.glBindTexture(GL.GL_TEXTURE_2D, depthStencilTexID);
425 if( !gl.isGLcore() ) {
427 }
428 }
429 interleavedVBO.enableBuffer(gl, true);
430
432
433 interleavedVBO.enableBuffer(gl, false);
434
436
437 gl.glViewport(viewport.x(), viewport.y(), viewport.width(), viewport.height());
438 }
439 {
440 // FBO stencil-buffer
441 gl.glViewport(viewport.x()+fboWidth, viewport.y()+fboHeight, fboWidth, fboHeight);
442
443 texType.setData(2);
444 st.uniform(gl, texType);
445
446 gl.glActiveTexture(GL.GL_TEXTURE0 + texUnit1.intValue());
447 {
448 gl.glBindTexture(GL.GL_TEXTURE_2D, stencilViewID);
449 if( !gl.isGLcore() ) {
451 }
452 }
453 interleavedVBO.enableBuffer(gl, true);
454
456
457 interleavedVBO.enableBuffer(gl, false);
458
460
461 gl.glViewport(viewport.x(), viewport.y(), viewport.width(), viewport.height());
462 }
463 st.useProgram(gl, false);
464 }
465
466 @Override
467 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
468 final GL4 gl = drawable.getGL().getGL4();
469
470 viewport.set(x, y, width, height);
471
472 System.err.println("**** Reshape.Reset: "+width+"x"+height);
473 resetFBOs(gl, width/2, height/2);
474
475 gl.glViewport(viewport.x(), viewport.y(), fboWidth, fboHeight);
477 demo.reshape(drawable, x, y, fboWidth, fboHeight);
478 if (null != demo2) {
479 demo2.reshape(drawable, x, y, fboWidth, fboHeight);
480 }
482 gl.glViewport(viewport.x(), viewport.y(), viewport.width(), viewport.height());
483
484 gl.setSwapInterval(swapInterval);
485
487 pmvMatrix.glLoadIdentity();
488 pmvMatrix.glOrthof(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 10.0f);
489
491 pmvMatrix.glLoadIdentity();
492
493 st.useProgram(gl, true);
494 st.uniform(gl, pmvMatrixUniform);
495 st.useProgram(gl, false);
496
497 }
498
499 private static final float[] s_quadVertices = {
500 -1f, -1f, 0f, // LB
501 1f, -1f, 0f, // RB
502 -1f, 1f, 0f, // LT
503 1f, 1f, 0f // RT
504 };
505 private static final float[] s_quadColors = {
506 1f, 1f, 1f, 1f,
507 1f, 1f, 1f, 1f,
508 1f, 1f, 1f, 1f,
509 1f, 1f, 1f, 1f };
510 private static final float[] s_quadTexCoords = {
511 0f, 0f, // LB
512 1f, 0f, // RB
513 0f, 1f, // LT
514 1f, 1f // RT
515 };
516
517 public static void main(final String[] args) {
518 final CommandlineOptions options = new CommandlineOptions(1280, 720, 0);
519 options.setGLProfile(GLProfile.GL4);
520 int demo2Type = 2;
521
522 for (int i = 0; i < args.length; ++i) {
523 if(args[i].equals("-demo2") && i+1 < args.length) {
524 ++i;
525 demo2Type = MiscUtils.atoi(args[i], demo2Type);
526 }
527 }
528
529 System.err.println(VersionUtil.getPlatformInfo());
530 // System.err.println(JoglVersion.getAllAvailableCapabilitiesInfo(dpy.getGraphicsDevice(), null).toString());
531 System.err.println(options);
532
533 final GLCapabilities reqCaps = options.getGLCaps();
534 System.out.println("Requested: " + reqCaps);
535 System.out.println("Demo2 Type: " + demo2Type);
536
537 final GLWindow window = GLWindow.create(reqCaps);
538 if( 0 == options.sceneMSAASamples ) {
540 }
541 window.setSize(options.surface_width, options.surface_height);
542 window.setTitle(GearsFBO02.class.getSimpleName());
543
544 window.addGLEventListener(new GearsFBO02(demo2Type, 1));
545 final Animator animator = new Animator(0 /* w/o AWT */);
546 animator.setUpdateFPSFrames(5*60, null);
547 animator.add(window);
548
549 window.addWindowListener(new WindowAdapter() {
550 @Override
551 public void windowDestroyed(final WindowEvent e) {
552 animator.stop();
553 }
554 });
555
556 window.setVisible(true);
557 animator.start();
558 }
559
560}
Rectangle with x, y, width and height integer components.
Definition: Recti.java:34
void set(final Recti o)
this = o, returns this.
Definition: Recti.java:59
final SyncMatrices4f getSyncPMv()
Returns SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setTitle(final String title)
Definition: GLWindow.java:297
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
Definition: GLWindow.java:882
CapabilitiesChooser setCapabilitiesChooser(final CapabilitiesChooser chooser)
Set the CapabilitiesChooser to help determine the native visual type.
Definition: GLWindow.java:261
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static final String GL4
The desktop OpenGL core profile 4.x, with x >= 0.
Definition: GLProfile.java:569
GLSL uniform data wrapper encapsulating data to be uploaded to the GPU as a uniform.
GLUniformData setData(final int data)
void setClearStencilBuffer(final boolean v)
Definition: GearsES2.java:109
void setGearsColor(final int idx, final float r, final float g, final float b, final float a)
Definition: GearsES2.java:117
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
Definition: GearsES2.java:422
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
Definition: GearsES2.java:186
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
Definition: GearsES2.java:385
void setClearBuffers(final boolean v)
Definition: GearsES2.java:108
void addPanning(final float x, final float y, final float z)
Definition: GearsES2.java:144
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: GearsES2.java:291
FBO demo using a texture attachment for color- and combined depth + stencil-buffer.
Definition: GearsFBO02.java:74
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 dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
GearsFBO02(final int demo2Type, final int swapInterval)
Definition: GearsFBO02.java:88
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.
static void main(final String[] args)
static int atoi(final String str, final int def)
Definition: MiscUtils.java:60
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368
void seal(final GL gl, final boolean seal)
Convenience method calling seal(boolean) and enableBuffer(GL, boolean).
void enableBuffer(final GL gl, final boolean enable)
Enables the buffer if enable is true, and transfers the data if required.
static GLArrayDataServer createGLSLInterleaved(final int compsPerElement, final int dataType, final boolean normalized, final int initialElementCount, final int vboUsage)
Create a VBO for GLSL interleaved array data starting with a new created Buffer object with initialEl...
GLArrayDataWrapper addGLSLSubArray(final String name, final int comps, final int vboTarget)
Configure a segment of this GLSL interleaved array (see createGLSLInterleaved(int,...
Buffer getBuffer()
The Buffer holding the data, may be null if a GPU buffer without client bound data.
PMVMatrix implements a subset of the fixed function pipeline GLMatrixFunc using PMVMatrix4f.
Definition: PMVMatrix.java:62
final void glMatrixMode(final int matrixName)
Sets the current matrix mode.
Definition: PMVMatrix.java:218
final void glOrthof(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar)
Multiply the current matrix with the orthogonal matrix.
Definition: PMVMatrix.java:469
final void glLoadIdentity()
Load the current matrix with the identity matrix.
Definition: PMVMatrix.java:325
Custom GLCapabilitiesChooser, filtering out all full screen anti-aliasing (FSAA, multisample) capabil...
Convenient shader code class to use and instantiate vertex or fragment programs.
Definition: ShaderCode.java:75
final int defaultShaderCustomization(final GL2ES2 gl, final boolean preludeVersion, final boolean addDefaultPrecision)
Default customization of this shader source code.
static ShaderCode create(final GL2ES2 gl, final int type, final int count, final Class<?> context, final String[] sourceFiles, final boolean mutableStringBuilder)
Creates a complete ShaderCode object while reading all shader source of sourceFiles,...
synchronized void add(final ShaderCode shaderCode)
Adds a new shader to this program.
ShaderState allows to sharing data between shader programs, while updating the attribute and uniform ...
void ownAttribute(final GLArrayData attribute, final boolean own)
Binds or unbinds the GLArrayData lifecycle to this ShaderState.
synchronized void useProgram(final GL2ES2 gl, final boolean on)
Turns the shader program on or off.
synchronized boolean attachShaderProgram(final GL2ES2 gl, final ShaderProgram prog, final boolean enable)
Attach or switch a shader program.
synchronized void destroy(final GL2ES2 gl)
Calls release(gl, true, true, true).
boolean uniform(final GL2ES2 gl, final GLUniformData data)
Set the uniform data, if it's location is valid, i.e.
void ownUniform(final GLUniformData uniform)
Bind the GLUniform lifecycle to this ShaderState.
static final int GL_VERTEX_SHADER
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_EXT_vertex_shader, GL_ARB_vertex_shader Alias for: GL_VERTEX_SH...
Definition: GL2ES2.java:39
static final int GL_FRAGMENT_SHADER
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_ATI_fragment_shader, GL_ARB_fragment_shader Alias for: GL_FRAGM...
Definition: GL2ES2.java:585
void glTextureView(int texture, int target, int origtexture, int internalformat, int minlevel, int numlevels, int minlayer, int numlayers)
Entry point to C language function: void {@native glTextureView}(GLuint texture, GLenum target,...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
boolean isGLES()
Indicates whether this GL object conforms to one of the OpenGL ES profiles, see isGLES1(),...
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
GL4 getGL4()
Casts this object to the GL4 interface.
void setSwapInterval(int interval)
Set the swap interval of the current context and attached onscreen GLDrawable.
boolean isGLcore()
Indicates whether this GL object uses a GL core profile.
boolean isGLES3()
Indicates whether this GL object conforms to the OpenGL ES ≥ 3.0 profile.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
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.
void display(GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void init(GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
Called by the drawable during the first repaint after the component has been resized.
void glFramebufferTexture2D(int target, int attachment, int textarget, int texture, int level)
Entry point to C language function: void {@native glFramebufferTexture2D}(GLenum target,...
static final int GL_TEXTURE_MAG_FILTER
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_MAG_FILTER" with expression '...
Definition: GL.java:197
void glDrawArrays(int mode, int first, int count)
Entry point to C language function: void {@native glDrawArrays}(GLenum mode, GLint first,...
static final int GL_ALWAYS
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_ALWAYS" with expression '0x0207',...
Definition: GL.java:209
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...
Definition: GL.java:673
static final int GL_TEXTURE_2D
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_2D" with expression '0x0DE1',...
Definition: GL.java:491
static final int GL_TEXTURE_WRAP_S
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_WRAP_S" with expression '0x28...
Definition: GL.java:485
void glBindTexture(int target, int texture)
Entry point to C language function: void {@native glBindTexture}(GLenum target, GLuint texture) Pa...
static final int GL_FLOAT
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FLOAT" with expression '0x1406',...
Definition: GL.java:786
void glGenTextures(int n, IntBuffer textures)
Entry point to C language function: void {@native glGenTextures}(GLsizei n, GLuint * textures) Par...
void glStencilOp(int fail, int zfail, int zpass)
Entry point to C language function: void {@native glStencilOp}(GLenum fail, GLenum zfail,...
int glCheckFramebufferStatus(int target)
Entry point to C language function: GLenum {@native glCheckFramebufferStatus}(GLenum target) Part ...
void glTexStorage2D(int target, int levels, int internalformat, int width, int height)
Entry point to C language function: void {@native glTexStorage2D}(GLenum target, GLsizei levels,...
void glRenderbufferStorage(int target, int internalformat, int width, int height)
Entry point to C language function: void {@native glRenderbufferStorage}(GLenum target,...
void glGenFramebuffers(int n, IntBuffer framebuffers)
Entry point to C language function: void {@native glGenFramebuffers}(GLsizei n, GLuint * framebuffer...
static final int GL_TEXTURE_MIN_FILTER
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_MIN_FILTER" with expression '...
Definition: GL.java:372
static final int GL_COLOR_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_COLOR_BUFFER_BIT" with expression '0x...
Definition: GL.java:390
void glBindRenderbuffer(int target, int renderbuffer)
Entry point to C language function: void {@native glBindRenderbuffer}(GLenum target,...
void glFramebufferRenderbuffer(int target, int attachment, int renderbuffertarget, int renderbuffer)
Entry point to C language function: void {@native glFramebufferRenderbuffer}(GLenum target,...
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_KEEP
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_KEEP" with expression '0x1E00',...
Definition: GL.java:401
static final int GL_TEXTURE_WRAP_T
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_WRAP_T" with expression '0x28...
Definition: GL.java:489
void glStencilFunc(int func, int ref, int mask)
Entry point to C language function: void {@native glStencilFunc}(GLenum func, GLint ref,...
static final int GL_DEPTH_TEST
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_TEST" with expression '0x0B71',...
Definition: GL.java:43
void glActiveTexture(int texture)
Entry point to C language function: void {@native glActiveTexture}(GLenum texture) Part of GL_ES_V...
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
void glTexParameteri(int target, int pname, int param)
Entry point to C language function: void {@native glTexParameteri}(GLenum target,...
void glStencilMask(int mask)
Entry point to C language function: void {@native glStencilMask}(GLuint mask) Part of GL_ES_VERSIO...
static final int GL_TRIANGLE_STRIP
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TRIANGLE_STRIP" with expression '0x00...
Definition: GL.java:760
void glBindFramebuffer(int target, int framebuffer)
Entry point to C language function: void {@native glBindFramebuffer}(GLenum target,...
static final int GL_NEAREST
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_NEAREST" with expression '0x2600',...
Definition: GL.java:715
void glFinish()
Entry point to C language function: void {@native glFinish}() Part of GL_ES_VERSION_2_0,...
void glViewport(int x, int y, int width, int height)
Entry point to C language function: void {@native glViewport}(GLint x, GLint y, GLsizei width,...
static final int GL_TEXTURE0
GL_ES_VERSION_2_0, GL_VERSION_1_3, GL_VERSION_ES_1_0, GL_ARB_multitexture Alias for: GL_TEXTURE0_ARB ...
Definition: GL.java:71
static final int GL_NOTEQUAL
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_NOTEQUAL" with expression '0x0205',...
Definition: GL.java:114
static final int GL_STENCIL_TEST
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_STENCIL_TEST" with expression '0x0B90...
Definition: GL.java:667
void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, Buffer pixels)
Entry point to C language function: void {@native glTexImage2D}(GLenum target, GLint level,...
static final int GL_REPLACE
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0, GL_EXT_texture Alias for: GL_REPLACE_EXT Defin...
Definition: GL.java:236
static final int GL_DEPTH_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_BUFFER_BIT" with expression '0x...
Definition: GL.java:738
static final int GL_CLAMP_TO_EDGE
GL_ES_VERSION_2_0, GL_VERSION_1_2, GL_VERSION_ES_1_0, GL_SGIS_texture_edge_clamp Alias for: GL_CLAMP_...
Definition: GL.java:775
void glGenRenderbuffers(int n, IntBuffer renderbuffers)
Entry point to C language function: void {@native glGenRenderbuffers}(GLsizei n, GLuint * renderbuff...
static final int GL_FRAMEBUFFER
GL_ES_VERSION_2_0, GL_ARB_framebuffer_object, GL_VERSION_3_0, GL_OES_framebuffer_object,...
Definition: GL.java:630
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...
Definition: GL.java:633
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.