Exemplo n.º 1
0
        public static Rectanglei GetMouseRect()
        {
            int x, y;

            Glfw.GetMousePos(out x, out y);
#if !DEBUG
            GlfwVidMode mode;
            Glfw.GetDesktopMode(out mode);
            x -= mode.Width / 2 - MainClass.WindowWidth / 2;
            y -= mode.Height / 2 - MainClass.WindowHeight / 2;
#endif
            Rectanglei mousePixel = new Rectanglei(x / MainClass.Scale, y / MainClass.Scale, 1, 1);
            return(mousePixel);
        }
Exemplo n.º 2
0
        public void Run()
        {
            Glfw.Init();
            try {
                Glfw.OpenWindowHint(OpenWindowHint.NoResize, 1);
                                #if !DEBUG
                GlfwVidMode mode;
                Glfw.GetDesktopMode(out mode);
                Glfw.OpenWindow(mode.Width, mode.Height, 8, 8, 8, 0, 24, 0, WindowMode.FullScreen);
                                #else
                Glfw.OpenWindow(WindowWidth, WindowHeight, 8, 8, 8, 0, 24, 0, WindowMode.Window);
                                #endif
                Glfw.SetWindowPos(100, 100);
                Glfw.SetWindowTitle("Caribbean Stick - The Dark Project");
                Glfw.SwapInterval(false);
                GL.Enable(EnableCap.TextureRectangle);
                GL.GenTextures(1, out oglTexture);
                GL.BindTexture(TextureTarget.TextureRectangle, oglTexture);
                GL.TexParameter(TextureTarget.TextureRectangle, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);

                // TODO: non-constant size???
                                #if !DEBUG
                GL.Viewport(mode.Width / 2 - WindowWidth / 2, mode.Height / 2 - WindowHeight / 2, WindowWidth, WindowHeight);
                                #else
                GL.Viewport(0, 0, WindowWidth, WindowHeight);
                                #endif
                GL.MatrixMode(MatrixMode.Projection);
                GL.Ortho(0.0, WindowWidth, WindowHeight, 0.0, 0.0, 1.0);
                GL.MatrixMode(MatrixMode.Modelview);

                CurrentGameState = new MenuState(this);

                float prevTime = (float)Glfw.GetTime();

                Glfw.PollEvents();
                while (Glfw.GetWindowParam(WindowParam.Opened) == 1)
                {
                    CurrentKS         = KeyboardState.GetState();
                    MouseClickCurrent = Glfw.GetMouseButton(MouseButton.LeftButton);
                    if (PreviousKS == null)
                    {
                        PreviousKS = CurrentKS;
                    }

//					if (CurrentKS[Key.Escape]) {
//						Glfw.CloseWindow();
//					}

                    float time  = (float)Glfw.GetTime();
                    float delta = time - prevTime;

                    CurrentGameState.Update(delta);
                    CurrentGameState.Draw();
                    DrawOGL();

                    prevTime = time;

                    PreviousKS         = CurrentKS;
                    MouseClickPrevious = MouseClickCurrent;

                    Glfw.SwapBuffers();
                    Glfw.PollEvents();
                }
            } finally {
                CurrentGameState.Dispose();
                Glfw.Terminate();
            }
        }