Exemplo n.º 1
0
        protected override void InitGLContext()
        {
            GL.glShadeModel(GL.GL_SMOOTH);                                              // enable smooth shading
            GL.glClearColor(1.0f, 1.0f, 1.0f, 0.5f);                                    // black background
            GL.glClearDepth(1.0f);                                                      // depth buffer setup
            GL.glEnable(GL.GL_DEPTH_TEST);                                              // enables depth testing
            GL.glDepthFunc(GL.GL_LEQUAL);                                               // type of depth testing
            fLightPosition = new float[4] {
                lx, ly, lz, 1f
            };
            GL.glLightfv(OpenGL.GL_LIGHT0, OpenGL.GL_POSITION, fLightPosition); //光源位置
            GL.glEnable(GL.GL_LIGHTING);                                        // Enable Lighting
            GL.glEnable(GL.GL_LIGHT0);                                          // Enable Default Light
            GL.glEnable(GL.GL_COLOR_MATERIAL);                                  // Enable Color Material
            GL.glLoadIdentity();
            GL.gluPerspective(90, 1, 20.0f, 40.0f);
            GL.gluLookAt(0.0f, 0.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

            //GL.glLightfv(OpenGL.GL_LIGHT0, OpenGL.GL_AMBIENT, fLightAmbient);//环境光源
            //GL.glLightfv(OpenGL.GL_LIGHT0, OpenGL.GL_DIFFUSE, fLightDiffuse);//漫射光源

            //GL.glEnable(OpenGL.GL_LIGHTING);//开启光照
            //GL.glEnable(OpenGL.GL_LIGHT0);

            //GL.glEnable(OpenGL.GL_NORMALIZE);

            //GL.glClearColor(0, 0, 0, 0);

            //m_Camera.setCamera(0.0f, 0.0f, 6.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
            //m_Camera.setSpeed(1f);
            //GL.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
            //GL.gluOrtho2D(-50,50,-50,50);
            #region mouse handles
            MouseControl mouseControl = new MouseControl(this);
            mouseControl.AddControl(this);
            mouseControl.LeftMouseDown += new MouseEventHandler(glOnLeftMouseDown);
            mouseControl.LeftMouseUp   += new MouseEventHandler(glOnLeftMouseUp);

            mouseControl.RightMouseDown  += new MouseEventHandler(glOnRightMouseDown);
            mouseControl.RightMouseUp    += new MouseEventHandler(glOnRightMouseUp);
            mouseControl.MiddleMouseDown += new MouseEventHandler(glOnMiddleMouseDown);
            mouseControl.MiddleMouseUp   += new MouseEventHandler(glOnMiddleMouseUp);
            mouseControl.MouseWheel      += new MouseEventHandler(glOnMouseWheel);
            #endregion
            this.KeyDown += new KeyEventHandler(glOnKeyDown);
        }
Exemplo n.º 2
0
        protected override void InitGLContext()
        {
            GL.glShadeModel(GL.GL_SMOOTH);                                              // enable smooth shading
            GL.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);                                    // black background
            GL.glClearDepth(1.0f);                                                      // depth buffer setup
            GL.glEnable(GL.GL_DEPTH_TEST);                                              // enables depth testing
            GL.glDepthFunc(GL.GL_LEQUAL);                                               // type of depth testing
            // GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);	// nice perspective calculations
            //GL.glPointSize(4.0f);

            GL.gluPerspective(25.0, (double)width / (double)height, 1.0, 15.0);
            //GL.glTranslatef(0.0f, 0.0f, -4.0f);
            //GL.gluLookAt(0.0,100.0,600.0,0.0,0.0,0.0,0.0,1.0,0.0);

            GL.glEnable(GL.GL_LIGHTING);         // Enable Lighting
            GL.glEnable(GL.GL_LIGHT0);           // Enable Default Light

            GL.glEnable(GL.GL_COLOR_MATERIAL);   // Enable Color Material
            GL.glLoadIdentity();

            LastRot.setIdentity(); // Reset Rotation
            ThisRot.setIdentity(); // Reset Rotation
            ThisRot.get_Renamed(matrix);

            LastScale = 1.0f;
            ThisScale = 1.0f;



            #region mouse handles
            MouseControl mouseControl = new MouseControl(this);
            mouseControl.AddControl(this);
            mouseControl.LeftMouseDown += new MouseEventHandler(glOnLeftMouseDown);
            mouseControl.LeftMouseUp   += new MouseEventHandler(glOnLeftMouseUp);

            mouseControl.RightMouseDown  += new MouseEventHandler(glOnRightMouseDown);
            mouseControl.RightMouseUp    += new MouseEventHandler(glOnRightMouseUp);
            mouseControl.MiddleMouseDown += new MouseEventHandler(glOnMiddleMouseDown);
            mouseControl.MiddleMouseUp   += new MouseEventHandler(glOnMiddleMouseUp);

            #endregion
        }