leiguoqiang
Topic Author
Posts: 8
Joined: 21 Dec 2015, 06:22

Use NoesisGUI in Xcode

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!
1.jpg
error prompt
1.jpg
error prompt
#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;
}
Attachments
2.jpg
Resource load
2.jpg (12.75 KiB) Viewed 2173 times
Last edited by leiguoqiang on 07 Jan 2016, 15:45, edited 1 time in total.
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Use NoesisGUI in Xcode

07 Jan 2016, 15:32

The key is this line:
Noesis::GUI::AddResourceProvider("..");
This indicates the root folder where resources are found. In the example given, they are expected to be found in the parent directory of the current working one.

You should adjust that value accordingly in your project.
 
leiguoqiang
Topic Author
Posts: 8
Joined: 21 Dec 2015, 06:22

Re: Use NoesisGUI in Xcode

07 Jan 2016, 15:47

But I gave it to a directory of absolute position, still it is。
Noesis::GUI::AddResourceProvider("/Users/leiguoqiang/Desktop/");
or
Noesis::GUI::AddResourceProvider("./");
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Use NoesisGUI in Xcode

07 Jan 2016, 15:55

And do you have UI.xaml.nsb (the preprocessed XAML using the BuildTool) at /Users/leiguoqiang/Desktop/ ?
 
leiguoqiang
Topic Author
Posts: 8
Joined: 21 Dec 2015, 06:22

Re: Use NoesisGUI in Xcode

07 Jan 2016, 16:22

Can not directly use the .xaml files?
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Use NoesisGUI in Xcode

07 Jan 2016, 16:25

Not in this version. You need to preprocess them using the BuildTool. This is something that is going to change in v1.3, by popular request : )
 
leiguoqiang
Topic Author
Posts: 8
Joined: 21 Dec 2015, 06:22

Re: Use NoesisGUI in Xcode

07 Jan 2016, 16:39

D17AB4DD-AF03-4AF0-B8FC-303C3D82A0EC.jpg
Thank you very mach! The running effect is very good!
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Use NoesisGUI in Xcode

07 Jan 2016, 16:56

Nice!! : D

Who is online

Users browsing this forum: No registered users and 1 guest