empty.cpp

This is an example of a minimal Tk11 application. The only thing it does is flash the screen periodically. It implements the most commonly used callbacks of the Tk11 framework but does not use all of them.

You can use this example as a template for building your own applications.

//          Copyright Florian Winter 2010 - 2010.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

#include <tk11/tk11.hpp>

using namespace tk11;


// Resize callback.
// Here we update all variables which depend on the size of the target window,
// such as projection matrices and viewport parameters.
void resize(unsigned int x_resolution, unsigned int y_resolution,
    bool fullscreen, ID3D11Device_ptr device, IDXGISwapChain_ptr swap_chain,
    ID3D11Texture2D_ptr back_buffer)
{}


// Scene initialization callback.
// Here we create resources, such as textures, buffers and shaders.
void init(ID3D11Device_ptr device) {}


// Background color.
// Updated every frame and used for clearing the back buffer.
static float background_color = 0;


// Scene update callback.
// Here we update all variables that change over time.
void update(const Duration& elapsed_time) {
  // Set clear color
  background_color =
    fmod(time_div_float<float>(elapsed_time, seconds(1)), 1.0f);
}


// Scene rendering callback.
// Here we render the scene to the main render target (the back buffer)
void render(ID3D11DeviceContext_ptr context,
    ID3D11RenderTargetView_ptr render_target,
    ID3D11DepthStencilView_ptr depth_stencil)
{
  // Clear render target
  float clear_color_rgba[] = {
    background_color, background_color, background_color, 0
  };
  context->ClearRenderTargetView(render_target.get(), clear_color_rgba);
}


int main() {
  try {
    // Window parameters
    Window_Parameters parameters;
    
    // Set windowed mode with 800x600 resolution
    parameters.x_resolution = 800;
    parameters.y_resolution = 600;
    parameters.fullscreen = false;

    // Set callbacks
    parameters.resize_callback = &resize;
    parameters.init_callback = &init;
    parameters.update_callback = &update;
    parameters.render_callback = &render;

    // Create framework
    Framework framework;

    // Create window
    Window window(framework, parameters);

    // Main loop
    framework.run();

    return 0;
  }
  catch(const boost::exception& e) {
    // Show an error dialog with diagnostic information about the exception
    // which occurred.
    // (Only for debugging. In a real application, you may want to translate
    // exceptions into more readable error messages).
    show_error_dialog(diagnostic_information(e));
    return 1;
  }
  catch(const std::exception& e) {
    // Show an error dialog with the name of the exception.
    // (Only for debugging. In a real application, you may want to translate
    // exceptions into more readable error messages).
    show_error_dialog(e.what());
    return 1;
  }
  catch(...) {
    // Show an error dialog.
    // (Only for debugging. In a real application, you may want to translate
    // exceptions into more readable error messages).
    show_error_dialog("Unknown exception");
    return 1;
  }
}
Tk11 Direct3D 11 Toolkit version 0.2 (SourceForge)
Copyright Florian Winter 2010 - 2010. Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Generated on Sun Apr 11 20:22:57 2010 for Tk11 by  doxygen 1.6.3