The image was not appearing because the application didn't handle image loading messages.
In HTML environment, images are a loaded asynchronously. When the GLG drawing containing images gets displayed, it generates requests for loading images. When the images got loaded, the application gets notified by receiving a GLG message with the ImageLoad format. In order to provide more control over rendering for applications with fast periodic updates, the drawing doesn't get automatically updated when each image is loaded. Instead, an application can invoke Update() when it receives ImageLoad message.
If an application has periodic timer-based updates, the next periodic update will render the image when the image gets ready. The test case you provided doesn't have periodic updates, and the image gets rendered only if the drawing is resized:
function StartProcessDemo(viewport)
{
viewport.InitialDraw(); // Generates image loading requests
UpdateProcessResources(); // Set some initial drawing resources
viewport.Update();
// The application will get notified about loaded images only after exiting this function.
}
To get the image properly rendered on the initial appearance in an application without periodic updates, it has to add an Input callback and handle ImageLoad messages in it:
function StartProcessDemo(viewport)
{
viewport.AddListener( GLG.GlgCallbackType.INPUT_CB, InputCallback );
UpdateProcessResources(); // Set some initial drawing resources
viewport.InitialDraw();
}
function InputCallback( /* GlgObject */ viewport, /* GlgObject */ message_obj )
{
format = message_obj.GetSResource( "Format" );
if( format == "ImageLoad" )
viewport.Update();
}
That should solve your problem.
----------------------------------------------------------------
As a side note, it is more efficient to invoke UpdateProcessResources() before InitialDraw() and eliminate the Update() call after it, as shown in the fixed example.
In the original example, the drawing gets rendered first by InitialDraw(), and then rendered the second time by Update() after changing resources. The only exception is for resources that get created only after the drawing is drawn, which is only the case in complex drawings.