Beispiel #1
0
int main(int argc, char** argv)
{
    Slot* slots;
    GLFWmonitor* monitor = NULL;
    int ch, i, width, height, count = 1;

    setlocale(LC_ALL, "");

    glfwSetErrorCallback(error_callback);

    if (!glfwInit())
        exit(EXIT_FAILURE);

    printf("Library initialized\n");

    glfwSetMonitorCallback(monitor_callback);
    glfwSetJoystickCallback(joystick_callback);

    while ((ch = getopt(argc, argv, "hfn:")) != -1)
    {
        switch (ch)
        {
            case 'h':
                usage();
                exit(EXIT_SUCCESS);

            case 'f':
                monitor = glfwGetPrimaryMonitor();
                break;

            case 'n':
                count = (int) strtol(optarg, NULL, 10);
                break;

            default:
                usage();
                exit(EXIT_FAILURE);
        }
    }

    if (monitor)
    {
        const GLFWvidmode* mode = glfwGetVideoMode(monitor);

        glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
        glfwWindowHint(GLFW_RED_BITS, mode->redBits);
        glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
        glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);

        width = mode->width;
        height = mode->height;
    }
    else
    {
        width  = 640;
        height = 480;
    }

    if (!count)
    {
        fprintf(stderr, "Invalid user\n");
        exit(EXIT_FAILURE);
    }

    slots = calloc(count, sizeof(Slot));

    for (i = 0;  i < count;  i++)
    {
        char title[128];

        slots[i].closeable = GLFW_TRUE;
        slots[i].number = i + 1;

        sprintf(title, "Event Linter (Window %i)", slots[i].number);

        if (monitor)
        {
            printf("Creating full screen window %i (%ix%i on %s)\n",
                   slots[i].number,
                   width, height,
                   glfwGetMonitorName(monitor));
        }
        else
        {
            printf("Creating windowed mode window %i (%ix%i)\n",
                   slots[i].number,
                   width, height);
        }

        slots[i].window = glfwCreateWindow(width, height, title, monitor, NULL);
        if (!slots[i].window)
        {
            free(slots);
            glfwTerminate();
            exit(EXIT_FAILURE);
        }

        glfwSetWindowUserPointer(slots[i].window, slots + i);

        glfwSetWindowPosCallback(slots[i].window, window_pos_callback);
        glfwSetWindowSizeCallback(slots[i].window, window_size_callback);
        glfwSetFramebufferSizeCallback(slots[i].window, framebuffer_size_callback);
        glfwSetWindowCloseCallback(slots[i].window, window_close_callback);
        glfwSetWindowRefreshCallback(slots[i].window, window_refresh_callback);
        glfwSetWindowFocusCallback(slots[i].window, window_focus_callback);
        glfwSetWindowIconifyCallback(slots[i].window, window_iconify_callback);
        glfwSetMouseButtonCallback(slots[i].window, mouse_button_callback);
        glfwSetCursorPosCallback(slots[i].window, cursor_position_callback);
        glfwSetCursorEnterCallback(slots[i].window, cursor_enter_callback);
        glfwSetScrollCallback(slots[i].window, scroll_callback);
        glfwSetKeyCallback(slots[i].window, key_callback);
        glfwSetCharCallback(slots[i].window, char_callback);
        glfwSetCharModsCallback(slots[i].window, char_mods_callback);
        glfwSetDropCallback(slots[i].window, drop_callback);

        glfwMakeContextCurrent(slots[i].window);
        gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
        glfwSwapInterval(1);
    }

    printf("Main loop starting\n");

    for (;;)
    {
        for (i = 0;  i < count;  i++)
        {
            if (glfwWindowShouldClose(slots[i].window))
                break;
        }

        if (i < count)
            break;

        glfwWaitEvents();

        // Workaround for an issue with msvcrt and mintty
        fflush(stdout);
    }

    free(slots);
    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Beispiel #2
0
int main()
{
    GLFWwindow *window;
    char *userptr = "userptr";

    glfwSetErrorCallback(errorcb);
    assert(glfwInit() == GL_TRUE);
    assert(!strcmp(glfwGetVersionString(), "3.0.0 JS WebGL Emscripten"));

    {
        int major, minor, rev;
        glfwGetVersion(&major, &minor, &rev);
        assert(major == 3);
        assert(minor == 0);
        assert(rev == 0);
    }

    {
        int count, x, y, w, h;
        GLFWmonitor **monitors = glfwGetMonitors(&count);
        assert(count == 1);
        for (int i = 0; i < count; ++i) {
            assert(monitors[i] != NULL);
        }

        assert(glfwGetPrimaryMonitor() != NULL);
        glfwGetMonitorPos(monitors[0], &x, &y);
        glfwGetMonitorPhysicalSize(monitors[0], &w, &h);
        assert(glfwGetMonitorName(monitors[0]) != NULL);
        glfwSetMonitorCallback(monitcb);

        // XXX: not implemented
        // assert(glfwGetVideoModes(monitors[0], &count) != NULL);
        // assert(glfwGetVideoMode(monitors[0]) != NULL);
        // glfwSetGamma(monitors[0], 1.0f);
        // assert(glfwGetGammaRamp(monitors[0]) != NULL);
        // glfwSetGammaRamp(monitors[0], ramp);
    }

    {
        int x, y, w, h;
        glfwDefaultWindowHints();
        glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);

        window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL);
        assert(window != NULL);

        glfwSetWindowPosCallback(window, wposicb);
        glfwSetWindowSizeCallback(window, wsizecb);
        glfwSetWindowCloseCallback(window, wcloscb);
        glfwSetWindowRefreshCallback(window, wrfrscb);
        glfwSetWindowFocusCallback(window, wfocucb);
        glfwSetWindowIconifyCallback(window, wiconcb);
        glfwSetFramebufferSizeCallback(window, wfsizcb);

        assert(glfwWindowShouldClose(window) == 0);
        glfwSetWindowShouldClose(window, 1);
        assert(glfwWindowShouldClose(window) == 1);

        glfwSetWindowTitle(window, "test");
        glfwSetWindowTitle(window, "glfw3.c");

        // XXX: not implemented
        // glfwSetWindowPos(window, 1, 1);

        glfwGetWindowPos(window, &x, &y); // stub
        glfwGetWindowSize(window, &w, &h);
        assert(w == 640 && h == 480);

        glfwSetWindowSize(window, 1, 1);
        glfwGetWindowSize(window, &w, &h);
        assert(w == 1 && h == 1);

        glfwSetWindowSize(window, 640, 480);
        glfwGetFramebufferSize(window, &w, &h);

        // XXX: not implemented
        // glfwIconifyWindow(window);
        // glfwRestoreWindow(window);
        // glfwShowWindow(window);
        // glfwHideWindow(window);

        assert(glfwGetWindowMonitor(window) == NULL);
        glfwDestroyWindow(window);

        window = glfwCreateWindow(640, 480, "glfw3.c", glfwGetPrimaryMonitor(), NULL);
        assert(window != NULL);
        assert(glfwGetWindowMonitor(window) == glfwGetPrimaryMonitor());
        glfwDestroyWindow(window);

        window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL);
        assert(window != NULL);

        assert(glfwGetWindowAttrib(window, GLFW_CLIENT_API) == GLFW_OPENGL_ES_API);

        assert(glfwGetWindowUserPointer(window) == NULL);
        glfwSetWindowUserPointer(window, userptr);
        assert(glfwGetWindowUserPointer(window) == userptr);
    }

    {
        double x, y;

        glfwSetKeyCallback(window, wkeypcb);
        glfwSetCharCallback(window, wcharcb);
        glfwSetMouseButtonCallback(window, wmbutcb);
        glfwSetCursorPosCallback(window, wcurpcb);
        glfwSetCursorEnterCallback(window, wcurecb);
        glfwSetScrollCallback(window, wscrocb);

        // XXX: stub, events come immediatly
        // glfwPollEvents();
        // glfwWaitEvents();

        assert(glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_NORMAL);

        // XXX: not implemented
        // glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);

        glfwGetKey(window, GLFW_KEY_A);
        glfwGetMouseButton(window, 0);
        glfwGetCursorPos(window, &x, &y);

        // XXX: not implemented
        // glfwSetCursorPos(window, 0, 0);
    }

    {
        // XXX: not implemented
        // glfwJoystickPresent(joy);
        // glfwGetJoystickAxes(joy, &count);
        // glfwGetJoystickButtons(joy, &count);
        // glfwGetJoystickName(joy);
    }

    {
        // XXX: not implemented
        // glfwSetClipboardString(window, "string");
        // glfwGetClipboardString(window);
    }

    {
        glfwGetTime();
        glfwSetTime(0);
    }

    {
        glfwMakeContextCurrent(window); // stub
        assert(glfwGetCurrentContext() == window);
        glfwSwapBuffers(window); // stub
        glfwSwapInterval(0); // stub
    }

    {
        assert(glfwExtensionSupported("nonexistant") == 0);
        assert(glfwGetProcAddress("nonexistant") == NULL);
    }

    glfwTerminate();

#ifdef REPORT_RESULT
    int result = 1;
    REPORT_RESULT();
#endif
    return 0;
}
bool GLViewImpl::initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor, bool resizable)
{
    setViewName(viewName);

    _frameZoomFactor = frameZoomFactor;

    glfwWindowHint(GLFW_RESIZABLE, resizable ? GL_TRUE : GL_FALSE);
    glfwWindowHint(GLFW_RED_BITS,_glContextAttrs.redBits);
    glfwWindowHint(GLFW_GREEN_BITS,_glContextAttrs.greenBits);
    glfwWindowHint(GLFW_BLUE_BITS,_glContextAttrs.blueBits);
    glfwWindowHint(GLFW_ALPHA_BITS,_glContextAttrs.alphaBits);
    glfwWindowHint(GLFW_DEPTH_BITS,_glContextAttrs.depthBits);
    glfwWindowHint(GLFW_STENCIL_BITS,_glContextAttrs.stencilBits);

    int needWidth = rect.size.width * _frameZoomFactor;
    int neeHeight = rect.size.height * _frameZoomFactor;

    _mainWindow = glfwCreateWindow(needWidth, neeHeight, _viewName.c_str(), _monitor, nullptr);

    if (_mainWindow == nullptr)
    {
        std::string message = "Can't create window";
        if (!_glfwError.empty())
        {
            message.append("\nMore info: \n");
            message.append(_glfwError);
        }

        MessageBox(message.c_str(), "Error launch application");
        return false;
    }

    /*
    *  Note that the created window and context may differ from what you requested,
    *  as not all parameters and hints are
    *  [hard constraints](@ref window_hints_hard).  This includes the size of the
    *  window, especially for full screen windows.  To retrieve the actual
    *  attributes of the created window and context, use queries like @ref
    *  glfwGetWindowAttrib and @ref glfwGetWindowSize.
    *
    *  see declaration glfwCreateWindow
    */
    int realW = 0, realH = 0;
    glfwGetWindowSize(_mainWindow, &realW, &realH);
    if (realW != needWidth)
    {
        rect.size.width = realW / _frameZoomFactor;
    }
    if (realH != neeHeight)
    {
        rect.size.height = realH / _frameZoomFactor;
    }

    glfwMakeContextCurrent(_mainWindow);

    glfwSetMouseButtonCallback(_mainWindow, GLFWEventHandler::onGLFWMouseCallBack);
    glfwSetCursorPosCallback(_mainWindow, GLFWEventHandler::onGLFWMouseMoveCallBack);
    glfwSetScrollCallback(_mainWindow, GLFWEventHandler::onGLFWMouseScrollCallback);
    glfwSetCharCallback(_mainWindow, GLFWEventHandler::onGLFWCharCallback);
    glfwSetKeyCallback(_mainWindow, GLFWEventHandler::onGLFWKeyCallback);
    glfwSetWindowPosCallback(_mainWindow, GLFWEventHandler::onGLFWWindowPosCallback);
    glfwSetFramebufferSizeCallback(_mainWindow, GLFWEventHandler::onGLFWframebuffersize);
    glfwSetWindowSizeCallback(_mainWindow, GLFWEventHandler::onGLFWWindowSizeFunCallback);
    glfwSetWindowIconifyCallback(_mainWindow, GLFWEventHandler::onGLFWWindowIconifyCallback);

    setFrameSize(rect.size.width, rect.size.height);

    // check OpenGL version at first
    const GLubyte* glVersion = glGetString(GL_VERSION);

    if ( utils::atof((const char*)glVersion) < 1.5 )
    {
        char strComplain[256] = {0};
        sprintf(strComplain,
                "OpenGL 1.5 or higher is required (your version is %s). Please upgrade the driver of your video card.",
                glVersion);
        MessageBox(strComplain, "OpenGL version too old");
        return false;
    }

    initGlew();

    // Enable point size by default.
    glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);

    return true;
}
Beispiel #4
0
int main(int argc, char** argv)
{
    int width, height, ch;
    GLFWmonitor* monitor = NULL;
    GLFWwindow* window;

    glfwSetErrorCallback(error_callback);

    if (!glfwInit())
        exit(EXIT_FAILURE);

    while ((ch = getopt(argc, argv, "fh")) != -1)
    {
        switch (ch)
        {
            case 'h':
                usage();
                exit(EXIT_SUCCESS);

            case 'f':
                monitor = glfwGetPrimaryMonitor();
                break;

            default:
                usage();
                exit(EXIT_FAILURE);
        }
    }

    if (monitor)
    {
        GLFWvidmode mode = glfwGetVideoMode(monitor);
        width = mode.width;
        height = mode.height;
    }
    else
    {
        width = 640;
        height = 480;
    }

    window = glfwCreateWindow(width, height, "Iconify", monitor, NULL);
    if (!window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    glfwSetKeyCallback(window, key_callback);
    glfwSetWindowSizeCallback(window, window_size_callback);
    glfwSetWindowCloseCallback(window, window_close_callback);
    glfwSetWindowFocusCallback(window, window_focus_callback);
    glfwSetWindowIconifyCallback(window, window_iconify_callback);

    printf("Window is %s and %s\n",
           glfwGetWindowParam(window, GLFW_ICONIFIED) ? "iconified" : "restored",
           glfwGetWindowParam(window, GLFW_FOCUSED) ? "focused" : "defocused");

    glEnable(GL_SCISSOR_TEST);

    while (!closed)
    {
        glfwGetWindowSize(window, &width, &height);

        glScissor(0, 0, width, height);
        glClearColor(0, 0, 0, 0);
        glClear(GL_COLOR_BUFFER_BIT);

        glScissor(0, 0, 640, 480);
        glClearColor(1, 1, 1, 0);
        glClear(GL_COLOR_BUFFER_BIT);

        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Beispiel #5
0
int main(int argc, char** argv)
{
    int ch, i, window_count;
    GLboolean auto_iconify = GL_TRUE, fullscreen = GL_FALSE, all_monitors = GL_FALSE;
    GLFWwindow** windows;

    while ((ch = getopt(argc, argv, "afhn")) != -1)
    {
        switch (ch)
        {
            case 'a':
                all_monitors = GL_TRUE;
                break;

            case 'h':
                usage();
                exit(EXIT_SUCCESS);

            case 'f':
                fullscreen = GL_TRUE;
                break;

            case 'n':
                auto_iconify = GL_FALSE;
                break;

            default:
                usage();
                exit(EXIT_FAILURE);
        }
    }

    glfwSetErrorCallback(error_callback);

    if (!glfwInit())
        exit(EXIT_FAILURE);

    glfwWindowHint(GLFW_AUTO_ICONIFY, auto_iconify);

    if (fullscreen && all_monitors)
    {
        int monitor_count;
        GLFWmonitor** monitors = glfwGetMonitors(&monitor_count);

        window_count = monitor_count;
        windows = calloc(window_count, sizeof(GLFWwindow*));

        for (i = 0;  i < monitor_count;  i++)
        {
            windows[i] = create_window(monitors[i]);
            if (!windows[i])
                break;
        }
    }
    else
    {
        GLFWmonitor* monitor = NULL;

        if (fullscreen)
            monitor = glfwGetPrimaryMonitor();

        window_count = 1;
        windows = calloc(window_count, sizeof(GLFWwindow*));
        windows[0] = create_window(monitor);
    }

    for (i = 0;  i < window_count;  i++)
    {
        glfwSetKeyCallback(windows[i], key_callback);
        glfwSetFramebufferSizeCallback(windows[i], framebuffer_size_callback);
        glfwSetWindowSizeCallback(windows[i], window_size_callback);
        glfwSetWindowFocusCallback(windows[i], window_focus_callback);
        glfwSetWindowIconifyCallback(windows[i], window_iconify_callback);
        glfwSetWindowRefreshCallback(windows[i], window_refresh_callback);

        window_refresh_callback(windows[i]);

        printf("Window is %s and %s\n",
            glfwGetWindowAttrib(windows[i], GLFW_ICONIFIED) ? "iconified" : "restored",
            glfwGetWindowAttrib(windows[i], GLFW_FOCUSED) ? "focused" : "defocused");
    }

    for (;;)
    {
        glfwPollEvents();

        for (i = 0;  i < window_count;  i++)
        {
            if (glfwWindowShouldClose(windows[i]))
                break;
        }

        if (i < window_count)
            break;

        // Workaround for an issue with msvcrt and mintty
        fflush(stdout);
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
int main(int argc, char* argv[]) {
  if(argc>1) {
    mainScript=argv[1];
  }

  //glfw
  if(!glfwInit()) {
    std::cout << "GLFW init error.\n";
    return 1;
  }

  window = glfwCreateWindow(1280, 600, "Demo", 0, 0);

  if(!window) {
    glfwTerminate();
    std::cout << "GLFW window creation error.\n";
    return 2;
  }

  glfwMakeContextCurrent(window);
  glfwSwapInterval(1);

  //glfw callbacks
  glfwSetKeyCallback(window, onKey);
  glfwSetMouseButtonCallback(window, onMouseButton);
  glfwSetCursorPosCallback(window, onCursor);
  glfwSetScrollCallback(window, onScroll);
  glfwSetWindowIconifyCallback(window,onIconify);
  glfwSetWindowFocusCallback(window,onFocus);
  glfwSetCursorEnterCallback(window, onCursorEnter);
  glfwSetCharCallback(window, onChar);

  //glew
  GLenum glewErr = glewInit();

  if(GLEW_OK != glewErr) {
    std::cout << "GLEW Error " << glewGetErrorString(glewErr) << std::endl;
    glfwTerminate();
    return 3;
  }

  //
  printVers();

  //


  int majorVer,minorVer;
  glGetIntegerv(GL_MAJOR_VERSION,&majorVer);
  glGetIntegerv(GL_MINOR_VERSION,&minorVer);
  //std::cout << majorVer<<" "<<minorVer << std::endl;

  //
  programManager=new ProgramManager();

  //
  if(majorVer>3 || minorVer>=3) {
    geometryShaderSupport=true;
    programManager->setGeometryShaderSupport(true);
    glPrimitiveRestartIndex(-1);
  }

  //
  initDeferred();

  //inits
  textureManager=new TextureManager();
  geometryVaoManager=new GeometryVaoManager();
  scene=new Scene(mainScript);

  //
  UpdateListener *fileListener=new UpdateListener();
  FW::FileWatcher fileWatcher;
 
  fileWatcher.addWatch("data/shader/geometry", fileListener);
  fileWatcher.addWatch("data/shader/deferred", fileListener);
  fileWatcher.addWatch("data/shader", fileListener);
  fileWatcher.addWatch("data/texture", fileListener);
  fileWatcher.addWatch("data/geometry", fileListener);
  fileWatcher.addWatch("data", fileListener);

  //
  int lastClientWidth=0,lastClientHeight=0;

  //
  while(!glfwWindowShouldClose(window)) {
    fileWatcher.update();
    double time = glfwGetTime();
    int clientWidth,clientHeight;
    glfwGetWindowSize(window, &clientWidth, &clientHeight);

    scene->run(time,clientWidth,clientHeight);

    glfwSetInputMode(window,GLFW_CURSOR, scene->isLockCursor()?GLFW_CURSOR_DISABLED:GLFW_CURSOR_NORMAL);


    if(lastClientWidth != clientWidth || lastClientHeight != clientHeight) {
      setupDeferred(clientWidth?clientWidth:128, clientHeight?clientHeight:128);
    }

    render(clientWidth,clientHeight);
    glfwSwapBuffers(window);
    glfwPollEvents();

    //
    lastClientWidth=clientWidth;
    lastClientHeight=clientHeight;
  }

  //uninits

  delete programManager;
  delete textureManager;
  delete geometryVaoManager;
  delete scene;


  uninitDeferred();

  //
  glfwTerminate();
  return 0;
}
	WindowGL33::IconifiedEventType::DelegatePtr WindowGL33::addIconifiedCallback(IconifiedCallbackType const& callback)
	{
		glfwSetWindowIconifyCallback(m_pWndHandle, WindowGL33::iconifiedCallback);
		return m_iconifiedCallbacks.addListener(callback);
	}
Beispiel #8
0
    GLWindow::GLWindow(const UknString& name, const RenderSettings& settings):
        mFrameBuffer(new GLFrameBuffer(false)),
        Window(name) {
            glfwSetErrorCallback(ErrorCallback);
            glfwInit();

            switch(settings.color_fmt) {
            case EF_RGBA8:
                glfwWindowHint(GLFW_RED_BITS, 8);
                glfwWindowHint(GLFW_BLUE_BITS, 8);
                glfwWindowHint(GLFW_GREEN_BITS, 8);
                glfwWindowHint(GLFW_ALPHA_BITS, 8);
                break;

            default:
                // error
                break;
            }

            switch(settings.depth_stencil_fmt) {
            case EF_D16:
                glfwWindowHint(GLFW_DEPTH_BITS, 16);
                glfwWindowHint(GLFW_STENCIL_BITS, 0);

                mFrameBuffer->mIsDepthBuffered = true;
                mFrameBuffer->mDepthBits = 16;
                mFrameBuffer->mStencilBits = 0;
                break;

            case EF_D24S8:
                glfwWindowHint(GLFW_DEPTH_BITS, 24);
                glfwWindowHint(GLFW_STENCIL_BITS, 8);

                mFrameBuffer->mIsDepthBuffered = true;
                mFrameBuffer->mDepthBits = 24;
                mFrameBuffer->mStencilBits = 8;
                break;

            default:
                glfwWindowHint(GLFW_DEPTH_BITS, 0);
                glfwWindowHint(GLFW_STENCIL_BITS, 0);

                mFrameBuffer->mIsDepthBuffered = false;
                mFrameBuffer->mDepthBits = 0;
                mFrameBuffer->mStencilBits = 0;
                break;
            }

            if(settings.sample_quality > 0) {
                glfwWindowHint(GLFW_SAMPLES, settings.sample_quality);
            }

            glfwWindowHint(GLFW_RESIZABLE, settings.resizable);

            /* maybe there are bugs... let glfw decide the best version */
            /*
            glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, UKN_OPENGL_VERSION_MAJOR);
            glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, UKN_OPENGL_VERSION_MINOR);
            if(UKN_OPENGL_VERSION_MAJOR >= 3) {
                glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#if defined(MIST_OS_OSX)
                glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#else
                glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
#endif
            }
            */
            if(!settings.native_window_handle) {
                if((mGlfwWindow = glfwCreateWindow(settings.width,
                                                   settings.height,
                                                   string::WStringToString(name).c_str(),
                                                   settings.full_screen ? glfwGetPrimaryMonitor() : 0,
                                                   0)) == 0) {
                        MIST_THROW_EXCEPTION(L"GLWindow::GLWindow: Error opening window");
                }
            } else {
                if((mGlfwWindow = glfwCreateWindowSlave((void*)settings.native_window_handle,
                                                        0)) == 0) {
                    MIST_THROW_EXCEPTION(L"GLWindow::GLWindow: Error creating slave window on native handle");
                }
            }
            glfwMakeContextCurrent(mGlfwWindow);

#if !defined(UKN_OSX_REQUEST_OPENGL_32_CORE_PROFILE)
            GLenum err = glewInit();
            if (GLEW_OK != err) {
                    MIST_THROW_EXCEPTION(mist::string::StringToWString(format_string("GLWindow::GLWindow: error initializing glew profilem, error; %s", glewGetErrorString(err))));
            }
#endif

            // if wnd pos is (0, 0), then put it in the center of current screen
            int32 wndPosX = settings.left, wndPosY = settings.top;
            if(wndPosX == 0 && wndPosY == 0) {
                Array<SystemInformation::DesktopMode> desktop_modes = SystemInformation::EnumDesktopMode();

                wndPosX = (desktop_modes[0].width - settings.width) / 2;
                wndPosY = (desktop_modes[0].height - settings.height) / 2;
            }


            glfwSetWindowPos(mGlfwWindow, wndPosX, wndPosY);
            glfwSetWindowUserPointer(mGlfwWindow, this);
            
            
            glfwSetErrorCallback(ErrorFunc);
            glfwSetWindowSizeCallback(mGlfwWindow, WindowSizeFunc);
            glfwSetWindowCloseCallback(mGlfwWindow, WindowCloseFunc);
            glfwSetWindowRefreshCallback(mGlfwWindow, WindowRefreshFunc);
            glfwSetWindowFocusCallback(mGlfwWindow, WindowFocusFunc);
            glfwSetWindowIconifyCallback(mGlfwWindow, WindowIconifyFunc);

            glfwSetKeyCallback(mGlfwWindow, KeyFunc);
            glfwSetCursorPosCallback(mGlfwWindow, MousePosFunc);
            glfwSetMouseButtonCallback(mGlfwWindow, MouseButtonFunc);
            glfwSetScrollCallback(mGlfwWindow, ScrollFunc);
            glfwSetCharCallback(mGlfwWindow, CharFunc);
            
            // to do with joysticks

            glfwSwapInterval(0);

            mFrameBuffer->attach(ATT_Color0, RenderViewPtr(new GLScreenColorRenderView(settings.width, 
                settings.height,
                settings.color_fmt)));
            mFrameBuffer->attach(ATT_DepthStencil, RenderViewPtr(new GLScreenDepthStencilRenderView(settings.width, 
                settings.height,
                settings.depth_stencil_fmt)));

            onResize() += Bind(this, &GLWindow::onWindowResize);

            updateWindowProperties(wndPosX, wndPosY, settings.width, settings.height);
    }