# Creating a prototype

The HOOPS Visualize installation includes simple applications for a variety of GUI technologies. These applications provide a framework for the tutorials discussed later in this guide, and can also serve as containers for prototyping code. This section reviews how to start with a simple HOOPS Visualize application and insert a ‘HelloWorld’ text string in the scene-graph. Your the GUI technology can be selected on the menu to the right.

## MFC - Microsoft Foundation Classes

The MFC demonstration application can be found in the HOOPS Visualize solution, mfc_simple_vcXX project. Open the file SampleHView.cpp and find the function `OnRunMyCode()`. After recompiling the project, the following code will be run when you start the application and click the down arrow:

    void CSampleHView::OnRunMyCode()
    {
            HC_Open_Segment_By_Key(m_pHView->GetModelKey());
            {
                    HC_Insert_Text(0, 0, 0, "Hello world");
            }
            HC_Close_Segment();

            m_pHView->Update();
    }

This code does the following:

1. Opens the model segment using the model key

2. Inserts the text string at the origin

3. Closes the segment, since we aren’t doing anything else

4. Updates the scene

## Windows Forms

This tutorial describes how to take the ‘simple’ HOOPS/Winforms application and display the text ‘Hello World’ in the viewport. You may wish to first review the HOOPS/Winforms documentation to get an idea of the structure of the provided application.

Let’s modify the csharp_simple application to display the ‘Hello World’ text each time a new window is opened. This can be achieved by adding code to the custom HSimpleModel constructor which does the following:

1. Opens the segment associated with the model object. The numerical identifier of the segment (called a ‘key’) is accessed by calling the model object’s `HBaseModel::GetModelKey` method, and the segment is opened using the `HCS.Open_Segment_By_Key` subroutine.

2. Inserts a piece of text into the segment by calling `HCS.Insert_Text`.

3. Closes the segment by calling `HCS.Close_Segment`.

The sample code would be added to the `HSimpleModel::Init` method in SimpleHNPanel.cs:

    public class HSimpleModel : HBaseModel
    {
      ...

      override public void Init()
      {
            base.Init();

            HCS.Open_Segment_By_Key(GetModelKey());
              HCS.Insert_Text(0.0f, 0.0f, 0.0f, "Hello World");
            HCS.Close_Segment();
      }

      ...
    }

## Qt

This tutorial describes how to take the ‘simple’ HOOPS/QT application and display the text ‘Hello World’ in the viewport. You may wish to first review the HOOPS/QT documentation to get an idea of the structure of the provided application.

The source code to the simple HOOPS/Qt application is located in <hoops_install_dir>/demo/qt/qt_simple_4. Compile and run it to make sure your development environment is set up correctly.

Let’s modify the application to display the ‘Hello World’ text each time a new window is opened. This can be achieved by adding code to the custom HOOPS/QT widget’s constructor, which does the following:

1. Opens the HOOPS/3dGS segment associated with the model object. The numerical identifier of the segment (called a ‘key’) is accessed by calling the model object’s `HBaseModel::GetModelKey` method, and the segment is opened using `Open_Segment_By_Key`.

2. Inserts a piece of text into the segment by calling `Insert_Text`.

3. Closes the segment by calling `Close_Segment`.

The modified `SimpleHQWidget` constructor would look like the following:

    SimpleHQWidget::SimpleHQWidget(QWidget* parent, const char* name, const char * filename)
            : HQWidget( parent, name )
    {
       CreateMenus();

       // Create and initialize HOOPS/MVO Model and View objects
       m_pHBaseModel = new HBaseModel();
       m_pHBaseModel->Init();

       HC_Open_Segment_By_Key(m_pHBaseModel->GetModelKey());
             HC_Insert_Text(0.0f, 0.0f, 0.0f, "Hello World");
       HC_Close_Segment();

       // Initialize View object to null ; gets created in SimpleHQWidget::Init
       m_pHView = 0;

       // if called with a file name we load it
       // otherwise open an empty view
       if(filename)
       m_pHBaseModel->Read(filename);

       // enable MouseMoveEvents
       setMouseTracking(true);

       // enable key events
       setEnabled(true);
       setFocusPolicy(QWidget::StrongFocus);
    }

Note that the sample code could have also been inserted in an overloaded method of `HBaseModel::Init`.

## Java

This tutorial describes how to take the ‘simple’ HOOPS/Java application and display the text ‘Hello World’ in the viewport. You may wish to first review the HOOPS/Java documentation to get an idea of the structure of the provided application.

The source code to the simple HOOPS/Java application is located in <hoops_install_dir>/demo/java/java_simple. Follow the steps in the readme.txt file to recompile and run it.

Let’s modify the application to display the ‘Hello World’ text each time a new window is opened. This can be achieved by adding code to the `HSimpleModel::Init` which does the following:

1. Opens the segment associated with the model object. The numerical identifier of the segment (called a ‘key’) is accessed by calling the model object’s `HBaseModel::GetModelKey` method, and the segment is opened using `::Open_Segment_By_Key`.

2. Inserts a piece of text into the segment by calling `::Insert_Text`.

3. Closes the segment by calling `::Close_Segment`.

The modified `HSimpleModel::Init` method would look like the following:

    class HSimpleModel  extends HBaseModel
    {
      ...

      public void Init()
      {
            super.Init();

            HJ.Open_Segment_By_Key(GetModelKey());
              HJ.Insert_Text(0.0f, 0.0f, 0.0f, "Hello World");
            HJ.Close_Segment();
      }

      ...
    }

Note that the sample code could have also been inserted in an overloaded method of `HBaseModel::Init`.