InitializeContexts() 공개 메소드

Creates the OpenGL contexts.
public InitializeContexts ( ) : void
리턴 void
예제 #1
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);
            }
        }
예제 #2
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();
        }
예제 #3
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();
        }
예제 #4
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++;
        }