private void DrawCanvas2d(float opacity)
        {
            if (this.Canvas == null || !this.showBackground)
            {
                return;
            }
            GL.Disable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            int w = this.Canvas.Width, h = this.Canvas.Height;

            GL.PushMatrix();
            GL.Viewport(0, this.view.Height - h, w, h);
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho(0, w, h, 0, -1, 1);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.PushMatrix();

            // translation and scaling
            GL.Translate(this.GlTrans.x, this.GlTrans.y, 0.0);
            GL.Scale(this.glScale, this.glScale, 1);

            // draw canvas
            GLBasicDraw.DrawTexture(w, h, this.CanvasTextureId, opacity);

            GL.PopMatrix();
            GL.PopMatrix();
            GL.Disable(EnableCap.Blend);
        }
Beispiel #2
0
        public void Init()
        {
            BrushSize = 16;                                             // brush size
            this.prevMousePosition = new MyVector2();                   // prev mouse pos
            this.mouseDownPosition = new MyVector2();                   // mouse down pos
            this.currMousePosition = new MyVector2();                   // curr mouse pos

            // initialize textures, airbrushes, and parameters
            this.LoadTextures();                                                                // load canvas, brush textures


            // 3d entities
            //this.eyePos = new MyVector3(0, 0.1, 1);				// eye (camera) position
            this.eyePos        = new MyVector3(0, 0, -0.5);                     // eye (camera) position
            this.lightPosition = new MyVector3(5, 5, 5);                        // light position


            // util
            Utils.InitialRandomColors(53);                                              // initial random colors

            // opengl
            GLBasicDraw.InitGlMaterialLights();


            // mode
            //this.currentMode = EnumOperationMode.Adjusting;
            this.currentMode = EnumOperationMode.Viewing;

            // opengl projector
            this.glProjector = new OpenGLProjector();
        }
 private void DrawLight()
 {
     for (int i = 0; i < GLBasicDraw.lightPositions.Count; ++i)
     {
         MyVector3 pos3 = new MyVector3(GLBasicDraw.lightPositions[i][0],
                                        GLBasicDraw.lightPositions[i][1],
                                        GLBasicDraw.lightPositions[i][2]);
         MyVector3 pos2 = this.camera.Project(pos3.x, pos3.y, pos3.z);
         GLBasicDraw.DrawCircle(new MyVector2(pos2.x, pos2.y), Color.Yellow, 0.2f);
     }
 }
        private void DrawScene3d()
        {
            if (this.camera.Calibrated == false)
            {
                return;
            }

            GLBasicDraw.InitGlMaterialLights(); // lights and materials
            int w = this.Canvas.Width, h = this.Canvas.Height;

            GL.Viewport(0, this.view.Height - h, w, h);

            // -------------------------------------------------------------------------
            // draw 3d sense
            MyMatrix4d m = this.arcBall.GetMatrix() * this.modelTransformation;

            m = MyMatrix4d.TranslationMatrix(this.currTransCenter) * m * MyMatrix4d.TranslationMatrix(
                new MyVector3() - this.currTransCenter);

            GL.PushMatrix();
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.LoadMatrix(this.camera.glprojMatrix);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.LoadMatrix(this.camera.glmodelViewMatrix);

            GL.PushMatrix();
            GL.MultMatrix(m.Transpose().ToArray());

            // Enable antialiased lines
            GL.Enable(EnableCap.PointSmooth);
            GL.Enable(EnableCap.LineSmooth);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);


            // draw all geometric faces (depth test enabled, blend disabled)
            if (!this.DrawTransparent)
            {
                GL.Enable(EnableCap.DepthTest);
                GL.Disable(EnableCap.Blend);
                GL.DepthFunc(DepthFunction.Less);
                GL.DepthMask(true);
            }

            if (!this.DrawTransparent)
            {
                GL.DepthFunc(DepthFunction.Lequal);
                GL.DepthMask(false); // Do not remove me, else get dotted lines
            }

            GL.Enable(EnableCap.Blend);
            /* --------------------------------------------------------------------------*/
            // draw the lines on top
            // painting goes here!
            /* --------------------------------------------------------------------------*/


            //DrawAxis();

            // draw highlights
            this.DrawHighlights3D();

            GL.Disable(EnableCap.LineSmooth);
            GL.Disable(EnableCap.PointSmooth);
            GL.Disable(EnableCap.Blend);
            GL.DepthMask(true);
            GL.PopMatrix();
            GL.PopMatrix();
        }