示例#1
0
        public static void Init(IntPtr hwnd)
        {
            var dc = GetDC(hwnd);

            DC = dc;
            var pfd = new PixelFormatDescriptor(null);
            var pfn = ChoosePixelFormat(dc, ref pfd);

            DescribePixelFormat(dc, pfn, (short)Marshal.SizeOf(typeof(PixelFormatDescriptor)), ref pfd);
            SetPixelFormat(dc, pfn, ref pfd);
            GLContext = CreateContext(dc);
            MakeCurrent(dc, GLContext);
            GenVertexArray =
                (glGenVertexArray)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glGenVertexArrays"), typeof(glGenVertexArray));
            BindVertexArray =
                (glBindVertexArray)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glBindVertexArray"), typeof(glBindVertexArray));
            GenBuffer =
                (glGenBuffers)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glGenBuffers"), typeof(glGenBuffers));
            BindBuffer =
                (glBindBuffer)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glBindBuffer"), typeof(glBindBuffer));
            BufferData =
                (glBufferData)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glBufferData"), typeof(glBufferData));
            VertexAttribPointer =
                (glVertexAttribPointer)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glVertexAttribPointer"),
                                                      typeof(glVertexAttribPointer));
            EnableVertexAttribArray =
                (glEnableVertexAttribArray)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glEnableVertexAttribArray"),
                                                      typeof(glEnableVertexAttribArray));
            UniformMatrix4 =
                (glUniformMatrix4fv)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glUniformMatrix4fv"),
                                                      typeof(glUniformMatrix4fv));
            CreateShader =
                (glCreateShader)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glCreateShader"), typeof(glCreateShader));
            CreateProgram =
                (glCreateProgram)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glCreateProgram"), typeof(glCreateProgram));
            CompileShader =
                (glPassShader)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glCompileShader"), typeof(glPassShader));
            DeleteShader =
                (glPassShader)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glDeleteShader"), typeof(glPassShader));
            LinkProgram =
                (glPassShader)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glLinkProgram"), typeof(glPassShader));
            UseProgram =
                (glPassShader)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glUseProgram"), typeof(glPassShader));
            DeleteProgram =
                (glPassShader)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glDeleteProgram"), typeof(glPassShader));
            ShaderSource =
                (glShaderSource)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glShaderSource"), typeof(glShaderSource));
            AttachShader =
                (glAttachShader)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glAttachShader"), typeof(glAttachShader));
            DetachShader =
                (glAttachShader)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glDetachShader"), typeof(glAttachShader));
            GetUniformLocation =
                (glGetUniformLocation)
                Marshal.GetDelegateForFunctionPointer(wglGetProcAddress("glGetUniformLocation"),
                                                      typeof(glGetUniformLocation));
        }
示例#2
0
 private static extern bool SetPixelFormat(IntPtr dc, int format, ref PixelFormatDescriptor pfd);
示例#3
0
 private static extern int ChoosePixelFormat(IntPtr dc, ref PixelFormatDescriptor pfd);
示例#4
0
 private static extern int DescribePixelFormat(IntPtr deviceContext, int pixel, int pfdSize,
                                               ref PixelFormatDescriptor pixelFormat);