Monday, 9 December 2013

Using multiple FBOs in OpenGL ES 2

I wrote previously about using FBOs in OpenGL ES 2. However, sometimes rendering to a single framebuffer is not enough. You may want to process the texture yet again before displaying it on the screen. Doing this is as easy as creating a new FBO and rendering to it. The code is almost identical to the previous one, except it uses two framebuffer objects. Here I'm using a blur shader (taken from here if I remember well):

FBO

Saturday, 7 December 2013

Java: How it works (part 1)

Keywords: JVM, classpath, classloader

I always wanted to know how I get from a bunch of .java files (that include a main method somewhere) to a program that does something. For the rest of the discussion, let's assume we are working with the following file:

A simple class

Firstly, all the .java files need to be compiled into .class files in order to be used by the JVM. In other words, the JVM has no idea and doesn't care about Java; it only cares about the instructions in a .class file. This means that, if you know what you're doing, you can even make your own compiler, along with a language that gets compiled to valid .class files. Actually there are already a number of JVM languages.

Now that you compiled your code successfully, you need to run it. java MySimpleClass starts a new JVM that will attempt to run your program by first using what is called a classloader. What the classloader does is try to find and load the contents of .class files in order to translate those contents into Java classes and interfaces. This process is called loading. The next step is called linking and it consists of adding the aforementioned classes and interfaces to the JVM run state. Next is class initialization, which consists of initializing the static members of the class and includes running static initialization blocks. Initialization will be covered more thoroughly in part 2.

Once these steps are done, the JVM is be ready to call main and run your code. :) Note that you may be able to execute code before main through static initialization blocks. Also, a very useful command is javap. It disassembles the contents of a .class file into a readable format, which could help understand at a deeper level what really happens in the JVM. Type
javap -v MySimpleClass.class 
in the terminal and have a look.

In part 2 I am going to look at a more complex example and talk a bit more about initialization and when it occurs. :)