Пример #1
0
        public GlfwPlatform(int width, int height, bool fullscreen = false)
        {
            midi = new MidiConsoleOut();

            // Handle Glfw errors:
            Glfw.SetErrorCallback((code, desc) => throw new Exception(String.Format("GLFW error code {0}: {1}", code, desc)));

            Debug.WriteLine("glfw.Init()");
            Glfw.Init();

            // Disable window resizing
            Glfw.WindowHint(Glfw.Hint.Resizable, false);
            // Enable multi-sampling
            Glfw.WindowHint(Glfw.Hint.Samples, 8);

            Glfw.Monitor monitor = fullscreen ? Glfw.GetPrimaryMonitor() : Glfw.Monitor.None;

            Debug.WriteLine("window = glfw.CreateWindow()");
            window = Glfw.CreateWindow(
                width,
                height,
                "e-sharp-minor",
                monitor,
                Glfw.Window.None
                );

            // Fetch the real window size:
            Glfw.GetWindowSize(window, out width, out height);

            // Window dimensions (aspect ratio) in VG coordinate space (non-retina):
            this.Width  = width;
            this.Height = height;

            // Get the real framebuffer size for OpenGL pixels; should work with Retina:
            int fbWidth, fbHeight;

            Glfw.GetFramebufferSize(window, out fbWidth, out fbHeight);

            // These are needed for vgClear since it works in framebuffer pixels.
            FramebufferWidth  = fbWidth;
            FramebufferHeight = fbHeight;

            Debug.WriteLine("glfw.MakeContextCurrent(window)");
            Glfw.MakeContextCurrent(window);

            // create an OpenVG context
            Debug.WriteLine("vgContext = vgPrivContextCreateAM(0)");
            vgContext = vgPrivContextCreateAM(IntPtr.Zero);

            // create a drawing surface (sRGBA premultiplied color space)
            //vgSurface = vgPrivSurfaceCreateAM(fbWidth, fbHeight, 0, 1, 1);
            vgSurface = vgPrivSurfaceCreateAM(fbWidth, fbHeight, 0, 1, 0);

            // bind context and surface
            vgPrivMakeCurrentAM(vgContext, vgSurface);

            // Create OpenVGContext:
            vg = new OpenVGContext();

            // Apply scale for retina display:
            vg.Seti(ParamType.VG_MATRIX_MODE, (int)MatrixMode.VG_MATRIX_PATH_USER_TO_SURFACE);
            vg.LoadIdentity();
            vg.Scale((float)fbWidth / (float)width, (float)fbHeight / (float)height);
            vg.Translate(0.5f, 0.5f);

            vg.Seti(ParamType.VG_MATRIX_MODE, (int)MatrixMode.VG_MATRIX_GLYPH_USER_TO_SURFACE);
            vg.LoadIdentity();
            vg.Scale((float)fbWidth / (float)width, (float)fbHeight / (float)height);
            vg.Translate(0.5f, 0.5f);

            vg.Seti(ParamType.VG_MATRIX_MODE, (int)MatrixMode.VG_MATRIX_PATH_USER_TO_SURFACE);

            // Disable vsync and show frame immediately after render:
            Glfw.SwapInterval(0);

            Debug.WriteLine("glfw.ShowWindow(window)");
            Glfw.ShowWindow(window);

            Glfw.SetKeyCallback(window, handleKeys);
            Glfw.SetMouseButtonCallback(window, handleMouseButton);
            Glfw.SetCursorPosCallback(window, handleMousePos);
        }
Пример #2
0
        public RpiPlatform(int display)
        {
            midi        = new MidiAlsaOut();
            fsw         = new LinuxEventDevice("/dev/input/by-id/usb-413d_2107-event-mouse");
            touchScreen = new LinuxEventDevice("/dev/input/event1");

            fsw.EventListener         += Fsw_EventListener;
            touchScreen.EventListener += TouchScreen_EventListener;

            bcmDisplay = (ushort)display;

            bcm_host_init();

            uint bcmWidth, bcmHeight;

            graphics_get_display_size(bcmDisplay, out bcmWidth, out bcmHeight);

            FramebufferWidth  = Width = (int)bcmWidth;
            FramebufferHeight = Height = (int)bcmHeight;

            VC_RECT_T dst_rect;
            VC_RECT_T src_rect;

            dst_rect.x      = 0;
            dst_rect.y      = 0;
            dst_rect.width  = Width;
            dst_rect.height = Height;

            src_rect.x      = 0;
            src_rect.y      = 0;
            src_rect.width  = Width << 16;
            src_rect.height = Height << 16;

            // TODO: translate error codes into exceptions?
            Debug.WriteLine("vc_dispmanx_display_open(...)");
            dispman_display = vc_dispmanx_display_open(bcmDisplay);
            Debug.WriteLine("dispman_display = {0}", dispman_display);
            Debug.WriteLine("vc_dispmanx_update_start(...)");
            dispman_update = vc_dispmanx_update_start(0 /* priority */);
            Debug.WriteLine("dispman_update = {0}", dispman_update);

            Debug.WriteLine("vc_dispmanx_element_add(...)");
            dispman_element = vc_dispmanx_element_add(
                dispman_update,
                dispman_display,
                0 /*layer*/,
                ref dst_rect,
                0 /*src*/,
                ref src_rect,
                DISPMANX_PROTECTION_T.DISPMANX_PROTECTION_NONE,
                IntPtr.Zero /*alpha*/,
                IntPtr.Zero /*clamp*/,
                0 /*transform*/
                );
            Debug.WriteLine("dispman_element = {0}", dispman_element);

            Debug.WriteLine("vc_dispmanx_update_submit_sync(dispman_update)");
            checkError(vc_dispmanx_update_submit_sync(dispman_update));

            // Create OpenVGContext:
            Debug.WriteLine("new OpenVGContext()");
            vg = new OpenVGContext();
        }