Use NoesisGUI in Xcode
Posted: 07 Jan 2016, 15:17
Hi!
I want integration NoesisGUI in the OS platform.But can't find the resource directory at run time。
What should resource directory Settings?Please help to see where I went wrong, or can provide a can run the Demo.
thanks!
I want integration NoesisGUI in the OS platform.But can't find the resource directory at run time。
What should resource directory Settings?Please help to see where I went wrong, or can provide a can run the Demo.
thanks!
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include "String.h"
#include "Noesis.h"
//#include "pch.h"
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include "NoesisGUI.h"
using namespace Noesis;
Ptr<Noesis::Gui::IRenderer> xamlRenderer;
int width, height;
#ifdef _MSC_VER
#define GL_FRAMEBUFFER 0x8D40
typedef void (WINAPI *PFNGLBINDFRAMEBUFFERPROC)(GLenum target, GLuint framebuffer);
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
typedef void (WINAPI * PFNGLUSEPROGRAMPROC)(GLuint program);
PFNGLUSEPROGRAMPROC glUseProgram;
#endif
/*
** Function called to update rendering
*/
void DisplayFunc(void)
{
// Tick kernel
Noesis::GUI::Tick();
// Update UI
xamlRenderer->Update(glutGet(GLUT_ELAPSED_TIME) / 1000.0f);
// ...Do something useful here because Update() is concurrent...
RenderCommands commands = xamlRenderer->WaitForUpdate();
// Render offscreen textures
if (commands.offscreenCommands != 0)
{
xamlRenderer->Render(commands.offscreenCommands.GetPtr());
}
static float alpha = 0;
glClearColor(0, 0, 0, 0);
//
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glClearDepth(1.0f);
glDepthMask(GL_TRUE);
glDisable(GL_CULL_FACE);
glDisable(GL_ALPHA_TEST);
glDisable(GL_STENCIL_TEST);
glDisable(GL_BLEND);
glDisable(GL_SCISSOR_TEST);
glUseProgram(0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, width, height);
glColorMask(true, true, true, true);
/* 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;
// Draw GUI
xamlRenderer->Render(commands.commands.GetPtr());
/* End */
glFlush();
glutSwapBuffers();
/* Update again and again */
glutPostRedisplay();
}
/*
** Function called when the window is created or resized
*/
void ReshapeFunc(int width_, int height_)
{
width = width_;
height = height_;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(20, width / (float) height, 5, 15);
glMatrixMode(GL_MODELVIEW);
glutPostRedisplay();
xamlRenderer->SetSize(width, height);
}
void KeyboardFunc(unsigned char key, int x, int y)
{
if (key == 9)
{
xamlRenderer->KeyDown(Noesis::Key_Tab);
}
else if (key == 8)
{
xamlRenderer->KeyDown(Noesis::Key_Back);
}
else
{
xamlRenderer->Char(key);
}
}
void KeyboardUpFunc(unsigned char key, int x, int y)
{
if (key == 9)
{
xamlRenderer->KeyUp(Noesis::Key_Tab);
}
else if (key == 8)
{
xamlRenderer->KeyUp(Noesis::Key_Back);
}
}
void MouseFunc(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON)
{
if (state == GLUT_UP)
{
xamlRenderer->MouseButtonUp(x, y, MouseButton_Left);
}
else
{
xamlRenderer->MouseButtonDown(x, y, MouseButton_Left);
}
}
}
void MouseMove(int x, int y)
{
xamlRenderer->MouseMove(x, y);
}
void ErrorHandler(const NsChar* filename, NsInt line, const NsChar* desc)
{
printf("\nERROR: %s\n\n", desc);
exit(1);
}
void Shutdown(void)
{
// Free global resources and shutdown kernel
xamlRenderer.Reset();
Noesis::GUI::Shutdown();
}
int main(int argc, char **argv)
{
/* Creation of the window */
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(500, 500);
glutCreateWindow("Spinning cube");
#ifdef _MSC_VER
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)wglGetProcAddress("glBindFramebuffer");
glUseProgram = (PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram");
#endif
// NoesisGUI setup
Noesis::GUI::InitOpenGL(ErrorHandler);
Noesis::GUI::AddResourceProvider("..");
// Create the UI renderer
Ptr<FrameworkElement> xaml = Noesis::GUI::LoadXaml<FrameworkElement>("UI.xaml");
xamlRenderer = Noesis::GUI::CreateRenderer(xaml.GetPtr());
xamlRenderer->SetAntialiasingMode(Noesis::Gui::AntialiasingMode_PPAA);
atexit(Shutdown);
/* Declaration of the callbacks */
glutDisplayFunc(&DisplayFunc);
glutReshapeFunc(&ReshapeFunc);
glutKeyboardFunc(&KeyboardFunc);
glutKeyboardUpFunc(&KeyboardUpFunc);
glutMouseFunc(&MouseFunc);
glutMotionFunc(&MouseMove);
glutPassiveMotionFunc(&MouseMove);
/* Loop */
glutMainLoop();
/* Never reached */
return 0;
}