Android: OpenGL 1.0 and 2.0 infos

So here I was again, trying to figure out a way to get opengl infos like max texture size, max uniform vectors, max vertex attributes, etc. for several android devices. Technically you could just use a small getter:

The problem was that on many devices the the returned number would always be 0. That’s because there hasn’t been created an opengl context yet. As suggested on Stackoverflow you could create a GLSurfaceView, add a renderer which could read the required infos by adding the glsurfaceview to the actual main active view and simply remove itself when done. In order to get opengles 1.0 and opengles 2.0 infos you would need to create two surfacesviews with different opengl versions. The following example looks a bit complicated, because I use fragments which i need to update on the main thread after I got all the infos I wanted. A full example is on github.

Android libgdx ShaderAssetLoader & StillModelLoader

I totally love how libgdx brings a lot of interfaces for your application to connect to the graphics library. For instance the asset manager is really thought through well in particular. It has some really useful methods like Assets.manager.getProgress(). Especially since you can easily write your own asset loader and be able to utilize the loading progress in your app.

1) Simply add your loader to the asset manager at some point.

2) load your assets at required places, e.g. loading screen
(Note: SHADER_PHONG = “data/Graphics/Shader/Phong”; and MODEL_TEAPOT = “data/Graphics/Shader/teapot.obj”)

3) get your shader or model wherever you need them

4) free the resource by unloading when you’re done with them (e.g. disposing your app; changing screens)

That’s the shader asset loader for loading custom shaders in libgdx. (Note: adapt your extensions)

And here is the StillModel loader for loading 3D meshes:

Conclusion: assets are handled well in libgdx :D

Android: Saving Screenshots in OpenGLES

1) Get your helper methods:

2) get a queue ready

3) add new filepath the the queue via e.g. events:

4) IMPORTANT! save the screen at the end of the opengl render process. (Note: If try to capture somewhere in the middle you might end up with a black screen or any other funny effects.)

WebGL: Three.js and particles from black and white shape

Well Three.js is amazing:

Just adapted the black and white shape image to this Particle Shape Tween. Which basically replaces the shape with particles.

WebGL: Earth Texture Shader

At university my computer graphic professor Hartmut Schirmacher gave us an excercise to implement various effects on a sphere in webgl with shaders based on his given webgl framework. His framework made it fairly easy though. Well here it is:

The features are:

  • Day and night light with smooth transition
  • Day changes based on the month
  • Moving clouds, which alternate in intensity over time
  • Wireframe and equator ring for orientation purposes
  • Specular lights based on barythmetic map
  • Height based on topyographic map
  • Bump map (work in progress)
  • Rotate with [Left click]
  • Drag with [Shift] + [Left click]
  • Zoom with [Alt] + [Left click]

All textures are taken from NASA’s Blue Marble collection.

This is my solution to cg2 exercersise a03.

WebGL: Robot

Another lovely javascript excerise. Just uncheck the animation to control it better.

This is my solution to cg2 exercersise a02.5-2.6.

WebGL: Backface Culling and Depth Test

One interesting part is the z-fighting, which doesn’t happen with polygon offset fill.

This is my solution to cg2 exercersise a02.1-2.4.

WebGL: warmup

What are the pros/cons of WebGL?
Read Quote of Henrik Bennetsen’s answer to What are the pros/cons of WebGL? on Quora

This is my “solution” to cg2 exercersise a00-warmup.

Shader to software skinning method conversation

An almost monolog on stackoverflow helped me to get skeleton animations at least usably working in render demo that I’ve put up in android market. By the way on how the shader computes mat4 * vec4 can be found in the opengles shading language specification.

All right I’ve got a mesh with around 8000+ vertices, it’s sekelon with up to 128 bones and all it’s bone keyframe transformations up to 400 each animation.

Ahri SkeletonAhri Skeleton

Ahri MeshAhri Mesh

On desktop I could use this in vertex shader in order to compute the skinning:

As you can see there are a lot of bones. On android I don’t have the luxury of wasting variables to make simple lookups. I’d need 128 mat4  * 4 vec4 = 512 shader uniform vector variables and my samsung galaxy s2 only supports 304. Anyway I can think of 2 solutions:

  1. divide the mesh into an ‘ok’ amount of bones and render the mesh with less bone matrices
  2. do the skinning in software and update the vertex/normal buffers

I’d prefer the first solution, because I’d have to update merely the bone matrices uniform each frame instead of the entire vertex buffer. At this point however I have no idea how to divide the mesh because each vertex can have up to 4 bone influences and so I implemented the 2nd choice for now. Work in progress…

Here is the equivalent java code:

Earth Seasons Shader for Android

In computer graphic 2 we were supposed to create a earth seasons shader. Here is the one I did for android:

earth shader image earth shader image2

Simple vertex shader

and the fragment/pixel shader:

Maybe this isn’t the most efficient way but it is a way and one that works nonetheless. (: