/* For graph of f(x)=sin(x) and f(x)=cos(x) * where time = [0, 24] * * 22-2: No sun * 2-7, 16-22: sun-rise, sun-set * 7-17: day * -- -- -- * where time = [0, 2pi] (y-axis) * * sun-rise: [0, pi/4] * day: [pi/4, 1.32] * sun-set: [1.32, pi] * night: [pi, 2pi] */ public SkyboxRenderer(MasterRenderer master) : base(master) { cube = new SimpleMesh(BufferUsageHint.StaticDraw, 3, VERTICES); skyMap = GLoader.LoadTexture("Textures/skyMap.png", TextureMinFilter.Nearest, TextureMagFilter.Nearest); shader = new SkyboxShader(); }
public MasterRenderer(int screenWidth, int screenHeight, GraphicsOptions options = null) { Instance = this; GFXSettings = options ?? new GraphicsOptions(); ScreenWidth = screenWidth; ScreenHeight = screenHeight; if (GLVersion == 0) { int major = GL.GetInteger(GetPName.MajorVersion); int minor = GL.GetInteger(GetPName.MinorVersion); GLVersion = major + minor * 0.1f; //if (major < 4) // throw new Exception(string.Format("OpenGL 4.0 or later is required to run this game. This machine is running: {0}", GLVersion)); if (major < 4) { DashCMD.WriteWarning("[OpenGL] OpenGL 4.0 or later is required to run this game properly!. This machine is running: {0}", GLVersion); } else { DashCMD.WriteLine("[OpenGL] Version: {0}", ConsoleColor.DarkGray, GLVersion); } } GLError.Begin(); Camera camera = new Camera(this); camera.MakeActive(); Lights = new LightList(); Texture.Blank = GLoader.LoadBlankTexture(Color.White); Renderer3Ds = new Dictionary <Type, Renderer3D>(); Renderer2Ds = new Dictionary <Type, Renderer2D>(); Gui = new GuiRenderer(this); Sprites = new SpriteRenderer(this); Sky = new SkyboxRenderer(this); AddRenderer(Gui); AddRenderer(Sprites); activePipeline = new ForwardPipeline(this); StateManager.Enable(EnableCap.CullFace); StateManager.Enable(EnableCap.DepthTest); GL.CullFace(CullFaceMode.Back); ErrorCode mInitError = GLError.End(); if (mInitError != ErrorCode.NoError) { throw new Exception(string.Format("Uncaught master renderer init opengl error: {0}", mInitError)); } }
public Shader(string vertexFilePath, string fragmentFilePath, string[] vertexLibs = null, string[] fragLibs = null) { this.Name = this.GetType().Name; uniforms = new Dictionary <string, Uniform>(); attributeLocations = new HashSet <int>(); // Load shaders from file int numShaders = 2 + (vertexLibs != null ? vertexLibs.Length : 0) + (fragLibs != null ? fragLibs.Length : 0); GLShader[] shaders = new GLShader[numShaders]; int shaderI = 0; // Main shaders shaders[shaderI++] = GLoader.LoadShader(vertexFilePath, ShaderType.VertexShader); shaders[shaderI++] = GLoader.LoadShader(fragmentFilePath, ShaderType.FragmentShader); // Libraries if (vertexLibs != null) { for (int i = 0; i < vertexLibs.Length; i++) { shaders[shaderI++] = GLoader.LoadShader(vertexLibs[i], ShaderType.VertexShader); } } if (fragLibs != null) { for (int i = 0; i < fragLibs.Length; i++) { shaders[shaderI++] = GLoader.LoadShader(fragLibs[i], ShaderType.FragmentShader); } } // Create program Program = GLoader.CreateProgram(shaders); // Bind attributes this.BindAttributes(); // Link Program GL.LinkProgram(Program.ProgramId); int linkStatus = GL.GetProgram(Program.ProgramId, ProgramParameter.LinkStatus); if (linkStatus == 0) { string programState = GL.GetProgramInfoLog(Program.ProgramId); throw new GPUResourceException(String.Format("Program Failed to Link. Vertex: {1}, Fragment: {2}, Reason: {0}", programState, vertexFilePath, fragmentFilePath)); } // Validate the program GL.ValidateProgram(Program.ProgramId); int validateStatus = GL.GetProgram(Program.ProgramId, ProgramParameter.ValidateStatus); if (validateStatus == 0) { string programState = GL.GetProgramInfoLog(Program.ProgramId); throw new GPUResourceException(String.Format("Program Failed to Validate. Vertex: {1}, Fragment: {2}, Reason: {0}", programState, vertexFilePath, fragmentFilePath)); } // Connect texture units Start(); this.ConnectTextureUnits(); Stop(); }