KUIML
Blue Cat's User Interface Programming Language
GL_OBJECT_3D

Description

This object can be used to write custom OpenGL scripts for 3D rendering. The rendering script can reference any data exposed to the scripting engine.

Most OpenGL 1.1 functions and constants (as defined in the gl.h C header) are available, execpt the functions using arrays (vertex arrays etc.). Extensions and shaders are not yet available.

This element is currently *experimental* and may change in future releases.

Inherited Attributes

See Attributes Common to 3D Objects.

Specific Attributes

Name Value Type Default Value Description Comment V. Exp.

render_script

script

empty

OpenGL script to render the object.


2.0

No

Exposed Actions

Invalidate

ref_type_action

Requests the object to be re-rendered.

2.0

2.0

Examples

3D Shapes

Display simple 3D shapes with an OpenGL script defined in a separate file:

doc_ref_3d_objects_gl_object_3d_example1.png

Skin file:

<?xml version="1.0" encoding="utf-8" ?>
<SKIN background_color="#000000" text_color="#ffffff">
    <!-- Custom 3D Viewer definition -->
    <DEFINE>
        <CUS_3D_VIEWER base_type="VIEW_3D" width="600" height="400" cursor="system::open_hand" y_ratio=".8" z_ratio=".5" transform.tz="-7" transform.ry="-45" transform.rx="-45"/>
    </DEFINE>

    <!-- Including the script file that defines the OpenGL rendering function-->
    <SCRIPT src="openGLShapes.cxx"/>

    <!-- The 3D Viewer -->
    <CUS_3D_VIEWER id="view3d">
        <!-- Custom GL scripting object, calling the glRenderShapes function defined in openGLshapes.cxx-->
        <GL_OBJECT_3D id="view3d.shapes" render_script="glRenderShapes(this.opacity)"/>
    </CUS_3D_VIEWER>

    <!-- Force the engine to expose the view3d.shapes.opacity attribute, as it is not referenced elsewhere-->
    <EXPOSED_OBJECTS object_ids="view3d.shapes.opacity"/>
</SKIN>

OpenGL script file (openGLShapes.cxx):

// function used to render simple OpenGL shapes
void glRenderShapes(float opacity)
{
// render cube
glBegin(GL_QUADS);
// Top face (y = 1.0f)
glColor4f(0.0f, 1.0f, 0.0f,opacity); // Green
glVertex3f( 1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f( 1.0f, 1.0f, 1.0f);
// Bottom face (y = -1.0f)
glColor4f(1.0f, 0.5f, 0.0f,opacity); // Orange
glVertex3f( 1.0f, -1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f( 1.0f, -1.0f, -1.0f);
// Front face (z = 1.0f)
glColor4f(1.0f, 0.0f, 0.0f,opacity); // Red
glVertex3f( 1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f( 1.0f, -1.0f, 1.0f);
// Back face (z = -1.0f)
glColor4f(1.0f, 1.0f, 0.0f,opacity); // Yellow
glVertex3f( 1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f( 1.0f, 1.0f, -1.0f);
// Left face (x = -1.0f)
glColor4f(0.0f, 0.0f, 1.0f,opacity); // Blue
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
// Right face (x = 1.0f)
glColor4f(1.0f, 0.0f, 1.0f,opacity); // Magenta
glVertex3f(1.0f, 1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glEnd();
// Render a pyramid
glTranslatef(-1.5f, 0.0f, -6.0f); // Move
glBegin(GL_TRIANGLES);
// Front
glColor4f(1.0f, 0.0f, 0.0f,opacity); // Red
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor4f(0.0f, 1.0f, 0.0f,opacity); // Green
glVertex3f(-1.0f, -1.0f, 1.0f);
glColor4f(0.0f, 0.0f, 1.0f,opacity); // Blue
glVertex3f(1.0f, -1.0f, 1.0f);
// Right
glColor4f(1.0f, 0.0f, 0.0f,opacity); // Red
glVertex3f(0.0f, 1.0f, 0.0f);
glColor4f(0.0f, 0.0f, 1.0f,opacity); // Blue
glVertex3f(1.0f, -1.0f, 1.0f);
glColor4f(0.0f, 1.0f, 0.0f,opacity); // Green
glVertex3f(1.0f, -1.0f, -1.0f);
// Back
glColor4f(1.0f, 0.0f, 0.0f,opacity); // Red
glVertex3f(0.0f, 1.0f, 0.0f);
glColor4f(0.0f, 1.0f, 0.0f,opacity); // Green
glVertex3f(1.0f, -1.0f, -1.0f);
glColor4f(0.0f, 0.0f, 1.0f,opacity); // Blue
glVertex3f(-1.0f, -1.0f, -1.0f);
// Left
glColor4f(1.0f,0.0f,0.0f,opacity); // Red
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor4f(0.0f,0.0f,1.0f,opacity); // Blue
glVertex3f(-1.0f,-1.0f,-1.0f);
glColor4f(0.0f,1.0f,0.0f,opacity); // Green
glVertex3f(-1.0f,-1.0f, 1.0f);
glEnd();
}