コード例 #1
0
 /// <summary>
 /// Clear buffers
 /// </summary>
 /// <param name="buffers">Buffers to clear</param>
 /// <param name="color">Color value to set</param>
 /// <param name="depth">Depth value to set</param>
 /// <param name="stencil">Stencil value to set</param>
 /// <remarks>Color, depth and stencil will set those default values whether they are set in the buffers parameter or not.</remarks>
 public void Clear(ClearFlags buffers, Vector4 color, double depth, int stencil)
 {
     GL.glClearColor(color.x, color.y, color.z, color.w);
     GL.glClearDepth(depth);
     GL.glClearStencil(stencil);
     GL.glClear((uint)buffers);
 }
コード例 #2
0
        /// <summary>
        /// Draw buffers
        /// </summary>
        /// <param name="mode">Element type to draw</param>
        /// <param name="update_values">Specifies if Glorg should update uniforms</param>
        /// <remarks>This function uses the currently set vertex and index buffer (if any) If no index buffer is set, the function will assume that elements follows each other in the vertex buffer.</remarks>
        public void Draw(DrawMode mode, bool update_values)
        {
            bool        found_err = false;
            OpenGLError err;

            GL.glGetError();
            if (update_values)
            {
                modelview_matrix.Update();
                projection_matrix.Update();
                texture_matrix.Update();
                normal_matrix.Update();

                err = (OpenGLError)GL.glGetError();
                if (err != OpenGLError.NoError && !encountered_draw_error)
                {
                    Debugging.Debug.WriteLine("Setting standard uniforms: " + err.ToString());
                    found_err = true;
                }
                if (active_shader != null)
                {
                    foreach (var u in active_shader.uniforms)
                    {
                        u.SetValue();
                    }
                    err = (OpenGLError)GL.glGetError();
                    if (err != OpenGLError.NoError && !encountered_draw_error)
                    {
                        Debugging.Debug.WriteLine("Setting uniforms: " + err.ToString());
                        found_err = true;
                    }
                }
            }
            if (vertex_buffer == null)
            {
                throw new InvalidOperationException("No vertex buffer has been set.");
            }
            if (index_buffer != null)
            {
                GL.glDrawElements((uint)mode, index_buffer.Count, index_buffer.Type, IntPtr.Zero);
            }
            else
            {
                GL.glDrawArrays((uint)mode, 0, vertex_buffer.Count);
            }
            err = (OpenGLError)GL.glGetError();
            if (err != OpenGLError.NoError && !encountered_draw_error)
            {
                Debugging.Debug.WriteLine("Drawing: " + err.ToString());
                found_err = true;
            }
            if (found_err)
            {
                encountered_draw_error = true;
            }
        }
コード例 #3
0
        public GraphicsDevice(IntPtr target)
        {
            context = OpenGLContext.GetContext();

            context.Samples = 4;
            // Create context using platform specific methods
            context.CreateContext(target, IntPtr.Zero, null);
            //GL.InitGeneral(context);
            //foreach (var str in GL.GetSupportedExtensions())
            //Console.WriteLine(str);

            modelview_matrix  = new MatrixState();
            projection_matrix = new MatrixState();
            texture_matrix    = new MatrixState();
            normal_matrix     = new MatrixState();

            var err = GL.glGetError();

            GL.InitGL_1_2(context);
            GL.InitGL_1_3(context);
            GL.InitGL_1_4(context);
            GL.InitGL_1_5(context);
            GL.InitGL_2_0(context);
            GL.InitGL_2_1(context);
            GL.InitGL_3_0(context);
            GL.InitGL_3_1(context);
            GL.InitGL_3_2(context);
            GL.InitFramebuffers(context);
            GL.InitVertexArrayObjects(context);
            var sp = GL.GetSupportedExtensions();

            if (sp.Contains("GL_AMD_debug_output"))
            {
                GL.InitDebugOutputAMD(context);
                GL.glDebugMessageCallbackAMD(new OpenGL.OpenGL.DebugProc(DebugProcecure), IntPtr.Zero);
                GL.glDebugMessageEnableAMD(0, 0, 0, new int[] { }, GL.boolean.TRUE);
            }

            err = GL.glGetError();

            GL.glEnable(GL.Const.GL_TEXTURE_2D);

            state       = new OpenGLState(this);
            state.Blend = true;
            state.BlendFunction(Blend.SrcAlpha, Blend.OneMinusSrcAlpha);
            state.Culling   = true;
            state.DepthTest = true;
        }
コード例 #4
0
ファイル: GraphicsDevice.cs プロジェクト: r-bel/glorg2
 /// <summary>
 /// Sets a vertex buffer as the current buffer. 
 /// </summary>
 /// <param name="vert">Vertex buffer to set. Pass this as null to disable vertex buffer</param>
 public void SetVertexBuffer(OpenGL.IVertexBuffer vert)
 {
     if (vertex_buffer != null)
         vertex_buffer.MakeNonCurrent();
     if (vert != null)
     {
         // Apply shader attributes for this vertex buffer
         if(active_shader != null && active_shader is StdMaterial)
             vert.ApplyStdMaterial(active_shader as StdMaterial);
         // Bind vertex buffer
         vert.MakeCurrent();
     }
     vertex_buffer = vert;
 }
コード例 #5
0
ファイル: GraphicsDevice.cs プロジェクト: r-bel/glorg2
 /// <summary>
 /// Sets an index buffer as the current buffer
 /// </summary>
 /// <param name="indices">Index buffer to set. Pass this as null to disable index buffer</param>
 public void SetIndexBuffer(OpenGL.IIndexBuffer indices)
 {
     if (index_buffer != null)
         index_buffer.MakeNonCurrent();
     if (indices != null)
         indices.MakeCurrent();
     index_buffer = indices;
 }
コード例 #6
0
ファイル: GraphicsDevice.cs プロジェクト: r-bel/glorg2
 /// <summary>
 /// Applies a texture
 /// </summary>
 /// <param name="texture"></param>
 public void MakeCurrent(OpenGL.Texture texture, uint index)
 {
     GL.glActiveTexture(index);
     GL.glBindTexture((uint)texture.target, texture.Handle);
 }
コード例 #7
0
 /// <summary>
 /// Sets the blending function
 /// </summary>
 /// <param name="sfactor">Source factor</param>
 /// <param name="dfactor">Destination factor</param>
 public void BlendFunction(Blend sfactor, Blend dfactor)
 {
     GL.glBlendFunc((uint)sfactor, (uint)dfactor);
 }
コード例 #8
0
 /// <summary>
 /// Sets polugon mode for a face
 /// </summary>
 /// <param name="face"></param>
 /// <param name="mode"></param>
 public void SetPolygonMode(CullFace face, PolygonMode mode)
 {
     GL.glPolygonMode((uint)face, (uint)mode);
 }
コード例 #9
0
 /// <summary>
 /// Clear buffers
 /// </summary>
 /// <param name="buffers">Buffers to clear</param>
 /// <param name="color">Color value to set</param>
 /// <remarks>Color will set those default values whether they are set in the buffers parameter or not.</remarks>
 public void Clear(ClearFlags buffers, Vector4 color)
 {
     GL.glClearColor(color.x, color.y, color.z, color.w);
     GL.glClear((uint)buffers);
 }
コード例 #10
0
 /// <summary>
 /// Applies a texture
 /// </summary>
 /// <param name="texture"></param>
 public void MakeCurrent(OpenGL.Texture texture, uint index)
 {
     GL.glActiveTexture(index);
     GL.glBindTexture((uint)texture.target, texture.Handle);
 }