Пример #1
0
        private void glControl1_Paint(object sender, PaintEventArgs e)
        {
            // Do standard clearing
            GL.ClearColor(Color.Turquoise);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // Don't do anything else if there is no map loaded
            if (loadedMap == null)
            {
                glControl1.SwapBuffers();
                return;
            }

            // Get uniform locations
            int modelLocation      = shaderProgram.GetUniformLocation("model");
            int viewLocation       = shaderProgram.GetUniformLocation("view");
            int projectionLocation = shaderProgram.GetUniformLocation("projection");
            int colorLocation      = shaderProgram.GetUniformLocation("colorVec");

            // Set uniforms
            Matrix4 viewMatrix = camera.CalculateLookAt();

            shaderProgram.Use();
            GL.UniformMatrix4(viewLocation, false, ref viewMatrix);
            GL.UniformMatrix4(projectionLocation, false, ref projectionMatrix);

            // Render all map objects
            foreach (string k in loadedMap.mobjs.Keys.ToArray())
            {
                bool isSelectedSection = k.Equals(SelectedSectionName);
                for (int i = 0; i < loadedMap.mobjs[k].Count; i++)
                {
                    MapObject mapObject = loadedMap.mobjs[k][i];
                    RenderMapObject(mapObject, (isSelectedSection && SelectedIndex == i), modelLocation, colorLocation);
                }
            }

            // Swap buffers
            glControl1.SwapBuffers();
        }
Пример #2
0
        private void glControl1_Paint(object sender, PaintEventArgs e)
        {
            // Do standard clearing
            GL.ClearColor(Color.Turquoise);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // Don't do anything else if there is no map loaded
            if (loadedMap == null)
            {
                glControl1.SwapBuffers();
                return;
            }

            // Get uniform locations
            int modelLocation      = shaderProgram.GetUniformLocation("model");
            int viewLocation       = shaderProgram.GetUniformLocation("view");
            int projectionLocation = shaderProgram.GetUniformLocation("projection");
            int colorLocation      = shaderProgram.GetUniformLocation("colorVec");

            // Set uniforms
            Matrix4 viewMatrix = camera.ToMatrix4();

            shaderProgram.Use();
            GL.UniformMatrix4(viewLocation, false, ref viewMatrix);
            GL.UniformMatrix4(projectionLocation, false, ref projectionMatrix);

            // Render all map objects
            foreach (string k in loadedMap.mobjs.Keys.ToArray())
            {
                foreach (MapObject mapObject in loadedMap.mobjs[k])
                {
                    RenderMapObject(mapObject, modelLocation, colorLocation);
                }
            }

            // Swap buffers
            glControl1.SwapBuffers();
        }