예제 #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            this.ClientSize = new System.Drawing.Size(800, 600);

            GL = new renderX(800, 600, this.Handle);
            GL.Clear();

            vertexBuffer = new GLBuffer(renderX.PrimitiveTypes.Cube(), 5, MemoryLocation.Heap);
            cubeShader   = new Shader(CubeVS, CubeFS, GLRenderMode.Triangle);

            cameraPosition = new Vector3(0, 0, -100);
            cameraRotation = new Vector3(0, 0, 0);

            GL.SetMatrixData(90, 160, 0);

            GL.ForceCameraPosition(cameraPosition);
            GL.ForceCameraRotation(cameraRotation);

            GL.SetFaceCulling(true, false);


            texture2d    = new GLTexture("container2.png", MemoryLocation.Heap, DuringLoad.Flip);
            TEXTURE_ADDR = (int *)texture2d.GetAddress();

            textureHeight         = texture2d.Height;
            textureWidthMinusOne  = texture2d.Width - 1;
            textureHeightMinusOne = texture2d.Height - 1;


            Timer timer = new Timer();

            timer.Interval = 15;
            timer.Tick    += timer_Tick;

            timer.Start();
        }
예제 #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            #region StartupWindow
            StartupForm StartForm = new StartupForm(Environment.GetCommandLineArgs());
            StartForm.ShowDialog();


            if (StartupForm.ApplicationTerminated)
            {
                this.Close();
                Application.Exit();
                return;
            }
            #endregion

            #region WindowSettings
            this.Size = new Size(StartupForm.W, StartupForm.H);
            int WindowWidth  = StartupForm.W - ClientSize.Width;
            int WindowHeight = StartupForm.H - ClientSize.Height;
            this.Size = new Size(StartupForm.W + WindowWidth, StartupForm.H + WindowHeight);
            this.SetStyle(ControlStyles.StandardDoubleClick, false);
            FBCaching        = StartupForm.NormalsInterpolated;
            this.MouseWheel += Form1_MouseWheel;
            #endregion

            #region FullscreenSettings
            if (StartupForm.FullscreenSelected)
            {
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                this.WindowState     = FormWindowState.Maximized;
                StartupForm.W        = this.Width;
                StartupForm.H        = this.Height;
            }
            #endregion



            #region VertexBufferInitialization
            STLImporter Importer = new STLImporter(StartupForm.FilePath);

            float[] vertexpoints = new float[Importer.AllTriangles.Length * 3 * 3];
            float[] normalBuffer = new float[Importer.AllTriangles.Length * 3];
            for (int i = 0; i < Importer.AllTriangles.Length; i++)
            {
                vertexpoints[i * 9]     = Importer.AllTriangles[i].vertex1.x;
                vertexpoints[i * 9 + 1] = Importer.AllTriangles[i].vertex1.y;
                vertexpoints[i * 9 + 2] = Importer.AllTriangles[i].vertex1.z;
                vertexpoints[i * 9 + 3] = Importer.AllTriangles[i].vertex2.x;
                vertexpoints[i * 9 + 4] = Importer.AllTriangles[i].vertex2.y;
                vertexpoints[i * 9 + 5] = Importer.AllTriangles[i].vertex2.z;
                vertexpoints[i * 9 + 6] = Importer.AllTriangles[i].vertex3.x;
                vertexpoints[i * 9 + 7] = Importer.AllTriangles[i].vertex3.y;
                vertexpoints[i * 9 + 8] = Importer.AllTriangles[i].vertex3.z;
                normalBuffer[i * 3]     = Importer.AllTriangles[i].normals.x;
                normalBuffer[i * 3 + 1] = Importer.AllTriangles[i].normals.y;
                normalBuffer[i * 3 + 2] = Importer.AllTriangles[i].normals.z;
            }
            #endregion

            ModelCenter = CalculateCenterOfModel(ref vertexpoints, out DistanceCenter);
            //   vertexpoints = STLImporter.AverageUpFaceNormalsAndOutputVertexBuffer(Importer.AllTriangles, 45);

            NormalBuffer = new GLBuffer(normalBuffer, 3, MemoryLocation.Heap);
            VertexBuffer = new GLBuffer(vertexpoints, 3, MemoryLocation.Heap);

            NormalBuffer = new GLBuffer(renderX.PrimitiveTypes.CubeNormals(), 3, MemoryLocation.Heap);
            VertexBuffer = new GLBuffer(renderX.PrimitiveTypes.Cube(), 5, MemoryLocation.Heap);


            //GL._DebugBlit
            StandardShader = new Shader(null, BasicShader, GLRenderMode.TriangleFlat);
            //StandardShader.SetOverrideAttributeCopy(true);
            // Skybox = new GLCubemap("skybox_data");


            DisplayTexture = new Shader(CubeShader, TextureShader, GLRenderMode.Triangle);
            //  DisplayTexture.SetOverrideAttributeCopy(false);
            //  DisplayTexture.SetOverrideAttributeCount(3);
            // GL.BlitInto

            texture2d    = new GLTexture("container2.png", MemoryLocation.Heap, DuringLoad.Flip);
            TEXTURE_ADDR = (int *)texture2d.GetAddress();

            textureHeight         = texture2d.Height;
            textureWidthMinusOne  = texture2d.Width - 1;
            textureHeightMinusOne = texture2d.Height - 1;


            #region MemoryAddresses
            nbAddr       = (float *)NormalBuffer.GetAddress();
            vertexpoints = null;

            #endregion

            #region CubeObject
            CubeVBO    = new GLBuffer(renderX.PrimitiveTypes.Cube(), 5, MemoryLocation.Heap);
            cubeShader = new Shader(CubeVS, CubeFS, GLRenderMode.TriangleFlat);
            cubeShader.SetOverrideAttributeCount(0);
            #endregion

            #region 3D_Grid
            float[] vpoints = new float[] {
                0, 0, 0, 9, 0, 0,
                0, 0, 1, 9, 0, 1,
                0, 0, 2, 9, 0, 2,
                0, 0, 3, 9, 0, 3,
                0, 0, 4, 9, 0, 4,
                0, 0, 5, 9, 0, 5,
                0, 0, 6, 9, 0, 6,
                0, 0, 7, 9, 0, 7,
                0, 0, 8, 9, 0, 8,
                0, 0, 9, 9, 0, 9,

                0, 0, 0, 0, 0, 9,
                1, 0, 0, 1, 0, 9,
                2, 0, 0, 2, 0, 9,
                3, 0, 0, 3, 0, 9,
                4, 0, 0, 4, 0, 9,
                5, 0, 0, 5, 0, 9,
                6, 0, 0, 6, 0, 9,
                7, 0, 0, 7, 0, 9,
                8, 0, 0, 8, 0, 9,
                9, 0, 0, 9, 0, 9
            };

            LineBuffer = new GLBuffer(vpoints, 3, MemoryLocation.Heap);
            LineShader = new Shader(GridShaderVS, GridShaderFS, GLRenderMode.Line, GLExtraAttributeData.XYZ_CameraSpace);

            #endregion

            #region CameraIndicator
            CameraIndicator = new Shader(CIVS, null, GLRenderMode.TriangleGouraud);
            CameraIndicator.SetOverrideCameraTransform(true);
            CameraIndicator.SetOverrideAttributeCopy(true);

            //Inner Part
            CICVertex  = new GLBuffer(renderX.PrimitiveTypes.CMI(), 3, MemoryLocation.Heap);
            CICNormals = new GLBuffer(renderX.PrimitiveTypes.CMINormals(), 3, MemoryLocation.Heap);

            //Outer Part
            CIPVertex  = new GLBuffer(renderX.PrimitiveTypes.CMS(), 3, MemoryLocation.Heap);
            CIPNormals = new GLBuffer(renderX.PrimitiveTypes.CMSNormals(), 3, MemoryLocation.Heap);

            CIC_Normals = (float *)CICNormals.GetAddress();
            CIP_Normals = (float *)CIPNormals.GetAddress();
            #endregion

            #region Post-Processing
            SSRShader = new Shader(null, SSR_Fragment, GLRenderMode.Triangle, GLExtraAttributeData.XYZ_XY_Both);

            SSRShaderPost = new Shader(SSR_Pass);
            #endregion

            #region MiniGLIndicator
            MiniGL = new renderX(130, 128);
            MiniGL.SetMatrixData(90, 10);
            MiniGL.SelectShader(CameraIndicator);
            MiniGL.SetFaceCulling(true, false);
            MiniGL.InitializeClickBuffer();
            MiniGL.SetClickBufferWrite(true);
            #endregion

            #region renderX_Initialization
            GL = new renderX(StartupForm.W, StartupForm.H, this.Handle);
            GL.SelectBuffer(VertexBuffer);
            GL.SelectShader(StandardShader);
            GL.SetMatrixData(90, 10);


            #endregion

            #region GLSettings
            cachedBuffer = new GLCachedBuffer(GL);

            GL.SetWireFrameOFFSET(-0.1f);
            GL.SetFaceCulling(true, false);

            #endregion

            //  GL.SetLinkedWireframe(true, 255, 255, 255);
            //  GL.SetViewportScaling(1920, 1080, InterpolationMethod.NearestNeighbour);
            GL.SetDebugWireFrameColor(255, 255, 255);
            // GL.SetLineAntiAliasing(true);
            GL.SetLineAntiAliasing(true);
            GL.SetLineThickness(1);
            // GL.SetLineThickness(3);
            //   GL.SetWireFrameOFFSET(-5000f);

            //    GL.SetLineAntiAliasing(true);

            //  GL.SetLinkedWireframe(true, 0, 0, 255);
            GL.InitializeVignetteBuffer(VignetteShader);

            //  cameraPosition = new Vector3(-1.16f, 18f, -33.5f);
            //   cameraRotation = new Vector3(0,0,90);

            cameraPosition = new Vector3(0, 0, -50);
            cameraRotation = new Vector3(0, 0, 0);


            #region RenderThreadStart
            RT              = new RenderThread(144);
            RT.RenderFrame += RT_RenderFrame;
            RT.Start();
            #endregion
        }