예제 #1
6
        /// <summary>
        /// Handles the OpenGLDraw event of the openGLControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RenderEventArgs"/> instance containing the event data.</param>
        public void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
        {
            //  Get the OpenGL object.
            gl = openGLControl.OpenGL;

            //  Clear the color and depth buffer.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            //  Load the identity matrix.
            gl.LoadIdentity();

            //  Rotate around the Y axis.
            //gl.Rotate(rotation, 0.0f, 1.0f, 0.0f);
            cord = ComInput.Coordinates.Instance;
            this.ModelRotater(gl);

            gl.Enable(OpenGL.GL_BLEND);
            gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);

            //  Draw a coloured parallelepiped.
            gl.Begin(OpenGL.GL_QUADS);

            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(-2.0f, -0.25f, -1.0f);

            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(2.0f, -0.25f, -1.0f);

            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(2.0f, 0.25f, -1.0f);

            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(-2.0f, 0.25f, -1.0f);
            //-------------------------------------
            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(-2.0f, -0.25f, -1.0f);

            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(-2.0f, -0.25f, 1.0f);

            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(-2.0f, 0.25f, 1.0f);

            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(-2.0f, 0.25f, -1.0f);
            //-------------------------------------
            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(-2.0f, -0.25f, 1.0f);

            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(2.0f, -0.25f, 1.0f);

            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(2.0f, 0.25f, 1.0f);

            gl.Color(0.0f, 1.0f, 0.0f);
            gl.Vertex(-2.0f, 0.25f, 1.0f);
            //-------------------------------------
            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(2.0f, -0.25f, 1.0f);

            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(2.0f, -0.25f, -1.0f);

            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(2.0f, 0.25f, -1.0f);

            gl.Color(1.0f, 0.0f, 0.0f);
            gl.Vertex(2.0f, 0.25f, 1.0f);
            //-------------------------------------
            gl.Color(0.0f, 1.0f, 1.0f);
            gl.Vertex(-2.0f, 0.25f, -1.0f);

            gl.Color(0.0f, 1.0f, 1.0f);
            gl.Vertex(2.0f, 0.25f, -1.0f);

            gl.Color(0.0f, 1.0f, 1.0f);
            gl.Vertex(2.0f, 0.25f, 1.0f);

            gl.Color(0.0f, 1.0f, 1.0f);
            gl.Vertex(-2.0f, 0.25f, 1.0f);
            //--------------------------------------
            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Vertex(-2.0f, -0.25f, -1.0f);

            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Vertex(2.0f, -0.25f, -1.0f);

            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Vertex(2.0f, -0.25f, 1.0f);

            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Vertex(-2.0f, -0.25f, 1.0f);

            gl.End();

            //-------------------Angle indicator prototype is here----------------------------------------------
            gl.LoadIdentity();

            gl.Rotate(cord.getX(), 1.0f, 0.0f, 0.0f);

            gl.Begin(OpenGL.GL_TRIANGLES);

            gl.Vertex(0.0f, 2.75f, 0.0f);
            gl.Vertex(0.25f, 3.25f, 0.0f);
            gl.Vertex(-0.25f, 3.25f, 0.0f);

            gl.End();

            gl.LoadIdentity();

            gl.Rotate(cord.getZ(), 0.0f, 1.0f, 0.0f);

            gl.Begin(OpenGL.GL_TRIANGLES);

            gl.Vertex(0.0f, 0.0f, 2.75f);
            gl.Vertex(0.0f, 0.25f, 3.25f);
            gl.Vertex(0.0f, -0.25f, 3.25f);

            gl.End();

            gl.LoadIdentity();

            gl.Rotate(cord.getY(), 0.0f, 0.0f, 1.0f);

            gl.Begin(OpenGL.GL_TRIANGLES);

            gl.Vertex(2.75f, 0.0f, 0.0f);
            gl.Vertex(3.25f, 0.0f, 0.25f);
            gl.Vertex(3.25f, 0.0f, -0.25f);

            gl.End();

            //------------------Circles of planes is here-----------------------------------------------

            gl.LoadIdentity();

            gl.Begin(OpenGL.GL_LINE_LOOP);
            for(int i = 0; i < 200; i++)
            {
                float theta = 2.0f * 3.1415926f * (float)i / 200f;//get the current angle

                float x = 3f * (float)System.Math.Cos(theta);//calculate the x component
                float y = 3f * (float)System.Math.Sin(theta);//calculate the y component

                gl.Color(0.0f, 1.0f, 0.0f);
                gl.Vertex(0f, y + 0.0f, x + 0.0f);//output vertex

            }
            gl.End();

            gl.Begin(OpenGL.GL_LINE_LOOP);
            for (int i = 0; i < 200; i++)
            {
                float theta = 2.0f * 3.1415926f * (float)i / 200f;//get the current angle

                float x = 3f * (float)System.Math.Cos(theta);//calculate the x component
                float y = 3f * (float)System.Math.Sin(theta);//calculate the y component

                gl.Vertex(x + 0.0f, 0.0f, y + 0.0f);//output vertex

            }
            gl.End();

            gl.Begin(OpenGL.GL_LINE_LOOP);
            for (int i = 0; i < 200; i++)
            {
                float theta = 2.0f * 3.1415926f * (float)i / 200f;//get the current angle

                float x = 3f * (float)System.Math.Cos(theta);//calculate the x component
                float y = 3f * (float)System.Math.Sin(theta);//calculate the y component

                gl.Vertex(x + 0.0f, y + 0.0f, 0.0f);//output vertex

            }
            gl.End();

            /* //--------------Coordinate axis's is here--------------------------------------------

            gl.LoadIdentity();

            gl.Begin(OpenGL.GL_LINE_STRIP);

            gl.Color(1.0f, 1.0f, 1.0f);

            gl.Vertex(-4.0f, 0.5f, 1.5f);
            gl.Vertex(2.5f, 0.5f, 1.5f);
            gl.Vertex(2.5f, 0.5f, -4.5f);
            gl.Vertex(2.5f, 0.5f, 1.5f);
            gl.Vertex(2.5f, 4.0f, 1.5f);

            gl.End();

            */ //------------Shpere is here-----------------------------

            gl.LoadIdentity();

            gl.Color(0.85f, 0.85f, 0.85f, 0.5f);

            gl.Begin(OpenGL.GL_QUADS);
            for (int i = 0; i < 1; i++)
            {
                this.draw_sphere(gl, 3);
            }
            gl.End();

            //---------------3D Text prototype is here-------------------

            gl.LoadIdentity();

            gl.Translate(0.0f, 3.5f, -3.0f);

            gl.Color(0.0f, 1.0f, 0.65f);

            gl.Rotate(270.0f, 0.0f, 1.0f, 0.0f);

            gl.DrawText3D("a", 0.2f,
                1.0f, 0.1f, "osX: 0");

            //  Nudge the rotation.
            rotation += 2.0f;
        }
예제 #2
0
        public void DrawGrid(OpenGL gl, int camX,int camY)
        {
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();

            int MapHeight = tileMap.mapHeight;
            int MapWidth = tileMap.mapWidth;

            float[] darkColor = { 0.2f, 0.2f, 0.2f };
            float[] lightColor = { 0.25f, 0.25f, 0.25f };
            for (int h = 0; h < MapHeight; h++)
            {
                if (h % 10 == 0)
                {
                    gl.LineWidth(2.0f);
                    gl.Color(lightColor);
                }
                else
                {
                    gl.LineWidth(1.0f);
                    gl.Color(darkColor);
                }
                if (h == 0)
                {
                    gl.LineWidth(4.0f);
                    gl.Color(lightColor);
                }
                gl.Begin(OpenGL.GL_LINES);							// Start Drawing Verticle Cell Borders
                gl.Vertex(0 - camX, h * tileSize - camY, 0);// Left Side Of Horizontal Line
                gl.Vertex((MapWidth * tileSize) - camX, (h * tileSize) - camY, 0);// Right Side Of Horizontal Line
                gl.End();
            }
            for (int v = 0; v < MapWidth; v++)
            {
                if (v % 10 == 0)
                {
                    gl.LineWidth(2.0f);
                    gl.Color(lightColor);
                }
                else
                {
                    gl.LineWidth(1.0f);
                    gl.Color(darkColor);
                }
                if (v == 0)
                {
                    gl.LineWidth(4.0f);
                    gl.Color(lightColor);
                }
                gl.Begin(OpenGL.GL_LINES);							// Start Drawing Verticle Cell Borders
                gl.Vertex(v * tileSize - camX, 0 - camY, 0);// Left Side Of Horizontal Line
                gl.Vertex((v * tileSize) - camX, (MapHeight * tileSize) - camY, 0);// Right Side Of Horizontal Line
                gl.End();
            }
        }
예제 #3
0
파일: Scene.cs 프로젝트: hhool/sharpgl
        /// <summary>
        /// Draws the scene.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        public void Draw(OpenGL gl)
        {
            //  Clear the scene.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);

            //  Bind the shader, set the matrices.
            shaderProgram.Bind(gl);
            shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array());

            //  Bind the out vertex array.
            vertexBufferArray.Bind(gl);

            //  Draw the square.
            gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 6); 

            //  Unbind our vertex array and shader.
            vertexBufferArray.Unbind(gl);
            shaderProgram.Unbind(gl);
        }
예제 #4
0
        private void SampleRendering(OpenGL gl, float rX, float rY, float rZ)
        {
            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.Translate(-1.5f, 0.0f, -6.0f);				// Move Left And Into The Screen

            gl.Rotate(rtri, rX, rY, rZ);				// 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, rX, rY, rZ);			// 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 += 1.0f;// 0.2f;						// Increase The Rotation Variable For The Triangle 
            rquad -= 1.0f;// 0.15f;						// Decrease The Rotation Variable For The Quad 
        }
예제 #5
0
        private void runGlThread(object args)
        {
            var inputs = (Tuple<CancellationToken>) args;

            var cancelToken = inputs.Item1;
            var gl = new OpenGL();

            int localRenderWidth = 1;
            int localRenderHeight = 1;
            if (!createRenderContext(gl, localRenderWidth, localRenderHeight))
            {
            //TODO better error handling here
            Console.WriteLine("*** Unable to create OpenGL Render Context");
            return;
            }

            uint activeVaoHandle;
            uint activeGlProgramHandle;
            initGLObjects(gl, out activeVaoHandle, out activeGlProgramHandle);

            ActiveProgramValues localActiveProgramValues = null;
            while (!cancelToken.IsCancellationRequested)
            {
            bool resizeRenderContext;
            lock (this)
            {
                if (!ReferenceEquals(localActiveProgramValues, activeProgramValues))
                {
                    localActiveProgramValues = activeProgramValues;
                    if (localActiveProgramValues.Valid)
                    {
                        linkProgram(gl, localActiveProgramValues, activeGlProgramHandle);
                    } else
                    {
                        // Leave the old program running. This prevents the user from seeing
                        // a black screen while they are in the process of modifying a shader.
                    }
                }

                resizeRenderContext = localRenderWidth != renderWidth || localRenderHeight != renderHeight;
                localRenderWidth = renderWidth;
                localRenderHeight = renderHeight;
            }

            if (resizeRenderContext)
            {
                localActiveProgramValues = null;
                deleteGlObjects(gl, activeVaoHandle, activeGlProgramHandle);
                if (!createRenderContext(gl, localRenderWidth, localRenderHeight))
                {
            //TODO better error handling here
                    Console.WriteLine("*** Unable to resize OpenGL Render Context");
                    return;
                }
                initGLObjects(gl, out activeVaoHandle, out activeGlProgramHandle);
            }

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT);
            gl.BindVertexArray(activeVaoHandle);
            gl.UseProgram(activeGlProgramHandle);
            gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 3);

            // do some other stuff while the image is rendering, to give it a chance to finish
            ShaderCompiler.ValidateShaders(gl);

            var provider = gl.RenderContextProvider as FBORenderContextProvider;
            Debug.Assert(provider != null, "Render context provider is not an FBO renderer");
            //TODO this call to blit will probably block. Find a better way to copy the image to CPU memory.
            gl.Blit(IntPtr.Zero);
            var hBitmap = provider.InternalDIBSection.HBitmap;

            if (hBitmap != IntPtr.Zero)
            {
                var bitmap = GetFormattedBitmapSource(hBitmap);
                // the bitmap needs to be frozen in order to share it between threads
                bitmap.Freeze();
                ImageRendered(bitmap);
            }
            }

            deleteGlObjects(gl, activeVaoHandle, activeGlProgramHandle);
        }
예제 #6
0
        public override void Draw(ref OpenGL gl)
        {
            if (!TexturesInitialised)
            {
                InitializeTexture(ref gl);
            }
            //  Clear the color and depth buffer.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            //  Load the identity matrix.
            gl.LoadIdentity();
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            gl.Enable(OpenGL.GL_LIGHTING);
            gl.Enable(OpenGL.GL_LIGHT0);
            gl.Enable(OpenGL.GL_DEPTH_TEST);
            gl.Enable(OpenGL.GL_NORMALIZE);
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, gtexture[0]);
            gl.Color(1.0f, 1.0f, 1.0f, 0.1f);

            gl.Begin(OpenGL.GL_QUADS);
            gl.FrontFace(OpenGL.GL_FRONT_FACE);

            gl.TexCoord(1.0f, 1.0f);
            gl.Vertex(gImage1.Width, gImage1.Height, 1.0f);
            gl.TexCoord(0.0f, 1.0f);
            gl.Vertex(0.0f, gImage1.Height, 1.0f);
            gl.TexCoord(0.0f, 0.0f);
            gl.Vertex(0.0f, 0.0f, 1.0f);
            gl.TexCoord(1.0f, 0.0f);
            gl.Vertex(gImage1.Width, 0.0f, 1.0f);
            gl.End();

            gl.Disable(OpenGL.GL_TEXTURE_2D);

            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.LoadIdentity();
            gl.Ortho(0.0, (double)gImage1.Width, (double)gImage1.Height, 0.0, -1.0, 1.0);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.Disable(OpenGL.GL_DEPTH_TEST);
        }
예제 #7
0
 public override void OnRender(OpenGL gl)
 {
     gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
     gl.ClearColor(0.137f, 0.121f, 0.125f, 0f);
     _graph.Render();
 }
예제 #8
0
        public void RenderObjects(OpenGL gl, GameObject[] objects)
        {
            //clears the screen
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            //St matrix mode to PROJECTION so we can move the camera
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            //  Load the identity matrix.
            gl.LoadIdentity();
            //Move the camera
            CamController.SetCam(gl);
            //Set matrix mode back to Modelview so we can draw objects
            gl.MatrixMode(OpenGL.GL_MODELVIEW);

            if (_mode == RenderMode.WireFrame || _mode == RenderMode.Hitboxes)
            {
                foreach(GameObject obj in objects){
                    //Draw the object with texture
                    obj.Draw(gl);
                    //Unbind texture so we can draw lines
                    gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
                    if ( _mode == RenderMode.Hitboxes)
                    {
                        obj.DrawVelocity(gl);
                        DrawCircle(gl, obj.GetPosition().x,obj.GetPosition().y, obj.GetPhysSize());
                    }
                    else
                    {
                        obj.DrawWireFrame(gl);
                    }
                }
            }
            else
            {
                foreach ( GameObject obj in objects )
                {
                    //Draw the object with texture
                    obj.Draw(gl);
                }
            }
            //Unbind texture
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
        }
예제 #9
0
 private void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
 {
     _gl = openGLControl.OpenGL;
     _gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
     _gl.LoadIdentity();
     _gl.LookAt(0, 0, _w, 0, 0, 0, 0, 1, 0); //-10, 10, _w, 0, 0, 0, 0, 1, 0
     _gl.Rotate((float)_rotX, (float)_rotY, (float)_rotZ);
     _gl.Translate(_transX, _transY, _transZ);
     foreach (Polygon polygon in _polygons)
         {
             if (!polygon.IsEnabled) continue;
             polygon.PushObjectSpace(_gl);
             polygon.Render(_gl, SharpGL.SceneGraph.Core.RenderMode.Render);
             polygon.PopObjectSpace(_gl);
         }
 }
예제 #10
0
        public override void OnRender(OpenGL gl)
        {
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.ClearColor(0.137f, 0.121f, 0.125f, 0f);

            _graph.Render();

            gl.Disable(OpenGL.GL_DEPTH_TEST);
            using (new Bind(_shader))
            {
                gl.UniformMatrix4(_modelUniform, 1, false, Mat4.Identity.ToColumnMajorArray());

                gl.PointSize(10f);
                gl.Begin(BeginMode.Points);
                gl.Vertex(6, 0);
                gl.End();
            }

            gl.PointSize(5f);

            _points.Render();
            gl.Enable(OpenGL.GL_DEPTH_TEST);
        }
예제 #11
0
 //新建画布
 public void Clear()
 {
     gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
 }
예제 #12
0
파일: Game.xaml.cs 프로젝트: royb3/pong
        private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            OpenGL gl = new OpenGL();

            ballX -= balMovX;
            ballY -= balMovY;
            if (Convert.ToInt32(ballX) == -gameSizeX)
            {
                balMovX = -0.08f;
            }
            else if (Convert.ToInt32(ballX) == gameSizeX)
            {
                balMovX = 0.08f;
            }
            if (Convert.ToInt32(ballY) == -gameSizeY)
            {
                balMovY = -0.03f;
            }
            else if (Convert.ToInt32(ballY) == gameSizeY)
            {
                balMovY = 0.03f;
            }

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();
            gl.Translate(gameX, gameY, gameZ);
            gameRect(gl);

            Ball(gl);
            Bed(gl,bed1X, bed1Y, bed1Z, 0.2f, 1.8f);
            Bed(gl,bed2X, bed2Y, bed2Z, 0.2f, 1.8f);

            gl.Flush();
        }