private static void _CreateAudioContext() { IntPtr d = Alc.OpenDevice(OpenTK.Audio.AudioContext.DefaultDevice); OpenTK.ContextHandle c = Alc.CreateContext(d, new int[0]); Alc.MakeContextCurrent(c); AL.Listener(ALListener3f.Position, 0, 0, 0); AL.Listener(ALListener3f.Velocity, 0, 0, 0); float[] vs = new float[] { 0, 0, -1, 0, 1, 0 }; AL.Listener(ALListenerfv.Orientation, ref vs); }
public static void CreateGLESContext() { //make open gl es current context GlfwWindowPtr currentContext = Glfw.GetCurrentContext(); _glContextHandler = new OpenTK.ContextHandle(currentContext.inner_ptr); _glfwContextForOpenTK = new GLFWContextForOpenTK(_glContextHandler); _externalContext = OpenTK.Graphics.GraphicsContext.CreateExternalContext(_glfwContextForOpenTK); //glfwContext = OpenTK.Graphics.GraphicsContext.CreateDummyContext(contextHandler); bool isCurrent = _glfwContextForOpenTK.IsCurrent; }
public static void Init() { _device = Alc.OpenDevice(null); _context = Alc.CreateContext(_device, (int[])null); Alc.MakeContextCurrent(_context); AL.DistanceModel(ALDistanceModel.InverseDistanceClamped); for (int i = 0; i < _maxSources; i++) { _sources[i].Source = new AudioSource(); _sources[i].Owner = null; } }
public static void Start() { GlfwWindowEventListener winEventListener = new GlfwWindowEventListener(); var form = new GlFwForm(800, 600, "hello!", winEventListener); form.MakeCurrent(); string versionStr3 = Marshal.PtrToStringAnsi(Glfw3.glfwGetVersionString()); OpenTK.Platform.Factory.GetCustomPlatformFactory = () => OpenTK.Platform.Egl.EglAngle.NewFactory(); OpenTK.Toolkit.Init(new OpenTK.ToolkitOptions { Backend = OpenTK.PlatformBackend.PreferNative, }); OpenTK.Graphics.PlatformAddressPortal.GetAddressDelegate = OpenTK.Platform.Utilities.CreateGetAddress(); //----------- IntPtr currentContext = Glfw3.glfwGetCurrentContext(); var contextHandler = new OpenTK.ContextHandle(currentContext); var glfwContext = new GLFWContextForOpenTK(contextHandler); var context = OpenTK.Graphics.GraphicsContext.CreateExternalContext(glfwContext); bool isCurrent = context.IsCurrent; var demoContext = new Mini.GLDemoContext(800, 600); demoContext.LoadDemo(new OpenTkEssTest.T108_LionFill()); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.ClearColor(1, 1, 1, 1); //-------------------------------------------------------------------------------- //setup viewport size //set up canvas int ww_w = 800; int ww_h = 600; int max = Math.Max(ww_w, ww_h); GL.Viewport(0, 0, max, max); //--------- form.RenderDel = () => { demoContext.Render(); form.SwapBuffers(); }; //--------- GlfwAppLoop.Run(); }
internal static void CreateGLESContext(PixelFarm.Forms.GlFwForm glFwForm) { //make open gl es current context //GlfwWindowPtr currentContext = Glfw.GetCurrentContext(); var s_glContextHandler = new OpenTK.ContextHandle(glFwForm.GlfwWindowPtr.inner_ptr); glFwForm.GlfwContextForOpenTK = new GLFWContextForOpenTK(s_glContextHandler); glFwForm.OpenTKGraphicContext = OpenTK.Graphics.GraphicsContext.CreateExternalContext(glFwForm.GlfwContextForOpenTK); //glfwContext = OpenTK.Graphics.GraphicsContext.CreateDummyContext(contextHandler); #if DEBUG bool isCurrent = glFwForm.GlfwContextForOpenTK.IsCurrent; #endif }
public AudioDevice() { try { _device = Alc.OpenDevice ( string.Empty ); int [] attribute = new int [ 0 ]; _context = Alc.CreateContext ( _device, attribute ); Alc.MakeContextCurrent ( _context ); } catch ( Exception e ) { throw new Exception ( string.Format ( "Audio device is not available or OpenAL library is not exist: {0}", e ), e ); } }
public OpenALKeySoundPlayer() { String defaultDevice = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultDeviceSpecifier); Device = Alc.OpenDevice(defaultDevice); if (Device == IntPtr.Zero) { Console.WriteLine("Failed to open default sound device"); return; } context = Alc.CreateContext(Device, new int[] { }); if (!Alc.MakeContextCurrent(context)) { Console.WriteLine("failed to make default context"); return; } AL.Listener(ALListener3f.Position, 0, 0, 0); AL.Listener(ALListener3f.Velocity, 0, 0, 0); AL.Listener(ALListenerfv.Orientation, ref ListenerOrientation); }
public static void Start() { if (!GLFWPlatforms.Init()) { Console.WriteLine("can't init"); return; } GlfwWindowPtr glWindow = Glfw.CreateWindow(800, 600, "PixelFarm on GLfw and OpenGLES2", new GlfwMonitorPtr(), //default monitor new GlfwWindowPtr()); //default top window /* Make the window's context current */ Glfw.MakeContextCurrent(glWindow); GlfwWindowPtr currentContext = Glfw.GetCurrentContext(); var contextHandler = new OpenTK.ContextHandle(currentContext.inner_ptr); OpenTK.Platform.Factory.GetCustomPlatformFactory = () => OpenTK.Platform.Egl.EglAngle.NewFactory(); OpenTK.Toolkit.Init(new OpenTK.ToolkitOptions { Backend = OpenTK.PlatformBackend.PreferNative, }); OpenTK.Graphics.PlatformAddressPortal.GetAddressDelegate = OpenTK.Platform.Utilities.CreateGetAddress(); var glfwContext = new GLFWContextForOpenTK(contextHandler); var context = OpenTK.Graphics.GraphicsContext.CreateExternalContext(glfwContext); bool isCurrent = context.IsCurrent; PixelFarm.GlfwWinInfo winInfo = new PixelFarm.GlfwWinInfo(glWindow); context.MakeCurrent(winInfo); //-------------------------------------- //-------------------------------------- //var demo = new OpenTkEssTest.T52_HelloTriangle2(); //var demo = new OpenTkEssTest.T107_SampleDrawImage(); //var demo = new OpenTkEssTest.T107_SampleDrawImage(); var demoContext = new Mini.GLDemoContext(800, 600); demoContext.LoadDemo(new OpenTkEssTest.T108_LionFill()); //var demo = new OpenTkEssTest.T107_SampleDrawImage(); //demo.Width = 800; //demo.Height = 600; //-------------------------------------------------------------------------------- GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.ClearColor(1, 1, 1, 1); //-------------------------------------------------------------------------------- //setup viewport size //set up canvas int ww_w = 800; int ww_h = 600; int max = Math.Max(ww_w, ww_h); GL.Viewport(0, 0, max, max); while (!Glfw.WindowShouldClose(glWindow)) { demoContext.Render(); /* Render here */ /* Swap front and back buffers */ Glfw.SwapBuffers(glWindow); /* Poll for and process events */ Glfw.PollEvents(); } demoContext.Close(); Glfw.Terminate(); }
public static void Start() { if (!Glfw.Init()) { Console.WriteLine("can't init glfw"); return; } //--------------------------------------------------- //at this, point no opengl func binding //--------------------------------------------------- //1. we specific which verision we want, //here => OpenGLES 2.0 Glfw.WindowHint(WindowHint.GLFW_CLIENT_API, (int)OpenGLAPI.OpenGLESAPI); Glfw.WindowHint(WindowHint.GLFW_CONTEXT_CREATION_API, (int)OpenGLContextCreationAPI.GLFW_EGL_CONTEXT_API); Glfw.WindowHint(WindowHint.GLFW_CONTEXT_VERSION_MAJOR, 3); Glfw.WindowHint(WindowHint.GLFW_CONTEXT_VERSION_MINOR, 0); //--------------------------------------------------- OpenTK.Platform.Factory.GetCustomPlatformFactory = () => OpenTK.Platform.Egl.EglAngle.NewFactory(); OpenTK.Toolkit.Init(new OpenTK.ToolkitOptions { Backend = OpenTK.PlatformBackend.PreferNative, }); OpenTK.Graphics.PlatformAddressPortal.GetAddressDelegate = OpenTK.Platform.Utilities.CreateGetAddress(); GlfwMonitorPtr monitor = new GlfwMonitorPtr(); //default monitor GlfwWindowPtr winPtr = new GlfwWindowPtr(); //default window GlfwWindowPtr glWindow = Glfw.CreateWindow(800, 600, "Test Glfw", monitor, winPtr); /* Make the window's context current */ Glfw.MakeContextCurrent(glWindow); Glfw.SwapInterval(1); GlfwWindowPtr currentContext = Glfw.GetCurrentContext(); var contextHandler = new OpenTK.ContextHandle(currentContext.inner_ptr); //faster: create external context var glfwContext = new GLFWContextForOpenTK(contextHandler); var context = OpenTK.Graphics.GraphicsContext.CreateExternalContext(glfwContext); //--------------------------- //slow ... use create dummy context //var context = OpenTK.Graphics.GraphicsContext.CreateDummyContext(contextHandler); //and you need to load gles2 binding points manaually (below) bool isCurrent = context.IsCurrent; PixelFarm.GlfwWinInfo winInfo = new PixelFarm.GlfwWinInfo(glWindow); context.MakeCurrent(winInfo); //-------------------------------------- //bind open gl funcs here.. //this not need if we use glfwcontext for opentk //new OpenTK.Graphics.ES20.GL().LoadEntryPoints(); //-------------------------------------- //create shader program var shaderProgram = new MiniShaderProgram(); //-------------------------------------- ShaderVtxAttrib3f a_position; ShaderVtxAttrib4f a_color; ShaderUniformMatrix4 u_matrix; ShaderUniformVar1 u_useSolidColor; ShaderUniformVar4 u_solidColor; MyMat4 orthoView; string vs = @" attribute vec3 a_position; attribute vec4 a_color; uniform mat4 u_mvpMatrix; uniform vec4 u_solidColor; uniform int u_useSolidColor; varying vec4 v_color; varying vec4 a_position_output; void main() { a_position_output = u_mvpMatrix* vec4(a_position[0],a_position[1],0,1); gl_Position = a_position_output; v_color= vec4(1,0,0,1); } "; //fragment source // string fs = @"void main() // { // gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); // } // "; string fs = @" precision mediump float; varying vec4 v_color; varying vec4 a_position_output; void main() { if(a_position_output[1]>0.5){ gl_FragColor = vec4(0,1,1,1); }else{ gl_FragColor= vec4(0,1,0,1); } } "; if (!shaderProgram.Build(vs, fs)) { throw new NotSupportedException(); } a_position = shaderProgram.GetAttrV3f("a_position"); a_color = shaderProgram.GetAttrV4f("a_color"); u_matrix = shaderProgram.GetUniformMat4("u_mvpMatrix"); u_useSolidColor = shaderProgram.GetUniform1("u_useSolidColor"); u_solidColor = shaderProgram.GetUniform4("u_solidColor"); //-------------------------------------------------------------------------------- GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.ClearColor(1, 1, 1, 1); //setup viewport size int ww_w = 800; int ww_h = 600; int max = Math.Max(ww_w, ww_h); //square viewport GL.Viewport(0, 0, max, max); orthoView = MyMat4.ortho(0, max, 0, max, 0, 1); //-------------------------------------------------------------------------------- //load image /* Loop until the user closes the window */ //int width, height; //Glfw.GetFramebufferSize(glWindow, out width, out height); //float ratio = (float)width / (float)height; GL.Viewport(0, 0, 800, 600); shaderProgram.UseProgram(); while (!Glfw.WindowShouldClose(glWindow)) { //set clear color to white GL.ClearColor(1f, 1, 1, 1); GL.Clear(ClearBufferMask.ColorBufferBit); //--------------------------------- //--------------------------------------------------------- u_matrix.SetData(orthoView.data); //--------------------------------------------------------- //DrawLines(0, 0, 300, 300); float x1 = 50, y1 = 20, x2 = 300, y2 = 20; float[] vtxs = new float[] { x1, y1, 1, x2, y2, 1, 50, 300, 1 }; u_useSolidColor.SetValue(1); u_solidColor.SetValue(1f, 0f, 0f, 1f);//use solid color a_position.LoadPureV3f(vtxs); GL.DrawArrays(BeginMode.Triangles, 0, 3); //--------------------------------------------------------- //GL.MatrixMode(MatrixMode.Modelview); //GL.LoadIdentity(); //GL.Begin(BeginMode.Triangles); //GL.Color3(1f, 0, 0); //GL.Vertex3(-0.6f, -0.4f, 0f); //GL.Color3(0f, 1f, 0); //GL.Vertex3(0.6f, -0.4f, 0f); //GL.Color3(0f, 0, 1f); //GL.Vertex3(0.0f, 0.6f, 0f); //GL.End(); //--------------------------------- /* Render here */ /* Swap front and back buffers */ Glfw.SwapBuffers(glWindow); /* Poll for and process events */ Glfw.PollEvents(); } Glfw.Terminate(); }
public SoundManager() { loadedSounds = new List <Sound>(); playingChannels = new SoundChannel[SOURCE_COUNT]; streamingThread = null; categoryModifiers = null; alcDevice = Alc.OpenDevice(null); if (alcDevice == null) { throw new Exception("Failed to open an ALC device!"); } AlcError alcError = Alc.GetError(alcDevice); if (alcError != AlcError.NoError) { //The audio device probably wasn't ready, this happens quite often //Just wait a while and try again Thread.Sleep(100); alcDevice = Alc.OpenDevice(null); alcError = Alc.GetError(alcDevice); if (alcError != AlcError.NoError) { throw new Exception("Error initializing ALC device: " + alcError.ToString()); } } int[] alcContextAttrs = new int[] { }; alcContext = Alc.CreateContext(alcDevice, alcContextAttrs); if (alcContext == null) { throw new Exception("Failed to create an ALC context! (error code: " + Alc.GetError(alcDevice).ToString() + ")"); } if (!Alc.MakeContextCurrent(alcContext)) { throw new Exception("Failed to assign the current ALC context! (error code: " + Alc.GetError(alcDevice).ToString() + ")"); } alcError = Alc.GetError(alcDevice); if (alcError != AlcError.NoError) { throw new Exception("Error after assigning ALC context: " + alcError.ToString()); } ALError alError = ALError.NoError; alSources = new uint[SOURCE_COUNT]; for (int i = 0; i < SOURCE_COUNT; i++) { AL.GenSource(out alSources[i]); alError = AL.GetError(); if (alError != ALError.NoError) { throw new Exception("Error generating alSource[" + i.ToString() + "]: " + AL.GetErrorString(alError)); } if (!AL.IsSource(alSources[i])) { throw new Exception("Generated alSource[" + i.ToString() + "] is invalid!"); } AL.SourceStop(alSources[i]); alError = AL.GetError(); if (alError != ALError.NoError) { throw new Exception("Error stopping newly generated alSource[" + i.ToString() + "]: " + AL.GetErrorString(alError)); } AL.Source(alSources[i], ALSourcef.MinGain, 0.0f); alError = AL.GetError(); if (alError != ALError.NoError) { throw new Exception("Error setting min gain: " + AL.GetErrorString(alError)); } AL.Source(alSources[i], ALSourcef.MaxGain, 1.0f); alError = AL.GetError(); if (alError != ALError.NoError) { throw new Exception("Error setting max gain: " + AL.GetErrorString(alError)); } AL.Source(alSources[i], ALSourcef.RolloffFactor, 1.0f); alError = AL.GetError(); if (alError != ALError.NoError) { throw new Exception("Error setting rolloff factor: " + AL.GetErrorString(alError)); } } AL.DistanceModel(ALDistanceModel.LinearDistanceClamped); alError = AL.GetError(); if (alError != ALError.NoError) { throw new Exception("Error setting distance model: " + AL.GetErrorString(alError)); } if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_EXT_CAPTURE")) { alcCaptureDeviceNames = new List <string>(Alc.GetString(IntPtr.Zero, AlcGetStringList.CaptureDeviceSpecifier)); } else { alcCaptureDeviceNames = null; } listenerOrientation = new float[6]; ListenerPosition = Vector3.Zero; ListenerTargetVector = new Vector3(0.0f, 0.0f, 1.0f); ListenerUpVector = new Vector3(0.0f, -1.0f, 0.0f); }
public SoundManager() { loadedSounds = new List <Sound>(); streamingThread = null; categoryModifiers = null; alcDevice = Alc.OpenDevice(null); if (alcDevice == null) { DebugConsole.ThrowError("Failed to open an ALC device! Disabling audio playback..."); Disabled = true; return; } AlcError alcError = Alc.GetError(alcDevice); if (alcError != AlcError.NoError) { //The audio device probably wasn't ready, this happens quite often //Just wait a while and try again Thread.Sleep(100); alcDevice = Alc.OpenDevice(null); alcError = Alc.GetError(alcDevice); if (alcError != AlcError.NoError) { DebugConsole.ThrowError("Error initializing ALC device: " + alcError.ToString() + ". Disabling audio playback..."); Disabled = true; return; } } int[] alcContextAttrs = new int[] { }; alcContext = Alc.CreateContext(alcDevice, alcContextAttrs); if (alcContext == null) { DebugConsole.ThrowError("Failed to create an ALC context! (error code: " + Alc.GetError(alcDevice).ToString() + "). Disabling audio playback..."); Disabled = true; return; } if (!Alc.MakeContextCurrent(alcContext)) { DebugConsole.ThrowError("Failed to assign the current ALC context! (error code: " + Alc.GetError(alcDevice).ToString() + "). Disabling audio playback..."); Disabled = true; return; } alcError = Alc.GetError(alcDevice); if (alcError != AlcError.NoError) { DebugConsole.ThrowError("Error after assigning ALC context: " + alcError.ToString() + ". Disabling audio playback..."); Disabled = true; return; } ALError alError = ALError.NoError; sourcePools = new SoundSourcePool[2]; sourcePools[(int)SourcePoolIndex.Default] = new SoundSourcePool(SOURCE_COUNT); playingChannels[(int)SourcePoolIndex.Default] = new SoundChannel[SOURCE_COUNT]; sourcePools[(int)SourcePoolIndex.Voice] = new SoundSourcePool(8); playingChannels[(int)SourcePoolIndex.Voice] = new SoundChannel[8]; AL.DistanceModel(ALDistanceModel.LinearDistanceClamped); alError = AL.GetError(); if (alError != ALError.NoError) { DebugConsole.ThrowError("Error setting distance model: " + AL.GetErrorString(alError) + ". Disabling audio playback..."); Disabled = true; return; } ListenerPosition = Vector3.Zero; ListenerTargetVector = new Vector3(0.0f, 0.0f, 1.0f); ListenerUpVector = new Vector3(0.0f, -1.0f, 0.0f); }