Exemple #1
0
        public override void draw(OpenTK.Matrix4 cam)
        {
            base.draw(cam);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, this.frameBuffer);
            GL.Viewport(0, 0, (int)bufferResolution.X, (int)bufferResolution.Y);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            coronaShader.Use();
            coronaShader.setUniform("iResolution", this.bufferResolution.X, this.bufferResolution.Y);
            coronaShader.setUniform("iGlobalTime", this.frameBufferTime);
            coronaShader.bindBufferToShaderAttrib<float>(bufferVerts, "vertIn");

            bufferElems.bind();
            GL.DrawElements(PrimitiveType.Quads, bufferElems.Size, DrawElementsType.UnsignedShort, 0);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.Viewport(0, 0, (int)Form1.resolution.X, (int)Form1.resolution.Y);

            billboardShader.Use();
            billboardShader.setUniform("view", cam);
            billboardShader.setUniform("proj", Form1.projectionMatrix);
            billboardShader.setUniform("model", this.transform);
            billboardShader.setUniform("scale", this.Scale * scaleFactor);
            billboardShader.setUniform("center", this.Position);
            billboardShader.setUniform("up", new Vector3(0,1,0));
            billboardShader.bindBufferToShaderAttrib<float>(squareVerts, "vertIn");
            billboardShader.bindBufferToShaderAttrib<float>(squareUvs, "uvIn", 2);

            squareElems.bind();
            GL.BindTexture(TextureTarget.Texture2D, this.bufferTexture);
            GL.DrawElements(PrimitiveType.Quads, squareElems.Size, DrawElementsType.UnsignedShort, 0);

            this.frameBufferTime += .005f;
        }
Exemple #2
0
        public override void OnRenderFrame(OpenTK.FrameEventArgs e, GameWindow window)
        {
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho(0, 1280, 0,720,0,1);
            GL.Disable(EnableCap.DepthTest);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.ClearColor(0.2f , 0.2f, 0.2f, 0);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            for (int y=0;y<720;y++)
            {
                for (int x = 0; x < 1280; x++)
                {
                    var c = (int) (Math.Floor(Math.Sin(x/35d)*128 + Math.Sin(y/28d)*32f + Math.Sin((x + y)/16d)*64));
                    c = mod(c, 256);
                    var r = cols[0, c] % 256;
                    var g = cols[1, c] % 256;
                    var b = cols[2, c] % 256;
                    GL.Color3(r/256, g/256, b/256);
                    GL.Begin(BeginMode.Points);
                        GL.Vertex2(x, y);
                    GL.End();
                }

            }
            window.SwapBuffers();
        }
        void mouse_ButtonUp(object sender, OpenTK.Input.MouseButtonEventArgs e)
        {
            MouseButton button = (MouseButton)e.Button;
            Vector2 position = new Vector2(e.X, e.Y);

            root.OnMouseUpEvent(new MouseButtonEventArgs(button, position, GetModifierKeys()));
        }
Exemple #4
0
        public static void Draw(OpenTK.Graphics.Color4 color, Vector3 position, bool cpupiece)
        {
            if(!Loaded)
                Load();
            GL.PushMatrix();

            Matrix4 translation = Matrix4.CreateTranslation(position) * LotusWindow.me.view * LotusWindow.me.proj;
            GL.LoadMatrix(ref translation);
            GL.Enable(EnableCap.Texture2D);
            if(!cpupiece)
                GL.BindTexture(TextureTarget.Texture2D, TextureLoader.get().getTexture("piece"));
            else
                GL.BindTexture(TextureTarget.Texture2D, TextureLoader.get().getTexture("aipiece"));
            GL.Begin(BeginMode.TriangleStrip);
            GL.Color4(color);
            GL.TexCoord2(new OpenTK.Vector2d(1, 0));
            GL.Vertex3(0, 0, 0);
            GL.TexCoord2(new OpenTK.Vector2d(0, 0));
            GL.Vertex3(32, 0, 0);
            GL.TexCoord2(new OpenTK.Vector2d(1, 1f));
            GL.Vertex3(0, 32, 0);
            GL.TexCoord2(new OpenTK.Vector2d(0, 1f));
            GL.Vertex3(32, 32, 0);

            GL.End();
            GL.PopMatrix();
        }
Exemple #5
0
		public void SetCornerColors(OpenTK.Graphics.Color4[] colors)
		{
			Flush(); //dont really need to flush with current implementation. we might as well roll modulate color into it too.
			if (colors.Length != 4) throw new ArgumentException("array must be size 4", "colors");
			for (int i = 0; i < 4; i++)
				CornerColors[i] = colors[i];
		}
Exemple #6
0
        //Methods
        //-Public
        public bool Move(OpenTK.Input.KeyboardState ks)
        {
            bool ret = false;

            //Move camera
            //if(Keyboard[Key.Left] && cameraCAM != null) {
            if(ks[OpenTK.Input.Key.Left]) {
                X -= 2f; ret = true;
            }
            else if(ks[OpenTK.Input.Key.Right]) {
                X += 2f; ret = true;
            }

            if(ks[OpenTK.Input.Key.Up]) {
                Y += 2f; ret = true;
            }
            else if(ks[OpenTK.Input.Key.Down]) {
                Y -= 2f; ret = true;
            }

            if((ks[OpenTK.Input.Key.Plus] || ks[OpenTK.Input.Key.KeypadPlus])) {
                Z += 1f; ret = true;
            }
            else if((ks[OpenTK.Input.Key.Minus] || ks[OpenTK.Input.Key.KeypadMinus])) {
                Z -= 1f; ret = true;
            }

            return ret;
        }
Exemple #7
0
        public override ModelBase LoadModel(OpenTK.Vector3 scale)
        {
            List<ModelBase.BoneDef> flatBoneList = m_Model.m_BoneTree.GetAsList();
            for (int i = 0; i < m_BCA.m_AnimationData.Length; i++)
            {
                string boneID = flatBoneList[i].m_ID;

                BCA.SRTContainer[] boneTransformations = m_BCA.GetAllLocalSRTValuesForBone(i);

                Dictionary<ModelBase.AnimationComponentType, ModelBase.AnimationComponentDataDef> animationComponentDataDefs =
                    new Dictionary<ModelBase.AnimationComponentType, ModelBase.AnimationComponentDataDef>();

                float[] valuesSx = new float[boneTransformations.Length];
                float[] valuesSy = new float[boneTransformations.Length];
                float[] valuesSz = new float[boneTransformations.Length];
                float[] valuesRx = new float[boneTransformations.Length];
                float[] valuesRy = new float[boneTransformations.Length];
                float[] valuesRz = new float[boneTransformations.Length];
                float[] valuesTx = new float[boneTransformations.Length];
                float[] valuesTy = new float[boneTransformations.Length];
                float[] valuesTz = new float[boneTransformations.Length];
                for (int j = 0; j < boneTransformations.Length; j++)
                {
                    valuesSx[j] = boneTransformations[j].m_Scale.X;
                    valuesSy[j] = boneTransformations[j].m_Scale.Y;
                    valuesSz[j] = boneTransformations[j].m_Scale.Z;
                    valuesRx[j] = boneTransformations[j].m_Rotation.X;
                    valuesRy[j] = boneTransformations[j].m_Rotation.Y;
                    valuesRz[j] = boneTransformations[j].m_Rotation.Z;
                    valuesTx[j] = boneTransformations[j].m_Translation.X;
                    valuesTy[j] = boneTransformations[j].m_Translation.Y;
                    valuesTz[j] = boneTransformations[j].m_Translation.Z;
                }

                animationComponentDataDefs.Add(ModelBase.AnimationComponentType.ScaleX,
                    new ModelBase.AnimationComponentDataDef(valuesSx, m_BCA.m_NumFrames, false, 1, false, ModelBase.AnimationComponentType.ScaleX));
                animationComponentDataDefs.Add(ModelBase.AnimationComponentType.ScaleY,
                    new ModelBase.AnimationComponentDataDef(valuesSy, m_BCA.m_NumFrames, false, 1, false, ModelBase.AnimationComponentType.ScaleY));
                animationComponentDataDefs.Add(ModelBase.AnimationComponentType.ScaleZ,
                    new ModelBase.AnimationComponentDataDef(valuesSz, m_BCA.m_NumFrames, false, 1, false, ModelBase.AnimationComponentType.ScaleZ));
                animationComponentDataDefs.Add(ModelBase.AnimationComponentType.RotateX,
                    new ModelBase.AnimationComponentDataDef(valuesRx, m_BCA.m_NumFrames, false, 1, false, ModelBase.AnimationComponentType.RotateX));
                animationComponentDataDefs.Add(ModelBase.AnimationComponentType.RotateY,
                    new ModelBase.AnimationComponentDataDef(valuesRy, m_BCA.m_NumFrames, false, 1, false, ModelBase.AnimationComponentType.RotateY));
                animationComponentDataDefs.Add(ModelBase.AnimationComponentType.RotateZ,
                    new ModelBase.AnimationComponentDataDef(valuesRz, m_BCA.m_NumFrames, false, 1, false, ModelBase.AnimationComponentType.RotateZ));
                animationComponentDataDefs.Add(ModelBase.AnimationComponentType.TranslateX,
                    new ModelBase.AnimationComponentDataDef(valuesTx, m_BCA.m_NumFrames, false, 1, false, ModelBase.AnimationComponentType.TranslateX));
                animationComponentDataDefs.Add(ModelBase.AnimationComponentType.TranslateY,
                    new ModelBase.AnimationComponentDataDef(valuesTy, m_BCA.m_NumFrames, false, 1, false, ModelBase.AnimationComponentType.TranslateY));
                animationComponentDataDefs.Add(ModelBase.AnimationComponentType.TranslateZ,
                    new ModelBase.AnimationComponentDataDef(valuesTz, m_BCA.m_NumFrames, false, 1, false, ModelBase.AnimationComponentType.TranslateZ));

                ModelBase.AnimationDef animation = new ModelBase.AnimationDef(boneID + "-animation", boneID, m_BCA.m_NumFrames,
                    animationComponentDataDefs);
                m_Model.m_Animations.Add(animation.m_ID, animation);
            }

            return m_Model;
        }
Exemple #8
0
		protected override void OnRenderFrame( OpenTK.FrameEventArgs e )
		{
			base.OnRenderFrame( e );
			base.MakeCurrent();
			if ( !_initialized )
			{
				Initialize();
				_initialized = true;
			}

			try
			{

				if ( _engine != null )
				{
					_engine.RenderOneFrame();
				}
			}
			catch ( Exception ex )
			{
				Console.WriteLine( "An exception has occurred. See below for details:" );
				Console.WriteLine( BuildExceptionString( ex ) );
			}
			//base.SwapBuffers();
		}
		public OpenTKGLContext( OpenTK.Platform.IWindowInfo windowInfo )
		{
			// setup created glcontrol / gtk control
			this.windowInfo = windowInfo;
			this.graphicsContext = new GraphicsContext( GraphicsMode.Default, this.windowInfo );
			Initialized = true;
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="GameContext" /> class.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="requestedWidth">Width of the requested.</param>
        /// <param name="requestedHeight">Height of the requested.</param>
        public GameContext(OpenTK.GameWindow control, int requestedWidth = 0, int requestedHeight = 0)
        {
            var creationFlags = GraphicsContextFlags.Default;
#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
            creationFlags |= GraphicsContextFlags.Embedded;
#endif

            if (requestedWidth == 0 || requestedHeight == 0)
            {
                requestedWidth = 1280;
                requestedHeight = 720;
            }

            // force the stencil buffer to be not null.
            var defaultMode = GraphicsMode.Default;
            var graphicMode = new GraphicsMode(defaultMode.ColorFormat, defaultMode.Depth, 8, defaultMode.Samples, defaultMode.AccumulatorFormat, defaultMode.Buffers, defaultMode.Stereo);
            
            GraphicsContext.ShareContexts = true;

            if (control == null)
            {
                int versionMajor, versionMinor;
                if (RequestedGraphicsProfile == null || RequestedGraphicsProfile.Length == 0)
                {
#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
                    versionMajor = 3;
                    versionMinor = 0;
#else
                    // PC: 4.3 is commonly available (= compute shaders)
                    // MacOS X: 4.1 maximum
                    versionMajor = 4;
                    versionMinor = 1;
#endif
                    Control = TryGameWindow(requestedWidth, requestedHeight, graphicMode, versionMajor, versionMinor, creationFlags);
                }
                else
                {
                    foreach (var profile in RequestedGraphicsProfile)
                    {
                        OpenGLUtils.GetGLVersion(profile, out versionMajor, out versionMinor);
                        var gameWindow = TryGameWindow(requestedWidth, requestedHeight, graphicMode, versionMajor, versionMinor, creationFlags);
                        if (gameWindow != null)
                        {
                            Control = gameWindow;
                            break;
                        }
                    }
                }
            }
            else
                Control = control;

            if (Control == null)
                throw new Exception("Unable to initialize graphics context.");

            RequestedWidth = requestedWidth;
            RequestedHeight = requestedHeight;
            ContextType = AppContextType.DesktopOpenTK;
        }
Exemple #11
0
 internal void Mouse_Move(object sender, OpenTK.Input.MouseMoveEventArgs e)
 {
     if (DragMode)
     {
         Yaw += e.XDelta;
         Pitch += e.YDelta;
     }
 }
Exemple #12
0
 void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
 {
     if (e.Key == OpenTK.Input.Key.F1)
     {
         shouldDraw = !shouldDraw;
         DepthScreen.IsVisible = shouldDraw;
     }
 }
Exemple #13
0
        public void Initialize(OpenTK.GameWindow gw)
        {
            gameWindow = gw;

            // Keydown registers key repeating, keyup does not.
            gw.KeyDown += gw_KeyDown;
            gw.KeyPress += gw_KeyPress;
        }
 protected override void KeyPressed(OpenTK.Input.Key keyelement)
 {
     if (keyelement == Key.Pause)
     {
         //unpause.
         Owner.currentState = ResumeState;
     }
 }
Exemple #15
0
		public void Clear(OpenTK.Graphics.OpenGL.ClearBufferMask mask)
		{
			var g = GetCurrentGraphics();
			if((mask & ClearBufferMask.ColorBufferBit) != 0)
			{
				g.Clear(_currentClearColor);
			}
		}
Exemple #16
0
 public override void OnKeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs args)
 {
     base.OnKeyDown(sender, args);
     if (args.Key == OpenTK.Input.Key.Escape)
     {
         StateHandler.Push(new GuiState(Graphics.RenderMode.Ortho, true));
     }
 }
Exemple #17
0
 public void Initialize(OpenTK.GameWindow window)
 {
     Window = window;
     window.ClientSize = new Size(mapLayout[0].Length * 30, mapLayout.Length * 30);
     TextureManager.Instance.UseNearestFiltering = true;
     map = GenerateMap(mapLayout, spriteSheets, spriteSources);
     hero = new PlayerCharacter(heroSheet, new Point(spawnTile.X * 30, spawnTile.Y * 30));
 }
		/// <summary>
		/// Inicjalizuje nowy opis zasobu.
		/// </summary>
		/// <param name="id">Identyfikator zasobu, zobacz: <see cref="Id"/>.</param>
		/// <param name="name">Nazwa zasobu, zobacz: <see cref="Name"/>.</param>
		/// <param name="description">Dłuższy opis zasobu.</param>
		/// <param name="size">Rozmiar zasobu.</param>
		/// <param name="image">Obrazek z zasobem.</param>
		/// <param name="polygon">Figura dla zasobu, zobacz <see cref="Polygon"/>.</param>
		public ResourceDescription(string id, string name, string description, OpenTK.Vector2 size, string image, Vector2[] polygon)
		{
			this.Id = id;
			this.Name = name;
			this.Description = description;
			this.Size = size;
			this.Image = image;
			this.Polygon = polygon;
		}
 public static void DrawBox(ref OpenTK.Vector3 bbMin, ref OpenTK.Vector3 bbMax, ref OpenTK.Matrix4 trans, OpenTK.Graphics.Color4 color)
 {
     using (debugProgram.Using("object_matrix", trans))
     using (Box box = new Box(bbMin, bbMax))
     {
         GL.VertexAttrib3(1, new[] { 1f, 1f, 1f });
         box.Render(new[] { debugProgram });
     }
 }
Exemple #20
0
        private void Window_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            if (!isDown[(int)e.Key] && KeyDown != null)
            {
                KeyDown(sender, e);
            }

            isDown[(int)e.Key] = true;
        }
Exemple #21
0
        protected override void OnMouseWheel(OpenTK.Input.MouseWheelEventArgs e)
        {
            if (Input._wheel < e.Value)
                Input._wheelState = -1;
            else
                Input._wheelState = 1;

            Input._wheel = e.Value;
        }
 void mouse_ButtonDown(object sender, OpenTK.Input.MouseButtonEventArgs e)
 {
     MouseButton button = (MouseButton)e.Button;
     Vector2 position = new Vector2(e.X, e.Y);
     if (root.Bounds.ContainsPoint(position))
     {
         root.OnMouseDownEvent(new MouseButtonEventArgs(button, position, GetModifierKeys()));
     }
 }
Exemple #23
0
 public void Initialize(OpenTK.GameWindow window)
 {
     Window = window;
     window.ClientSize = new Size(15 * TILE_SIZE, 7 * TILE_SIZE);
     TextureManager.Instance.UseNearestFiltering = true;
     hero = new PlayerCharacter(heroSheet);
     currentMap = new Map(startingMap,hero);
     projectiles = new List<Bullet>();
 }
Exemple #24
0
        public bool IsPressed(OpenTK.Input.Key key)
        {
            if (isDown[(int)key] && !isChecked[(int)key])
            {
                isChecked[(int)key] = true;
                return true;
            }

            return false;
        }
Exemple #25
0
 private void ButtonDownEvent( object sender, OpenTK.Input.MouseButtonEventArgs e )
 {
     if ( e.Button == OpenTK.Input.MouseButton.Left )
         MouseButton |= MouseButton.Left;
     if ( e.Button == OpenTK.Input.MouseButton.Right )
         MouseButton |= MouseButton.Right;
     if ( e.Button == OpenTK.Input.MouseButton.Middle )
         MouseButton |= MouseButton.Middle;
     Position = new Daramkun.Liqueur.Mathematics.Vector2 ( e.X, e.Y );
 }
Exemple #26
0
        private void Window_KeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            isDown[(int)e.Key] = false;
            isChecked[(int)e.Key] = false;

            if (KeyUp != null)
            {
                KeyUp(sender, e);
            }
        }
        public override void OnKeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            if (Enabled && (e.Key == OpenTK.Input.Key.Tab))
            {
                Accumulate = !Accumulate;
                return;
            }

            base.OnKeyUp(sender, e);
        }
Exemple #28
0
 public GLVertex(OpenTK.Vector4 a_v4Position, System.Drawing.Color a_oColor, OpenTK.Vector2 a_v2UV)
 {
     m_v4Position = a_v4Position;
     // We order the color RGBA because this is the order expected by OpenGL/Graphics card.
     m_v4Color.X = a_oColor.R / 255.0f;
     m_v4Color.Y = a_oColor.G / 255.0f;
     m_v4Color.Z = a_oColor.B / 255.0f;
     m_v4Color.W = a_oColor.A / 255.0f;
     m_v2UV = a_v2UV;
 }
Exemple #29
0
        public void AddVertex(OpenTK.Vector3 position, OpenTK.Vector3 normal, OpenTK.Vector2 texcoords, OpenTK.Graphics.Color4 colour)
        {
            var v = new Vertex();
            v.Position = position;
            v.Normal = normal;
            v.UV = new OpenTK.Vector4(texcoords.X, texcoords.Y, 0, 0);
            v.Colour = colour;

            verts.Add(v);
        }
Exemple #30
0
        public static Vector4 Project(OpenTK.Vector4 objPos, ref Matrix4 projection, Matrix4 view, Size viewport)
        {
            Vector4 vec = objPos;

            vec = Vector4.Transform(vec, Matrix4.Mult(projection, view));

            vec.X = (vec.X + 1) * (viewport.Width / 2);
            vec.Y = (vec.Y + 1) * (viewport.Height / 2);

            return vec;
        }
Exemple #31
0
 get => new Vector2(this.marginX, this.marginY);