public override bool Compile() { if (Loaded) { return(true); } if (!CompileFromFile(VSPath, FSPath)) { return(false); } aVertexLoc = GL.GetAttribLocation(Id, "aVertex"); aUvLoc = GL.GetAttribLocation(Id, "aUv"); uMvpLoc = GL.GetUniformLocation(Id, "uMvp"); uColorLoc = GL.GetUniformLocation(Id, "uColor"); uTxtLoc = GL.GetUniformLocation(Id, "uTxt"); if (!RectangleGL.StaticLoaded) { RectangleGL.Load(); } Loaded = true; return(true); }
private void CleanupGL() { ColorShader.Instance.Unload(); EchoShader.Instance.Unload(); RectangleGL.Unload(); GL.DeleteRenderbuffer(depthBufferId); GL.DeleteFramebuffer(frameBufferId); GL.DeleteTexture(textureId); }
private void StartupGL() { #if DEBUG EchoWindow = true; #endif render_window = new GameWindow( (EchoWindow ? textureSizeX : 640), (EchoWindow ? textureSizeY : 480), new OpenTK.Graphics.GraphicsMode(new OpenTK.Graphics.ColorFormat(8, 8, 8, 8), 16, 0), "OpenVR Cards Subsystem", GameWindowFlags.Default, DisplayDevice.Default, 3, 3, OpenTK.Graphics.GraphicsContextFlags.Default) { Visible = EchoWindow, VSync = VSyncMode.Off }; render_window.MakeCurrent(); #if DEBUG cb = DBGProc; GL.Enable(EnableCap.DebugOutput); GL.DebugMessageCallback(cb, IntPtr.Zero); #endif GL.ClearColor(0, 0, 0, 0); VAO = GL.GenVertexArray(); GL.BindVertexArray(VAO); frameBufferId = GL.GenFramebuffer(); GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBufferId); textureId = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, textureId); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, textureSizeX, textureSizeY, 0, PixelFormat.Rgb, PixelType.Byte, IntPtr.Zero); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); depthBufferId = GL.GenRenderbuffer(); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, depthBufferId); GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.DepthComponent16, textureSizeX, textureSizeY); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, depthBufferId); GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, textureId, 0); GL.DrawBuffer(DrawBufferMode.ColorAttachment0); FramebufferErrorCode error = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); if (error != FramebufferErrorCode.FramebufferComplete) { throw new Exception("OpenGL Error."); } GL.Viewport(0, 0, textureSizeX, textureSizeY); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); ColorShader.Instance.Compile(); EchoShader.Instance.Compile(); RectangleGL.Load(); EchoScene.Instance.Window = render_window; EchoScene.Instance.EchoTexture = textureId; CardRectangle.Scale = new Vector2(textureSizeX, 300); CardRectangle.Shader = ColorShader.Instance; CardScene = new Scene(textureSizeX, textureSizeY); CardFont.Load(); #if DEBUG Debug.WriteLine("StartupGL Complete"); #endif }