SourceForge.net Logo
Home
Documentation
Tutorials
    Beginning
    Gears
    Noise
    Bumpmapping
    Point sprites
    Hello World
    Armature
    Geometryshader
    Toolscripting
    Keyframe animation
    Instancing
    Bezier Surface
    Deferred shading
    Depth peeling
    Particle System
Links
Support This Project
OpenGL
Welcome to the first Lumina tutorial.
This tutorial is only Lumina specific. It gives a small overview about the GUI and
scripting.

1. Start Lumina
Start Lumina from a shell. This is important to see the shadercompilers debugging
messages. In the Mainwindow you see two widgets: A tree and a "Cam". If you expand
the tree the "Cam" is shown as item.

2. Create a node
To clean up the GUI, the most actions are moved to context menus. Open the "World"
contextmenu and select "Add Node"

This action will create a new node item. This items type is a container.

3. Create objects
Open the "Node" contextmenu and create a Script, Vertexshader, Fragmentshader, Texture
and a Testobject. The last action will open a dialog. Select the Torus and select 6 for
the resolution and click on "Create". After that drag the new widgets on top of each
other.




4. Load a Textures

Load an image via Textures contextmenu. The image should have a power of 2 resolution.
JPG PNG and DDS images are supported.

5. Vertexshader code
Copy this code to the vertex shader texteditor:
void main(void){

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}



6. Fragmentshader code
Copy this code to the fragment shader texteditor:

uniform sampler2D Tex0;
uniform vec4 col;
void main(void){
gl_FragColor = texture2D(Tex0, vec2(gl_TexCoord[0]));
}


7. Script code
Copy following code to the "Script":


shader = gl.Shader(Vertexshader,Fragmentshader);
shader.Uniformi("Tex0",0);
tan = shader.Loc("Tangent");

function render(){
Texture.Bind(0);

gl.Rotate(60 * World.getTime(), 0,1,0);

shader.Bind();

Torus.UvCoords.Bind();
Torus.Tangent.Bind(tan);
Torus.Vertex.Bind();
Torus.Normal.Bind();

Torus.Index.Draw();
}

Edit: With Lumina-0.3.0 it isn't required to unbind shaders or mesh components anymore


The most Opengl wrapping functions are simplified and looking more than pseudo code.
In most cases the postfixes like 1f 2f 3f 4f are drooped. Uniformi is a exception to
prevent against ambiguousness. The gl_ (functions) od GL_ (constants) prefixes are
dropped too, they are replaced by their corresponding objects.
Any items from the tree could be accessed by their names relative from the "Script"s
Node or absolute to the "World" node.

This script code shouldn't be hard to understand. The fist line compiles and links the
shader. The second sets the fragment shader uniform sampler2D variable to 0. The third
line caches only the vertex shader "Tangent" attribute location if it exists. All this
three lines would be executing one time at starting the script.

The "render" function will be executed for every new frame:
Texture.Bind(0);
This binds the texture tu the first TMU (Texture Mapping Unit). Textures didn't need to
be unbind after use.

gl.Rotate(60 * World.getTime(), 0,1,0);
This is a simplified Opengl rotate like gl_rotate4f(). World.getTime() is a function
that returns the the "Timebars" time in seconds, multiplied with 60.0 it'll result in
a 360 degrees rotation after 6 seconds (the default timebar length)

shader.Bind();
This binds the shader it's equal to glUseProgramObjectARB(shader) in C/C++

Torus.???.Bind();
This binds the single VBO (Vertexbufferobject) streams. The default attribute can be
overwritting by passing the location as argument (Vertex,Color,Normal and UvCoords have
defaults)

Torus.Index.Draw();
The index stream has it own Draw method. The type (gl.QUADS gl.TRIANGLES) is already
stored internally.


8. Run the script
Select "Run Script" from the "Script" contextmenu. You should see something like:
EDIT