void glCanvas1_OpenGLDraw(object sender, PaintEventArgs e) { // set background color. OpenGL.ClearColor(ClearColor.R / 255.0f, ClearColor.G / 255.0f, ClearColor.B / 255.0f, ClearColor.A / 255.0f); OpenGL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT); this.blendSwitch.On(); var arg = new RenderEventArgs(RenderModes.Render, this.glCanvas1.ClientRectangle, this.camera); { mat4 projection = this.camera.GetProjectionMat4(); //mat4 view = this.camera.GetViewMat4(); mat4 view = this.earth.GetViewMatrix(this.camera); mat4 model = this.earth.GetModelRotationMatrix(this.EarthScale); this.earthRenderer.SetUniform("projectionMatrix", projection); this.earthRenderer.SetUniform("viewMatrix", view); this.earthRenderer.SetUniform("modelMatrix", model); this.earthRenderer.Render(arg); } { mat4 projection = this.camera.GetProjectionMat4(); mat4 view = this.camera.GetViewMat4(); mat4 model = mat4.identity(); this.eclipticRenderer.SetUniform("projectionMatrix", projection); this.eclipticRenderer.SetUniform("viewMatrix", view); this.eclipticRenderer.SetUniform("modelMatrix", model); this.eclipticRenderer.Render(arg); } this.blendSwitch.Off(); { this.uiRoot.Layout(); mat4 projection, view, model; { projection = glAxis.GetOrthoProjection(); vec3 position = (this.camera.Position - this.camera.Target).normalize(); view = glm.lookAt(position, new vec3(0, 0, 0), camera.UpVector); float length = Math.Max(glAxis.Size.Width, glAxis.Size.Height) / 2; model = glm.scale(mat4.identity(), new vec3(length, length, length)); glAxis.Renderer.SetUniform("projectionMatrix", projection); glAxis.Renderer.SetUniform("viewMatrix", view); glAxis.Renderer.SetUniform("modelMatrix", model); glAxis.Render(arg); } } }
void glCanvas1_OpenGLDraw(object sender, PaintEventArgs e) { // set background color. OpenGL.ClearColor(ClearColor.R / 255.0f, ClearColor.G / 255.0f, ClearColor.B / 255.0f, ClearColor.A / 255.0f); OpenGL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT); this.earth.ScaleFactor = this.CelestialBodyScale; this.sun.ScaleFactor = this.celestialBodyScale; var arg = new RenderEventArgs(RenderModes.Render, this.glCanvas1.ClientRectangle, this.camera); { this.backgroundStars.Render(arg); } { mat4 projection = this.camera.GetProjectionMat4(); mat4 view = this.camera.GetViewMat4(); mat4 model = glm.scale(mat4.identity(), (float)(Sun.radius) * new vec3( this.celestialBodyScale, this.celestialBodyScale, this.celestialBodyScale)); this.sunshineRenderer.SetMVP(projection * view * model); this.sunshineRenderer.Render(arg); } { mat4 projection = this.camera.GetProjectionMat4(); //mat4 view = this.camera.GetViewMat4(); mat4 view = this.earth.GetViewMatrix(this.camera); mat4 model = this.earth.GetModelRotationMatrix(); this.earthRenderer.SetUniform("projectionMatrix", projection); this.earthRenderer.SetUniform("viewMatrix", view); this.earthRenderer.SetUniform("modelMatrix", model); this.earthRenderer.Render(arg); } { mat4 projection = this.camera.GetProjectionMat4(); mat4 view = this.camera.GetViewMat4(); mat4 model = this.sun.GetModelRotationMatrix(); this.sunRenderer.SetUniform("projectionMatrix", projection); this.sunRenderer.SetUniform("viewMatrix", view); this.sunRenderer.SetUniform("modelMatrix", model); this.sunRenderer.SetUniform("time", sunTimeElapsed); sunTimeElapsed += 0.01f; //randomTime += (float)random.NextDouble() / 1000.0f; //this.sunRenderer.SetUniform("time",randomTime); //this.sunRenderer.ShaderProgram.Bind(); //this.sunRenderer.ShaderProgram.SetUniform("time", new float[] { randomTime, randomTime }); //this.sunRenderer.ShaderProgram.Unbind(); //this.sunRenderer.SetUniform("time", new float[] { randomTime, randomTime }); //this.sunRenderer.SetUniform("colorTexture", new samplerValue(BindTextureTarget.Texture2D, this.sunColorTexture.Id, OpenGL.GL_TEXTURE0)); if (this.RenderSun) { this.sunRenderer.Render(arg); } } { mat4 projection = this.camera.GetProjectionMat4(); mat4 view = this.camera.GetViewMat4(); mat4 model = mat4.identity(); this.eclipticRenderer.SetUniform("projectionMatrix", projection); this.eclipticRenderer.SetUniform("viewMatrix", view); this.eclipticRenderer.SetUniform("modelMatrix", model); this.eclipticRenderer.Render(arg); } { this.uiRoot.Layout(); mat4 projection, view, model; { projection = glAxis.GetOrthoProjection(); vec3 position = (this.camera.Position - this.camera.Target).normalize(); view = glm.lookAt(position, new vec3(0, 0, 0), camera.UpVector); float length = Math.Max(glAxis.Size.Width, glAxis.Size.Height) / 2; model = glm.scale(mat4.identity(), new vec3(length, length, length)); glAxis.Renderer.SetUniform("projectionMatrix", projection); glAxis.Renderer.SetUniform("viewMatrix", view); glAxis.Renderer.SetUniform("modelMatrix", model); glAxis.Render(arg); } } }