Provides a simple OpenGL control allowing quick development of Windows Forms-based OpenGL applications.
상속: System.Windows.Forms.UserControl
예제 #1
0
 public UserControl1()
 {
     InitializeComponent();
     s = new SimpleOpenGlControl();
     s.Paint += new PaintEventHandler(s_Paint);
     dosomething();
 }
        public GLGraphics(SimpleOpenGlControl control, Color clearColor)
        {
            this.glControl = control;
            fontCache = new Dictionary<string, int>();

            InitGL(control.Width, control.Height, clearColor, control);
        }
예제 #3
0
        int zbox = 100; //Размер коробки

        #endregion Fields

        #region Constructors

        //Инициализация экземпляра класса
        public GLDrawing(SimpleOpenGlControl s1, GLMode g1)
        {
            s = s1;
            obcnt = 0;
            g = g1;
            glb = new GLBase[NMAX];
        }
예제 #4
0
        public ModelViewer()
        {
            try
            {
                InitializeComponent();
                Label not = new Label();
                not.AutoSize = false;
                not.Text = "Not a model";
                not.Dock = DockStyle.Fill;
                not.TextAlign = ContentAlignment.MiddleCenter;
                not.Visible = false;
                Controls.Add(not);

                try
                {
                    gl_control = new SimpleOpenGlControl();
                    if (SoftwareRendering)
                        gl_control.Visible = false;
                    gl_control.Dock = DockStyle.Fill;
                    gl_control.MouseDown += image_MouseDown;
                    gl_control.MouseMove += image_MouseMove;
                    gl_control.MouseWheel += image_MouseWheel;
                    gl_control.InitializeContexts();
                    gl_control.SizeChanged += gl_control_SizeChanged;
                    gl_control.KeyDown += gl_control_KeyDown;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to initialize OpenGL.\n\n" + ex.Message + "\n\n" + ex.StackTrace, "OpenGL Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    SoftwareRendering = true;
                }

                software_control = new SelectablePictureBox();
                software_control.Dock = DockStyle.Fill;
                software_control.MouseDown += image_MouseDown;
                software_control.MouseMove += image_MouseMove;
                software_control.MouseWheel += image_MouseWheel;
                software_control.SizeChanged += gl_control_SizeChanged;
                software_control.KeyDown += gl_control_KeyDown;
                if (!SoftwareRendering)
                    software_control.Visible = false;

                Controls.Add(gl_control);
                Controls.Add(software_control);

                selected_model = null;
            }
            catch (Exception e)
            {
                MessageBox.Show("An error occurred while loading the model viewer.\nIt's probably related to OpenGL.\n\n" + e.Message + "\n\n" + e.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #5
0
        public EvoGL(Form f, SimpleOpenGlControl mySimpleGlControl, Point windowSize, Point windowPosition)
        {
            //Setup Thread && start
            //_evoGlThread = new Thread(DrawThread);
            //_evoGlThread.Start();

            //Wait for OpenGL To Set
            //while (_myOpenGlControl == null)
            //{ }

            //Set Gl Control
            _myOpenGlControl = mySimpleGlControl;

            //var d = delegate(object o) {
            //    int x = 5;
            //};

            //Set Draw
            _myTimer.Interval = (int)(1000.0 / this._reqFPS);

            if (this._myTimer.Interval == 0)
                this._myTimer.Interval = 1;

            _myTimer.Tick += new EventHandler(delegate(object o, EventArgs ea) {
                this._myOpenGlControl.Refresh(); });
            _myOpenGlControl.Paint += new System.Windows.Forms.PaintEventHandler(this.openGlControl_Paint);

            //Set Gl MouesControls
            _myOpenGlControl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.openGlControl_MouseDown);
            _myOpenGlControl.MouseMove += new System.Windows.Forms.MouseEventHandler(this.openGlControl_MouseMove);
            _myOpenGlControl.MouseUp += new System.Windows.Forms.MouseEventHandler(this.openGlControl_MouseUp);
            _myOpenGlControl.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.openGlControl_MouseWheel);
            _myOpenGlControl.MouseHover += new System.EventHandler(this.openGlControl_MouseHover);

            //Set Form
            f.Resize += new EventHandler(this.MainForm_ResizeEnd);

            //Set Window
            setWindow(windowSize, windowPosition);

            //Initialize
            InitializeContexts();

            //Set OGLSize
            this._myOpenGlControl.Width = (int)this._windowSize.X;
            this._myOpenGlControl.Height = (int)this._windowSize.Y;
            _OGLSize = new Point(_myOpenGlControl.Size.Width, _myOpenGlControl.Size.Height);
            this.Resize();

            //Start FPS clock
            this._fpsClock = new Clock(true, 0, 333);
        }
예제 #6
0
        public SlabModelPanel(int aSlabId, int aStandartSizeId, SimpleOpenGlControl aModelControl)
        {
            if (aModelControl == null) {
                throw new ArgumentNullException("aModelControl");
            }

            slabId = aSlabId;
            standartSizeId = aStandartSizeId;
            control = aModelControl;
            dimentionControl = new DimentionControl();
            dimentionControl.Hide();
            dimentionControl.Parent = control;

            Initialize();
        }
예제 #7
0
        public OpenGLAdapter(SimpleOpenGlControl viewport)
        {
            _viewport = viewport;
            _viewport.InitializeContexts();

            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_RGB | Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
            Gl.glClearColor(255, 255, 255, 1);
            Gl.glViewport(0, 0, _viewport.Width, _viewport.Height);
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluOrtho2D(0, _viewport.Height, 0, _viewport.Width);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glLoadIdentity();
        }
예제 #8
0
        /// <summary>
        /// Constructor for the renderer
        /// </summary>
        /// <param name="control">Gives the reference to the SimpleOpenGLControl you've created on a form</param>
        /// <param name="fps">The frames per second (max) to render at. Set this to be about 30 for good performance.</param>
        public Renderer(SimpleOpenGlControl control, double fps)
        {
            this.control = control;
            this.fps = fps;
            #region UI Initialization

            camOrtho = new GLUtility.GLCameraOrtho(w);
            camFree = new GLUtility.GLCameraFree(w);
            camChase = new GLUtility.GLCameraChase(w);
            camPrev = camCurrent = camOrtho;

            #endregion

            //This is baaaaad. Fix it.
            instance = this;
        }
예제 #9
0
        public MouseControl(SimpleOpenGlControl connectedOpenGLWindow)
        {
            this.Dimension = Dimension.TwoDimension;

            this.RotateButton_down = false;
            this.MoveButton_down = false;
            
            this.Range = 100;
            this.Mouse_Scale_Sensitive = 1.2f;
            this.M_Scale = 1;
            this.AutoRefresh = true;

            this.ConnectedOpenGLWindow = connectedOpenGLWindow;
            this.ConnectedOpenGLWindow.MouseDown += this.MouseDown;
            this.ConnectedOpenGLWindow.MouseMove += this.MouseMove;
            this.ConnectedOpenGLWindow.MouseUp += this.MouseUp;
            this.ConnectedOpenGLWindow.MouseWheel += this.MouseWheel;
            this.ConnectedOpenGLWindow.MouseDoubleClick += this.MouseDoubleClick;
        }
예제 #10
0
        public static void OpenGLInit(SimpleOpenGlControl RenderWindow)
        {
            Texture.RenderWindow = RenderWindow;

            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_RGB | Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);

            Il.ilInit();
            Il.ilEnable(Il.IL_ORIGIN_SET);

            Gl.glClearColor(255, 255, 255, 1);

            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Gl.glRotatef(270, 0, 0, 1);
            Glu.gluPerspective(0, RenderWindow.Width / (float)RenderWindow.Height, 0.1, 200);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glLoadIdentity();
        }
 public void InitGL(int width, int height, Color clearColor, SimpleOpenGlControl ctrl)
 {
     //Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ZERO);
     Gl.glClearColor(((float)clearColor.R / 255.0f), ((float)clearColor.G / 255.0f), ((float)clearColor.B / 255.0f), 0);
     Gl.glClearDepth(1);
     //Gl.glDepthFunc(Gl.GL_ALWAYS); //stuff the z buffer
     //Gl.glEnable(Gl.GL_DEPTH_TEST);
     Gl.glDisable(Gl.GL_DEPTH_TEST);
     Gl.glEnable(Gl.GL_BLEND);
     Gl.glEnable(Gl.GL_LINE_STIPPLE);
     Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
     Gl.glShadeModel(Gl.GL_SMOOTH);
     Gl.glViewport(0, 0, width, height);
     //Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST);
     Gl.glEnable(Gl.GL_LINE_SMOOTH);
     Gl.glHint(Gl.GL_LINE_SMOOTH_HINT, Gl.GL_NICEST);
     Gl.glLineWidth(1.5f);
 }
예제 #12
0
 /// <summary>
 /// Инициализация прорисовки. Необходимо выполнить первым.
 /// </summary>
 /// <param name="Gl_control">Элемент управления для отрисовки.</param>
 public static void Init(SimpleOpenGlControl Gl_control)
 {
     _Gl_control = Gl_control;
 }
예제 #13
0
 public static void InitGL(int width, int height, Color clearColor, SimpleOpenGlControl ctrl)
 {
     InitGL(width, height, clearColor, ctrl, false);
 }
예제 #14
0
        public static void InitGL(int width, int height, Color clearColor, SimpleOpenGlControl ctrl, bool fast)
        {
            // Attempt To Get A Device Context
            hDC = User.GetDC(ctrl.Handle);
            measureGraphics = null;

              //Gl.glClearColor(((float)clearColor.R / 255.0f), ((float)clearColor.G / 255.0f), ((float)clearColor.B / 255.0f), 0);
            /*
              float[] fogColor = {.5f, .5f, .5f, 1};                // Fog Color
              float[] lightAmbient = {0.5f, 0.5f, 0.5f, 1};
              float[] lightDiffuse = {1, 1, 1, 1};
              float[] lightPosition = {0, 0, 30, 1};

              float[] mat_diffuse = {0.1f, 0.5f, 0.8f, 1.0f};
              float[] no_mat = { 0.0f, 0.0f, 0.0f, 1.0f };
              Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_DIFFUSE, mat_diffuse);
              Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_SPECULAR, no_mat);
              Gl.glMaterialf(Gl.GL_FRONT, Gl.GL_SHININESS, 0.0f);
              Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_EMISSION, no_mat);
            */
              Gl.glShadeModel(Gl.GL_SMOOTH);                                      // Enable Smooth Shading
              Gl.glClearDepth(1);                                                 // Depth Buffer Setup
              Gl.glEnable(Gl.GL_DEPTH_TEST);                                      // Enables Depth Testing
              Gl.glDepthFunc(Gl.GL_LEQUAL);                                       // The Type Of Depth Testing To Do
              Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST);         // Really Nice Perspective Calculations
              /*
            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_AMBIENT, lightAmbient);            // Setup The Ambient Light
              Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_DIFFUSE, lightDiffuse);            // Setup The Diffuse Light
              Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_POSITION, lightPosition);          // Position The Light
              Gl.glEnable(Gl.GL_LIGHT1);                                          // Enable Light One
              Gl.glFogi(Gl.GL_FOG_MODE, Gl.GL_EXP);                      // Fog Mode
              Gl.glFogfv(Gl.GL_FOG_COLOR, fogColor);                              // Set Fog Color
              Gl.glFogf(Gl.GL_FOG_DENSITY, 0.3f);                                // How Dense Will The Fog Be
              Gl.glHint(Gl.GL_FOG_HINT, Gl.GL_DONT_CARE);                         // Fog Hint Value
              Gl.glFogf(Gl.GL_FOG_START, 1);                                      // Fog Start Depth
              Gl.glFogf(Gl.GL_FOG_END, 20);                                        // Fog End Depth
              */
              Gl.glEnable(Gl.GL_BLEND);
              Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
              Gl.glHint(Gl.GL_LINE_SMOOTH_HINT, Gl.GL_DONT_CARE);
              Gl.glEnable(Gl.GL_LINE_SMOOTH);
            /*
            if (!fast)

            Gl.glClearDepth(1);

            Gl.glEnable(Gl.GL_BLEND);
            Gl.glEnable(Gl.GL_LINE_SMOOTH);
            Gl.glEnable(Gl.GL_DEPTH_TEST);

            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
            Gl.glHint(Gl.GL_LINE_SMOOTH_HINT, Gl.GL_DONT_CARE);
              Gl.glDepthFunc(Gl.GL_LEQUAL);
            if (!fast)
            {
                Gl.glEnable(Gl.GL_LINE_STIPPLE);
                Gl.glShadeModel(Gl.GL_SMOOTH);
            }
             * */
            //Gl.glViewport(0, 0, width, height);
            /*
            Gl.glEnable(Gl.GL_BLEND);
            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
            Gl.glShadeModel(Gl.GL_FLAT);
              Gl.glShadeModel(Gl.GL_SMOOTH);

            if (!fast)
            {
            Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST);

            }
            Gl.glLineWidth(1.0f);
            */
            glBuildFont();
        }
예제 #15
0
        public void AddNewTabWithExperiment(Experiment c)
        {
            ExperimentControl p = new ExperimentControl();
            p.Name = "ExpCtrl";
            p.LoadExperiment(c);

            p.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;

            p.Size = Tabs.Size;
            p.Left = Tabs.Left;
            p.Top = Tabs.Top - 25;

            Size _Size = p.Size;
            _Size.Width -= 202;
            _Size.Height -= 26;
            //p.Size = _Size;
            p.Experiment.Graphics.SetDrawingBorder(p.Left, p.Top, _Size);

            //���������� ���� ������������
            switch (p.Experiment.Graphics.Needs)
            {
                case ExperimentNeeds.None: break;
                case ExperimentNeeds.Normal: break; //���������� ����������
                case ExperimentNeeds.ZedGraph:
                    //�������� ��������
                    ZedGraph.ZedGraphControl zgc = new ZedGraph.ZedGraphControl();
                    zgc.Size = _Size;
                    p.Controls.Add(zgc);
                    GraphPane zgcPane = zgc.GraphPane;
                    zgcPane.Chart.Fill = new Fill(Color.White, Color.LightBlue, 45.0F);
                    p.Experiment.Graphics.CreateControl(zgc); //�������� ������� Zedgraph'�
                    break;

                case ExperimentNeeds.XNA: break;//�������� 3�-�����
                case ExperimentNeeds.Graph:
                        ZedGraphControl graph = new ZedGraphControl();
                        graph.Size = _Size;
                        p.Controls.Add(graph);

                        GraphPane myPane;
                        /*graph.Top = 0;
                        graph.Left = 0;
                        graph.Height = this.Height;
                        graph.Width = this.Width;
                        */
                        myPane = graph.GraphPane;
                        p.Experiment.Graphics.SetGraphInfo(myPane);
                        myPane.Legend.IsVisible = false;
                        myPane.Chart.Fill = new Fill(Color.White, Color.LightBlue, 45.0F);
                        break;
                case ExperimentNeeds.OpenGL:
                        SimpleOpenGlControl tao_ctrl = new SimpleOpenGlControl();
                        tao_ctrl.Size = _Size;
                        tao_ctrl.Name = "TaoControl";
                        p.Controls.Add(tao_ctrl);
                        tao_ctrl.MouseDown += p.OGL_MouseDown;
                        tao_ctrl.MouseUp += p.OGL_MouseUp;
                        tao_ctrl.MouseMove += p.OGL_MouseMove;
                        //tao_ctrl.MouseWheel += p.OGL_MouseWheel;
                        tao_ctrl.KeyDown += p.OGL_KeyDown;

                        tao_ctrl.InitializeContexts();
                        break;
            }

            p.LoadParameters(p.Experiment.Graphics.ParameterListTemplate);
            //    p.Experiment.pList = p.Experiment.Graphics.ParameterListTemplate;

            p.Experiment.Graphics.SetParameters(p.Experiment.Graphics.ParameterListTemplate);
            p.Anchor = AnchorStyles.Bottom & AnchorStyles.Right & AnchorStyles.Top & AnchorStyles.Left;

            Tabs.TabPages.Add("exp" + ExperimentCount, "����������� " + ExperimentCount);
            Tabs.TabPages[ExperimentCount].Controls.Add(p);
            Tabs.SelectTab(ExperimentCount);
            Tabs.TabPages[ExperimentCount].Focus();

            ExperimentCount++;
        }
예제 #16
0
 //Constructor
 public EvoGL(Form f, SimpleOpenGlControl glc, double width, double height)
     : this(f, glc, new Point(width, height), new Point())
 {
 }
예제 #17
0
 /// <summary>
 /// Constructor for the renderer with a default select  tool (old behvaior)
 /// </summary>
 /// <param name="control">Gives the reference to the SimpleOpenGLControl you've created on a form</param>
 /// <param name="fps">The frames per second (max) to render at. Set this to be about 30 for good performance.</param>
 public Renderer(SimpleOpenGlControl control, double fps, bool useIntegratedSelectTool)
     : this(control, fps)
 {
     SelectTool s = new SelectTool(new ToolManager());
     AddTool(s, true);
 }
예제 #18
0
파일: Form1.cs 프로젝트: RubisetCie/box2c
        private void Form1_Load(object sender, EventArgs e)
        {
            sogc = new SimpleOpenGlControl();
            sogc.Dock = DockStyle.Fill;
            sogc.Paint += new PaintEventHandler(sogc_Paint);
            sogc.Resize += new EventHandler(sogc_Resize);
            Controls.Add(sogc);

            sogc.InitializeContexts();
            InitOpenGL(sogc.Size, 1, PointF.Empty);

            // Define the gravity vector.
            b2Vec2 gravity = new b2Vec2(0.0f, -10.0f);

            // Do we want to let bodies sleep?
            bool doSleep = true;

            // Construct a world object, which will hold and simulate the rigid bodies.
            world = new b2World(gravity, doSleep);
            //	world.SetWarmStarting(true);

            {
                b2BodyDef bd = new b2BodyDef();
                b2Body ground = world.CreateBody(bd);

                b2PolygonShape shape = new b2PolygonShape();
                shape.SetAsEdge(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
                ground.CreateFixture(shape, 0.0f);
            }

            {
                float a = 0.5f;
                b2CircleShape shape = new b2CircleShape();
                shape.m_radius = a;

                b2Vec2 x = new b2Vec2(-7.0f, 0.95f);
                b2Vec2 y;
                b2Vec2 deltaX = new b2Vec2(0, 1.25f);
                b2Vec2 deltaY = new b2Vec2(0, 1.25f);
                y= deltaY;

                for (int j = 0; j < 8; ++j)
                {
                    b2BodyDef bd = new b2BodyDef();
                    bd.type = b2BodyType.b2_dynamicBody;
                    bd.position = y;
                    b2Body body = world.CreateBody(bd);
                    body.CreateFixture(shape, 5.0f);

                    y += deltaY;
                }
            }

            GDIDebugThing.instance.SetFlags(EDebugFlags.e_shapeBit);
            world.SetDebugDraw(GDIDebugThing.instance);

            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Interval = 85;
            timer.SynchronizingObject = this;
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
            timer.Start();
        }