DI-Guy Graphics API, Immediate Mode with DI-Guy Loader Example

simple_playback_ogl.cpp

DI-Guy API Version 12.5.1

This file was automatically generated from simple_playback_ogl.cpp. Do not edit this file directly; the changes will be lost.
This example program loads and plays back a DI-Guy Scenario (.dss) file using immediate mode OpenGL calls and the DI-Guy geometry loader.

This example makes use of the following 3rdparty software to create a 3D graphics environment:

Header files and forward declarations
#include <stdlib.h>
#include <stdio.h>

#include <diguy_graphics_api.h>

#include <diguy_module_script_lua.h>

#include <diguyApp.h>
#include <diguyScenario.h>
#include <diguyViewCamera.h>
#include <diguyCharacter.h>
#include <diguySceneObject.h>
#include <libbdilog.h>

#include "set_up_view.h"

#include "diguyOglGraphicsLink.h"
#include "diguyOglGraphicsShape.h"
#include "diguyOglGraphicsMaterial.h"
#include "diguyOglGraphicsTexture.h"
#include "diguyOglGraphicsMesh.h"
#include "diguyOglGraphicsShaderInstance.h"
#include "diguyOglGraphicsShaderProgram.h"
#include "diguyOglGraphicsShaderTechnique.h"

#include <GL/glut.h>

static double t = 0.0;
static diguyScenario* scenario = NULL;
main
Description:

Initialize the 3D environment, the DI-Guy Graphics API, and various DI-Guy modules. Once initiailzed, start the main loop of the example.

int
main(int argc, char** argv)
{
    char* arg_dss_filename;

    void glut_idle_callback(void);
    void glut_display_callback(void);
    void glut_keyboard_callback(unsigned char key, int x, int y);

    /*
     *  These calls initialize the BDI logging mechanism.  Log messages of
     *   priority BDI_LOG_DEBUG or higher get recorded into the file
     *   diguy_log.txt.  Log messages of priority BDI_LOG_WARN or higher get
     *   printed on standard out.
     */
    bdi_log_file_enable(BDI_LOG_DEBUG, "diguy_log.txt", 1);
    bdi_log_stdout_enable(BDI_LOG_WARN);

    /*
     *  Decide which file to play back.
     */
    if (argc > 1)
        arg_dss_filename = argv[1];
    else
        arg_dss_filename = "example.dss";

    /*
     *  Create a graphics window.
     */
    view_initialize();

    /*
     *  Initialize glew, the GL Extension Wrangler library.
     */
    GLboolean glew_initialized = initialize_glew();

    if (!glew_initialized)
    {
        exit(EXIT_FAILURE);
    }

    /*
     *  glew checks to see if required shader extensions are available.  If
     *   they're not, skinned appearances will not work.
     */
    if (!s_shader_extension_available)
    {
        bdi_log_printf(BDI_LOG_WARN,
            "WARNING: OpenGL shader extension not available; skinned "
            "appearances not available.\n");
    }

    /*
     *  Set graphics object create functions.  This has to be done before
     *   calling diguy_graphics_initialize().
     */
    diguy_graphics_set_link_create_func(diguyOglGraphicsLink_create_func);
    diguy_graphics_set_shape_create_func(diguyOglGraphicsShape_create_func);
    diguy_graphics_set_material_create_func(diguyOglGraphicsMaterial_create_func);
    diguy_graphics_set_texture_create_func(diguyOglGraphicsTexture_create_func);
    diguy_graphics_set_mesh_create_func(diguyOglGraphicsMesh_create_func);

    diguy_graphics_set_shader_technique_create_func(diguyOglGraphicsShaderTechnique_create_func);
    diguy_graphics_set_shader_program_create_func(diguyOglGraphicsShaderProgram_create_func);
    diguy_graphics_set_shader_instance_create_func(diguyOglGraphicsShaderInstance_create_func);

    /*
     *  Initialize DI-Guy.
     */
    bdiGraphicsInitGraphicsAPI graphics_init;
    diguy_graphics_get_defaults(&graphics_init);

    graphics_init.use_cached_compressed_textures = 1;
    graphics_init.use_cached_optimized_geometry = 1;
    graphics_init.use_shaders = 1;
    graphics_init.use_linear_traversal_draw = 1;

    if (diguy_graphics_initialize(&graphics_init))
    {
        bdi_log_printf(BDI_LOG_ERROR, "DI-Guy failed to initialize.\n");
        exit(EXIT_FAILURE);
    }

    /*
     *  Initialize the DI-Guy lua interpreter.
     */
    if (diguy_script_lua_initialize())
    {
        bdi_log_printf(BDI_LOG_WARN, "WARNING: DI-Guy lua interpreter failed to initialize.\n");
    }

    /*
     *  Create a scenario.
     */
    scenario = diguy_create_scenario();
    if (!scenario)
    {
        bdi_log_printf(BDI_LOG_ERROR, "DI-Guy failed to create a scenario.\n");
        exit(EXIT_FAILURE);
    }

    /*
     *  Enable scene objects.
     */
    scenario->set_scene_objects_enabled(1);

    /*
     *  Uncomment to turn on asynchronous texture loading to demonstrate it.
     */
    //diguyCharacter::set_texture_load_behavior(DIGUY_LOAD_PRIORITY_ASYNC);
    //diguySceneObject::set_texture_load_behavior(DIGUY_LOAD_PRIORITY_ASYNC);

    /*
     *  Load the dss file.
     */
    scenario->load(arg_dss_filename);

    /*
     *  Initialize the view and camera.
     *  Do this post scenario load to override scenario values
     */
    view_set_camera(scenario, 0.0f, 15.0f, 2.0f,
        0.0f, 0.0f, 1.0f);

    view_set_light(scenario, 0.7f, 0.7f, 1.0f);

    /*
     *  Start time now.
     */
    t = 0.0;
    view_init_time(t);

    /*
     *  Start the glut main loop.
     */
    glutIdleFunc(glut_idle_callback);
    glutDisplayFunc(glut_display_callback);
    glutKeyboardFunc(glut_keyboard_callback);
    glutMainLoop();

    return 0;
}
shutdown
Description:

Deinitialize all of DI-Guy and exit the program.

void
shutdown()
{
    glutIdleFunc(NULL);

    diguy_destroy_scenario(scenario);
    diguy_script_lua_deinitialize();
    diguy_deinitialize();

    exit(EXIT_SUCCESS);
}
glut_keyboard_callback
Description:

Called by glut on a key press. Handle the key press.

void
glut_keyboard_callback(unsigned char k, int /*x*/, int /*y*/)
{
    if (scenario)
    {
        switch (k)
        {
            case 27:  // ESC
            case 3:   // ctrl c
            case 'q':
                shutdown();
                break;
        }
    }
}
glut_idle_callback
Description:

Called by glut periodically, when not responding to other events. Advance simulation time and update DI-Guy.

void
glut_idle_callback(void)
{
    /*
     *  Advance time.
     */
    t = view_get_time();
    //t += 0.025;

    if (scenario)
    {
        /*
         *  See if the scenario tout (T Out) is reached.  If so, shut down.
         */
        if (t >= scenario->get_tout())
            shutdown();
        
        /*
         *  Update the scenario to the current time.
         */
        scenario->update(t);
    }

    /*
     *  Tell glut that it should re-render.
     */
    glutPostRedisplay();
}
glut_display_callback
Description:

Called by glut when it's time to re-render.

void
glut_display_callback(void)
{
    glPushMatrix(); {

        view_clear_screen();
        if (scenario->get_num_scene_objects() == 0)
            view_draw_background();

        /*
         *  Tell the scenario to draw all of its characters, etc.
         */
        scenario->draw();

    } glPopMatrix();

    glutSwapBuffers();
}



Copyright (C) 1992-2012 Boston Dynamics

ALL RIGHTS RESERVED.

These coded instructions, statements, and computer programs contain unpublished proprietary information of Boston Dynamics and are protected by Copyright Laws of the United States. They may not be used, duplicated, or disclosed in any form, in whole or in part, without the prior written consent from Boston Dynamics.

RESTRICTED RIGHTS LEGEND

Use, duplication, or disclosure by the government is subject to restrictions as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Sofware clause at DFARS 252.227-7013 and/or in similar or successor clauses in the FAR, or the DOD or NASA FAR Supplement, or to subparagraphs (c)(1) and (c)(2) of the Commercial Computer Software--Restricted Rights at 48 CFR 52.227-19, as applicable. Unpublished-rights reserved under the Copyright Laws of the United States.

Contractor/Manufacturer is:

Boston Dynamics/78 Fourth Avenue/Waltham MA 02451.