public static void SaveToRGB(Texture2 <Vector4> texture, System.Drawing.Bitmap bitmap)
        {
            int width  = texture.Width;
            int height = texture.Height;

            System.Drawing.Imaging.BitmapData data = bitmap.LockBits(
                new System.Drawing.Rectangle(0, 0, width, height),
                System.Drawing.Imaging.ImageLockMode.WriteOnly,
                System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            unsafe
            {
                byte *pixel = (byte *)data.Scan0;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        Vector4 color = texture.GetPixel(x, y);
                        byte    r     = (byte)(color.R * 255);
                        byte    g     = (byte)(color.G * 255);
                        byte    b     = (byte)(color.B * 255);
                        pixel[0] = b;
                        pixel[1] = g;
                        pixel[2] = r;
                        pixel   += 3;
                    }
                }
            }

            bitmap.UnlockBits(data);
        }
        public static void LoadFromRGB(Texture2 <Vector4> texture, System.Drawing.Bitmap bitmap)
        {
            int width  = bitmap.Width;
            int height = bitmap.Height;

            System.Drawing.Imaging.BitmapData data = bitmap.LockBits(
                new System.Drawing.Rectangle(0, 0, width, height),
                System.Drawing.Imaging.ImageLockMode.ReadOnly,
                System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            unsafe
            {
                byte *pixel = (byte *)data.Scan0;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        float b = pixel[0] / 255.0f;
                        float g = pixel[1] / 255.0f;
                        float r = pixel[2] / 255.0f;
                        pixel += 3;
                        texture.SetPixel(x, y, new Vector4(r, g, b, 1.0f));
                    }
                }
            }
        }
Exemple #3
0
        public TextureViewModel(Texture2 texture)
        {
            Assert.NotNull(texture);

            this.Name    = texture.Name;
            this.Texture = texture;
            this.Image   = texture.Image;
        }
Exemple #4
0
 public override void PostDeserialize(DeserializationContext deserializationContext)
 {
     Texture            = new Texture2(Filename, IsNormalMap);
     Texture.Anisotropy = Anisotropy;
     Texture.MagFilter  = MagFilter;
     Texture.MinFilter  = MinFilter;
     Texture.Wrap       = WrapMode;
 }
Exemple #5
0
        protected override void OnStart()
        {
            base.OnStart();

            var points = new List <Vector3>();

            points.Add(new Vector3(0, 0, 0));
            points.Add(new Vector3(0, 0, 1));
            points.Add(new Vector3(0, 1, 1));
            points.Add(new Vector3(0, 1, 0));
            points.Add(new Vector3(0, 0, 0));
            points.Add(new Vector3(0, -2, 0));
            points.Add(new Vector3(0, -2, -2));

            points = Spline.CatmullRom(points, 0.02f);

            var trajectory = new List <ExtrusionPoint>();

            points.ForEach(_ => trajectory.Add(new ExtrusionPoint()
            {
                Radius = 0.1f, Position = _
            }));

            var wellMesh = CircularExtrusion.Create(trajectory);

            wellMesh.DrawStyle = PolygonMode.Fill;

            _wellMaterial = new Material(MaterialType.FlatVertexColor);
            var texture = new Texture2();

            _wellMaterial.MainTexture = new Texture2("Resources\\Textures\\Wellbore\\fluid_colors.png", false);
            _wellMaterial.SetTexture("uniform_DisplaceTexture", texture);
            _wellMaterial.Color = Vector4.One;

            var renderer = SceneObject.AddComponent <MeshRenderable>();

            renderer.Mesh     = wellMesh;
            renderer.Material = _wellMaterial;

            var buffer = new ByteBuffer(1024 * 4);

            for (int i = 0; i < buffer.Length; i += 4)
            {
                var t = 0.1f + (i / (float)buffer.Length);

                var noise1 = GetNoise(t * 400f) * 0.6f;
                var noise2 = Math.Pow(GetNoise(t * 6), 2);
                //noise1 = 0;
                //noise2 = 0;
                buffer[i] = (byte)(255 * (noise1 + noise2) / 1.6f);
            }

            texture.SetImage(buffer, new Size(1, buffer.Length / 4), PixelFormat.Red, PixelInternalFormat.R8);
        }
Exemple #6
0
        public Texture2 CreateTexture()
        {
            var result = new Texture2();

            result.MinFilter  = TextureFilter.LinearMipmapLinear;
            result.MagFilter  = TextureFilter.Linear;
            result.Wrap       = TextureWrapMode.ClampToEdge;
            result.Anisotropy = 4;
            result.SetImage(_bmp, false, false, false);
            return(result);
        }
Exemple #7
0
        public Texture2Asset(SerializationContext context, Texture2 texture)
        {
            Assert.NotNull(texture);

            Filename    = texture.Filename;
            Name        = texture.Name;
            Texture     = texture;
            IsNormalMap = texture.IsNormalMap;
            Anisotropy  = texture.Anisotropy;
            MagFilter   = texture.MagFilter;
            MinFilter   = texture.MinFilter;
            WrapMode    = texture.Wrap;
        }
Exemple #8
0
        public UIRender(Renderbuffer renderBuffer)
        {
            this._screenSize = renderBuffer.Size;

            _context      = GL.GetCurrent(true);
            _shader       = new UIShader();
            _renderBuffer = renderBuffer;

            _framebuffer = new Framebuffer(_screenSize);

            _framebuffer.AttachRenderbuffer(FramebufferAttachment.ColorAttachment0, renderBuffer);
            _idTexture = _framebuffer.AddColorTexture(Core.FramebufferAttachment.ColorAttachment1, PixelInternalFormat.R32ui, PixelFormat.Red);

            _framebuffer.CheckStatus(true);
        }
Exemple #9
0
 private static void OnClose()
 {
     System.Media.SoundPlayer sh = new System.Media.SoundPlayer(@"C:\Users\DariusziElżbieta\Documents\3D_Rectangles\DDD\bin\Debug\shot.wav");
     sh.Play();
     Thread.Sleep(600);
     cube.Dispose();
     cubeUV.Dispose();
     cubeElements.Dispose();
     cubeNormals.Dispose();
     Texture1.Dispose();
     Texture2.Dispose();
     Texture3.Dispose();
     Texture4.Dispose();
     program.Dispose();
 }
        private void New_Click(object sender, RoutedEventArgs e)
        {
            var openFileDialog = FileDialogHelper.CreateOpenImageDialog();

            if (openFileDialog.ShowDialog(this.GetWindow()) != true)
            {
                return;
            }

            var texture   = new Texture2(openFileDialog.FileName, false);
            var viewModel = new TextureViewModel(texture);

            viewModel.TextureDisposed += TextureDisposedHandler;
            _textures.Add(viewModel);
        }
Exemple #11
0
        private void SelectTexture_Click(object sender, RoutedEventArgs e)
        {
            var wnd = new ChildWindow();

            wnd.Owner = this.GetWindow();

            var textureSelector = new TexturePreviewSelector();

            textureSelector.Canceled += (s, ea) => {
                wnd.Close();
            };
            textureSelector.TextureSelected += (s, ea) => {
                wnd.Close();
                Texture = ea.Value;
            };

            wnd.Content = textureSelector;
            wnd.Show();
        }
Exemple #12
0
 private void RemoveTexture_Click(object sender, RoutedEventArgs e)
 {
     Texture = null;
 }
Exemple #13
0
        public Graphics(UserControl control, SceneTime time, ShadingTechnique technique)
        {
            Assert.NotNull(control);
            Assert.NotNull(time);

            IsDisposed = false;
            CurrentShadingTechnique = technique;

            if (GL.GetCurrent(false) != null || GetCurrent(false) != null)
            {
                var error = "Only one NetGL view per thread is now supported. Try launching 3D view in different thread.";
                Log.Error(error);
                throw new InvalidOperationException(error);
            }

            _control = control;
            _time    = time;

            try {
                _glContext = new GL(_control.Handle);
            }
            catch {
                Dispose();
                throw;
            }

            _currentContext.Value = this;

            _glContext.Enable(EnableCap.DepthTest);
            _glContext.Enable(EnableCap.Texture2D);
            _glContext.Enable(EnableCap.CullFace);
            _glContext.Enable(EnableCap.ProgramPointSize);
            _glContext.Enable(EnableCap.PointSprite);
            _glContext.CullFace(MaterialFace.Back);
            _glContext.FrontFace(FrontFaceDirection.CounterClockwise);
            _glContext.BlendEquation(BlendEquations.FuncAdd);
            _glContext.BlendFunc(BlendMode.SrcAlpha, BlendMode.OneMinusSrcAlpha);

            _glContext.SwapInterval(_swapInterval);

            _globalUniforms   = new GlobalUniformsBufferObject();
            _standartUniforms = new StandardUniformsBufferObject();
            _defaultMaterial  = new Material(MaterialType.DiffuseColor);
            _blankTexture     = new Texture2();
            _blankTexture.SetImage(new byte[4] {
                255, 0, 255, 255
            }, new Size(1, 1), Core.PixelFormat.Rgba, Core.PixelInternalFormat.Rgba8);
            _quadShader = new QuadShader();

            _displayQuadVao = CreateDisplayQuadVao();

            switch (CurrentShadingTechnique)
            {
            case ShadingTechnique.Forward:
                _renderTechnique = new ForwardRender();
                break;

            case ShadingTechnique.Deferred:
                _renderTechnique = new DeferredRender();
                break;

            default:
                throw new NotSupportedException(CurrentShadingTechnique.ToString());
            }

            ScreenSize = _control.ClientSize;
        }