Michael Bien's Weblog don't panic http://michael-bien.com/mbien/feed/entries/atom 2011-02-01T02:32:14+01:00 Apache Roller (incubating) http://michael-bien.com/mbien/entry/java_binding_for_the_opencl Java Binding for the OpenCL API mbien 2010-09-10T22:49:42+02:00 2010-09-11T17:37:34+02:00 <p> I am currently working on Java Binding for the <a href="http://en.wikipedia.org/wiki/Opencl">OpenCL</a> API using <a href="http://jogamp.org/gluegen/www/">GlueGen</a> (as used in <a href="http://jogl.jogamp.org">JOGL</a>, <a href="http://joal.jogamp.org">JOAL</a>). The project started as part of my bachelor of CS thesis short after the release of the first OpenCL specification draft and is now fully feature complete with OpenCL 1.1. <a href="http://jogamp.org/jocl/www/">JOCL</a> is currently in the stabilization phase, a beta release shouldn't be far away. </p> <h3>Overview - How does it work?</h3> JOCL enables applications running on the JVM to use OpenCL for massively parallel, high performance computing tasks, executed on heterogeneous hardware (GPUs, CPUs, FPGAs etc) in a platform independent manner. JOCL consists of two parts, the low level and the high level binding. <p> The <b>low level bindings (LLB)</b> are automatically generated using the official OpenCL <a href="http://www.khronos.org/registry/cl/">headers</a> as input and provide a high performance, JNI based, 1:1 mapping to the C functions. </p> <p>This has the following advantages:</p> <ul> <li>reduces maintenance overhead and ensures spec conformance</li> <li>compiletime JNI bindings are the fastest way to access native libs from the JVM</li> <li>makes translating OpenCL C code into Java + JOCL very easy (e.g. from books or tutorials)</li> <li>flexibility and stability: OpenCL libs are loaded dynamically and accessed via function pointers</li> </ul> <p> The hand written <b>high level bindings (HLB)</b> is build on top of LLB and hides most boilerplate code (like object IDs, pointers and resource management) behind easy to use java objects. HLB use direct NIO buffers internally for fast memory transfers between the JVM and the OpenCL implementation and is very GC friendly. Most of the API is designed for method chaining but of course you don't have to use it this way if you don't want to. JOCL also seamlessly integrates with JOGL 2 (both are built and tested together). Just pass the JOGL context as parameter to the JOCL context factory and you will receive a shared context. If you already know OpenCL and Java, HLB should be very intuitive for you. </p> <p> The project is available on <a href="http://jocl.jogamp.org">jogamp.org</a>. Please use the <a href="http://jogamp.org/forum.html">mailinglist / forum</a> for feedback or questions and the <a href="http://jogamp.org/bugzilla/">bugtracker</a> if you experience any issues. The JOCL <a href="http://github.com/mbien/jocl">root repository</a> is located on github, you may also want to take a look at the <a href="http://github.com/mbien/jocl-demos">jocl-demos</a> project. (If the demos are not enough you might also want to take a look at the junit tests) </p> <h3>Screenshots (sourcecode in jocl-demos project):</h3> <a href="http://jogamp.org/jocl/www/Julia3d.png"><img src="http://jogamp.org/jocl/www/Julia3d_sm.png" width="400" height="300" alt="JOCL Julia Set"></img></a> <img src="http://jogamp.org/jocl/www/mandelbrot64_sm.png" width="256" height="256" alt="high precision"></img> <p> More regarding OpenGL interoperability and other features in upcoming blog entries. </p> <p> The following sample shows basic setup, computation and cleanup using the high level APIs. </p> <h3>Hello World or parallel a+b=c</h3> <pre class="brush: java;"> /** * Hello Java OpenCL example. Adds all elements of buffer A to buffer B * and stores the result in buffer C. * Sample was inspired by the Nvidia VectorAdd example written in C/C++ * which is bundled in the Nvidia OpenCL SDK. * @author Michael Bien */ public class HelloJOCL { public static void main(String[] args) throws IOException { // Length of arrays to process (arbitrary number) int elementCount = 11444777; // Local work size dimensions int localWorkSize = 256; // rounded up to the nearest multiple of the localWorkSize int globalWorkSize = roundUp(localWorkSize, elementCount); // setup CLContext context = CLContext.create(); CLProgram program = context.createProgram( HelloJOCL.class.getResourceAsStream("VectorAdd.cl") ).build(); CLBuffer&lt;FloatBuffer&gt; clBufferA = context.createFloatBuffer(globalWorkSize, READ_ONLY); CLBuffer&lt;FloatBuffer&gt; clBufferB = context.createFloatBuffer(globalWorkSize, READ_ONLY); CLBuffer&lt;FloatBuffer&gt; clBufferC = context.createFloatBuffer(globalWorkSize, WRITE_ONLY); out.println("used device memory: " + (clBufferA.getSize()+clBufferB.getSize()+clBufferC.getSize())/1000000 +"MB"); // fill read buffers with random numbers (just to have test data). fillBuffer(clBufferA.getBuffer(), 12345); fillBuffer(clBufferB.getBuffer(), 67890); // get a reference to the kernel functon with the name 'VectorAdd' // and map the buffers to its input parameters. CLKernel kernel = program.createCLKernel("VectorAdd"); kernel.putArgs(clBufferA, clBufferB, clBufferC).putArg(elementCount); // create command queue on fastest device. CLCommandQueue queue = context.getMaxFlopsDevice().createCommandQueue(); // asynchronous write to GPU device, // blocking read later to get the computed results back. long time = nanoTime(); queue.putWriteBuffer(clBufferA, false) .putWriteBuffer(clBufferB, false) .put1DRangeKernel(kernel, 0, globalWorkSize, localWorkSize) .putReadBuffer(clBufferC, true); time = nanoTime() - time; // cleanup all resources associated with this context. context.release(); // print first few elements of the resulting buffer to the console. out.println("a+b=c results snapshot: "); for(int i = 0; i < 10; i++) out.print(clBufferC.getBuffer().get() + ", "); out.println("...; " + clBufferC.getBuffer().remaining() + " more"); out.println("computation took: "+(time/1000000)+"ms"); } private static final void fillBuffer(FloatBuffer buffer, int seed) { Random rnd = new Random(seed); while(buffer.remaining() != 0) buffer.put(rnd.nextFloat()*100); buffer.rewind(); } private static final int roundUp(int groupSize, int globalSize) { int r = globalSize % groupSize; if (r == 0) { return globalSize; } else { return globalSize + groupSize - r; } } } </pre> <h3>VectorAdd.cl</h3> <pre class="brush: GLSL;"> // OpenCL Kernel Function for element by element vector addition kernel void VectorAdd(global const float* a, global const float* b, global float* c, int numElements) { // get index into global data array int iGID = get_global_id(0); // bound check (equivalent to the limit on a 'for' loop) if (iGID >= numElements) { return; } // add the vector elements c[iGID] = a[iGID] + b[iGID]; } </pre> http://michael-bien.com/mbien/entry/new_getting_started_with_jogl New Getting Started with JOGL 2 tutorials mbien 2010-09-04T00:22:38+02:00 2010-09-04T00:22:38+02:00 <p> Thanks to <a href="https://sites.google.com/site/justinscsstuff/Home">Justin Stoecker</a>, computer science graduate student at the University of Miami, JOGL gets a new set of getting started tutorials: </p> <i> <p> JOGL, or Java Bindings for OpenGL, allows Java programs to access the OpenGL API for graphics programming. The graphics code in JOGL programs will look almost identical to that found in C or C++ OpenGL programs, as the API is automatically generated from C header files. This is one of the greatest strengths of JOGL, as it is quite easy to port OpenGL programs written in C or C++ to JOGL; learning JOGL is essentially learning OpenGL[...] </p> </i> <h3>Tutorials:</h3> <ul> <li><a href="https://sites.google.com/site/justinscsstuff/jogl-tutorials">index</a></li> <li><a href="https://sites.google.com/site/justinscsstuff/jogl-tutorial-1">Tutorial 1 - Environment Setup</a></li> <li><a href="https://sites.google.com/site/justinscsstuff/jogl-tutorial-2">Tutorial 2 - Creating a Window</a></li> <li><a href="https://sites.google.com/site/justinscsstuff/jogl-tutorial-3">Tutorial 3 - Creating a Render Loop</a></li> </ul> Thanks Justin!<br/> http://michael-bien.com/mbien/entry/jogl_2_composeable_pipline JOGL 2 - Composeable Pipline mbien 2010-08-25T15:27:31+02:00 2010-08-25T15:27:31+02:00 JOGL provides a feature called 'composeable pipeline' which can be quite useful in some situations. It enables you to put additional delegating layers between your java application and the OpenGL driver. A few usecases could be: <ul> <li>performance metrics</il> <li>logging, debugging or diagnostics</il> <li>to ignore specific function calls</il> </ul> It is very easy to set up. Just put this line into your code and the DebugGL layer will throw a GLException as soon an error occurs (you want this usually when you are developing the software). <pre class="brush: java;"> public void init(GLAutoDrawable drawable) { // wrap composeable pipeline in a Debug utility, all OpenGL error codes are automatically // converted to GLExceptions as soon as they appear drawable.setGL(new DebugGL3(drawable.getGL().getGL3())); //.. } </pre> Another predefined layer is TraceGL which intercepts all OpenGL calls and prints them to an output stream. <pre class="brush: java;"> drawable.setGL(new TraceGL3(drawable.getGL().getGL3(), System.out)); </pre> see also <a href="http://michael-bien.com/mbien/entry/jogl_2_opengl_profiles_explained">GL Profiles</a> <br/> http://michael-bien.com/mbien/entry/converting_from_cvs_to_git Converting from CVS to GIT mbien 2010-06-09T22:37:38+02:00 2010-06-09T22:39:16+02:00 <p> This post is a short description how to convert a CVS repository into GIT. I used the tool <a href="http://cvs2svn.tigris.org/cvs2git.html">cvs2svn</a> from Tigris.org for this task. As an example I will use the project <a href="http://bytonic.de/html/jake2.html">jake2</a>. </p> <h3>0. Install cvs2svn and cvs</h3> ('cvs2svn' not only does cvs2svn conversion it also contains the shell commands cvs2git and cvs2bzr) <pre class="brush: bash;"> sudo apt-get install cvs sudo apt-get install cvs2svn </pre> <h3>1. Download the CVS repository</h3> This is mandatory. In contrary to SVN you can't just read out the complete versioning history just by using the CVS protocol. To convert from CVS you will need direct file access to the repository. <p> Sourceforge for example supports repository synchronization via rsync to allow backups. Thats what I used to get a copy of the jake2 repository. </p> <pre class="brush: bash;"> rsync -av rsync://jake2.cvs.sourceforge.net/cvsroot/jake2/* . </pre> <h3>2. Convert into GIT fast-import format</h3> Take a look at <i>/usr/share/doc/cvs2svn/examples/cvs2git-example.options.gz</i> and extract the example configuration file. The file is very good documented so I won't repeat things here. But the most important step is to provide an author mapping from cvs to git authors (search for 'author_transforms'). <pre class="brush: bash;"> cvs2git --options=cvs2git.options </pre> <p> This will produce a dump and blob file for step 3. </p> <h3>3. Create GIT repository and import CVS history</h3> <pre class="brush: bash;"> mkdir gitrepo cd gitrepo git init cat ../repo-tmp/git-blob.dat ../repo-tmp/git-dump.dat | git fast-import </pre> <h3>4. Manual cleanup</h3> cvs2git will do its best to convert tags and branches into git tags and branches and usually add an artificial commit do document that. Now you will probably want to take a look at the repository with a history browser like gitk or giggle... and clean it up a bit. E.g remove branches which could be tags etc. If this is to much work you might consider to tweak the configuration of step 2 and convert again with different strategies. <br/><br/> - - - - <p> btw you can find the jake2 git repo <a href="http://github.com/mbien/jake2">here</a>. </p> http://michael-bien.com/mbien/entry/you_have_won_the_jackpot You have won the Jackpot 3.0 mbien 2010-06-03T23:16:27+02:00 2010-06-03T23:20:16+02:00 You probably remember the project called <b>Jackpot</b> which <a href="http://nighthacks.com/roller/jag/">James Gosling</a> was initially involved with. It was basically a way to migrate client code between incompatible third party libraries by specifying refactoring rules. The project was that good integrated into NetBeans that it looked dead from the outside for a long time, since it was only used internally. NetBeans 6.9 uses Jackpot for most of the in-code hints for instance. <p> There where various ways to specify the transformation rules, e.g. via a special <a href="http://bitbucket.org/jlahoda/jackpot30/wiki/RulesLanguage">declarative language</a> or even in <a href="https://lang.dev.java.net/">Annotations</a> directly in the library-code which would cause incompatibilities (or e.g in conjunction with @Deprecated). </p> <p> Jan Lahoda recently started with the efforts to make the project usable as standalone tool again. Jackpot 3.0 is available via <a href="http://bitbucket.org/jlahoda/jackpot30/wiki/Home">bitbucket</a> for early adopters. </p> <h3>Back to the Future</h3> I used this opportunity to test jackpotc (the jackpot compiler) with <a href="http://jogamp.org">JOGL</a>. What I tired is to provide transformations which transform old JOGL 1.1.1 code into latest JOGL 2 compatible client code. So firstly thanks to Jan for fixing all the bugs we run into while testing the experimental commandline compiler. <p> The first thing I did was to transform the code to properly use OpenGL <a href="http://michael-bien.com/mbien/entry/jogl_2_opengl_profiles_explained">profiles</a>. As testcode i will use the famous Gears OpenGL demo (but those kind of automatic transformations will only pay of if you use them on large codebases). Since it was written against JOGL 1.1.1 it can only use OpenGL up to version 2.x, which means we can simply use the GL2 profile. </p> <h3>Transformation Rules</h3> <pre class="brush: java;"> 'JOGL2 API change: javax.media.opengl.GL -> javax.media.opengl.GL2': javax.media.opengl.GL=>javax.media.opengl.GL2;; 'JOGL2 API change: new javax.media.opengl.GLCapabilities(javax.media.opengl.GLProfile)': new javax.media.opengl.GLCapabilities()=> new javax.media.opengl.GLCapabilities(javax.media.opengl.GLProfile.get(javax.media.opengl.GLProfile.GL2));; 'JOGL2 API change: GL gl = drawable.getGL() -> GL2 gl = drawable.getGL().getGL2()': $d.getGL() :: $d instanceof javax.media.opengl.GLAutoDrawable=> $d.getGL().getGL2();; </pre> <p> Just by looking at the transformation rules you can easily see that it is far more powerfull as any simple text replacement could be. Jackpot uses javac and can therefore work with full qualified names, <i>instanceof</i> and more. It will also correctly fix imports for you (there is currently a open bug in this area). The quotes are used as description string which will be printed when jackpotc runs on every code occurrence which applies. </p> <h3>Invoking Jackpot</h3> <pre class="brush: bash;"> jackpotc -sourcepath $SRC -cp $LIBS -d $OUTPUT\ -Ajackpot30_extra_hints=./jogl1Tojogl2.hint $FILESET </pre> <p> <b>$LIBS</b> must contain both library versions, JOGL 1.1.1 and JOGL 2. This is not optimal but it will probably work in most situations to just use both without thinking about an particular ordering or the need to do multiple iterations. </p> <h3>Results</h3> If everything runs fine the console output should look like the sample below for each transformation which applies for the given <b>$FILESET</b>: <pre class="brush: java; wrap-lines: true"> ./test/oldgears/src/jogl111/gears/Gears.java:54: warning: JOGL2 API change: GL gl = drawable.getGL() -> GL2 gl = drawable.getGL().getGL2() GL gl = drawable.getGL(); ... </pre> The final result is a diff patch located in <b>$OUTPUT/META_INF/upgrade</b> called <b>upgrade.diff</b> containing the complete changeset for the transformation. Now the only thing you have to do is to review the changes and apply them. <pre class="brush: java"> @@ -51,7 +51,7 @@ // Use debug pipeline // drawable.setGL(new DebugGL(drawable.getGL())); - GL gl = drawable.getGL(); + GL2 gl = drawable.getGL().getGL2(); ... </pre> <p> You can find the complete demo and all ready-to-run shellscripts in the tools/jackpotc folder inside JOGL's git <a href="http://github.com/mbien/jogl">repository</a>. The classic JOGL 2 Gears demo can be found in form of an applet <a href="http://jogamp.org/jogl-demos/www/applettest-jnlp.html">here</a> (uses latest hudson builds... can be unstable). </p> <p> happy coding! </p> <br/> - - - -<br/> The JOGL repositories are open for contributions. If you would like to add some rules or fix other things... feel free to fork the repos on github and commit to them. (same rule applies for all <a href="http://jogamp.org/">JogAmp</a> Projects like JOCL, JOAL, GlueGen... etc) <br/> http://michael-bien.com/mbien/entry/jogamp_at_siggraph_2010 JogAmp at SIGGRAPH 2010 mbien 2010-05-23T21:17:07+02:00 2010-05-23T21:17:07+02:00 <b>The <a href="http://jogamp.org/">JogAmp</a> team will be present at <a href="http://www.siggraph.org/s2010">SIGGRAPH</a> this year:</b> <pre> 3D & Multimedia Across Platforms and Devices Using JOGL Tuesday, 27 July | 4:00 PM - 6:00 PM This session discusses the features, contributions, and future of OpenGL, OpenCL, and OpenMax across devices and OS exposed on top of Java using the JogAmp open-source libraries. </pre> <a href="http://www.siggraph.org/s2010/for_attendees/birds_feather">link to Session</a><br/><br/> hope to meet you there.<br/><br/> <b>about <a href="http://jogamp.org/">JogAmp</a>.</b><br/> <i>JogAmp is the home of high performance Java libraries for 3D Graphics, Multimedia and Processing. JogAmp consists currently of the projects JOGL, JOCL and JOAL which provide cross platform language bindings to the OpenGL, OpenCL, OpenAL and OpenMAX APIs.</i><br/><br/> <object width="640" height="385"><param name="movie" value="http://www.youtube-nocookie.com/v/hTNfGZTnp3c&hl=en_US&fs=1&hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/hTNfGZTnp3c&hl=en_US&fs=1&hd=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object><br/> - - - -<br/> (yes i know i should start bogging again :))<br/><br/> http://michael-bien.com/mbien/entry/netbeans_git_plugin NetBeans GIT support mbien 2009-09-06T17:15:41+02:00 2009-09-06T17:23:45+02:00 <p> If you are using <a href="http://git-scm.com/">GIT</a> as SCM and NetBeans as IDE you should probably check out <a href="http://nbgit.org/">NBGit</a>. The plugin integrates GIT in NetBeans in the same way as the out of the box Mercurial support does it. In fact both modules have the same origin since nbgit is a fork of the mercurial integration project and incrementally adds features to catch up. </p> <p> <a href="http://code.google.com/p/nbgit/wiki/News">NBGit Version 0.3</a> is already fairly stable and provides the basic set of features you would expect from distributed versioning system IDE integration. </p> <h3>Features</h3> <ul> <li>Graph visualization of parallel branches (Browser similar to giggle)</li> <li>Versioning History (git log)</li> <li>Show changes (git status)</li> <li>update/commit/reset</li> <li>clone/clone other/git init</li> <li>custom actions (custom git commands)</li> <li>diff</li> <li>in-editor annotation of code changes</li> <li>ignore files (parsing '.gitignore' files)</li> <li>git properties (username, email etc via options)</li> </ul> <p> The project is developed by volunteers outside Sun, if you like to see GIT integration as out-of-the-box feature in a future version of NetBeans <a href="http://www.netbeans.org/issues/show_bug.cgi?id=131531">please vote for this RFE</a>. </p> <p> I use the plugin for most of my open source projects and haven't experience any serious issues so far. I would say its already safe to use since you can't do anything wrong if you do a 'git status' -> 'git push' via command line as last step anyway. </p> <h3>Screenshots</h3> <p> <img src="http://people.fh-landshut.de/~mbien/weblog/nbgit/gitshowcase_sm.png" alt="showcase shot"/> </p> <p> <img src="http://people.fh-landshut.de/~mbien/weblog/nbgit/clone.png" alt="clone shot"/> <img src="http://people.fh-landshut.de/~mbien/weblog/nbgit/in-editor.png" alt="editor shot"/> </p> http://michael-bien.com/mbien/entry/jogl_2_opengl_profiles_explained JOGL 2 - OpenGL Profiles explained mbien 2009-08-22T20:20:41+02:00 2010-06-16T21:13:09+02:00 <p> <b>June 16 2010, updated blogpost: OpenGL 4</b> </p> <p> JOGL 2 supports several OpenGL Profiles. In this blog entry I try to explain what profiles are and why they are needed.</p><h3>History</h3><p>SGI released the first OpenGL specification 1992. Since this point OpenGL 1.x constantly evolved (under the ARB and later Khronos Group) by adding new functions to the core API. This went well until programmable graphics hardware became mainstream and shaders became suddenly more flexible and efficient as the generic fixed function pipeline.</p><p> OpenGL 2.x was the last version in which you could freely mix the fixed function pipeline with the programmable pipeline (as a core feature).</p> <a href="http://www.khronos.org/news/press/releases/khronos-releases-opengl-3.2-third-major-opengl-release-within-twelve-months/"> <img src="http://www.opengl.org/img/uploads/news/OpenGL-3-evolution_sml.jpg" class="left" alt=""/></a> <p> With the release of OpenGL 3.0 the whole fixed function pipeline has been deprecated but you could still use it if you haven't requested a forward compatible context.</p><p> OpenGL 3.1 and 3.2 removed most deprecated functionality from core specification, however some implementations (e.g. Nvidia drivers) still allow to get them back via an optional compatibility extension. Since 3.1 was the first release which broke compatibility, it is often seen as major OpenGL 3 release. <br /></p> <h3>JOGL 2 (JSR 231)<br /></h3> <p>JOGL 1.1.1 lived in the timeframe up to OpenGL 3.0 which made it easy to stay in sync with the spec. To be able to solve the issue with the deprecation of functionality, JOGL 2 (JSR maintenance release) introduces an abstraction of the original OpenGL versioning called Profile. Profiles allow Java applications to be written in a way which allows compatibility with multiple OpenGL versions at the same time. Since OpenGL ES (GL for embedded systems) has overlapping functionality with OpenGL itself it opened the opportunity to add even Profiles which bridge desktop and embedded implementations. The class diagram below shows the dependencies between <a href="http://jogamp.org/jogl/doc/bouml/html-svg/">all available Profiles</a>.<br /> </p> <p> <embed src="http://jogamp.org/jogl/doc/bouml/html-svg/fig128069.svg" width="735" height="600"/> </p> <p> Before you start writing a JOGL application you will have to decide first which GLProfile you want to use. The code snippet below lists all currently supported profiles (extracted from <a href="http://jogamp.org/deployment/jogl-next/javadoc_public/javax/media/opengl/GLProfile.html">GLProfile</a>). </p> <br/> <h3>Current list of supported profiles and their mapping to the implementation versions</h3> <pre class="brush: java;"> /** The desktop OpenGL compatibility profile 4.x, with x >= 0, ie GL2 plus GL4.<br> <code>bc</code> stands for backward compatibility. */ public static final String GL4bc = "GL4bc"; /** The desktop OpenGL core profile 4.x, with x >= 0 */ public static final String GL4 = "GL4"; /** The desktop OpenGL compatibility profile 3.x, with x >= 1, ie GL2 plus GL3.<br> <code>bc</code> stands for backward compatibility. */ public static final String GL3bc = "GL3bc"; /** The desktop OpenGL core profile 3.x, with x >= 1 */ public static final String GL3 = "GL3"; /** The desktop OpenGL profile 1.x up to 3.0 */ public static final String GL2 = "GL2"; /** The embedded OpenGL profile ES 1.x, with x >= 0 */ public static final String GLES1 = "GLES1"; /** The embedded OpenGL profile ES 2.x, with x >= 0 */ public static final String GLES2 = "GLES2"; /** The intersection of the desktop GL2 and embedded ES1 profile */ public static final String GL2ES1 = "GL2ES1"; /** The intersection of the desktop GL3, GL2 and embedded ES2 profile */ public static final String GL2ES2 = "GL2ES2"; /** The intersection of the desktop GL3 and GL2 profile */ public static final String GL2GL3 = "GL2GL3"; </pre> <p> <i>Note: GL2 Profile supports OpenGL up to version 3.0 (included) - this is not a bug: OpenGL 3.1 was the big game changer</i> </p> <p> The next two code snippets show the basic steps how to set up OpenGL with JOGL 2. </p> <h3>Context creation</h3> <pre class="brush: java;"> //create a profile, in this case OpenGL 3.1 or later GLProfile profile = GLProfile.get(GLProfile.GL3); //configure context GLCapabilities capabilities = new GLCapabilities(profile); capabilities.setNumSamples(2); // enable anti aliasing - just as a example capabilities.setSampleBuffers(true); //initialize a GLDrawable of your choice GLCanvas canvas = new GLCanvas(capabilities); //register GLEventListener canvas.addGLEventListener(...); //... (start rendering thread -> start rendering...) </pre> <br/> <h3>Rendering</h3> <pre class="brush: java;"> public void display(GLAutoDrawable drawable) { GL3 gl = drawable.getGL().getGL3(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); //.. render something } </pre> <h3>Summary</h3> <p> Profiles make JOGL 2 very flexible and allow it to build modular and portable applications. For instance part A of an application can be written against the GL2ES2 interface and part B (which is more hardware specific) against the GL3 interface. This would in theory allow to reuse A in an embedded application and B could e.g. disable itself on old desktop hardware which runs only OpenGL 2.x or fall back to a GL2 implementation. </p> <p> More information can be found on <a href="http://jogamp.org">JogAmp.org</a> (<a href="http://jogamp.org/deployment/jogl-next/javadoc_public/">direct link to javadoc</a>) </p> <p> The next release of the <a href="http://kenai.com/projects/netbeans-opengl-pack">OpenGL Pack</a> for NetBeans will fully support JOGL 2. Beta builds can be found <a href="http://projectkenai.com/projects/netbeans-opengl-pack/downloads/directory/early-access">here</a> (builds contain JOGL2 beta5): </p> http://michael-bien.com/mbien/entry/xpath_plugin_now_available_via XPath plugin now available via NetBeans plugin portal mbien 2009-08-07T00:18:03+02:00 2009-08-07T00:18:03+02:00 <p>The <a href="http://michael-bien.com/mbien/entry/xpath_netbeans_plugin">XPath Utility</a> I submitted to the NetBeans <a href="http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=18522">Plugin Portal</a> over two months ago has been recently <a href="http://plugins.netbeans.org/PluginPortal/faces/PluginVerificationPage.jsp?verification_id=18526">verified</a> against NetBeans 6.7. This makes the plugin now directly available from within the IDE over the Plugin manager (Tools -&gt; Plugins).</p> <p><img alt="NB Plugin Manager" src="http://people.fh-landshut.de/%7Embien/weblog/xpath_module/XPathUtilPluginPortal.png" /></p> <p>One .nbm less to carry with me ;)<br /></p> http://michael-bien.com/mbien/entry/object_pooling_determinism_vs_throughput Object Pooling - Determinism vs. Throughput mbien 2009-08-06T00:08:40+02:00 2009-08-10T11:28:12+02:00 <p> Object pooling in java is often seen as an anti pattern and/or wasted effort - but there are still valid reasons to think about pooling for certain kind of applications.</p><p> The JVM allocates objects much faster from managed heap (young generation; contiguous and defragmented) as you could ever recycle objects from a self written pool running on top of a VM. A good configured garbage collector is also able to delete unused objects fast. GCs in fact don't delete objects explicitly, they rather evacuate all surviving objects and sweep whole memory regions in a very efficient manner and only when its necessary to reduce runtime overhead.</p><p>Object allocation (of small objects) on modern JVMs is even so fast that making a copy of immutable objects sometimes outperforms modification of mutable (and often old) objects. JVM languages like scala or clojure make heavy use of this observation. One of the reasons for that anomaly is that generational JVMs are designed to be able to deal with loads of short living objects which makes them inexpensive compared to long living objects in old generations.</p> <h3>Performance does not always mean Throughput<br /></h3> <p>Rendering a game with 60fps might be optimal throughput for a renderer but the performance might be still unacceptable when all frames are rendered in the first half of the second with the second half spent on GC ;). Even if Object Pools may not increase system throughput they can still increase determinism of your application. Here are some observations and tips which might help: <br /></p> <h3>When should I consider Object Pools?</h3> <ul> <li>GC tuning did not help - you want to try something else</li> <li>The application creates a lot of objects which die in the old generation</li> <li>Your Objects are expansive to create but easy to recycle</li> <li>Determinism, e.g response time (soft real time requirements) is more important for you than throughput</li> </ul> <h3>Pro Pooling:</h3> <ul> <li>pools reduce GC activity in peak times (worst case scenarios)</li> <li>are easy to implement and test (its basically an array ;))</li> <li>are easy to disable (inject a fake pool which returns only new Objects)</li> </ul> <h3>Con Pooling:</h3> <ul> <li>more (old) objects are referenced when a GC kicks in (increases gc overhead)</li> <li>memory leaks (don't forget to reclaim your objects!)</li> <li>cause additional problems in a multi-threaded scenario (new Object() is thread safe!)</li> <li>may decrease throughput</li> <li>cumbersome, repetitive client code</li> </ul> <p> When you decided to use pools you have to make sure to reclaim all objects as soon they are no longer used. One way of doing this is by applying the <i>static factory method</i> pattern for object allocation and a per object dispose method for deallocation. </p> <pre class="brush: java;"> /**not Thread safe!**/ public class Vector3f { private static final ObjectPool&lt;Vector3f&gt; pool; public float x, y, z; private boolean disposed; static{ pool = new &lt;Vector3f&gt;ObjectPool(1024); for(int i = 0; i < 1024; i++) { pool.reclaim(new Vector3f()); } } private Vector3f() {} public static Vector3f create(float x, float y, float z) { Vector v = pool.isEmpty() ? new Vector() : pool.get(); v.x = x; v.y = y; v.z = z; v.disposed = false; return v; } public void dispose() { if(!disposed) { disposed = true; pool.reclaim(this); } } } </pre> <p> To demonstrate the perceived performance difference I captured two flyovers of my old <a href="http://michael-bien.com/mbien/entry/pictures_of_my_old_3d">3d engine</a>. The second flyover was captured with disabled object pools. The terrain engine triangulates the ground dependent on the position and view direction of the observer which makes object allocation hard to predict. The triangulation runs in parallel to the rendering thread which made the pool implementations a bit more complex as the example above. </p> <h3>Every vertex, normal, triangle and quad-tree node is a pooled object (wireframe on mouse over)</h3> <img src="http://people.fh-landshut.de/~mbien/weblog/obj_pools/Screenshot-18_small_sol.png" name="img1" onmouseover="document.img1.src='http://people.fh-landshut.de/~mbien/weblog/obj_pools/Screenshot-19_small_wire.png'" onmouseout="document.img1.src='http://people.fh-landshut.de/~mbien/weblog/obj_pools/Screenshot-18_small_sol.png'"> </img> <h3>on the left: flyover with pre allocated object pools; right: dynamic object allocation (new Object())</h3> <video width="256" height="192" autobuffer="true" controls="true"> <source src="http://people.fh-landshut.de/~mbien/weblog/obj_pools/pooled_small.ogg" type="video/ogg"> Your browser does not support the HTML5 video tag </source> </video> <video width="256" height="192" autobuffer="true" controls="true"> <source src="http://people.fh-landshut.de/~mbien/weblog/obj_pools/dynamic_small.ogg" type="video/ogg"> Your browser does not support the HTML5 video tag </source> </source> </video> <p> Notice the pauses at 7, 17 and 26s on the flyover with disabled pools (right video). </p> <p> <i>Note on the videos: The quality is very bad since the tool I used created 700MB large files for the 30s videos a lot of frames got skipped. I even sampled them down from 1600x1200 to 1024x768 and limited the fps to 30 but the bottleneck was still the hard disk. This is the main reason why even the left video does not look smooth. (I even had to boot windows the first time in 2 years to use the tool!). I'll try to capture better vids next time.</i> </p> <h3>Conclusion</h3> <p> Using pools requires discipline, is error prone, not good for system throughput and does not play very well with threads. However there are some attempts to make them more usable in case you think you need them. The physics engine <a href="http://jbullet.advel.cz/">JBullet</a> for example uses JStackAlloc to prevent repetitive and cumbersome code by using automatic bytecode instrumentation in the build process. Type Annotations (JSR 308 targeted for <a href="http://openjdk.java.net/projects/jdk7/features/#f619">OpenJDK 7</a>) in combination with project <a href="http://projectlombok.org/">lombok</a> and/or the automatic resource management proposal might provide further possibilities for simplifying the usage of object pools in java and reduce the risk for memory leaks. </p> http://michael-bien.com/mbien/entry/netbeans_opengl_pack_0_51 NetBeans OpenGL Pack 0.5.5 released mbien 2009-06-29T18:58:43+02:00 2009-06-29T19:09:55+02:00 <a href="http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=3260"><img vspace="0" hspace="10" border="0" align="left" src="https://netbeans-opengl-pack.dev.java.net/resources/NetBeansOpenGLPackLogo.png" alt="NetBeans OpenGL Pack logo" /></a> The NetBeans 6.7 compatible OpenGL Pack has been updated to version 0.5.5 and is now available on the <a href="http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=3260">plugin portal</a> also. The current release is feature compatible with 0.5.4 (<a href="http://michael-bien.blogdns.com/mbien/entry/gl_pack_0_5_4">release notes</a>) only JOGL and project webstart extensions have been updated to JOGL 1.1.1a security update. http://michael-bien.com/mbien/entry/using_applets_as_fallback_mode Using Applets as fallback mode for video on pre html5 browsers mbien 2009-06-23T19:04:52+02:00 2010-06-10T02:11:44+02:00 <p> The upcoming html5 standard will make it very easy to embed media of not proprietary formats in webpages. For example <a href="http://www.whatwg.org/specs/web-apps/current-work/#video">video</a> can be embedded in the same way you would probably do it with an image. But what happens when your browser does not support html5 yet? </p> <p> Firstly: don't panic! Secondly: you could consider using for example the <b>256kb</b> large <a href="http://maikmerten.livejournal.com/tag/cortado">cortado applet</a> as fallback mode, since pre html5 browsers will ignore unknown tags like the video tag they will still read the object tag. Using an applet as cross platform fallback mode for playing e.g. <a href="http://www.theora.org/">theora</a> encoded hd movies is therefore fairly easy - <b>you even don't have to convert the video to an other format</b>. </p> <p> The upcoming html5 standard will make it very easy to embed media of not proprietary formats in webpages. For example <a href="http://www.whatwg.org/specs/web-apps/current-work/#video">video</a> can be embedded in the same way you would probably do it with an image. But what happens when your browser does not support html5 yet? </p> <p> Firstly: don't panic! Secondly: you could consider using for example the <b>256kb</b> large <a href="http://maikmerten.livejournal.com/tag/cortado">cortado applet</a> as fallback mode, since pre html5 browsers will ignore unknown tags like the video tag they will still read the object tag. Using an applet as cross platform fallback mode for playing e.g. <a href="http://www.theora.org/">theora</a> encoded hd movies is therefore fairly easy - <b>you even don't have to convert the video to an other format</b>. </p> <h4>source</h4> <pre class="brush: xml;"> &lt;video width="320" height="240" controls&gt; &lt;source src="video.ogg" type="video/ogg"&gt; &lt;object width="320" height="240" type="application/x-java-applet"&gt; Your browser does not support the &lt;code&gt;video&lt;/code&gt; element and also does not support java applets. You can download the movie on http://www.bigbuckbunny.org/. &lt;param name="archive" value="my/host/cortado.jar" /&gt; &lt;param name="code" value="com.fluendo.player.Cortado.class" /&gt; &lt;param name="url" value="video.ogg" /&gt; &lt;/object&gt; &lt;/source&gt; &lt;/video&gt; </pre> <h4>400p Big Buck Bunny trailer [<a href="http://www.bigbuckbunny.org/">link</a>]</h4> <video width="640" height="480" controls> <source src="http://download.blender.org/peach/trailer/trailer_400p.ogg" type="video/ogg"> <object width="640" height="480" type="application/x-java-applet"> Your browser does not support the <code>video</code> element and also does not support java applets. You can download the movie on http://www.bigbuckbunny.org/. <param name="archive" value="http://people.fh-landshut.de/~mbien/cortado/cortado.jar" /> <param name="code" value="com.fluendo.player.Cortado.class" /> <param name="url" value="http://download.blender.org/peach/trailer/trailer_400p.ogg" /> </object> </source> </video> <p> happy coding! </p> http://michael-bien.com/mbien/entry/java_ee_6_the_salvation Java EE 6 - The Salvation mbien 2009-06-16T14:38:06+02:00 2009-06-16T15:18:04+02:00 <p><a href="http://press.adam-bien.com/"><img vspace="0" hspace="10" border="0" align="left" src="http://www.lulu.com/items/volume_65/7274000/7274143/2/preview/detail_7274143.jpg" /></a>My Brother Adam Bien released his new book <b><i>Real World Java EE Patterns - Rethinking Best Practices</i></b> yesterday. It is available as download or softcover. I am sure you will like it. (all in english)<br /></p><p>You can testread the first two chapters <a href="http://www.lulu.com/preview/paperback-book/real-world-java-ee-patterns-rethinking-best-practices/7274143">here</a>, more infos are on his <a href="http://www.adam-bien.com/roller/abien/entry/real_world_java_ee_patterns">blog</a>.</p><p>He will check in all samples of his book to this <a href="http://kenai.com/projects/javaee-patterns">projekt</a> on kenai.com - so make sure you bookmark it or do a mercurial refresh in your favourite IDE when you are interested.<br /></p> http://michael-bien.com/mbien/entry/gl_pack_0_5_4 OpenGL Pack 0.5.4 now ready for NetBeans 6.7 mbien 2009-06-14T20:38:23+02:00 2009-06-14T20:38:23+02:00 <p><a href="http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=3260"><img vspace="0" hspace="10" border="0" align="left" src="https://netbeans-opengl-pack.dev.java.net/resources/NetBeansOpenGLPackLogo.png" alt="NetBeans OpenGL Pack logo" /></a>NetBeans OpenGL Pack 0.5.4 is now ready to be used in the upcoming NetBeans 6.7 release, currently as rc2 available.</p> <p>It wasn't sure if we would be able to ship the GLSL editor in this release since NetBeans 6.7 changed the editor APIs once again. But fortunately the P1 bug was <a href="http://www.netbeans.org/issues/show_bug.cgi?id=161517">fixed in time</a> and we (and apparently many others, thanks for voting!) can keep using the Generic Language Framework (GLF aka Schlieman) - at least for now since GLF it is now a deprecated/unsupported module.<br /></p> <p>Build 0.5.4 will break compatibility with NB 6.5. The latest and also all other releases can be downloaded on the <a href="https://netbeans-opengl-pack.dev.java.net/servlets/ProjectDocumentList?folderID=11496&expandFolder=11496&folderID=8522">project page</a>. I will wait with the upload to the plugin portal until NetBeans 6.7 final is released.</p> <h4>Features/Enhancements:<br /></h4><p>Anyway. Not much changed since the <a href="http://michael-bien.blogdns.com/mbien/entry/netbeans_opengl_pack_2_in">last release</a>. The most important point is probably that the GLWorker used internally for tasks like shader compilation or capabilities viewer is now more stable on systems which do software rendering (e.g Mesa GL).</p><p>I added also an experimental feature which lets you define GLSL shader dependencies similar to java imports.</p><p>It is very common in GLSL to reuse code by simple concatenation of files. For example a set of independent shaders can reuse a code fragment defining some generic mathematical functions if the fragment has been concatenated to the top of all shaders which make use of the functions. Editing those kind of shaders would produce compilation errors without a way to inform the editor about those dependencies. </p><p>For example the following shader uses the function <em>light()</em> of <em>PerPixelLight.frag</em> by inserting the file <em>./PerPixelLight.frag</em> at the position of the <em>//import</em> statement.<br /></p> <h4>PerPixelLight.frag</h4> <pre class="brush: GLSL;"> vec4 light(void) { // insert fancy light calculation here } </pre> <h4>PlanetShader.frag</h4> <pre class="brush: GLSL;"> //import PerPixelLight.frag uniform samplerCube cubemap; varying vec3 vertex; void main (void) { //Cubemap gl_FragColor = vec4(textureCube(cubemap, vertex)) * light(); } </pre> <p>When you compile a shader with dependencies you should see something like that in the output window:<br /><img vspace="0" hspace="0" border="0" align="baseline" src="https://netbeans-opengl-pack.dev.java.net/resources/dependencyOutput.png" /><br /><br />All dependencies are listed in the compiler log and even the line numbers of the compiler warnings are translated back to the code fragments, which lets you jump via hyperlink directly to the annotated files. <br /></p><p>Just a warning: Please don't define cyclic dependencies, however double imports should work in theory (have I mentioned it is experimental? ;))<br /></p> <p>Happy coding!<br /></p> http://michael-bien.com/mbien/entry/javaone09_keynote_replays_and_technical JavaOne 09 keynote replays and technical session slides available mbien 2009-06-06T15:57:27+02:00 2009-06-09T01:22:15+02:00 <p>For those who haven't watched to the keynotes live or per live stream can now watch the <a href="http://java.sun.com/javaone/2009/general_sessions.jsp">replays</a> of all general sessions (on your favourite screen of your live - sorry couldn't resist ;)).</p><p>The good thing about that is: you can hit the fast forward button as soon as the marketing guys start talking ;).</p><p>The slides of most presentations are also <strike><a href="http://www28.cplan.com/cc230/sessions_catalog.jsp?ilc=230-1&amp;ilg=english&amp;isort=&amp;isort_type=&amp;is=yes&amp;icriteria1=+&amp;icriteria2=+&amp;icriteria8=&amp;icriteria3=&amp;icriteria9=&amp;icriteria4=+&amp;icriteria7=+">available</a></strike> [<a href="http://developers.sun.com/learning/javaoneonline/j1online.jsp?track=embedded&amp;yr=2009">updated link</a>] for download. <br /></p><p>Especially recommended are James Gosling's toy show (last session), the first two keynotes and of course the pdfs of the technical sessions.<br /></p> http://michael-bien.com/mbien/entry/xpath_netbeans_plugin XPath NetBeans plugin mbien 2009-05-26T22:21:56+02:00 2009-05-26T23:46:10+02:00 <p>I built some time ago a NetBeans plugin which simplifies browsing through large xml documents a bit. Just start typing a XPath expression in the text field of the TopComponent and the result of the (last) xml editor in focus are computed and printed in the textarea below. (You can open the XPath window either by using the context menu on xml files or directly via the window menu)</p><p>It uses the JDK's javax.xml.xpath package which means XPath 1.0 support.<br /></p><p><img hspace="0" border="0" align="baseline" vspace="0" alt="xpath query results" src="http://people.fh-landshut.de/%7Embien/weblog/xpath_module/xpath_result.png" /> </p><p>it also supports basic auto completion:<br /></p><p><img hspace="0" border="0" align="baseline" vspace="0" alt="xpath completion for expressions" src="http://people.fh-landshut.de/%7Embien/weblog/xpath_module/xpath_completion.png" /></p><p>localized error messages (in other words: XPathExpressionException.getCause().getLocalizedMessage()):<br /></p><p><img hspace="0" border="0" align="baseline" vspace="0" alt="error messages" src="http://people.fh-landshut.de/%7Embien/weblog/xpath_module/xpath_error.png" />&nbsp;</p><p>I uploaded the module to the <a href="http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=18522">plugin portal</a>. Feel free to use it ;)<br /></p><p> </p> http://michael-bien.com/mbien/entry/netbeans_opengl_pack_2_in NetBeans OpenGL Pack #2 in most popular plugins ranking mbien 2009-05-19T20:50:12+02:00 2009-06-12T12:09:39+02:00 <p><a href="http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=3260"><img vspace="0" hspace="10" border="0" align="left" alt="NetBeans OpenGL Pack logo" src="https://netbeans-opengl-pack.dev.java.net/resources/NetBeansOpenGLPackLogo.png" /></a>Since I haven't bloged for a long time about the OpenGL Pack, here are some notes for the last two update releases.</p><p>Beside updates and fixes the only new feature I added is the OpenGL Quicksearch. It uses the NetBeans 6.5 Quicksearch functionality (similar to ctrl + 3 in eclipse) and searches through several OpenGL resources.</p><p><br /><strong><br />currently are five resources available for search:</strong><br /></p><ul><li><a href="http://opengl.org/sdk/docs/man/">OpenGL SDK</a><br /></li><li><a href="http://www.opengl.org/registry/">OpenGL SDK Extension Registry</a></li><li><a href="http://developer.nvidia.com/object/nvidia_opengl_specs.html">Nvidia Extensions</a></li><li><a href="http://ati.amd.com/developer/sdk/radeonSDK/html/info/Prog3D.html">ATI/AMD Extensions</a></li><li>JOGL sources (only when JOGL module installed and used in at least one opened project)</li></ul><p>power users can restrict the search to a category with the following prefixes ([prefix&nbsp; space] searchstring&nbsp; (space searchstring)*):<br /><strong>gl</strong> for GL SDK, <strong>ext</strong> for GL extensions, <strong>nv</strong> for Nvidia extensions, <strong>ati</strong> for ATI/AMD Extensions.<br /></p> <p><br /> <a href="https://netbeans-opengl-pack.dev.java.net/resources/JOGL_FormDesigner_Integration2.png"> <img width="319" height="200" alt="JOGL component in NetBeans Formdesigner" src="https://netbeans-opengl-pack.dev.java.net/resources/JOGL_FormDesigner_Integration2_small.png" /> </a> <a href="https://netbeans-opengl-pack.dev.java.net/resources/OpenGL_QuickSearch.png"> <img width="106" height="200" alt="OpenGL quicksearch" src="https://netbeans-opengl-pack.dev.java.net/resources/OpenGL_QuickSearch_small.png" /> </a> <a href="https://netbeans-opengl-pack.dev.java.net/resources/compilerErrorAnnotations.PNG"> <img width="274" height="200" alt="GLSL editor" src="https://netbeans-opengl-pack.dev.java.net/resources/compilerErrorAnnotations_small.png" /> </a> </p> <p>Pictures featuring: Form Designer sample project, GL Quicksearch, updated GLSL 1.3 editor<br /></p><p><strong>Changes in 0.5.3: </strong><br /></p><ul><li>Java Applet and Webstart support</li><li>OpenGL Quicksearch</li><li>GLSL editor updated to support GLSL 1.3 (OpenGL 3.0 spec)</li><li>two new NetBeans Form Designer sample JOGL projects</li><li>NetBeans 6.5 and JDK6 are the new minimum requirements<br /></li></ul><p><strong>Changes in 0.5.2 since <a href="http://michael-bien.blogdns.com/mbien/entry/netbeans_opengl_pack_0_5">last release</a>:</strong></p><ul><li>JOGL distribution has been updated to version 1.1.1</li><li>GLSL linker now does not stop linking shaders on compiler warnings</li><li>the pack should now correctly deploy JOGL and GlueGen's native libraries on all supported platforms (64bit bug)</li></ul><p>To download the pack, please visit the <a href="http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=3260">plugin portal</a>. </p><p>As always, please use the <a href="https://netbeans-opengl-pack.dev.java.net/servlets/ProjectMailingListList">user mailing list</a> for feedback and the <a href="https://netbeans-opengl-pack.dev.java.net/servlets/ProjectIssues">issue tracker</a> for bug reports on the <a href="https://netbeans-opengl-pack.dev.java.net/">project page</a>.</p><p>- - - - -<br /></p><p>BTW the pack recenty reached the <strong>36k downloads</strong> milestone which makes it to the #2 in the most popular plugins category of the plugin portal ;) </p> http://michael-bien.com/mbien/entry/enabling_the_new_java_browser Enabling the new java browser plugin on ubuntu mbien 2009-05-17T01:36:52+02:00 2009-05-17T01:39:28+02:00 <p>When you are using Ubuntu and upgraded from older releases to intrepid or jaunty you might have run into a setup bug which causes the browser to keep using the old java plugin despite having latest Java SE and plugin packages installed (e.g 1.6 update 13 from multiverse repository).</p><p>To fix this you will have to update some symlinks and let them point to the correct location.</p><p>one easy way of doing this is by using the update-alternatives command:</p><pre> sudo update-alternatives --all<br /></pre><p>this will iterate through all symlinks in /etc/alternatives which have more than one alternative and ask you which one to use. Simple update all links which point to: </p><pre>.../libjavaplugin_oji.so<br /></pre><p>to the location of the new plugin (e.g for i386):<br /> </p><pre>/usr/lib/jvm/java-6-sun/jre/lib/i386/libnpjp2.so<br /></pre><p>For all other links just hit Return. <br /></p><p>This is a little bit of a brute force approach but there shouldn't be many of them and it is the only way to make sure you don't overlook one of them since they are all called differently ;) <br /> </p><p>Next time you restart your browser the new plugin should be loaded and applets which use e.g <a href="http://michael-bien.blogdns.com/mbien/entry/java_javascript_interoperability_example">jnlp for deployment</a> (or out of process functionality) should work.<br /> </p> http://michael-bien.com/mbien/entry/java_javascript_interoperability_example Java - JavaScript Communication example mbien 2009-05-12T16:22:57+02:00 2009-07-05T16:31:45+02:00 <p>Communication between java applets and javascript code is already available <a href="http://java.sun.com/products/plugin/1.3/docs/jsobject.html">since J2SE 1.3</a> (aka <a href="http://en.wikipedia.org/wiki/LiveConnect">LiveConnect</a>, which was btw. <a href="http://www.youtube.com/watch?v=4wi9Q1x8j7E">rewritten from scratch</a> in Java 6 update 10 as part of the new plugin) and is really easy to implement. It is a simple way to break out of the sandbox and do things which would usually require full system access (a signed applet + user approval via security dialog). For example applets living in a sandbox are only allowed to read mouse events via the AWT/Swing event mechanism which works as long the mouse is over the applet. </p><p>To read e.g the mouse position globaly you would need to call <i>MouseInfo.getPointerInfo().getLocation()</i> which would cause a <i>java.security.AccessControlException: access denied.</i> However, in javascript it is trivial to track mouse events for the whole html document (e.g google adds track onclick x,y events).<br /></p><p> All you have to do is to use the object tag instead of applet tag (which is deprecated anyway) and give the object (applet) a name via the id attribute.</p><pre style="border: 1px inset ; margin: 0px; padding: 3px; overflow: auto; text-align: left;" dir="ltr" class="alt2">&lt;<font color="#ff0000"><b>form name=&quot;FishForm&quot;</b></font>&gt; <br /> &lt;object width=&quot;256&quot; height=&quot;256&quot; type=&quot;application/x-java-applet&quot; <font color="#ff0000"><b>id=&quot;CrazyFish&quot;</b></font>&gt;<br /> &lt;param value=&quot;http://people.fh-landshut.de/~mbien/weblog/java_js_interop/launch.jnlp&quot; name=&quot;jnlp_href&quot; /&gt;<br /> &lt;param value=&quot;false&quot; name=&quot;draggable&quot; /&gt;<br /> &lt;/object&gt;<br />&lt;/form&gt;<br /></pre><p>&nbsp;now you can simply call methods as usual. </p><pre style="border: 1px inset ; margin: 0px; padding: 3px; overflow: auto; text-align: left;" dir="ltr" class="alt2">&lt;script language=&quot;JavaScript1.2&quot;&gt;<br /> //...<br /> document.onmousemove = onMouseMoved;<br /><br /> var tempX = 0;<br /> var tempY = 0;<br /><br /> var applet = document<font color="#ff0000"><b>.FishForm.CrazyFish</b></font>;<br /><br /> function onMouseMoved(e) {<br /> //...<br /> // javascript -&gt; java calls<br /> applet.jsObjectOrigin(findPosX(applet), findPosY(applet));<br /> applet.jsMouseMoved(tempX, tempY)<br /> return true<br /> }<br /> //...<br /> &lt;/script&gt;<br /></pre><p>&nbsp;the other side is a plain old public method implemented in the java applet.<br /></p> <pre style="border: 1px inset ; margin: 0px; padding: 3px; overflow: auto; text-align: left;" dir="ltr" class="alt2">&nbsp; /**<br /> * called from javascript.<br /> */<br /> public void jsMouseMoved(int x, int y) {<br /> //do something usefull<br /> }</pre><p>&nbsp;RIA/Web2.0 Observer Pattern in action ;) </p> <form name="FishForm" id="FishForm"> <div id="FishBanner"> <script> var attribs = { width:256, height:256, id:'CrazyFish' }; var params = { jnlp_href:'http://people.fh-landshut.de/~mbien/weblog/java_js_interop/launch.jnlp' }; var banner0 = new Image(); banner0.src = "http://michael-bien.com/mbien/resource/banner_scripts/play.png"; var banner1 = new Image(); banner1.src = "http://michael-bien.com/mbien/resource/banner_scripts/play-active.png"; </script> <a href="javascript:deployApplet('FishForm','FishBanner',attribs,params);startEvents();" onmouseover="play.src=banner1.src;" onmouseout ="play.src=banner0.src;"> <img id='play' src="http://michael-bien.com/mbien/resource/banner_scripts/play.png" width="48" height="48" border="0" hspace="100" vspace="100"/> </a> </div> </form><p> <script language="JavaScript1.2"> <!-- function startEvents() { // Detect if the browser is IE or not. // If it is not IE, we assume that the browser is NS. var IE = document.all?true:false // If NS -- that is, !IE -- then set up for mouse capture if (!IE) document.captureEvents(Event.MOUSEMOVE) document.onmousemove = onMouseMoved; var tempX = 0; var tempY = 0; var applet = document.FishForm.CrazyFish; function onMouseMoved(e) { if (IE) { // grab the x-y pos.s if browser is IE tempX = event.clientX + document.body.scrollLeft tempY = event.clientY + document.body.scrollTop } else { // grab the x-y pos.s if browser is NS tempX = e.pageX tempY = e.pageY } // catch possible negative values in NS4 if (tempX < 0) {tempX = 0} if (tempY < 0) {tempY = 0} // javascript -> java calls applet.jsObjectOrigin(findPosX(applet), findPosY(applet)); applet.jsMouseMoved(tempX, tempY) return true } function findPosX(obj) { var curleft = 0; if (document.getElementById || document.all) { while (obj.offsetParent) { curleft += obj.offsetLeft obj = obj.offsetParent; } } else if (document.layers) curleft += obj.x; return curleft; } function findPosY(obj) { var curtop = 0; if (document.getElementById || document.all) { while (obj.offsetParent) { curtop += obj.offsetTop obj = obj.offsetParent; } } else if (document.layers) curtop += obj.y; return curtop; } } --> </script> (The applet won't work with JRE version &lt; 1.6 update 10 (or the equivalent on Mac OS) since I used the jnlp deployment mechanism, but it wouldn't have been necessary for this particular applet)</p><p>... and never forget Web 2.0 is watching you <br /></p> http://michael-bien.com/mbien/entry/there_is_no_place_like There is no place like 127.0.0.1 mbien 2009-05-06T17:48:19+02:00 2009-06-11T16:05:26+02:00 <p>I have decided to host my blog myself and thought I report about some highlights ;). The reason why I haven't bloged for a long time was actually a configuration issue of the old setup which confused <b><i>&lt;myDomain&gt;/myBlog</i></b> with <b><i>&lt;myBrother'sDomain&gt;/myBlog</i></b>. Selfhosting is also a good opportunity to play with enterprise software at home in a daily basis (not only the usual try and remove evaluation with constructed dummy projects or brainstormed scenarios).</p>I initially evaluated OpenSolaris since I was really eager to try out ZFS. But I decided to stay with Ubuntu 9.04 server edition (aka jaunty jackalope) since I already use the desktop version for my workstation. The other reason was the lower memory footprint of Ubuntu (256MB) compared to OpenSolaris (512MB) which is relevant if you run your site on over 10 years old hardware like I do.<br /><p>Ubuntu has great software repositories which just provide everything to get started (e.g Sun JDK6.13 and in theory also glassfish, netbeans, eclipse, your favourite database etc but i prefer in those cases zip files ;-) ).</p><p>Installation with gimmicks like Software RAID (RAID 1), firewall configuration went flawlessly. The combination GlassFish2.1 + Roller 4.0.1 + hsql 1.8 worked also on first attempt.<br /></p><p><b>a few thing I noticed:</b></p><ul><li>5 years ago the whole process would take far longer than two evenings</li><li>-XX:OnOutOfMemoryError=&lt;send me a mail command&gt; (since java 1.6) is really cool<br /></li><li>Cloudcomputing is overrated (web services should always be weather independent)</li><li>There is no place like 127.0.0.1</li></ul><p>don't worry the upcomming entries should be more technical - this is mainly a test ;-)</p>