The Modern OpenGL tutorials series continue - now with a first section on lighting, covering the different kind of lights (sun, hemi, spot, etc.) using a simple diffuse model and clear code.
http://en.wikibooks.org/wiki/OpenGL_Programming#The_lighting_arc
This one is derived from the excellent set of Blender GLSL tutorials by Martin Kraus.
As usual, the documentation is CC-BY-SA/GFDL, and the code is in the public domain.
We're also expecting another tutorial on scientific visualisation.
[EDIT: lighNing->lighing - sorry for the typo :)]
Guus started a new section in the OpenGL wikibook about scientific uses! In a first tutorial, he showcases how to interactively plot a simple mathematic function:
http://en.wikibooks.org/wiki/OpenGL_Programming#The_scientific_arc
The lighting front is also progressing with a new tutorial on ambient and specular lights:
http://en.wikibooks.org/wiki/GLSL_Programming/GLUT/Specular_Highlights
Enjoy!
Guus wrote another scientific OpenGL tutorial, storing ordinates as a one-dimensional texture for increased performances.
http://en.wikibooks.org/wiki/OpenGL_Programming/Scientific_OpenGL_Tutorial_02
I also went ahead and added a tutorial on two-sided lighting:
http://en.wikibooks.org/wiki/GLSL_Programming/GLUT/Two-Sided_Surfaces
Remember: this is free documentation that you can share and/or improve upon - make sure you do so
Using plain C arrays of coordinates, instead of Vertex Buffer Objects, confused some readers. I did it so that the very first tutorials would be simpler.
However, it also appears that plain C arrays are not supported at all starting with OpenGL 3.0. Plus, specifying offsets is done differently in each case, and people will use VBOs in the end for performances.
So the basic tutorials are now rewritten to use VBOs It took me longer than expected!
http://en.wikibooks.org/wiki/OpenGL_Programming#The_basics_arc
I searched forever for a way to just build the examples in the Android NDK, preferably from the command line. Here's how.
First step: build the C++ code:
cd /usr/src/android-ndk-r6/samples/san-angeles/
/usr/src/android-ndk-r6/ndk-build
Simple enough.
Second step:
You will then need to generate your final .apk through the usual means. -- Android NDK Dev Guide
Thanks a ****ing lot!
In addition the documentation is very much Eclipse-centered - and I can't be bothered to install and configure all the Eclipse stack for a mere Java wrapper for the above-generated .so
file XD
We first need to use the 'android' wrapper and download the "SDK Platform Android 2.2, API 8, revision 3" - aka "android-8", the first environment to support OpenGL ES 2.
/usr/src/android-sdk-linux_x86/tools/android
It appears we first need to "manage the project", more precisely import from an existing project:
http://developer.android.com/guide/developing/projects/projects-cmdline.html
So we create a project by importing the sources from the current directory:
/usr/src/android-sdk-linux_x86/tools/android update project \
--name san-angeles --path . --target "android-8"
Then we use ant to build the thing:
http://developer.android.com/guide/developing/building/building-cmdline.html
apt-get install ant openjdk-6-jdk
ant debug # avoid messing with signing
We now have a bin/san-angeles-debug.apk
and we can run it in the emulator. Create a new "Virtual device" using the "android-8" platform we downloaded above, and launch it. Given the time needed to boot the OS, I suggest enabling snapshots. Scaling to display resulted in a very tiny, dark and slow display, in a first step I suggest using a non-scaled one.
/usr/src/android-sdk-linux_x86/tools/android
At last we can run it! Install it in the emulator:
/usr/src/android-sdk-linux_x86/platform-tools/adb install -r bin/san-angeles-debug.apk
You'll find a DemoActivity in your apps directory
Note: I tried to compile the "hello-gl2", showcasing OpenGL ES 2.0, but sadly it crashes:
Sorry! The application GL2JNI (process com.android.gl2jni) has stopped unexpectedly. Please try again.
The emulator apparently doesn't advertise EGL_OPENGL_ES2_BIT (checked in in GL2JNIView.java
).
If you try to by-pass it, you'll get loads of:
E/libEGL ( 333): called unimplemented OpenGL ES API
It's worth noting the OpenGLES20 sample from the "API Demos" application uses a fall-back OpenGL ES 1 renderer if v2 is not available - it made me mistakenly believe that OpenGL ES 2 was supported only from Java >(
OpenGL ES 2 is not supported in the emulator as of 2011-09-17 - period.
Here's a third tutorial from Guus focused on GPU-assisted plotting. It also provides excellent exercices on manipulating the OpenGL windows using the Viewport and the Scissors
http://en.wikibooks.org/wiki/OpenGL_Programming/Scientific_OpenGL_Tutorial_03
The OpenGL wikibook is free documentation, and you are welcome to redistribute it under certain conditions; see the CC-BY-SA or GFDL licenses for details
After some restless hours of debugging, here's Phong lighting
http://en.wikibooks.org/wiki/GLSL_Programming/GLUT/Smooth_Specular_Highlights
The code can be optimized, but should give you a clear understanding on how to make smooth OpenGL lighting. And you can admire the stunning results with a mere basic material and one lamp!
Here's the fourth tutorial from Guus on Scientific OpenGL, this time going 3D, plotting the "Mexican Hat" function, and covering various line drawing methods as well as Index Buffer Objects.
http://en.wikibooks.org/wiki/OpenGL_Programming/Scientific_OpenGL_Tutorial_04