InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Why Using Swing For High Performance Is Not A Good Idea ? |
|
Answer» First, all this inherents all arguments from 'Why using AWT for high performance is not a good idea Second, it involves compositioning using different methods, some may not be available on some platforms. From fast to slow: 1.) External Java2D's GLContext and FBO object.
2.) Own PBuffer GLContext, which has to be composed.
3.) Own Pixmap GLContext, which has to be composed.
As you see, no straight forward HW RENDERING is involved, assuming that even the windowing manager is using offscreen SURFACES - you would have 2 compositions here already. At least (1) would be 'acceptable' here, if available, but if only (2) is available - the performance would not match the STATE of the art! Sure, it might be enough for some UIs or static pictures .. or so, OTHERWISE, I would prefer the 'overlay' method, ie using a GLCanvas within a Swing COMPONENT, while no menu is being shown. However you do it .. the generic AWT 'restrictions' apply here as well. First, all this inherents all arguments from 'Why using AWT for high performance is not a good idea Second, it involves compositioning using different methods, some may not be available on some platforms. From fast to slow: 1.) External Java2D's GLContext and FBO object. 2.) Own PBuffer GLContext, which has to be composed. 3.) Own Pixmap GLContext, which has to be composed. As you see, no straight forward HW rendering is involved, assuming that even the windowing manager is using offscreen surfaces - you would have 2 compositions here already. At least (1) would be 'acceptable' here, if available, but if only (2) is available - the performance would not match the state of the art! Sure, it might be enough for some UIs or static pictures .. or so, otherwise, I would prefer the 'overlay' method, ie using a GLCanvas within a Swing component, while no menu is being shown. However you do it .. the generic AWT 'restrictions' apply here as well. |
|
| 2. |
Why Using Awt For High Performance Is Not A Good Idea ? |
|
Answer» AWT (on many implementations) holds the lock to the underlying native resources, e.g. X11 display, screen and window surface, HENCE we have to obey these locks for any GL action bound to such. This is still PRETTY standard matter as long these locks only have to be applied to the actual resource in use. On AWT, it turns out that we have to use the global JAWT toolkit lock for any native operation, ie OpenGL. This might not be a problem for a single threaded GL application, but if you start a multithreaded beast, you will recognize that it will stumble around. You can verify this BEHAVIOR with the ES1 RedSquare demo:
java demos.es1.RedSquare -awt -swapi 0 -GL2 Even here you MAY experience some stuttering .. If you force disabling the toolkit lock: java -Dnativewindow.nolocking=true demos.es1.RedSquare -awt -swapi 0 -GL2 The demo may freeze FOREVER .. due to native locking.
java -Djava.awt.headless=true demos.es1.RedSquare -swapi 0 -GL2 Runs much smoother .. without the stuttering locking experience .. This becomes much clearer with more threads:
java demos.es1.RedSquare -awt -swapi 0 -GL2 -GL2 -GL2
java -Djava.awt.headless=true demos.es1.RedSquare -swapi 0 -GL2 -GL2 -GL2 AWT (on many implementations) holds the lock to the underlying native resources, e.g. X11 display, screen and window surface, hence we have to obey these locks for any GL action bound to such. This is still pretty standard matter as long these locks only have to be applied to the actual resource in use. On AWT, it turns out that we have to use the global JAWT toolkit lock for any native operation, ie OpenGL. This might not be a problem for a single threaded GL application, but if you start a multithreaded beast, you will recognize that it will stumble around. You can verify this behavior with the ES1 RedSquare demo: java demos.es1.RedSquare -awt -swapi 0 -GL2 Even here you may experience some stuttering .. If you force disabling the toolkit lock: java -Dnativewindow.nolocking=true demos.es1.RedSquare -awt -swapi 0 -GL2 The demo may freeze forever .. due to native locking. java -Djava.awt.headless=true demos.es1.RedSquare -swapi 0 -GL2 Runs much smoother .. without the stuttering locking experience .. This becomes much clearer with more threads: java demos.es1.RedSquare -awt -swapi 0 -GL2 -GL2 -GL2 java -Djava.awt.headless=true demos.es1.RedSquare -swapi 0 -GL2 -GL2 -GL2 |
|
| 3. |
How To Use Newt With Multiple Windows & Threads? |
|
Answer» Newt is capable of handling multiple threads and windows. For best performance, you may CREATE one THREAD per window, if POSSIBLE. Below you see the invocation of the ES2 RedSquare jogl-demos UTILIZING multiple threads.
The serialization of the main Java class through com.sun.javafx.newt.util.MainThread may be used for all platforms, since it only takes effect on MacOSX. This ALLOWS you an almost platform independent invocation of your multithreaded Java applications. Newt is capable of handling multiple threads and windows. For best performance, you may create one thread per window, if possible. Below you see the invocation of the ES2 RedSquare jogl-demos utilizing multiple threads. The serialization of the main Java class through com.sun.javafx.newt.util.MainThread may be used for all platforms, since it only takes effect on MacOSX. This allows you an almost platform independent invocation of your multithreaded Java applications. |
|
| 4. |
What Is Newt's Threading Model For Native Window Events ? |
|
Answer» As of today, Newt's DEFAULT threading model to handle native events is the event DISPATCH thread (EDT) model. Newt's EDT impl. creates one EDT per NEWT Display, as the Display is a unique abstraction of a graphics device connection SERVING all of it's Screens and Windows. EDT is being used to
EDT is not
Using EDT is not mandatory, and you can turn it off in the NewtFactory, and deal with the event dispatch manually. As of today, Newt's default threading model to handle native events is the event dispatch thread (EDT) model. Newt's EDT impl. creates one EDT per NEWT Display, as the Display is a unique abstraction of a graphics device connection serving all of it's Screens and Windows. EDT is being used to EDT is not Using EDT is not mandatory, and you can turn it off in the NewtFactory, and deal with the event dispatch manually. |
|
| 5. |
How To Develop Cross-device Applications? |
|
Answer» First you have to PICK your LOWEST common DENOMINATOR of an OpenGL profile, ie OpenGL ES1 or ES2. For either we offer an intersecting desktop GL profile, GL2ES1 or GL2ES2. Use the latter while creating your GLCapabilities. Build and run your application with the minimum GL profile JARS, e.g. on the desktop use: ~/jogl-demos> . ./setenv-jogl.sh JOGL_GL2ES12_MIN ../jogl/build Here you are on a Unix platform (not Window) and your common build subdirectory is 'build'. jogl-demos/setenv-jogl.sh is provided within jogl-demos, which itself utilizes jogl/etc/profile.jogl. This uses the GlueGen/JOGL JARS:
This uses the GlueGen/JOGL atomic JARS for minimal deployment:
Now, the same Java application shall run on all devices, desktop and mobile. See demos.es1.RedSquare of the jogl-demos repository. On the desktop you may run the ES1 demo: ~/jogl-demos> sh java-run-newt.sh demos.es1.RedSquare -GL2ES1 and the output is: NULL RedSquare.run() 0 GLProfile[GL2ES1/GL2ES12] GL Profile: GLProfile[GL2ES1/GL2ES12] GLProfile[GL2ES1/GL2ES12] GL:com.sun.opengl.impl.gl2es12.GL2ES12Impl@b815859 GLProfile[GL2ES1/GL2ES12] GL_VERSION=3.0.0 NVIDIA 185.18.14 GLProfile[GL2ES1/GL2ES12] GL_EXTENSIONS: .. First you have to pick your lowest common denominator of an OpenGL profile, ie OpenGL ES1 or ES2. For either we offer an intersecting desktop GL profile, GL2ES1 or GL2ES2. Use the latter while creating your GLCapabilities. Build and run your application with the minimum GL profile JARS, e.g. on the desktop use: ~/jogl-demos> . ./setenv-jogl.sh JOGL_GL2ES12_MIN ../jogl/build Here you are on a Unix platform (not Window) and your common build subdirectory is 'build'. jogl-demos/setenv-jogl.sh is provided within jogl-demos, which itself utilizes jogl/etc/profile.jogl. This uses the GlueGen/JOGL JARS: This uses the GlueGen/JOGL atomic JARS for minimal deployment: Now, the same Java application shall run on all devices, desktop and mobile. See demos.es1.RedSquare of the jogl-demos repository. On the desktop you may run the ES1 demo: ~/jogl-demos> sh java-run-newt.sh demos.es1.RedSquare -GL2ES1 and the output is: null RedSquare.run() 0 GLProfile[GL2ES1/GL2ES12] GL Profile: GLProfile[GL2ES1/GL2ES12] GLProfile[GL2ES1/GL2ES12] GL:com.sun.opengl.impl.gl2es12.GL2ES12Impl@b815859 GLProfile[GL2ES1/GL2ES12] GL_VERSION=3.0.0 NVIDIA 185.18.14 GLProfile[GL2ES1/GL2ES12] GL_EXTENSIONS: .. |
|
| 6. |
How To Contribute? |
|
Answer» Basic contributions
At this level, you only need to be able to download and use a JogAmp project like JOGL. Here are some helpful links:
Advanced contributions
Basic contributions At this level, you only need to be able to download and use a JogAmp project like JOGL. Here are some helpful links: Advanced contributions |
|
| 7. |
How To Build Jogl? |
|
Answer» Here are the steps that are required in order to build JOGL.
It is crucial that you checkout the source code under a common root directory: /home/dude/projects/jogamp> git clone --recurse-submodules git://jogamp.org/srv/scm/gluegen.git gluegen /home/dude/projects/jogamp> git clone --recurse-submodules git://jogamp.org/srv/scm/jogl.git jogl Now you should have following directory structure: /home/dude/projects/jogamp Note-1: The GlueGen source must be fetched using -recurse-submodules, which imports JCPP, now used as the default C preprocessor. Note-2: In case you do not get the JOGL sources with -recurse-submodules, you will miss the following features: Note-3: OculusVR Support Unset your CLASSPATH ENVIRONMENT variable: The Ant build requires that the JOGL jars not be visible on the classpath. On Unix, type unsetenv CLASSPATH into a csh or tcsh shell, or unset CLASSPATH into a Bourne shell. On Windows, type set CLASSPATH= into a command prompt. Optional Copy and EDIT gluegen.properties: To specify different basic options for components and compilers, copy gluegen/make/gluegen.properties into your home directory (pointed to by the JAVA system property user.home). Optional Copy and edit jogl.properties: To specify different basic options for the build, copy jogl/make/jogl.properties into your home directory (pointed to by the Java system property user.home). Edit the copy to change desired settings. Build the source tree: Open a command shell in the "gluegen/make" directory of the source tree and type "ant". Then open a command shell in the "jogl/make" directory of the source tree and type "ant". An experimental binding to the high-level Cg language by NVidia corporation can be generated by specifying -Djogl.cg=1 to ant; e.g. ant -Djogl.cg=1. The Cg binding has been tested on Windows, Linux, and Mac OS X. Test your build: Stay in your command shell in the "jogl/make" directory of the source tree and type "ant junit.run". Build Javadoc: Stay in your command shell in the "jogl/make" directory of the source tree and type "ant javadoc.all". This will produce the end-user DOCUMENTATION for JOGL along with some auxiliary utility packages. Note that there are a lot of warnings produced by ANTLR about the C grammar and our modifications to some of the signatures of the productions; the C grammar warnings have been documented by the author of the grammar as having been investigated completely and harmless, and the warnings about our modifications are also harmless. Here are the steps that are required in order to build JOGL. It is crucial that you checkout the source code under a common root directory: /home/dude/projects/jogamp> git clone --recurse-submodules git://jogamp.org/srv/scm/gluegen.git gluegen /home/dude/projects/jogamp> git clone --recurse-submodules git://jogamp.org/srv/scm/jogl.git jogl Now you should have following directory structure: /home/dude/projects/jogamp Note-1: The GlueGen source must be fetched using -recurse-submodules, which imports JCPP, now used as the default C preprocessor. Note-2: In case you do not get the JOGL sources with -recurse-submodules, you will miss the following features: Note-3: OculusVR Support Unset your CLASSPATH environment variable: The Ant build requires that the JOGL jars not be visible on the classpath. On Unix, type unsetenv CLASSPATH into a csh or tcsh shell, or unset CLASSPATH into a Bourne shell. On Windows, type set CLASSPATH= into a command prompt. Optional Copy and edit gluegen.properties: To specify different basic options for components and compilers, copy gluegen/make/gluegen.properties into your home directory (pointed to by the Java system property user.home). Optional Copy and edit jogl.properties: To specify different basic options for the build, copy jogl/make/jogl.properties into your home directory (pointed to by the Java system property user.home). Edit the copy to change desired settings. Build the source tree: Open a command shell in the "gluegen/make" directory of the source tree and type "ant". Then open a command shell in the "jogl/make" directory of the source tree and type "ant". An experimental binding to the high-level Cg language by NVidia corporation can be generated by specifying -Djogl.cg=1 to ant; e.g. ant -Djogl.cg=1. The Cg binding has been tested on Windows, Linux, and Mac OS X. Test your build: Stay in your command shell in the "jogl/make" directory of the source tree and type "ant junit.run". Build Javadoc: Stay in your command shell in the "jogl/make" directory of the source tree and type "ant javadoc.all". This will produce the end-user documentation for JOGL along with some auxiliary utility packages. Note that there are a lot of warnings produced by ANTLR about the C grammar and our modifications to some of the signatures of the productions; the C grammar warnings have been documented by the author of the grammar as having been investigated completely and harmless, and the warnings about our modifications are also harmless. |
|
| 8. |
Jogl, Platform And Opengl Version? |
|
Answer» Please perform a runtime version check, which provides the following information:
SEND us the resulting file test.log Detailed Bug Information
Applications Adding a comprehensive junit test would help us the most to reproduce the bug, to discuss it with you and to achieve a good response time. You may add it to your bug report directly or better, give us your git repository pull request. If possible, please add the following system properties to enable DEBUG logging: -Dnewt.debug=all -Dnativewindow.debug=all -Djogl.debug=all For example: java -Djava.awt.headless=true -Dnewt.debug=all -Dnativewindow.debug=all -Djogl.debug=all demos.es2.RedSquare 2>&1 | tee RedSquare.report.log Attach the log file to your bug report .. Applets and Java Webstart To test applets and javaws use
where you add the following JRE ARGUMENTS. The jnlp prefix supports the javaws launch method.
Of course you have to add these arguments to all of your JRE lines, ie 0 and 1, etc, if they exist. You also want to
Hence the java properties file (see location above) shall contain the following: ... Best practice:
Please perform a runtime version check, which provides the following information: Send us the resulting file test.log Detailed Bug Information Applications Adding a comprehensive junit test would help us the most to reproduce the bug, to discuss it with you and to achieve a good response time. You may add it to your bug report directly or better, give us your git repository pull request. If possible, please add the following system properties to enable DEBUG logging: -Dnewt.debug=all -Dnativewindow.debug=all -Djogl.debug=all For example: java -Djava.awt.headless=true -Dnewt.debug=all -Dnativewindow.debug=all -Djogl.debug=all demos.es2.RedSquare 2>&1 | tee RedSquare.report.log Attach the log file to your bug report .. Applets and Java Webstart To test applets and javaws use where you add the following JRE Arguments. The jnlp prefix supports the javaws launch method. Of course you have to add these arguments to all of your JRE lines, ie 0 and 1, etc, if they exist. You also want to Hence the java properties file (see location above) shall contain the following: ... Best practice: |
|
| 9. |
Jogl Demos? |
|
Answer» Let’s assume we are in the test directory ‘test’, from which we operate from this point.
We assume java is in your binary search PATH. On X11/Unix and MaxOSX you can test the build as follows: sh java-run-newt.sh demos.es2.RedSquare -GL2 -GL2 -GL2 On Windows you shall be able to run: java-win32.bat demos.es2.RedSquare -GL2 -GL2 -GL2 The windows scripts are pretty simple and flat. The magic unix scripts offer more features and can be used either in the autobuild environment or in your development one.
JOGL profiles are one of JOGL_ALL, JOGL_ES1_MIN, JOGL_ES1_MAX, JOGL_ES2_MIN, JOGL_ES2_MAX, JOGL_GL2ES12_MIN, JOGL_GL2ES12_MAX, JOGL_GL2_MIN, JOGL_GL2_MAX. Looks up the set of JAR files necessary to SATISFY the chosen JOGL-PROFILE. This allows you to test a specific environment, ie ES2 without GL2 and AWT, using JOGL_ES2_MIN. For this case I would recommend the native ES2 implementation from imageon SDK_OGLES2_LINUX_PCEMULATION_2.02.22.0756. Let’s assume we are in the test directory ‘test’, from which we operate from this point. We assume java is in your binary search path. On X11/Unix and MaxOSX you can test the build as follows: sh java-run-newt.sh demos.es2.RedSquare -GL2 -GL2 -GL2 On Windows you shall be able to run: java-win32.bat demos.es2.RedSquare -GL2 -GL2 -GL2 The windows scripts are pretty simple and flat. The magic unix scripts offer more features and can be used either in the autobuild environment or in your development one. JOGL profiles are one of JOGL_ALL, JOGL_ES1_MIN, JOGL_ES1_MAX, JOGL_ES2_MIN, JOGL_ES2_MAX, JOGL_GL2ES12_MIN, JOGL_GL2ES12_MAX, JOGL_GL2_MIN, JOGL_GL2_MAX. Looks up the set of JAR files necessary to satisfy the chosen JOGL-PROFILE. This allows you to test a specific environment, ie ES2 without GL2 and AWT, using JOGL_ES2_MIN. For this case I would recommend the native ES2 implementation from imageon SDK_OGLES2_LINUX_PCEMULATION_2.02.22.0756. |
|
| 10. |
Runtime Version Check? |
|
Answer» The SIMPLEST VERIFICATION of a JOGL build is to use the RUNTIME version check and the runtime debug TEST. The simplest verification of a JOGL build is to use the runtime version check and the runtime debug test. |
|
| 11. |
What Are The Runtime Opengl Version Requirements ? |
|
Answer» The current JOGL2 spec is in WIP state, but mostly FINISHED. We do not require any extra features of GL versions > 1.1, hence it shall just work. E.g. if you want to
Just query their availability e.g.: gl.isExtensionAvailable("GL_VERSION_1_3") If you call a > 1.2 GL function where it is not available, a GLException is thrown. JOGL requires at LEAST an OpenGL version 1.1, DUE to its dynamical function binding STARTING with OpenGL 1.2. The current JOGL2 spec is in WIP state, but mostly finished. We do not require any extra features of GL versions > 1.1, hence it shall just work. E.g. if you want to Just query their availability e.g.: gl.isExtensionAvailable("GL_VERSION_1_3") If you call a > 1.2 GL function where it is not available, a GLException is thrown. JOGL requires at least an OpenGL version 1.1, due to its dynamical function binding starting with OpenGL 1.2. |
|
| 12. |
When I Use Feature X My Drawing Suddenly Drops To Glacial Speeds. |
|
Answer» Typically this is a sign that the drivers have defaulted BACK to SOFTWARE rendering (particularly in the case of shaders). Alternatively, you may not be picking up the correct native drivers for your video CARD (on Win32, this seems to happen alarmingly often). CHECK that your drivers are up to date and that the features you want are supported in hardware. You may have to scale back your TECHNIQUES to keep it in pure hardware. Typically this is a sign that the drivers have defaulted back to software rendering (particularly in the case of shaders). Alternatively, you may not be picking up the correct native drivers for your video card (on Win32, this seems to happen alarmingly often). Check that your drivers are up to date and that the features you want are supported in hardware. You may have to scale back your techniques to keep it in pure hardware. |
|
| 13. |
Nothing Is Being Drawn In A Canvas In Fullscreen Mode? |
|
Answer» A PROBLEM that seems to be inherent in mixing swing with heavyweight components on a Win32 system (Java3D suffers from the same problem, for example). This is due to some INTERACTIONS with DirectDraw. To get the rendering HAPPENING again, SET the following property on the command line to DISABLE DirectDraw usage: -Dsun.java2d.noddraw=true. A problem that seems to be inherent in mixing swing with heavyweight components on a Win32 system (Java3D suffers from the same problem, for example). This is due to some interactions with DirectDraw. To get the rendering happening again, set the following property on the command line to disable DirectDraw usage: -Dsun.java2d.noddraw=true. |
|
| 14. |
Net.java.games.jogl.glexception: Unable To Lock Surface? |
|
Answer» JOGL appears to have some very weird internal setup TIMING that CAUSES problems in odd ways. This exception comes when you have ATTEMPTED to do something to the GLCanvas before adding it to another component that is not already visible. To avoid this, make SURE you call setVisible(true) on the containing Frame/Window before adding the GLCanvas. JOGL appears to have some very weird internal setup timing that causes problems in odd ways. This exception comes when you have attempted to do something to the GLCanvas before adding it to another component that is not already visible. To avoid this, make sure you call setVisible(true) on the containing Frame/Window before adding the GLCanvas. |
|