Пример #1
1
        /// <summary>
        /// Pushes this object into the provided OpenGL instance.
        /// This will generally push elements of the attribute stack
        /// and then set current values.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        public virtual void Push(OpenGL gl)
        {
            //  Push texture attributes.
            gl.PushAttrib(Enumerations.AttributeMask.Texture);

            //  Bind the texture.
            Bind(gl);
        }
Пример #2
0
        /// <summary>
        /// Creates the display list. This function draws the
        /// geometry as well as compiling it.
        /// </summary>
        private void CreateDisplayList(OpenGL gl)
        {
            //  Create the display list.
            displayList = new DisplayList();

            //  Generate the display list and
            displayList.Generate(gl);
            displayList.New(gl, DisplayList.DisplayListMode.CompileAndExecute);

            //  Push attributes, set the color.
            gl.PushAttrib(OpenGL.GL_CURRENT_BIT | OpenGL.GL_ENABLE_BIT |
                OpenGL.GL_LINE_BIT);
            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.LineWidth(1.0f);

            //  Draw the grid lines.
            gl.Begin(OpenGL.GL_LINES);
            for (int i = -10; i <= 10; i++)
            {
                float fcol = ((i % 10) == 0) ? 0.3f : 0.15f;
                gl.Color(fcol, fcol, fcol);
                gl.Vertex(i, -10, 0);
                gl.Vertex(i, 10, 0);
                gl.Vertex(-10, i, 0);
                gl.Vertex(10, i, 0);
            }
            gl.End();

            //  Restore attributes.
            gl.PopAttrib();

            //  End the display list.
            displayList.End(gl);
        }
Пример #3
0
 /// <summary>
 /// Sets the attributes.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 public override void SetAttributes(OpenGL gl)
 {
     if(enableAlphaTest.HasValue) gl.EnableIf(OpenGL.GL_ALPHA_TEST,enableAlphaTest.Value);
     if(enableAutoNormal.HasValue) gl.EnableIf(OpenGL.GL_AUTO_NORMAL,enableAutoNormal.Value);
     if(enableBlend.HasValue) gl.EnableIf(OpenGL.GL_BLEND,enableBlend.Value);
     if(enableCullFace.HasValue) gl.EnableIf(OpenGL.GL_CULL_FACE,enableCullFace.Value);
     if(enableDepthTest.HasValue) gl.EnableIf(OpenGL.GL_DEPTH_TEST,enableDepthTest.Value);
     if(enableDither.HasValue) gl.EnableIf(OpenGL.GL_DITHER,enableDither.Value);
     if(enableFog.HasValue) gl.EnableIf(OpenGL.GL_FOG,enableFog.Value);
     if(enableLighting.HasValue) gl.EnableIf(OpenGL.GL_LIGHTING,enableLighting.Value);
     if(enableLineSmooth.HasValue) gl.EnableIf(OpenGL.GL_LINE_SMOOTH,enableLineSmooth.Value);
     if(enableLineStipple.HasValue) gl.EnableIf(OpenGL.GL_LINE_STIPPLE,enableLineStipple.Value);
     if(enableColorLogicOp.HasValue) gl.EnableIf(OpenGL.GL_COLOR_LOGIC_OP,enableColorLogicOp.Value);
     if(enableIndexLogicOp.HasValue) gl.EnableIf(OpenGL.GL_INDEX_LOGIC_OP,enableIndexLogicOp.Value);
     if(enableNormalize.HasValue) gl.EnableIf(OpenGL.GL_NORMALIZE,enableNormalize.Value);
     if(enablePointSmooth.HasValue) gl.EnableIf(OpenGL.GL_POINT_SMOOTH,enablePointSmooth.Value);
     if(enablePolygonOffsetLine.HasValue) gl.EnableIf(OpenGL.GL_POLYGON_OFFSET_LINE,enablePolygonOffsetLine.Value);
     if(enablePolygonOffsetFill.HasValue) gl.EnableIf(OpenGL.GL_POLYGON_OFFSET_FILL,enablePolygonOffsetFill.Value);
     if(enablePolygonOffsetPoint.HasValue) gl.EnableIf(OpenGL.GL_POLYGON_OFFSET_POINT,enablePolygonOffsetPoint.Value);
     if(enablePolygonSmooth.HasValue) gl.EnableIf(OpenGL.GL_POLYGON_SMOOTH,enablePolygonSmooth.Value);
     if(enablePolygonStipple.HasValue) gl.EnableIf(OpenGL.GL_POLYGON_STIPPLE,enablePolygonStipple.Value);
     if(enableScissorTest.HasValue) gl.EnableIf(OpenGL.GL_SCISSOR_TEST,enableScissorTest.Value);
     if(enableStencilTest.HasValue) gl.EnableIf(OpenGL.GL_STENCIL,enableStencilTest.Value);
     if(enableTexture1D.HasValue) gl.EnableIf(OpenGL.GL_TEXTURE_1D,enableTexture1D.Value);
     if (enableTexture2D.HasValue) gl.EnableIf(OpenGL.GL_TEXTURE_2D, enableTexture2D.Value);
 }
Пример #4
0
 public void SetData(OpenGL gl, uint attributeIndex, float[] rawData, bool isNormalised, int stride)
 {
     //  Set the data, specify its shape and assign it to a vertex attribute (so shaders can bind to it).
     gl.BufferData(OpenGL.GL_ARRAY_BUFFER, rawData, OpenGL.GL_STATIC_DRAW);
     gl.VertexAttribPointer(attributeIndex, stride, OpenGL.GL_FLOAT, isNormalised, 0, IntPtr.Zero);
     gl.EnableVertexAttribArray(attributeIndex);
 }
Пример #5
0
        /// <summary>
        /// Sets the attributes.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        public override void SetAttributes(OpenGL gl)
        {
            if(enableAlphaTest.HasValue && alphaTestFunction.HasValue && alphaTestReferenceValue.HasValue) 
            {
                gl.EnableIf(OpenGL.GL_ALPHA_TEST, enableAlphaTest.Value);
                gl.AlphaFunc(alphaTestFunction.Value, alphaTestReferenceValue.Value);
            }
            
            if(enableBlend.HasValue && blendingSourceFactor.HasValue && blendingDestinationFactor.HasValue) 
            {
                gl.EnableIf(OpenGL.GL_BLEND, enableBlend.Value);
                gl.BlendFunc(blendingSourceFactor.Value, blendingDestinationFactor.Value);
            }

            if(enableDither.HasValue) gl.EnableIf(OpenGL.GL_DITHER, enableDither.Value);
            if(drawBufferMode.HasValue) gl.DrawBuffer(drawBufferMode.Value);
            
            if(enableLogicOp.HasValue && logicOp.HasValue) 
            {
                gl.EnableIf(OpenGL.GL_COLOR_LOGIC_OP, enableLogicOp.Value);
                gl.LogicOp(logicOp.Value);
            }
            if(colorModeClearColor != null) gl.ClearColor(colorModeClearColor.R, colorModeClearColor.G, colorModeClearColor.B, colorModeClearColor.A);
            //todowritemask
        }
Пример #6
0
        /// <summary>
        /// Render to the provided instance of OpenGL.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="renderMode">The render mode.</param>
        public override void Render(OpenGL gl, RenderMode renderMode)
        {
            //	Create the evaluator.
            gl.Map1(OpenGL.GL_MAP1_VERTEX_3,//	Use and produce 3D points.
                0,								//	Low order value of 'u'.
                1,								//	High order value of 'u'.
                3,								//	Size (bytes) of a control point.
                ControlPoints.Width,			//	Order (i.e degree plus one).
                ControlPoints.ToFloatArray());	//	The control points.

            //	Enable the type of evaluator we wish to use.
            gl.Enable(OpenGL.GL_MAP1_VERTEX_3);

            //	Beging drawing a line strip.
            gl.Begin(OpenGL.GL_LINE_STRIP);

            //	Now draw it.
            for (int i = 0; i <= segments; i++)
                gl.EvalCoord1((float)i / segments);

            gl.End();

            //	Draw the control points.
            ControlPoints.Draw(gl, DrawControlPoints, DrawControlGrid);
        }
Пример #7
0
 public void Create(OpenGL gl)
 {
     //  Generate the texture object array.
     uint[] ids = new uint[1];
     gl.GenTextures(1, ids);
     textureObject = ids[0];
 }
Пример #8
0
 public void Create(OpenGL gl)
 {
     //  Generate the vertex array.
     uint[] ids = new uint[1];
     gl.GenVertexArrays(1, ids);
     vertexArrayObject = ids[0];
 }
Пример #9
0
 /// <summary>
 /// Sets the attributes.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 public override void SetAttributes(OpenGL gl)
 {
     if (enable.HasValue) gl.EnableIf(OpenGL.GL_LIGHTING, enable.Value);
     if (ambientLight != null) gl.LightModel(LightModelParameter.Ambient, ambientLight);
     if (localViewer.HasValue) gl.LightModel(LightModelParameter.LocalViewer, localViewer.Value == true ? 1 : 0);
     if (twoSided.HasValue) gl.LightModel(LightModelParameter.TwoSide, twoSided.Value == true ? 1 : 0);
 }
Пример #10
0
 public void Create(OpenGL gl)
 {
     //  Generate the vertex array.
     uint[] ids = new uint[1];
     gl.GenBuffers(1, ids);
     bufferObject = ids[0];
 }
        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="openGLVersion">The desired OpenGL version.</param>
        /// <param name="gl">The OpenGL context.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="bitDepth">The bit depth.</param>
        /// <param name="parameter">The extra parameter.</param>
        /// <returns></returns>
        public override bool Create(OpenGLVersion openGLVersion, OpenGL gl, int width, int height, int bitDepth, object parameter)
        {
            //  Call the base.
            base.Create(openGLVersion, gl, width, height, bitDepth, parameter);

            //  Get the desktop DC.
            IntPtr desktopDC = Win32.GetDC(IntPtr.Zero);

            //  Create our DC as a compatible DC for the desktop.
            deviceContextHandle = Win32.CreateCompatibleDC(desktopDC);

            //  Release the desktop DC.
            Win32.ReleaseDC(IntPtr.Zero, desktopDC);

            //  Create our dib section.
            dibSection.Create(deviceContextHandle, width, height, bitDepth);

            //  Create the render context.
            Win32.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero);
            renderContextHandle = Win32.wglCreateContext(deviceContextHandle);

            //  Make current.
            MakeCurrent();

            //  Update the context if required.
            UpdateContextVersion(gl);

            //  Return success.
            return true;
        }
Пример #12
0
 /// <summary>
 /// Destroy in the context of the supplied OpenGL instance.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 public void DestroyInContext(OpenGL gl)
 {
     //  Delete the shader.
     gl.DeleteShader(ShaderObject);
     ShaderObject = 0;
     CurrentOpenGLContext = null;
 }
Пример #13
0
        /// <summary>
        /// Creates the shader program.
        /// </summary>
        /// <param name="gl">The gl.</param>
        /// <param name="vertexShaderSource">The vertex shader source.</param>
        /// <param name="fragmentShaderSource">The fragment shader source.</param>
        /// <param name="attributeLocations">The attribute locations. This is an optional array of
        /// uint attribute locations to their names.</param>
        /// <exception cref="ShaderCompilationException"></exception>
        public void Create(OpenGL gl, string vertexShaderSource, string fragmentShaderSource, 
            Dictionary<uint, string> attributeLocations)
        {
            //  Create the shaders.
            vertexShader.Create(gl, OpenGL.GL_VERTEX_SHADER, vertexShaderSource);
            fragmentShader.Create(gl, OpenGL.GL_FRAGMENT_SHADER, fragmentShaderSource);

            //  Create the program, attach the shaders.
            shaderProgramObject = gl.CreateProgram();
            gl.AttachShader(shaderProgramObject, vertexShader.ShaderObject);
            gl.AttachShader(shaderProgramObject, fragmentShader.ShaderObject);

            //  Before we link, bind any vertex attribute locations.
            if (attributeLocations != null)
            {
                foreach (var vertexAttributeLocation in attributeLocations)
                    gl.BindAttribLocation(shaderProgramObject, vertexAttributeLocation.Key, vertexAttributeLocation.Value);
            }

            //  Now we can link the program.
            gl.LinkProgram(shaderProgramObject);

            //  Now that we've compiled and linked the shader, check it's link status. If it's not linked properly, we're
            //  going to throw an exception.
            if (GetLinkStatus(gl) == false)
            {
                throw new ShaderCompilationException(string.Format("Failed to link shader program with ID {0}.", shaderProgramObject), GetInfoLog(gl));
            }
        }
Пример #14
0
        /// <summary>
        /// Initialises the Scene.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        public void Initialise(OpenGL gl)
        {
            //  We're going to specify the attribute locations for the position and normal,
            //  so that we can force both shaders to explicitly have the same locations.
            const uint positionAttribute = 0;
            const uint normalAttribute = 1;
            var attributeLocations = new Dictionary<uint, string>
            {
                {positionAttribute, "Position"},
                {normalAttribute, "Normal"},
            };

            //  Create the per pixel shader.
            shaderPerPixel = new ShaderProgram();
            shaderPerPixel.Create(gl,
                ManifestResourceLoader.LoadTextFile(@"Shaders\PerPixel.vert"),
                ManifestResourceLoader.LoadTextFile(@"Shaders\PerPixel.frag"), attributeLocations);

            //  Create the toon shader.
            shaderToon = new ShaderProgram();
            shaderToon.Create(gl,
                ManifestResourceLoader.LoadTextFile(@"Shaders\Toon.vert"),
                ManifestResourceLoader.LoadTextFile(@"Shaders\Toon.frag"), attributeLocations);

            //  Generate the geometry and it's buffers.
            trefoilKnot.GenerateGeometry(gl, positionAttribute, normalAttribute);
        }
Пример #15
0
 /// <summary>
 /// Sets the attributes.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 public override void SetAttributes(OpenGL gl)
 {
     if (enableDepthTest.HasValue) gl.EnableIf(OpenGL.GL_DEPTH_TEST, enableDepthTest.Value);
     if (depthFunction.HasValue) gl.DepthFunc(depthFunction.Value);
     if (depthClearValue.HasValue) gl.ClearDepth(depthClearValue.Value);
     if (enableDepthWritemask.HasValue) gl.EnableIf(OpenGL.GL_DEPTH_WRITEMASK, enableDepthWritemask.Value);
 }
Пример #16
0
 /// <summary>
 /// Sets the attributes.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 public override void SetAttributes(OpenGL gl)
 {
     if (viewportX.HasValue && viewportY.HasValue && viewportWidth.HasValue && viewportHeight.HasValue)
         gl.Viewport(viewportX.Value, viewportY.Value, viewportWidth.Value, viewportHeight.Value);
     if (depthRangeNear.HasValue && depthRangeFar.HasValue)
         gl.DepthRange(depthRangeNear.Value, depthRangeFar.Value);
 }
Пример #17
0
        /// <summary>
        /// Only valid to be called after the render context is created, this function attempts to
        /// move the render context to the OpenGL version originally requested. If this is &gt; 2.1, this
        /// means building a new context. If this fails, we'll have to make do with 2.1.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        protected void UpdateContextVersion(OpenGL gl)
        {
            //  If the request version number is anything up to and including 2.1, standard render contexts
            //  will provide what we need (as long as the graphics card drivers are up to date).
            var requestedVersionNumber = VersionAttribute.GetVersionAttribute(requestedOpenGLVersion);
            if (requestedVersionNumber.IsAtLeastVersion(3, 0) == false)
            {
                createdOpenGLVersion = requestedOpenGLVersion;
                return;
            }

            //  Now the none-trivial case. We must use the WGL_ARB_create_context extension to 
            //  attempt to create a 3.0+ context.
            try
            {
                int[] attributes = 
                {
                    OpenGL.WGL_CONTEXT_MAJOR_VERSION_ARB, requestedVersionNumber.Major,  
                    OpenGL.WGL_CONTEXT_MINOR_VERSION_ARB, requestedVersionNumber.Minor,
                    OpenGL.WGL_CONTEXT_FLAGS_ARB, OpenGL.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
                    0
                };
                var hrc = gl.CreateContextAttribsARB(IntPtr.Zero, attributes);
                Win32.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero);
                Win32.wglDeleteContext(renderContextHandle);
                Win32.wglMakeCurrent(deviceContextHandle, hrc);
                renderContextHandle = hrc; 
            }
            catch(Exception)
            {
                //  TODO: can we actually get the real version?
                createdOpenGLVersion = OpenGLVersion.OpenGL2_1;
            }
        }
Пример #18
0
 /// <summary>
 /// Destroy in the context of the supplied OpenGL instance.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 public void DestroyInContext(OpenGL gl)
 {
     //  Delete the shader.
     gl.DeleteProgram(ProgramObject);
     ProgramObject = 0;
     CurrentOpenGLContext = null;
 }
Пример #19
0
        /// <summary>
        /// Render to the provided instance of OpenGL.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="renderMode">The render mode.</param>
        public override void Render(OpenGL gl, Core.RenderMode renderMode)
        {
            base.Render(gl, renderMode);

            //	Begin drawing a NURBS surface.
            gl.BeginSurface(nurbsRenderer);

            //	Draw the surface.
            gl.NurbsSurface(nurbsRenderer,		//	The internal nurbs object.
                sKnots.Length,					//	Number of s-knots.
                sKnots,							//	The s-knots themselves.
                tKnots.Length,					//	The number of t-knots.
                tKnots,							//	The t-knots themselves.
                ControlPoints.Width * 3,		//	The size of a row of control points.
                3,								//	The size of a control points.
                ControlPoints.ToFloatArray(),	//	The control points.
                ControlPoints.Width,			//	The order, i.e degree + 1.
                ControlPoints.Height,			//	The order, i.e degree + 1.
                OpenGL.GL_MAP2_VERTEX_3);			//	Type of data to generate.

            //	End the surface.
            gl.EndSurface(nurbsRenderer);

            //	Draw the control points.
            ControlPoints.Draw(gl, DrawControlPoints, DrawControlGrid);
        }
Пример #20
0
        /// <summary>
        /// Initialises the scene.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="width">The width of the screen.</param>
        /// <param name="height">The height of the screen.</param>
        public void Initialise(OpenGL gl, float width, float height)
        {
            //  Set a blue clear colour.
            gl.ClearColor(0.4f, 0.6f, 0.9f, 0.0f);

            //  Create the shader program.
            var vertexShaderSource = ManifestResourceLoader.LoadTextFile("Shader.vert");
            var fragmentShaderSource = ManifestResourceLoader.LoadTextFile("Shader.frag");
            shaderProgram = new ShaderProgram();
            shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
            shaderProgram.BindAttributeLocation(gl, attributeIndexPosition, "in_Position");
            shaderProgram.BindAttributeLocation(gl, attributeIndexColour, "in_Color");
            shaderProgram.AssertValid(gl);

            //  Create a perspective projection matrix.
            const float rads = (60.0f / 360.0f) * (float)Math.PI * 2.0f;
            projectionMatrix = glm.perspective(rads, width / height, 0.1f, 100.0f);

            //  Create a view matrix to move us back a bit.
            viewMatrix = glm.translate(new mat4(1.0f), new vec3(0.0f, 0.0f, -5.0f));

            //  Create a model matrix to make the model a little bigger.
            modelMatrix = glm.scale(new mat4(1.0f), new vec3(2.5f));

            //  Now create the geometry for the square.
            CreateVerticesForSquare(gl);
        }
Пример #21
0
        /// <summary>
        /// This function begins feedback, recording the scene etc. End finishes
        /// feedback, and parses the feedback buffer.
        /// </summary>
        public virtual void Begin(OpenGL gl)
        {
            //	Set the feedback buffer.
            gl.FeedbackBuffer(feedbackBuffer.Length, OpenGL.GL_3D_COLOR_TEXTURE, feedbackBuffer);

            //	Set the rendermode to feedback.
            gl.RenderMode(OpenGL.GL_FEEDBACK);
        }
Пример #22
0
        /// <summary>
        /// Create in the context of the supplied OpenGL instance.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        public override void CreateInContext(OpenGL gl)
        {
            //  Create the fragment shader.
            ShaderObject = gl.CreateShader(OpenGL.GL_FRAGMENT_SHADER);

            //  Store the current context.
            CurrentOpenGLContext = gl;
        }
Пример #23
0
 /// <summary>
 /// Sets the attributes.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 public override void SetAttributes(OpenGL gl)
 {
     if (perspectiveCorrectionHint.HasValue) gl.Hint(HintTarget.PerspectiveCorrection, perspectiveCorrectionHint.Value);
     if (pointSmoothHint.HasValue) gl.Hint(HintTarget.LineSmooth, pointSmoothHint.Value);
     if (lineSmoothHint.HasValue) gl.Hint(HintTarget.PointSmooth, lineSmoothHint.Value);
     if (polygonSmoothHint.HasValue) gl.Hint(HintTarget.PolygonSmooth, polygonSmoothHint.Value);
     if (fogHint.HasValue) gl.Hint(HintTarget.Fog, fogHint.Value);
 }
        /// <summary>
        /// Pushes the effect onto the specified parent element.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="parentElement">The parent element.</param>
        public override void Push(OpenGL gl, Core.SceneElement parentElement)
        {
            //  Push the stack.
            gl.PushMatrix();

            //  Perform the transformation.
            arcBall.TransformMatrix(gl);
        }
Пример #25
0
 /// <summary>
 /// Render to the provided instance of OpenGL.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 /// <param name="renderMode">The render mode.</param>
 public virtual void Render(OpenGL gl, RenderMode renderMode)
 {
     //	Set the quadric properties.
     gl.QuadricDrawStyle(glQuadric, (uint)drawStyle);
     gl.QuadricOrientation(glQuadric, (int)orientation);
     gl.QuadricNormals(glQuadric, (uint)normals);
     gl.QuadricTexture(glQuadric, textureCoords ? 1 : 0);
 }
Пример #26
0
 /// <summary>
 /// Unfreezes the specified gl.
 /// </summary>
 /// <param name="gl">The gl.</param>
 public void Unfreeze(OpenGL gl)
 {
     if (isFrozen)
     {
         displayList.Delete(gl);
         isFrozen = false;
     }
 }
Пример #27
0
        /// <summary>
        /// Render to the provided instance of OpenGL.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="renderMode">The render mode.</param>
        public override void Render(OpenGL gl, RenderMode renderMode)
        {
            //  Call the base.
            base.Render(gl, renderMode);

            //	Draw a sphere with the current settings.
            gl.Sphere(glQuadric, radius, slices, stacks);
        }
Пример #28
0
        /// <summary>
        /// Sets the attributes.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        public override void SetAttributes(OpenGL gl)
        {
            if (enableScissorTest.HasValue) 
                gl.EnableIf(OpenGL.GL_SCISSOR_TEST, enableScissorTest.Value);
            if (scissorX.HasValue && scissorY.HasValue && scissorWidth.HasValue && scissorHeight.HasValue) 
                gl.Scissor(scissorX.Value, scissorY.Value, scissorWidth.Value, scissorHeight.Value);

        }
Пример #29
0
        /// <summary>
        /// Render to the provided instance of OpenGL.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="renderMode">The render mode.</param>
        public override void Render(OpenGL gl, RenderMode renderMode)
        {
            //  Call the base.
            base.Render(gl, renderMode);

            //	Draw a quadric with the current settings.
            gl.Cylinder(glQuadric, baseRadius, topRadius, height, slices, stacks);
        }
Пример #30
0
 /// <summary>
 /// This is the class' main function, to override this function and perform a 
 /// perspective transformation.
 /// </summary>
 public override void TransformProjectionMatrix(OpenGL gl)
 {
     //  Perform the look at transformation.
     gl.Perspective(FieldOfView, AspectRatio, Near, Far);
     gl.LookAt((double)Position.X, (double)Position.Y, (double)Position.Z,
         (double)target.X, (double)target.Y, (double)target.Z,
         (double)upVector.X, (double)upVector.Y, (double)upVector.Z);
 }
        /// <summary>
        /// Render texture with FBO and draw it to memory.
        /// </summary>
        private void RenderTexWithFBOandDraw()
        {
            OpenGL gl = openGLControl.OpenGL;
            // render to texture 
            // adjust viewport and projection matrix to texture dimension
            gl.Viewport(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.LoadIdentity();
            gl.Perspective(fovy, (double)Width / (double)Height, 0.01f, 100.0);
            gl.LookAt(
                status.eye.x + status.kinect.x, 
                status.eye.y + status.kinect.y, 
                status.eye.z + status.kinect.z, 
                buildingModelCursor.GetCoordinate().x,
                buildingModelCursor.GetCoordinate().y, 
                buildingModelCursor.GetCoordinate().z, 
                0, 1, 0
                );

            // with FBO
            // set the rendering destination to FBO
            gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, framebuffer_name[0]);

            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.LoadIdentity();
            // clear buffer
            gl.ClearColor(0, 0, 0, 1);
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            // start to draw
            gl.PushMatrix();

            //  Load the identity matrix.
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            drawer.DrawBuildingPart(gl, buildingModelCursor, DrawType.Full);
            if (status != null && buildingModelCursor != null)
            {
                switch (buildingModelCursor.GetBuildingType())
                {
                    case BuildingObjectType.Floor:
                        drawer.DrawBuildingPart(gl, buildingOutsideModel, DrawType.WireFrame);
                        drawer.DrawBuildingPart(gl, buildingModelCursor, DrawType.Full);
                        break;
                    case BuildingObjectType.Object:
                        System.Collections.Hashtable childs = buildingModelCursor.Father.GetChilds();
                        foreach (System.Collections.DictionaryEntry childEntry in buildingModelCursor.Father.GetChilds())
                        {
                            BuildingObjectLib3DS child = childEntry.Value as BuildingObjectLib3DS;
                            if (child != buildingModelCursor)
                            {
                                drawer.DrawBuildingPart(gl,
                                    child,
                                    DrawType.WireFrame);
                            }
                            else
                            {
                                drawer.DrawBuildingPart(gl,
                                    child,
                                    DrawType.Full);
                            }
                        }
                        break;
                    case BuildingObjectType.Room:
                    // TODO
                    case BuildingObjectType.Outside:
                    case BuildingObjectType.Building:
                        drawer.DrawBuildingPart(gl, buildingModelCursor, DrawType.Full);
                        break;
                }
            }
            //drawer.DrawBuildingPart(gl, modelForFun, DrawType.Full);
            gl.PopMatrix();

            // back to normal window-system-provided framebuffer
            gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, 0); // unbind

            // trigger mipmaps generation explicitly
            // NOTE: If GL_GENERATE_MIPMAP is set to GL_TRUE, then glCopyTexSubImage2D()
            // triggers mipmap generation automatically. However, the texture attached
            // onto a FBO should generate mipmaps manually via glGenerateMipmapEXT().
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, texture_name[0]);
            gl.GenerateMipmapEXT(OpenGL.GL_TEXTURE_2D);
            //gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_ADD);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);

            // TODO: without FBO, maybe need
        }
Пример #32
0
 public SkeletonMeshRenderer(OpenGL gl)
 {
     batcher    = new MeshBatcher(gl);
     Bone.yDown = false;
 }
Пример #33
0
 /// <summary>
 /// Draw string in opengl
 /// </summary>
 /// <param name="gl"></param>
 /// <param name="dispText"></param>
 /// <param name="posX"></param>
 /// <param name="posY"></param>
 /// <param name="foreColor"></param>
 private void DrawString(OpenGL gl, string dispText, int posX, int posY, float[] foreColor)
 {
     gl.DrawText(posX, posY, foreColor[0], foreColor[1], foreColor[2], this.FontFamily.Source, (float)this.FontSize, dispText);
 }
Пример #34
0
 /// <summary>
 /// Pops us from Object Space using the transformation into the specified OpenGL instance.
 /// </summary>
 public void PopObjectSpace(OpenGL gl)
 {
     //  Pop the matrix.
     gl.PopMatrix();
 }
Пример #35
0
        public void Render(OpenGL gl, RenderMode renderMode)
        {
            //if (renderMode == RenderMode.HitTest) { return; }

            RenderModel(args, gl, renderMode);
        }
Пример #36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OpenGLEventArgs"/> class.
 /// </summary>
 /// <param name="gl">The gl.</param>
 public OpenGLEventArgs(OpenGL gl)
 {
     OpenGL = gl;
 }
Пример #37
0
 public void Draw(OpenGL gl, float width, Color color)
 {
     this.model.Draw(gl, width, color);
 }
Пример #38
0
 /// <summary>
 /// Create in the context of the supplied OpenGL instance.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 public void CreateInContext(OpenGL gl)
 {
     //  Create the NURBS renderer.
     nurbsRenderer        = gl.NewNurbsRenderer();
     CurrentOpenGLContext = gl;
 }
Пример #39
0
        /// <summary>
        /// Draw axis with all lines
        /// </summary>
        /// <param name="gl"></param>
        private void DrawAxis(OpenGL gl, double width, double height)
        {
            //Get the axis color, secondary lines color and ticks color
            var axisLineColor          = AxisBrush.GetRGBAf();
            var axisSecondaryLineColor = SecondaryGridBrush.GetRGBAf();
            var ticksColor             = TicksBrush.GetRGBAf();
            var ticksScaleColor        = TicksScaleBrush.GetRGBAf();

            // Get length of Tick line
            double tickWidth = 5;

            #region Draw YTicks and labels
            // Ticks line of axis-Y and ticks
            double gapY            = height / (YGapCount + 1);
            double realValueOfGapY = (MaxY - MinY) / (YGapCount + 1);
            for (int num = 0; num <= YGapCount + 1; num++)
            {
                double posX = tickWidth;
                double posY = gapY * num;

                // Draw secondary line
                if (IsSecondaryLineVisible)
                {
                    gl.PushAttrib(OpenGL.GL_ENABLE_BIT);

                    if (IsDotDash)
                    {
                        gl.LineStipple(1, 0xAAAA);
                        gl.Enable(OpenGL.GL_LINE_STIPPLE);
                    }
                    else
                    {
                        gl.Disable(OpenGL.GL_LINE_STIPPLE);
                    }

                    gl.Color(axisSecondaryLineColor[0], axisSecondaryLineColor[1], axisSecondaryLineColor[2]);// will be chaged by drawText if without it
                    gl.Begin(OpenGL.GL_LINES);
                    gl.Vertex(0.0d, posY);
                    gl.Vertex(width, posY);
                    gl.End();
                    gl.PopAttrib();
                }

                // Draw ticks line
                gl.Color(ticksScaleColor[0], ticksScaleColor[1], ticksScaleColor[2]);// will be chaged by drawText if without it
                gl.Begin(OpenGL.GL_LINES);
                gl.Vertex(0.0d, posY);
                gl.Vertex(tickWidth, posY);
                gl.End();

                // Draw ticks
                string dispText = (num * realValueOfGapY + MinY).ToString("f2");
                double textWidth = 0, textHeight = 0;
                GetSizeOfText(gl, dispText, ref textWidth, ref textHeight);

                double textPosX = 2 * tickWidth;
                double textPosY = num == YGapCount + 1 ? posY - textHeight : (num == 0 ? posY + 2 : posY);

                DrawString(gl, dispText, (int)textPosX, (int)textPosY, ticksColor);
            }
            #endregion

            #region Draw XTicks and labels
            // Ticks line of axis-X and ticks
            double gapX            = width / (XGapCount + 1);
            double realValueOfGapX = (MaxX - MinX).TotalMilliseconds / (XGapCount + 1);// Milliseconds in one gap
            for (int num = 0; num <= XGapCount + 1; num++)
            {
                double posX = num * gapX;

                // Draw secondary line
                if (IsSecondaryLineVisible)
                {
                    gl.PushAttrib(OpenGL.GL_ENABLE_BIT);

                    if (IsDotDash)
                    {
                        gl.LineStipple(1, 0xAAAA);
                        gl.Enable(OpenGL.GL_LINE_STIPPLE);
                    }
                    else
                    {
                        gl.Disable(OpenGL.GL_LINE_STIPPLE);
                    }

                    gl.Color(axisSecondaryLineColor[0], axisSecondaryLineColor[1], axisSecondaryLineColor[2]);// will be chaged by drawText if without it
                    gl.Begin(OpenGL.GL_LINES);
                    gl.Vertex(posX, 0.0d);
                    gl.Vertex(posX, height);
                    gl.End();
                    gl.PopAttrib();
                }

                // Draw ticks line
                gl.Color(ticksScaleColor[0], ticksScaleColor[1], ticksScaleColor[2]);// will be chaged by drawText if without it
                gl.Begin(OpenGL.GL_LINES);
                gl.Vertex(posX, 0.0d);
                gl.Vertex(posX, tickWidth);
                gl.End();

                // Draw text
                string dispText = (MinX + TimeSpan.FromMilliseconds(realValueOfGapX * num)).ToString("HH:mm:ss");
                double textWidth = 0, textHeight = 0;
                GetSizeOfText(gl, dispText, ref textWidth, ref textHeight);

                double textPosX = num == XGapCount + 1 ? posX - textWidth - 5 : posX - textWidth / 2;
                double textPosY = tickWidth + textHeight / 2;

                DrawString(gl, dispText, (int)textPosX, (int)textPosY, ticksColor);
            }
            #endregion

            #region Draw Axis-X and Axis-Y
            // Left line of axis-Y
            gl.Color(axisLineColor[0], axisLineColor[1], axisLineColor[2]);
            gl.Begin(OpenGL.GL_LINES);
            gl.Vertex(0.0d, 0.0d);
            gl.Vertex(0.0d, height);
            gl.End();

            // Draw right line when the axis is boxed
            if (IsBoxed)
            {
                gl.Begin(OpenGL.GL_LINES);
                gl.Vertex(width, 0.0d);
                gl.Vertex(width, height);
                gl.End();
            }

            // Left line of axis-Y
            gl.Color(axisLineColor[0], axisLineColor[1], axisLineColor[2]);
            gl.Begin(OpenGL.GL_LINES);
            gl.Vertex(0.0d, 0.0d);
            gl.Vertex(width, 0.0d);
            gl.End();

            // Draw right line when the axis is boxed
            if (IsBoxed)
            {
                gl.Begin(OpenGL.GL_LINES);
                gl.Vertex(0.0d, height);
                gl.Vertex(width, height);
                gl.End();
            }
            #endregion
        }
Пример #40
0
 /// <summary>
 /// Render to the provided instance of OpenGL.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 /// <param name="renderMode">The render mode.</param>
 public override void Render(OpenGL gl, Core.RenderMode renderMode)
 {
     //	Set the properties.
     gl.NurbsProperty(nurbsRenderer, (int)OpenGL.GLU_DISPLAY_MODE, (float)displayMode);
 }
Пример #41
0
 public void Sync(EnginePtr exeeng, Direct3D exed3d, OpenGL exeogl, Havok exehvk, GuiFactory exegui, Forms exefms, DirectIpt exedip, WinIpt exewip, FFmpeg exeffm, CryptoPP execpp, ID3Lib exeid3, WinAudio exewad, XAudio2 exexa2, WinMidi exemid, WinSock exewsk, AsyncWorkers exeaws, SQLite exesql, HaruPdf exepdf, RayTracer exertr, Pbrt exepbrt, PythonScriptEngine exepse, Console execle)
 {
     IronSightEnginePINVOKE.Direct3D_Sync(swigCPtr, EnginePtr.getCPtr(exeeng), Direct3D.getCPtr(exed3d), OpenGL.getCPtr(exeogl), Havok.getCPtr(exehvk), GuiFactory.getCPtr(exegui), Forms.getCPtr(exefms), DirectIpt.getCPtr(exedip), WinIpt.getCPtr(exewip), FFmpeg.getCPtr(exeffm), CryptoPP.getCPtr(execpp), ID3Lib.getCPtr(exeid3), WinAudio.getCPtr(exewad), XAudio2.getCPtr(exexa2), WinMidi.getCPtr(exemid), WinSock.getCPtr(exewsk), AsyncWorkers.getCPtr(exeaws), SQLite.getCPtr(exesql), HaruPdf.getCPtr(exepdf), RayTracer.getCPtr(exertr), Pbrt.getCPtr(exepbrt), PythonScriptEngine.getCPtr(exepse), Console.getCPtr(execle));
     if (IronSightEnginePINVOKE.SWIGPendingException.Pending)
     {
         throw IronSightEnginePINVOKE.SWIGPendingException.Retrieve();
     }
 }
Пример #42
0
        // Constructor, Initializes a new instance of the "FormGPS" class.
        public FormGPS()
        {
            //winform initialization
            InitializeComponent();

            //build the gesture structures
            SetupStructSizes();

            //create a new section and set left and right positions
            //created whether used or not, saves restarting program
            for (int j = 0; j < MAXSECTIONS; j++)
            {
                section[j] = new CSection(this);
            }

            //  Get the OpenGL object.
            OpenGL gl     = openGLControl.OpenGL;
            OpenGL glBack = openGLControlBack.OpenGL;

            //create the world grid
            worldGrid = new CWorldGrid(gl, this);

            //our vehicle made with gl object and pointer of mainform
            vehicle = new CVehicle(gl, this);

            //our NMEA parser
            pn = new CNMEA(this);

            //create the ABLine instance
            ABLine = new CABLine(gl, this);

            //new instance of contour mode
            ct = new CContour(gl, this);

            //new instance of contour mode
            curve = new CABCurve(gl, this);

            //new instance of auto headland turn
            yt = new CYouTurn(gl, glBack, this);

            //module communication
            mc = new CModuleComm(this);

            //perimeter list object
            periArea = new CPerimeter(gl);

            //boundary object
            boundz = new CBoundary(gl, glBack, this);

            //headland object
            hl = new CHeadland(gl, this);

            //rate object
            rc = new CRate(this);

            //headland entry/exit sequences
            seq = new CSequence(this);

            //nmea simulator built in.
            sim = new CSim(this);

            //all the autosteer objects
            ast = new CAutoSteer(this);

            //all the attitude, heading, roll, pitch reference system
            ahrs = new CAHRS(this);

            //A recorded path
            recPath = new CRecordedPath(gl, this);

            //start the stopwatch
            swFrame.Start();

            //resource for gloabal language strings
            _rm = new ResourceManager("AgOpenGPS.gStr", Assembly.GetExecutingAssembly());
        }
Пример #43
0
 public VBO(OpenGL gl)
 {
     _gl = gl;
     _gl.GenBuffers(1, _handle);
 }
Пример #44
0
 public DrawHelper(OpenGL ngl, uint nOpenglMode, List <Point> nListPoints)
 {
     gl         = ngl;
     openglMode = nOpenglMode;
     listPoints = nListPoints;
 }
Пример #45
0
 private void setLightColor(OpenGL gl)
 {
     gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_AMBIENT, lightColor[0]);  //环境光
     gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_DIFFUSE, lightColor[1]);  //漫反射
     gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_SPECULAR, lightColor[2]); //镜面光
 }
Пример #46
0
        public override void glBind(MDagPath shapePath)
        {
            // ONLY push and pop required attributes performance reasons...
            //
            OpenGL.glPushAttrib(OpenGL.GL_LIGHTING_BIT);

            lightingOn = OpenGL.glIsEnabled(OpenGL.GL_LIGHTING);
            if (lightingOn > 0)
            {
                OpenGL.glEnable(OpenGL.GL_COLOR_MATERIAL);
                OpenGL.glColorMaterial(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_DIFFUSE);
            }

            // Base colour is always white
            OpenGL.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

            // Bind texture
            if (libOpenMayaNet.MAYA_API_VERSION >= 800)
            {
                MObject      l_object  = shapePath.node;
                MFnMesh      mesh      = new MFnMesh(l_object);
                String       uvSetName = "map1";
                MObjectArray textures  = new MObjectArray();

                boundTexture = false;
                mesh.getAssociatedUVSetTextures(uvSetName, textures);
                if (textures.length > 0)
                {
                    MImageFileInfo.MHwTextureType hwType = new MImageFileInfo.MHwTextureType();
                    MHwTextureManager.glBind(textures[0], ref hwType);
                    boundTexture = true;
                }

                if (!boundTexture)
                {
                    OpenGL.glDisable(OpenGL.GL_TEXTURE_2D);
                    OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, 0);
                }
            }
            else
            {
                // To get this code branch to compile, replace <change file name here>
                // with an appropriate file name
                if (id == 0)
                {
                    MImage fileImage = new MImage();
                    fileImage.readFromFile("<change file name here>");
                    uint[] param = new uint[1];
                    OpenGL.glGenTextures(1, param);
                    id = param[0];
                    OpenGL.glEnable(OpenGL.GL_TEXTURE_2D);
                    OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, id);
                    unsafe
                    {
                        uint width = 0, height = 0;
                        fileImage.getSize(out width, out height);
                        byte *pPixels = fileImage.pixels();
                        OpenGL.glTexImage2D(OpenGL.GL_TEXTURE_2D,
                                            0,
                                            (int)OpenGL.GL_RGBA8,
                                            (int)width,
                                            (int)height,
                                            0,
                                            OpenGL.GL_RGBA,
                                            OpenGL.GL_UNSIGNED_BYTE,
                                            pPixels);
                    }
                }
                else
                {
                    OpenGL.glEnable(OpenGL.GL_TEXTURE_2D);
                    OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, id);
                }
                boundTexture = true;
            }

            if (boundTexture)
            {
                OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, (int)OpenGL.GL_REPEAT);
                OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, (int)OpenGL.GL_REPEAT);
                OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, (int)OpenGL.GL_LINEAR);
                OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, (int)OpenGL.GL_LINEAR);
            }
            OpenGL.glEnableClientState(OpenGL.GL_VERTEX_ARRAY);

            return;
        }
Пример #47
0
 /// <summary>
 /// Destroy in the context of the supplied OpenGL instance.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 public void DestroyInContext(OpenGL gl)
 {
     //  Destroy the NURBS renderer.
     gl.DeleteNurbsRenderer(nurbsRenderer);
     CurrentOpenGLContext = null;
 }
Пример #48
0
 public void DrawArea(OpenGL gl, Color color)
 {
     this.model.DrawArea(gl, color);
 }
Пример #49
0
 private void SetVertex(OpenGL gl, float x, float y, float z)
 {
     gl.Vertex(x * zoom, y * zoom, z * zoom);
 }
Пример #50
0
 // unbind OpenGL Vertex Array Object and OpenGL Vertex Buffer Object
 private static void unbindBuffers()
 {
     OpenGL.BindBuffer(OpenGL.GL_ARRAY_BUFFER, 0);
     OpenGL.BindVertexArray(0);
 }
Пример #51
0
        private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            this.Title = "APLIMAT Final Exam";
            OpenGL gl = args.OpenGL;

            // Clear The Screen And The Depth Buffer
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            // Move Left And Into The Screen
            gl.LoadIdentity();
            gl.Translate(0.0f, 0.0f, -100.0f);


            if (Keyboard.IsKeyDown(Key.W))
            {
                playerCube.ApplyForce(Vector3.Up * speed);
            }

            if (Keyboard.IsKeyDown(Key.D))
            {
                playerCube.ApplyForce(Vector3.Right * speed);
            }

            if (Keyboard.IsKeyDown(Key.A))
            {
                playerCube.ApplyForce(Vector3.Left * speed);
            }
            if (Keyboard.IsKeyDown(Key.S))
            {
                playerCube.ApplyForce(Vector3.Down * speed);
            }

            Console.WriteLine("X:" + playerCube.Position.x + " Y:" + playerCube.Position.y);


            gl.Color(0.196078f, 0.6f, 0.8f);
            sea.Draw(gl);

            gl.Color(1.0, 1.0, 1.0);
            playerCube.Draw(gl);


            if (sea.Contains(playerCube))
            {
                var dragForce = sea.CalculateDragForce(playerCube) * 1f;
                playerCube.ApplyForce(dragForce);
                sea.changeColor(gl, 0, 0, 61);

                if (playerCube.Position.y <= sea1)
                {
                    playerCube.Position.y  = sea1;
                    playerCube.Velocity.y *= -1;
                }

                if (playerCube.Position.x >= sea3)
                {
                    playerCube.Position.x  = sea3;
                    playerCube.Velocity.x *= -1;
                }

                if (playerCube.Position.x <= sea2)
                {
                    playerCube.Position.x  = sea2;
                    playerCube.Velocity.x *= -1;
                }
            }


            if (!sea.Contains(playerCube))
            {
                if (playerCube.Position.y <= sea4)
                {
                    if (playerCube.Position.x <= sea2)
                    {
                        playerCube.Position.y  = sea4;
                        playerCube.Velocity.y *= -1;
                        playerCube.Velocity.x *= -1;
                    }


                    if (playerCube.Position.x >= -54 && playerCube.Position.x <= -28)
                    {
                        playerCube.Position.y  = 3.5f;
                        playerCube.Velocity.y *= -1;
                        playerCube.Velocity.x *= -1;
                    }

                    if (playerCube.Position.x >= -13 && playerCube.Position.x <= 13)
                    {
                        playerCube.Position.y  = 3.5f;
                        playerCube.Velocity.y *= -1;
                        playerCube.Velocity.x *= -1;
                    }

                    if (playerCube.Position.x >= 28 && playerCube.Position.x <= 54)
                    {
                        playerCube.Position.y  = 3.5f;
                        playerCube.Velocity.y *= -1;
                        playerCube.Velocity.x *= -1;
                    }

                    if (playerCube.Position.x >= sea3)
                    {
                        playerCube.Position.y  = sea4;
                        playerCube.Velocity.y *= -1;
                        playerCube.Velocity.x *= -1;
                    }
                }


                if (playerCube.Position.x >= sea2 && playerCube.Position.x <= sea3)
                {
                    if (playerCube.Position.y <= sea4)
                    {
                        if (playerCube.Position.x <= sea2)
                        {
                            playerCube.Position.x  = sea2;
                            playerCube.Velocity.x *= -1;
                        }



                        if (playerCube.Position.x >= sea3)
                        {
                            playerCube.Position.x  = sea3;
                            playerCube.Velocity.x *= -1;
                        }
                    }
                }
            }

            //cliff and sea
            #region


            gl.Color(0.36, 0.25, 0.20);
            cliff1.Draw(gl);
            cliff1.Scale = new Vector3(1 * cliff1.Mass / 4, 1 * cliff1.Mass / 2, 0);

            cliff2.Draw(gl);
            cliff2.Scale = new Vector3(1 * cliff2.Mass / 4, 1 * cliff2.Mass / 2, 0);

            cliff3.Draw(gl);
            cliff3.Scale = new Vector3(1 * cliff3.Mass / 1, 1 * cliff3.Mass / 8, 0);

            //middle cliff
            cliff4.Draw(gl);
            cliff4.Scale = new Vector3(1 * cliff4.Mass / 8, 1 * cliff4.Mass / 4, 0);

            cliff5.Draw(gl);
            cliff5.Scale = new Vector3(1 * cliff5.Mass / 8, 1 * cliff5.Mass / 4, 0);

            cliff6.Draw(gl);
            cliff6.Scale = new Vector3(1 * cliff6.Mass / 8, 1 * cliff6.Mass / 4, 0);
            #endregion

            #region sample for testing

            #endregion


            #region idea2

            #endregion

            #region keypress

            if (Keyboard.IsKeyDown(Key.W))
            {
                myCube.ApplyForce(Vector3.Up * speed);
            }

            if (Keyboard.IsKeyDown(Key.D))
            {
                myCube.ApplyForce(Vector3.Right * speed);
            }

            if (Keyboard.IsKeyDown(Key.A))
            {
                myCube.ApplyForce(Vector3.Left * speed);
            }
            if (Keyboard.IsKeyDown(Key.S))
            {
                myCube.ApplyForce(Vector3.Down * speed);
            }

            if (Mouse.LeftButton == MouseButtonState.Pressed)
            {
            }

            #endregion
        }
Пример #52
0
        public void Draw(OpenGL gl, Skeleton skeleton)
        {
            if (skeleton == null)
            {
                return;
            }

            var   drawOrder = skeleton.DrawOrder;
            var   drawOrderItems = skeleton.DrawOrder.Items;
            float skeletonR = skeleton.R, skeletonG = skeleton.G, skeletonB = skeleton.B, skeletonA = skeleton.A;

            for (int i = 0, n = drawOrder.Count; i < n; i++)
            {
                float[]    vertices   = this.vertices;
                Slot       slot       = drawOrderItems[i];
                Attachment attachment = slot.Attachment;
                if (attachment is RegionAttachment)
                {
                    RegionAttachment regionAttachment = (RegionAttachment)attachment;

                    MeshItem item = batcher.NextItem(4, 6);
                    item.triangles = quadTriangles;
                    VertexPositionColorTexture[] itemVertices = item.vertices;

                    AtlasRegion region = (AtlasRegion)regionAttachment.RendererObject;
                    item.texture = (uint)region.page.rendererObject;

                    Color color;
                    float a = skeletonA * slot.A * regionAttachment.A;
                    if (premultipliedAlpha)
                    {
                        color = new Color(
                            skeletonR * slot.R * regionAttachment.R * a,
                            skeletonG * slot.G * regionAttachment.G * a,
                            skeletonB * slot.B * regionAttachment.B * a, a);
                    }
                    else
                    {
                        color = new Color(
                            skeletonR * slot.R * regionAttachment.R,
                            skeletonG * slot.G * regionAttachment.G,
                            skeletonB * slot.B * regionAttachment.B, a);
                    }
                    itemVertices[TL].color = color;
                    itemVertices[BL].color = color;
                    itemVertices[BR].color = color;
                    itemVertices[TR].color = color;

                    regionAttachment.ComputeWorldVertices(slot.Bone, vertices);
                    itemVertices[TL].position = new Vector2(vertices[RegionAttachment.X1], vertices[RegionAttachment.Y1]);
                    itemVertices[BL].position = new Vector2(vertices[RegionAttachment.X2], vertices[RegionAttachment.Y2]);
                    itemVertices[BR].position = new Vector2(vertices[RegionAttachment.X3], vertices[RegionAttachment.Y3]);
                    itemVertices[TR].position = new Vector2(vertices[RegionAttachment.X4], vertices[RegionAttachment.Y4]);

                    float[] uvs = regionAttachment.UVs;
                    itemVertices[TL].textureCoordinate = new Vector2(uvs[RegionAttachment.X1], uvs[RegionAttachment.Y1]);
                    itemVertices[BL].textureCoordinate = new Vector2(uvs[RegionAttachment.X2], uvs[RegionAttachment.Y2]);
                    itemVertices[BR].textureCoordinate = new Vector2(uvs[RegionAttachment.X3], uvs[RegionAttachment.Y3]);
                    itemVertices[TR].textureCoordinate = new Vector2(uvs[RegionAttachment.X4], uvs[RegionAttachment.Y4]);
                }
                else if (attachment is MeshAttachment)
                {
                    MeshAttachment mesh        = (MeshAttachment)attachment;
                    int            vertexCount = mesh.WorldVerticesLength;
                    if (vertices.Length < vertexCount)
                    {
                        vertices = new float[vertexCount];
                    }
                    mesh.ComputeWorldVertices(slot, vertices);

                    int[]    triangles = mesh.Triangles;
                    MeshItem item      = batcher.NextItem(vertexCount, triangles.Length);
                    item.triangles = triangles;

                    AtlasRegion region = (AtlasRegion)mesh.RendererObject;
                    item.texture = (uint)region.page.rendererObject;

                    Color color;
                    float a = skeletonA * slot.A * mesh.A;
                    if (premultipliedAlpha)
                    {
                        color = new Color(
                            skeletonR * slot.R * mesh.R * a,
                            skeletonG * slot.G * mesh.G * a,
                            skeletonB * slot.B * mesh.B * a, a);
                    }
                    else
                    {
                        color = new Color(
                            skeletonR * slot.R * mesh.R,
                            skeletonG * slot.G * mesh.G,
                            skeletonB * slot.B * mesh.B, a);
                    }

                    float[] uvs = mesh.UVs;
                    VertexPositionColorTexture[] itemVertices = item.vertices;
                    for (int ii = 0, v = 0; v < vertexCount; ii++, v += 2)
                    {
                        itemVertices[ii].color             = color;
                        itemVertices[ii].position          = new Vector2(vertices[v], vertices[v + 1]);
                        itemVertices[ii].textureCoordinate = new Vector2(uvs[v], uvs[v + 1]);
                    }
                }
            }

            batcher.Draw(gl);
        }
Пример #53
0
        public static void Run()
        {
            GLFW.SetErrorCallback(onError);

            if (!GLFW.Initialize())
            {
                Console.WriteLine($"Failed to initialize GLFW.");
                return;
            }

            var possibleWindow = createWindow("GLFW Drawing Test");

            if (!possibleWindow.HasValue)
            {
                Console.WriteLine($"Unable to load create window.");
                GLFW.Terminate();
                return;
            }

            IntPtr window = possibleWindow.Value;

            GLFW.MakeContextCurrent(window);

            GLFW.SetKeyCallback(window, keyBindings);

            setupViewport(window);

            string vertexShaderText = loadShaderFile("Shaders/triangle.vert");
            // create the OpenGL Vertex Shader Object
            uint vertexShader = 0;

            try {
                vertexShader = createShader(OpenGL.GL_VERTEX_SHADER, vertexShaderText);
            }
            catch (ShaderCompileException e) {
                Console.WriteLine(e.Message);
                GLFW.Terminate();
                return;
            }

            string fragmentShaderText = loadShaderFile("Shaders/orange.frag");
            // create the OpenGL Fragment Shader Object
            uint fragmentShader = 0;

            try {
                fragmentShader = createShader(OpenGL.GL_FRAGMENT_SHADER, fragmentShaderText);
            }
            catch (ShaderCompileException e) {
                Console.WriteLine(e.Message);
                OpenGL.DeleteShader(vertexShader);
                GLFW.Terminate();
                return;
            }

            uint program = 0;

            try {
                program = createProgram(vertexShader, fragmentShader);
            }
            catch (LinkingException e) {
                Console.WriteLine(e.Message);
                OpenGL.DeleteShader(vertexShader);
                OpenGL.DeleteShader(fragmentShader);
                GLFW.Terminate();
                return;
            }

            OpenGL.DeleteShader(vertexShader);
            OpenGL.DeleteShader(fragmentShader);

            uint vertexArray  = loadVertexArrayObject();
            uint vertexBuffer = loadVertexBufferObject();

            // (x, y, z) coordinate pairs
            float[] vertices =
            {
                0.0f,   0.5f, 0.0f, // top
                0.5f,  -0.5f, 0.0f, // bottom right
                -0.5f, -0.5f, 0.0f  // bottom left
            };
            loadVertices(vertices);

            // divide by 3 since each vertex is made up of 3 points
            setupDrawing(vertices.Length / 3);

            unbindBuffers();

            while (GLFW.WindowShouldClose(window) == 0)
            {
                GLFW.PollEvents();

                // red, green, and blue values range from 0 (0) - 255 (1)
                OpenGL.ClearColor(1 / 255.0f, 113 / 255.0f, 187 / 255.0f, 1.0f);
                OpenGL.Clear(OpenGL.GL_COLOR_BUFFER_BIT);

                OpenGL.UseProgram(program);
                OpenGL.BindVertexArray(vertexArray);
                OpenGL.DrawArrays(OpenGL.GL_TRIANGLES, 0, 3);
                OpenGL.BindVertexArray(0);

                GLFW.SwapBuffers(window);
            }
            // delete vertex array
            OpenGL.DeleteVertexArrays(1, ref vertexArray);
            // delete vertex buffer
            OpenGL.DeleteBuffers(1, ref vertexBuffer);

            // terminate GLFW, clearing any resources allocated by GLFW
            GLFW.Terminate();
        }
Пример #54
0
        private void FillNode(TreemapNode n, RectD nBounds, RectD vBounds, double pxX, double pxY, int depth)
        {
            if (Overlaps(nBounds, vBounds))
            {
                GLTexture tex = n.Texture;
                if (tex != null && tex.Valid)
                {
                    OpenGL.glEnd();
                    OpenGL.glEnable(OpenGL.GL_TEXTURE_2D);
                    OpenGL.glDisable(OpenGL.GL_BLEND);
                    tex.Bind();

                    OpenGL.glColor3f(1.0f, 1.0f, 1.0f);
                    OpenGL.glBegin(OpenGL.GL_QUADS);
                }
                else
                {
                    RGB col = new RGB(new HSV(depth * (1.0f / 6.0f), 0.5f - depth / 256.0f, 1));
                    OpenGL.glColor3f(col.r, col.g, col.b);
                }

                {
                    OpenGL.glTexCoord2f(0.0f, 0.0f);
                    OpenGL.glVertex2f((float)nBounds.Left, (float)nBounds.Top);

                    OpenGL.glTexCoord2f(0.0f, 1.0f);
                    OpenGL.glVertex2f((float)nBounds.Left, (float)nBounds.Bottom);

                    OpenGL.glTexCoord2f(1.0f, 1.0f);
                    OpenGL.glVertex2f((float)nBounds.Right, (float)nBounds.Bottom);

                    OpenGL.glTexCoord2f(1.0f, 0.0f);
                    OpenGL.glVertex2f((float)nBounds.Right, (float)nBounds.Top);
                }

                if (tex != null && tex.Valid)
                {
                    OpenGL.glEnd();
                    tex.Unbind();
                    OpenGL.glDisable(OpenGL.GL_TEXTURE_2D);
                    OpenGL.glEnable(OpenGL.GL_BLEND);
                    OpenGL.glBegin(OpenGL.GL_QUADS);
                }

                RectD conBounds = new RectD(
                    nBounds.Left + nBounds.Width * 0.01f,
                    nBounds.Top + nBounds.Height * 0.03f,
                    nBounds.Right - nBounds.Width * 0.01f,
                    nBounds.Bottom - nBounds.Height * 0.01f);

                for (int i = 0, c = n.Children.Count; i != c; ++i)
                {
                    TreemapNode cn = n.Children[i];

                    RectD cBounds = new RectD(
                        cn.Bounds.Left * conBounds.Width + conBounds.Left,
                        cn.Bounds.Top * conBounds.Height + conBounds.Top,
                        cn.Bounds.Right * conBounds.Width + conBounds.Left,
                        cn.Bounds.Bottom * conBounds.Height + conBounds.Top);

                    if (cBounds.Width > pxX * 5)
                    {
                        cBounds.Left  += pxX * m_pxNodeMargin;
                        cBounds.Right -= pxX * m_pxNodeMargin;
                    }

                    if (cBounds.Height > pxY * 5)
                    {
                        cBounds.Top    += pxY * m_pxNodeMargin;
                        cBounds.Bottom -= pxY * m_pxNodeMargin;
                    }

                    FillNode(cn, cBounds, vBounds, pxX, pxY, depth + 1);
                }
            }
        }
Пример #55
0
 private void openGLControl1_OpenGLInitialized(object sender, EventArgs e)
 {
     OpenGL gl = openGLControl1.OpenGL;
     gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
 }
Пример #56
0
 public SSBObject()
 {
     Device = GraphicsManager.Instance.Device;
 }
Пример #57
0
 public SceneInfo_Secondary(OpenGL _gl, DataForDraw_angled _Data) : base(_gl)
 {
     Data = _Data;
 }
Пример #58
0
        //vẽ hình
        static void Repaint(Point pStart, Point pEnd, int Shape, int Size, Scolor Color, bool checkClickDown, ref Sgraph temp, ref OpenGL gl)
        {
            double Rx, Ry;
            Point  pTemp = new Point();

            gl.Color(Color.R / 255.0, Color.G / 255.0, Color.B / 255.0, 0);
            gl.LineWidth(Size);
            switch (Shape)
            {
            case 0:                        //vẽ đoạn thẳng

                gl.Begin(OpenGL.GL_LINES); // chọn chế độ vẽ đường thẳng
                gl.Vertex(pStart.X, gl.RenderContextProvider.Height - pStart.Y);
                gl.Vertex(pEnd.X, gl.RenderContextProvider.Height - pEnd.Y);

                gl.End();
                gl.Flush();    // Thực hiện lệnh vẽ ngay lập tức thay vì đợi sau 1 khoảng thời gian



                break;

            case 1:    //vẽ hình tròn
                double thetar;
                Rx = Math.Sqrt(Math.Pow(pStart.X - pEnd.X, 2) + Math.Pow(pStart.Y - pEnd.Y, 2));
                gl.Begin(OpenGL.GL_LINE_LOOP);
                for (int i = 0; i < 360; i++)
                {
                    thetar = i * Math.PI / 180;
                    gl.Vertex(pStart.X + Rx * Math.Cos(thetar), gl.RenderContextProvider.Height - pStart.Y + Rx * Math.Sin(thetar));
                }
                gl.End();
                gl.Flush();    // Thực hiện lệnh vẽ ngay lập tức thay vì đợi sau 1 khoảng thời gian
                break;

            case 2:    //ve hình chữ nhật

                gl.Begin(OpenGL.GL_LINE_LOOP);
                gl.Vertex(pStart.X, gl.RenderContextProvider.Height - pStart.Y);
                gl.Vertex(pStart.X, gl.RenderContextProvider.Height - pEnd.Y);
                gl.Vertex(pEnd.X, gl.RenderContextProvider.Height - pEnd.Y);
                gl.Vertex(pEnd.X, gl.RenderContextProvider.Height - pStart.Y);

                gl.End();
                gl.Flush();    // Thực hiện lệnh vẽ ngay lập tức thay vì đợi sau 1 khoảng thời gian
                if (checkClickDown == false)
                {
                    temp.List_Graph_Point.Clear();
                    temp.List_Graph_Point.Add(pStart);
                    pTemp.X = pStart.X;
                    pTemp.Y = pEnd.Y;
                    temp.List_Graph_Point.Add(pTemp);
                    temp.List_Graph_Point.Add(pEnd);
                    pTemp.X = pEnd.X;
                    pTemp.Y = pStart.Y;
                    temp.List_Graph_Point.Add(pTemp);
                }
                break;

            case 3:    //ve elip
                Rx = Math.Sqrt(Math.Pow(pStart.X - pEnd.X, 2));
                Ry = Math.Sqrt(Math.Pow(pStart.Y - pEnd.Y, 2));
                double x, y;

                gl.Begin(OpenGL.GL_LINE_LOOP);
                for (int i = 0; i < 360; i++)
                {
                    thetar = i * Math.PI / 180;
                    x      = pStart.X + Rx * Math.Cos(thetar);
                    y      = gl.RenderContextProvider.Height - pStart.Y + Ry * Math.Sin(thetar);
                    gl.Vertex(x, y);
                }
                gl.End();
                gl.Flush();    // Thực hiện lệnh vẽ ngay lập tức thay vì đợi sau 1 khoảng thời gian
                break;

            case 4:    //ve tam giac deu

                Rx = Math.Sqrt(Math.Pow(pStart.X - pEnd.X, 2) + Math.Pow(pStart.Y - pEnd.Y, 2));

                gl.Begin(OpenGL.GL_LINE_LOOP);

                for (int i = 0; i < 360; i += 120)
                {
                    {
                        thetar = i * Math.PI / 180;
                        gl.Vertex(pStart.X + Rx * Math.Cos(thetar - Math.PI / 2), gl.RenderContextProvider.Height - pStart.Y - Rx * Math.Sin(thetar - Math.PI / 2));
                    }
                }
                gl.End();
                gl.Flush();    // Thực hiện lệnh vẽ ngay lập tức thay vì đợi sau 1 khoảng thời gian
                if (checkClickDown == false)
                {
                    temp.List_Graph_Point.Clear();
                    for (int i = 0; i < 360; i += 120)
                    {
                        {
                            thetar  = i * Math.PI / 180;
                            pTemp.X = (int)(pStart.X + Rx * Math.Cos(thetar - Math.PI / 2));
                            pTemp.Y = (int)(pStart.Y + Rx * Math.Sin(thetar - Math.PI / 2));
                            temp.List_Graph_Point.Add(pTemp);
                        }
                    }
                }
                break;

            case 5:    //ve ngu giac deu

                Rx = Math.Sqrt(Math.Pow(pStart.X - pEnd.X, 2) + Math.Pow(pStart.Y - pEnd.Y, 2));

                gl.Begin(OpenGL.GL_LINE_LOOP);
                for (int i = 0; i < 360; i += 72)
                {
                    //if (i % 72 == 0)
                    {
                        thetar = i * Math.PI / 180;
                        gl.Vertex(pStart.X + Rx * Math.Cos(thetar + Math.PI / 2), gl.RenderContextProvider.Height - pStart.Y + Rx * Math.Sin(thetar + Math.PI / 2));
                    }
                }
                gl.End();
                gl.Flush();    // Thực hiện lệnh vẽ ngay lập tức thay vì đợi sau 1 khoảng thời gian
                if (checkClickDown == false)
                {
                    temp.List_Graph_Point.Clear();
                    for (int i = 0; i < 360; i += 72)
                    {
                        {
                            thetar  = i * Math.PI / 180;
                            pTemp.X = (int)(pStart.X + Rx * Math.Cos(thetar + Math.PI / 2));
                            pTemp.Y = (int)(pStart.Y - Rx * Math.Sin(thetar + Math.PI / 2));
                            temp.List_Graph_Point.Add(pTemp);
                        }
                    }
                }
                break;

            case 6:    //ve luc giac deu
                Rx = Math.Sqrt(Math.Pow(pStart.X - pEnd.X, 2) + Math.Pow(pStart.Y - pEnd.Y, 2));

                gl.Begin(OpenGL.GL_LINE_LOOP);
                for (int i = 1; i < 360; i++)
                {
                    if (i % 30 == 0 && i % 60 != 0)
                    {
                        thetar = i * Math.PI / 180;
                        gl.Vertex(pStart.X + Rx * Math.Cos(thetar + Math.PI / 2), gl.RenderContextProvider.Height - pStart.Y + Rx * Math.Sin(thetar + Math.PI / 2));
                    }
                }
                gl.End();
                gl.Flush();    // Thực hiện lệnh vẽ ngay lập tức thay vì đợi sau 1 khoảng thời gian
                if (checkClickDown == false)
                {
                    temp.List_Graph_Point.Clear();
                    for (int i = 0; i < 360; i++)
                    {
                        if (i % 30 == 0 && i % 60 != 0)
                        {
                            thetar  = i * Math.PI / 180;
                            pTemp.X = (int)(pStart.X + Rx * Math.Cos(thetar + Math.PI / 2));
                            pTemp.Y = (int)(pStart.Y - Rx * Math.Sin(thetar + Math.PI / 2));
                            temp.List_Graph_Point.Add(pTemp);
                        }
                    }
                }
                break;
            }
        }
Пример #59
0
 public override void CreateInContext(OpenGL gl)
 {
     ShaderObject         = gl.CreateShader(0x8DD9);
     CurrentOpenGLContext = gl;
 }
Пример #60
0
        private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs e)
        {
            UpdateLabelInfo();

            //  Get the OpenGL object, just to clean up the code.
            OpenGL gl = this.openGLControl1.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
            gl.LoadIdentity();                                                 // Reset The View

            // gl.Color(1.0f, 1.0f, 1.0f);
            // gl.FontBitmaps.DrawText(gl, 0, 0, "Arial", "Argh");
            var width  = this.openGLControl1.Width;
            var height = this.openGLControl1.Height;

            //gl.Ortho(-width / 2, width / 2, -height / 2, height / 2, -100, 100);
            //gl.LookAt()


            gl.Translate(-1.5f, 0.0f, -6.0f);           // Move Left And Into The Screen

            gl.Rotate(rtri, 0.0f, 1.0f, 0.0f);          // Rotate The Pyramid On It's Y Axis

            gl.Begin(OpenGL.GL_TRIANGLES);              // Start Drawing The Pyramid

            gl.Color(1.0f, 0.0f, 0.0f);                 // Red
            gl.Vertex(0.0f, 1.0f, 0.0f);                // Top Of Triangle (Front)
            gl.Color(0.0f, 1.0f, 0.0f);                 // Green
            gl.Vertex(-1.0f, -1.0f, 1.0f);              // Left Of Triangle (Front)
            gl.Color(0.0f, 0.0f, 1.0f);                 // Blue
            gl.Vertex(1.0f, -1.0f, 1.0f);               // Right Of Triangle (Front)

            gl.Color(1.0f, 0.0f, 0.0f);                 // Red
            gl.Vertex(0.0f, 1.0f, 0.0f);                // Top Of Triangle (Right)
            gl.Color(0.0f, 0.0f, 1.0f);                 // Blue
            gl.Vertex(1.0f, -1.0f, 1.0f);               // Left Of Triangle (Right)
            gl.Color(0.0f, 1.0f, 0.0f);                 // Green
            gl.Vertex(1.0f, -1.0f, -1.0f);              // Right Of Triangle (Right)

            gl.Color(1.0f, 0.0f, 0.0f);                 // Red
            gl.Vertex(0.0f, 1.0f, 0.0f);                // Top Of Triangle (Back)
            gl.Color(0.0f, 1.0f, 0.0f);                 // Green
            gl.Vertex(1.0f, -1.0f, -1.0f);              // Left Of Triangle (Back)
            gl.Color(0.0f, 0.0f, 1.0f);                 // Blue
            gl.Vertex(-1.0f, -1.0f, -1.0f);             // Right Of Triangle (Back)

            gl.Color(1.0f, 0.0f, 0.0f);                 // Red
            gl.Vertex(0.0f, 1.0f, 0.0f);                // Top Of Triangle (Left)
            gl.Color(0.0f, 0.0f, 1.0f);                 // Blue
            gl.Vertex(-1.0f, -1.0f, -1.0f);             // Left Of Triangle (Left)
            gl.Color(0.0f, 1.0f, 0.0f);                 // Green
            gl.Vertex(-1.0f, -1.0f, 1.0f);              // Right Of Triangle (Left)
            gl.End();                                   // Done Drawing The Pyramid

            gl.LoadIdentity();
            gl.Translate(1.5f, 0.0f, -7.0f);            // Move Right And Into The Screen

            gl.Rotate(rquad, 1.0f, 1.0f, 1.0f);         // Rotate The Cube On X, Y & Z

            gl.Begin(OpenGL.GL_QUADS);                  // Start Drawing The Cube

            gl.Color(0.0f, 1.0f, 0.0f);                 // Set The Color To Green
            gl.Vertex(1.0f, 1.0f, -1.0f);               // Top Right Of The Quad (Top)
            gl.Vertex(-1.0f, 1.0f, -1.0f);              // Top Left Of The Quad (Top)
            gl.Vertex(-1.0f, 1.0f, 1.0f);               // Bottom Left Of The Quad (Top)
            gl.Vertex(1.0f, 1.0f, 1.0f);                // Bottom Right Of The Quad (Top)


            gl.Color(1.0f, 0.5f, 0.0f);                 // Set The Color To Orange
            gl.Vertex(1.0f, -1.0f, 1.0f);               // Top Right Of The Quad (Bottom)
            gl.Vertex(-1.0f, -1.0f, 1.0f);              // Top Left Of The Quad (Bottom)
            gl.Vertex(-1.0f, -1.0f, -1.0f);             // Bottom Left Of The Quad (Bottom)
            gl.Vertex(1.0f, -1.0f, -1.0f);              // Bottom Right Of The Quad (Bottom)

            gl.Color(1.0f, 0.0f, 0.0f);                 // Set The Color To Red
            gl.Vertex(1.0f, 1.0f, 1.0f);                // Top Right Of The Quad (Front)
            gl.Vertex(-1.0f, 1.0f, 1.0f);               // Top Left Of The Quad (Front)
            gl.Vertex(-1.0f, -1.0f, 1.0f);              // Bottom Left Of The Quad (Front)
            gl.Vertex(1.0f, -1.0f, 1.0f);               // Bottom Right Of The Quad (Front)

            gl.Color(1.0f, 1.0f, 0.0f);                 // Set The Color To Yellow
            gl.Vertex(1.0f, -1.0f, -1.0f);              // Bottom Left Of The Quad (Back)
            gl.Vertex(-1.0f, -1.0f, -1.0f);             // Bottom Right Of The Quad (Back)
            gl.Vertex(-1.0f, 1.0f, -1.0f);              // Top Right Of The Quad (Back)
            gl.Vertex(1.0f, 1.0f, -1.0f);               // Top Left Of The Quad (Back)

            gl.Color(0.0f, 0.0f, 1.0f);                 // Set The Color To Blue
            gl.Vertex(-1.0f, 1.0f, 1.0f);               // Top Right Of The Quad (Left)
            gl.Vertex(-1.0f, 1.0f, -1.0f);              // Top Left Of The Quad (Left)
            gl.Vertex(-1.0f, -1.0f, -1.0f);             // Bottom Left Of The Quad (Left)
            gl.Vertex(-1.0f, -1.0f, 1.0f);              // Bottom Right Of The Quad (Left)

            gl.Color(1.0f, 0.0f, 1.0f);                 // Set The Color To Violet
            gl.Vertex(1.0f, 1.0f, -1.0f);               // Top Right Of The Quad (Right)
            gl.Vertex(1.0f, 1.0f, 1.0f);                // Top Left Of The Quad (Right)
            gl.Vertex(1.0f, -1.0f, 1.0f);               // Bottom Left Of The Quad (Right)
            gl.Vertex(1.0f, -1.0f, -1.0f);              // Bottom Right Of The Quad (Right)
            gl.End();                                   // Done Drawing The Q

            gl.Flush();

            rtri  += 3.0f; // 0.2f;						// Increase The Rotation Variable For The Triangle
            rquad -= 3.0f; // 0.15f;						// Decrease The Rotation Variable For The Quad
        }