| 本帖最后由 drzzm32 于 2014-9-19 20:37 编辑 
 
 好吧,久违的更新。。。 
 这次是说在Visual Basic .NET下用OpenGL API。(DirectX的话还在研究) 
 
 
 
 它是由麻省理工学院写的,基于.NET Framework的一个扩展框架,目的是让在.NET Framework下更容易使用OpenGL,OpenAL,PhysX,以及其他。当前最新是2.1版本。(估计也只有这个版本了) 
 不知什么问题,貌似它的Alut库以及其他部分库不全。。。(求测试) 
 
 
 The Tao Framework is a C# library giving .NET and Mono developers access to popular graphics and gaming libraries like OpenGL and SDL. It was originally developed by the C# OpenGL programmer Randy Ridge, and since its start many developers have contributed to the project. The latest version of Tao is version 2.1 released on May 1, 2008.
 Tao Framework has been superseded by OpenTK.[1]
 
 In 2012, in parallel with the development of OpenTK, a new project called TaoClassic has been introduced on SourceForge, as a direct continuation of Tao Framework, with the same licensing conditions and design disciplines, but with new authors and cutting-edge features, like support for OpenGL 4.3, 64-bit operating systems, etc.[2]
 
 
 很强大的工具,嗯。步入正题。我用的是Visual Studio 2013
 框架安装好后,新建工程,添加引用,就是安装目录下的bin里的dll,需要才加。
 安装目录下还有很多资源,自己去研究。。。
 然后需要在工具箱里选择项,添加控件,是这个文件:Tao.Platform.Windows.dll
 之后把程序做好了还要把这个文件复制到输出目录,因为默认是不复制的。
 
 
 然后是一点提示:
 对于OpenGL的控件,有些属性是无法在编辑窗口修改的,需要在代码里设置。而且有些不允许修改。
 在控件里封装的一个重要方法,InitializeContexts(),需要在程序初始化阶段调用,作为控件初始化,但是我不知道他为何不用构造函数。。。
 而且,所有绘图代码,即glBegin()到glEnd(),最好写在控件的Paint方法里,写在外面效率爆低,原因不明。
 别忘了在代码头部Imports Tao.OpenGL。。。
 
 
 然后。。。我看看网上有没有教程。。。目测只有实体书。。。(TB)
 建议看看他的范例。。。其他的话。。。我只能说这点了,我还要尝试DirectX。。。
 
 给些自己写的代码。。。慎用。。。OpenAL的,GL的根本没法移植。。。
 
 复制代码Public Class AudioGroup
            Shared Sub ALInitilize()
                Dim DeviceNum As System.IntPtr = Alc.alcOpenDevice(vbEmpty)
                Dim Context As System.IntPtr = Alc.alcCreateContext(DeviceNum, vbEmpty)
                Alc.alcMakeContextCurrent(Context)
            End Sub
            Shared Sub ALDispose()
                Dim Context As System.IntPtr = Alc.alcGetCurrentContext
                Dim Device As System.IntPtr = Alc.alcGetContextsDevice(Context)
                Alc.alcMakeContextCurrent(vbEmpty)
                Alc.alcDestroyContext(Context)
                Alc.alcCloseDevice(Device)
            End Sub
            Public Class AudioSystem
                Shared Sub SourceConfig(ByVal Type As Integer, ByVal Index As Integer, ByVal x As Single, ByVal y As Single, ByVal z As Single, _
                                         ByVal vx As Single, ByVal vy As Single, ByVal vz As Single)
                    Al.alGenSources(1, AudioSource(Type, Index))
                    Al.alSourcei(AudioSource(Type, Index), Al.AL_BUFFER, AudioBuffer(Type, Index))
                    Al.alSource3f(AudioSource(Type, Index), Al.AL_POSITION, x, y, z)
                    Al.alSource3f(AudioSource(Type, Index), Al.AL_VELOCITY, vx, vy, vz)
                    Al.alSourcei(AudioSource(Type, Index), Al.AL_LOOPING, Al.AL_TRUE)
                    Al.alSourcef(AudioSource(Type, Index), Al.AL_GAIN, 1)
                    Al.alSourcef(AudioSource(Type, Index), Al.AL_PITCH, 1)
                End Sub
                Shared Sub ListenerConfig(ByVal x As Single, ByVal y As Single, ByVal z As Single, ByVal vx As Single, ByVal vy As Single, ByVal vz As Single, _
                                          ByVal a As Single, ByVal b As Single, ByVal c As Single, ByVal d As Single, ByVal e As Single, ByVal f As Single)
                    Al.alListener3f(Al.AL_POSITION, x, y, z)
                    Al.alListener3f(Al.AL_VELOCITY, vx, vy, vz)
                    Dim Orientation() As Single = {a, b, c, d, e, f}
                    Al.alListenerfv(Al.AL_ORIENTATION, Orientation)
                End Sub
                Shared Sub AudioPlay(ByVal Type As Integer, ByVal Index As Integer)
                    Al.alSourcePlay(AudioSource(Type, Index))
                End Sub
            End Class
        End Class
 
 
 
 |