Okay, I'm playing around with it some more. It seems to matter
where the textblock setting code is called.
So I took the spinning cube sample from the opengl example from Noesis.
These four lines are what I'm using: There's a textblock with the following code added to the UIgl.xaml and built:
<Grid HorizontalAlignment="Left" Margin="0,120,0,0" Width="176">
<TextBlock x:Name="TB" Height="20" Margin="0,8,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Foreground="White" HorizontalAlignment="Center"/>
</Grid>
I am accessing it via code in the spinning cube example provided with Noesis. I'm getting different results depending on the location.
Ptr<IUIResource> guiResource = NsDynamicCast< Ptr<IUIResource> >(NsGetSystem<IResourceSystem>()->Load("Gui/Samples/SDKTutorial/UIgl.xaml"));
FrameworkElement *fe = NsStaticCast<FrameworkElement*>(guiResource->GetRoot());
TextBlock* pTextblock= NsStaticCast<TextBlock*>(fe->FindName("TB"));
pTextblock->SetValue<NsString>(TextBlock::TextProperty,"hello");
If I put this in before the atexit in the initialization code, the 'hello' persists as the label on the textblock.
int main(int argc, char **argv)
{
/* Creation of the window */
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(1000, 1000);
glutCreateWindow("Spinning cube");
#ifdef NOESIS_GUI
{
// Install an error handler to catch any problem with NoesisGui
Noesis::Core::SetErrorHandler(ErrorHandler);
// Force the OpenGL renderer
NsConfigValue("Render.RenderSystem", "Render", "GL");
// Launch Noesis Kernel
NsGetKernel()->Init();
// Create a OpenGL context that will be used by NoesisGui.
HDC hDC = wglGetCurrentDC();
IGLRenderSystem::SetContext(hDC, wglCreateContext(hDC));
NsGetKernel()->InitSystems();
// Load the .xaml resource
Ptr<IUIResource> guiResource = NsDynamicCast< Ptr<IUIResource> >(NsGetSystem<IResourceSystem>()->Load("Gui/Samples/SDKTutorial/UIgl.xaml"));
gUIRoot.Reset(NsStaticCast<UIElement*>(guiResource->GetRoot()));
// Create the UI renderer
gUIRenderer = CreateRenderer(gUIRoot.GetPtr());
gUIRenderer->SetAntialiasingMode(Noesis::Gui::AntialiasingMode_PPAA);
FrameworkElement *fe = NsStaticCast<FrameworkElement*>(guiResource->GetRoot());
TextBlock* pTextblock= NsStaticCast<TextBlock*>(fe->FindName("TB"));
pTextblock->SetValue<NsString>(TextBlock::TextProperty,"hello");
atexit(Shutdown);
}
#endif
/* OpenGL settings */
glClearColor(0, 0, 0, 0);
glEnable(GL_DEPTH_TEST);
/* Declaration of the callbacks */
glutDisplayFunc(&DisplayFunc);
glutReshapeFunc(&ReshapeFunc);
glutKeyboardFunc(&KeyboardFunc);
glutMouseFunc(&MouseFunc);
glutMotionFunc(&MouseMove);
glutPassiveMotionFunc(&MouseMove);
/* Loop */
glutMainLoop();
/* Never reached */
return 0;
}
It does not update the textblock label if instead the code is put into the render code before the renderer update: i.e.
void DisplayFunc(void)
{
static float alpha = 0;
/* Clear the buffer, clear the matrix */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
/* A step backward, then spin the cube */
glTranslatef(0, 0, -10);
glRotatef(30, 1, 0, 0);
glRotatef(alpha, 0, 1, 0);
/* We tell we want to draw quads */
glBegin(GL_QUADS);
/* Every four calls to glVertex, a quad is drawn */
glColor3f(0, 0, 0); glVertex3f(-1, -1, -1);
glColor3f(0, 0, 1); glVertex3f(-1, -1, 1);
glColor3f(0, 1, 1); glVertex3f(-1, 1, 1);
glColor3f(0, 1, 0); glVertex3f(-1, 1, -1);
glColor3f(1, 0, 0); glVertex3f( 1, -1, -1);
glColor3f(1, 0, 1); glVertex3f( 1, -1, 1);
glColor3f(1, 1, 1); glVertex3f( 1, 1, 1);
glColor3f(1, 1, 0); glVertex3f( 1, 1, -1);
glColor3f(0, 0, 0); glVertex3f(-1, -1, -1);
glColor3f(0, 0, 1); glVertex3f(-1, -1, 1);
glColor3f(1, 0, 1); glVertex3f( 1, -1, 1);
glColor3f(1, 0, 0); glVertex3f( 1, -1, -1);
glColor3f(0, 1, 0); glVertex3f(-1, 1, -1);
glColor3f(0, 1, 1); glVertex3f(-1, 1, 1);
glColor3f(1, 1, 1); glVertex3f( 1, 1, 1);
glColor3f(1, 1, 0); glVertex3f( 1, 1, -1);
glColor3f(0, 0, 0); glVertex3f(-1, -1, -1);
glColor3f(0, 1, 0); glVertex3f(-1, 1, -1);
glColor3f(1, 1, 0); glVertex3f( 1, 1, -1);
glColor3f(1, 0, 0); glVertex3f( 1, -1, -1);
glColor3f(0, 0, 1); glVertex3f(-1, -1, 1);
glColor3f(0, 1, 1); glVertex3f(-1, 1, 1);
glColor3f(1, 1, 1); glVertex3f( 1, 1, 1);
glColor3f(1, 0, 1); glVertex3f( 1, -1, 1);
/* No more quads */
glEnd();
/* Rotate a bit more */
alpha = alpha + 0.1;
#ifdef NOESIS_GUI
// Tick kernel
Ptr<IUIResource> guiResource = NsDynamicCast< Ptr<IUIResource> >(NsGetSystem<IResourceSystem>()->Load("Gui/Samples/SDKTutorial/UIgl.xaml"));
FrameworkElement *fe = NsStaticCast<FrameworkElement*>(guiResource->GetRoot());
TextBlock* pTextblock= NsStaticCast<TextBlock*>(fe->FindName("TB"));
pTextblock->SetValue<NsString>(TextBlock::TextProperty,"hello");
NsGetKernel()->Tick();
// Update renderer
gUIRenderer->Update(glutGet(GLUT_ELAPSED_TIME) / 1000.0f);
// ...Do something useful here because Update() is concurrent...
RenderCommands* commands = gUIRenderer->WaitForUpdate();
// Render
gUIRenderer->Render(commands);
// ...Do something useful here because Render() is concurrent...
gUIRenderer->WaitForRender();
#endif
/* End */
glFlush();
glutSwapBuffers();
/* Update again and again */
glutPostRedisplay();
}
So I'm not sure how to dynamically update the textblock.
Thanks in advance for any help.