public void Render(object Sender, FrameEventArgs E) { Timekeeper.Start(); GL.Clear(ClearBufferMask.ColorBufferBit); // PlayerView.Setup(800, 800); // PlayerView.Update(); //Spritebatch.Begin(); Texture.Bind(); // GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); CurrentShader.Enable(); Sprite.mov(mov); Sprite.Draw(); CurrentShader.Disable(); // GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); GameScreen.SwapBuffers(); frames++; if (Timekeeper.GetElapsed().Seconds == 1) { RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Render() FPS " + frames); Timekeeper.Reset(); frames = 0; } // RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Render() MS " + Timekeeper.GetTime().Milliseconds.ToString()); }
public void Run() { RobustConsole.Write(LogLevel.Warning, "RobustEngine", "Starting Run loop..."); Timekeeper.Start(); GameScreen.Run(60); }
public void Init() { RobustConsole.ClearConsole(); RobustConsole.SetLogLevel(LogLevel.Debug); RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Init() Intializing..."); Timekeeper = new Clock(); VSettings = new VideoSettings(); //TODO import video settings here GameScreen = new GameWindow(800, 800, GraphicsMode.Default, "RobustWando", GameWindowFlags.Default, DisplayDevice.Default, 3, 3, GraphicsContextFlags.Debug); //GameScreen = new GameWindow(); //GameScreen.Size = VSettings.Size; //GameScreen.WindowBorder = VSettings.Border; //GameScreen.Title = "Space Station 14"; //GameScreen.Visible = true; GameScreen.MakeCurrent(); //OPENGL CONTEXT STARTS HERE GLINFO += "\n\n------------------------------------------------------------------"; GLINFO += "\n OpenGL Version: " + GL.GetString(StringName.Version); GLINFO += "\n Vendor: " + GL.GetString(StringName.Vendor); GLINFO += "\n GLSL Version: " + GL.GetString(StringName.ShadingLanguageVersion); GLINFO += "\n------------------------------------------------------------------\n"; RobustConsole.Write(LogLevel.Info, this, GLINFO); GameScreen.RenderFrame += Render; GameScreen.UpdateFrame += Update; GL.Enable(EnableCap.Texture2D); //GL.Enable(EnableCap.VertexArray); var ImageTestFile = Path.Combine(Environment.CurrentDirectory, "Graphics", "Shaders", "ImageTest"); //TESTING Texture = new Texture2D("Devtexture_Floor.png"); PlayerView = new View(Vector2.One, 0, 10); // Spritebatch = new SpriteBatch(1920, 1080); Sprite = new Sprite("test", Texture); CurrentShader = new Shader(ImageTestFile + ".vert", ImageTestFile + ".frag"); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.ClearColor(Color.Gray); GL.Viewport(0, 0, 800, 600); GL.Ortho(-400, 400, -300, 300, 0, 1); //Context = new GraphicsContext(GraphicsMode.Default, GameScreen.WindowInfo,4,4,GraphicsContextFlags.Default); //Context.MakeCurrent(GameScreen.WindowInfo); //(Context as IGraphicsContextInternal).LoadAll(); //GL.Enable(EnableCap.Blend); RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Init() Done."); ReadyToRun = true; }
private int getUniformLoc(string VarName) { if (!UniformLocations.ContainsKey(VarName)) { UniformLocations.Add(VarName, GL.GetUniformLocation(PID, VarName)); } if (UniformLocations[VarName] == -1 && DEBUG) { RobustConsole.Write(LogLevel.Warning, this, "| Shader PID:" + PID + " | Could not find Uniform Variable named " + VarName + "!. Uniform data will be discarded!"); } return(UniformLocations[VarName]); }
/// <summary> /// Compiles the vertex/fragment shader. Reports any compile-time issues. /// </summary> private void Compile(string VertexCode, string FragCode) { DEBUG = false; VSID = GL.CreateShader(ShaderType.VertexShader); FSID = GL.CreateShader(ShaderType.FragmentShader); VIDDump = File.ReadAllText(VertexCode); FIDDump = File.ReadAllText(FragCode); GL.ShaderSource(VSID, VIDDump); GL.ShaderSource(FSID, FIDDump); int VertexCompiled; int FragmentCompiled; int ProgramComplied; GL.CompileShader(VSID); GL.GetShader(VSID, ShaderParameter.CompileStatus, out VertexCompiled); if (VertexCompiled != 1) { RobustConsole.Write(LogLevel.Critical, this, GL.GetShaderInfoLog(VSID)); } GL.CompileShader(FSID); GL.GetShader(FSID, ShaderParameter.CompileStatus, out FragmentCompiled); if (FragmentCompiled != 1) { RobustConsole.Write(LogLevel.Critical, this, GL.GetShaderInfoLog(FSID)); } PID = GL.CreateProgram(); GL.AttachShader(PID, VSID); GL.AttachShader(PID, FSID); GL.LinkProgram(PID); GL.GetProgram(PID, GetProgramParameterName.LinkStatus, out ProgramComplied); if (ProgramComplied != 1) { RobustConsole.Write(LogLevel.Critical, this, GL.GetShaderInfoLog(PID)); } GL.DetachShader(PID, VSID); GL.DetachShader(PID, FSID); GL.DeleteShader(VSID); GL.DeleteShader(FSID); UniformLocations = new Dictionary <string, int>(); }
public static void CheckGLErrors() { var FBOEC = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); while ((FBOEC == FramebufferErrorCode.FramebufferComplete)) { RobustConsole.Write(LogLevel.Verbose, "RobustEngine", FBOEC.ToString()); //TODO expand error message break; } var EC = GL.GetError(); while (EC != ErrorCode.NoError) { RobustConsole.Write(LogLevel.Fatal, "RobustEngine", EC.ToString()); // TODO expand error message } }
public void Stop() { RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Stopping..."); }
public void Render(object Sender, FrameEventArgs E) { GL.Clear(ClearBufferMask.ColorBufferBit); // PlayerView.Setup(800, 800); // PlayerView.Update(); // Spritebatch.Begin(); CurrentShader.Enable(); // Sprite.Rect.DebugMode = Debug.None; // Sprite.Rect.SetFillColor(Color.Blue); LineTest.SetFillColor(Color.Red); LineTest.SetOrigin(LineTest.Center); // LineTest.SetPosition(new Vector2(.10f * x, .10f * y)); // LineTest.SetRotation(mov, Axis.Z); LineTest.Update(); LineTest.Draw(); //LineTest.SetFillColor(Color.Blue); //LineTest.SetOrigin(LineTest.Center); //// LineTest.SetPosition(new Vector2(.10f * x, .10f * y)); //LineTest.SetRotation(90f, Axis.Z); //LineTest.Update(); //LineTest.Draw(); //TriangleTest.SetFillColor(Color.Blue); //TriangleTest.SetOrigin(TriangleTest.BottomLeft); //TriangleTest.SetScale(scal); //TriangleTest.SetRotation(-mov, Axis.Z); //TriangleTest.SetPosition(new Vector2(scale, scale)); //TriangleTest.Update(); //TriangleTest.Draw(); //Sprite.SetOrigin(Sprite.Rect.Center); //Sprite.SetScale(new Vector2(scale, scale)); //+ (.001f * x), scale + (.001f * y))); //Sprite.SetRotation(mov, Axis.Z); //Sprite.SetPosition(new Vector2(scale, scale)); //Sprite.Update(); //Sprite.Draw(); //// Sprite.SetOrigin(new Vector2(-.5f, -.5f)); //Sprite.SetScale(new Vector2(scale, scale)); //Sprite.SetRotation(mov); //Sprite.SetPosition(new Vector2(scale * x, -scale * y)); //Sprite.Update(); //Sprite.Draw(); //// Sprite.SetOrigin(new Vector2(-.5f, -.5f)); //Sprite.SetScale(new Vector2(scale, scale)); //Sprite.SetRotation(mov); //Sprite.SetPosition(new Vector2(-scale * x, scale * y)); //Sprite.Update(); //Sprite.Draw(); //// Sprite.Rect.DebugMode = Debug.Wireframe; //// Sprite.SetOrigin(new Vector2(-.5f, -.5f)); //Sprite.SetScale(new Vector2(scale, scale)); ; //Sprite.SetRotation(mov); //Sprite.SetPosition(new Vector2(scale * x, scale * y)); //Sprite.Update(); //Sprite.Draw(); // Texture.Unbind(); CurrentShader.Disable(); GameScreen.SwapBuffers(); frames++; if (Timekeeper.GetElapsed().Seconds >= 1) { RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Render() FPS " + frames); Timekeeper.Start(); frames = 0; } // RobustConsole.Write(LogLevel.Debug, "RobustEngine", "Render() MS " + Timekeeper.GetTime().Milliseconds.ToString()); }