void Mainloop(float delta) { this.window.SwapBuffers(); GL.ClearColor(1f, 0f, 1f, 1.0f); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Clear(ClearBufferMask.DepthBufferBit); this.window.Title = delta.ToString(); return; if (b_W) { camera.moveFront(delta * camaraSpeed); } if (b_S) { camera.moveFront(delta * -camaraSpeed); } if (b_A) { camera.moveSideways(delta * -camaraSpeed); } if (b_D) { camera.moveSideways(delta * camaraSpeed); } if (b_Q) { camera.moveUp(delta * camaraSpeed); } if (b_E) { camera.moveUp(-delta * camaraSpeed); } if (b_F) { spotColor = new Vector3(2); } else { spotColor = new Vector3(0); } GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.diffuse"), ref spotColor); GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.specular"), ref spotColor); spotColor *= 0.1F; GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.ambient"), ref spotColor); camera.update(); modelViewProj = camera.GetViewProj() * camModelRender; Matrix4 modelView = camera.GetView() * camModelRender; var matrix4 = new OpenTK.Matrix4(); matrix4.Transpose(); Matrix4 invModelView = new Matrix4(); //TODO: glm.transpose( inverse( modelView ) ); Vector3 transformedSunDirection = new Vector3(); //TODO: transpose( inverse( camera.GetView() ) ) * vec4( sunDirection, 1.0F ); GL.Uniform3(directionLocation, ref transformedSunDirection); Matrix4 pointLightMatrix = glm.rotate(new mat4(1f), -delta, new vec3(0, 1, 0)).M(); pointLightPosition = pointLightMatrix * pointLightPosition; Vector3 transformedPointLightPosition = new Vector3(); //TODO:(Vector3) ( camera.GetView() * ( pointLightPosition ) ); GL.Uniform3(pointLightLocation, ref transformedPointLightPosition); GL.UniformMatrix4(modelViewProjMatrixLocation, false, ref modelViewProj); GL.UniformMatrix4(modelViewLocation, false, ref modelView); GL.UniformMatrix4(invModelViewLocation, false, ref invModelView); /// for (int i = 0; i < this.mats.Count; ++i) { //mats[i] =Matrix4.ro rotate(mats[i],time * , Vector3 (0, time,0)); modelViewProj = camera.GetViewProj() * mats[i]; modelView = camera.GetView() * mats[i]; invModelView = (modelView.Inverted()); GL.UniformMatrix4(modelViewProjMatrixLocation, false, ref modelViewProj); GL.UniformMatrix4(modelViewLocation, false, ref modelView); GL.UniformMatrix4(invModelViewLocation, false, ref invModelView); //TODO:models[i] -> Render(); } }
public Program() { InternalInit(); Console.WriteLine("Shaders: " + ShaderPos + "\n [" + vertexShader + ", " + fragmentShader + "]"); shader = new Shader((this.ShaderPos + this.vertexShader), (this.ShaderPos + this.fragmentShader)); shader.bind(); PrintStatus('S', shader.GetShaderID(), "-> Shader", 9, 1); directionLocation = GL.GetUniformLocation(shader.GetShaderID(), "u_directional_light.direction"); sunColor = new Vector3(.8f); sunDirection = new Vector3(0f, -1f, 0f); var z = new Vector3(0.0000001f); int zero = 0; GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_directional_light.diffuse"), ref sunColor); GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_directional_light.specular"), ref z); sunColor *= 0.2F; GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_directional_light.ambient"), ref sunColor); //GL.Uniform1iv(GL.GetUniformLocation(shader.GetShaderID(), "u_use_sun"),1,(int*)&zero)); Vector3 pointColor = new Vector3(0, 0, 30); //pointColor *= 0; GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_point_light.diffuse"), ref pointColor); GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_point_light.specular"), ref pointColor); pointColor *= 0.2F; GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_point_light.ambient"), ref pointColor); GL.Uniform1(GL.GetUniformLocation(shader.GetShaderID(), "u_point_light.linear"), 0.027f); GL.Uniform1(GL.GetUniformLocation(shader.GetShaderID(), "u_point_light.quadratic"), 0.0028f); pointLightPosition = new Vector4(1f, 1f, 10f, 1f); pointLightLocation = GL.GetUniformLocation(this.shader.GetShaderID(), "u_point_light.position"); spotColor = new Vector3(2); //spotColor *= 0; GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.diffuse"), ref spotColor); GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.specular"), ref spotColor); spotColor *= 0.1F; GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.ambient"), ref spotColor); Vector3 spotLightPosition = new Vector3(0.0F); GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.position"), ref spotLightPosition); spotLightPosition.Z = 1.0f; GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.direction"), ref spotLightPosition); GL.Uniform1(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.innerCone"), 0.99f); GL.Uniform1(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.outerCone"), 0.98f); string path = (ModelsPos); string ext = (".bmf"); int idx = 0; foreach (var p in new DirectoryInfo(path).GetFiles()) { if (p.Extension == ext) { Console.WriteLine("Loading: " + p + '\n'); var t = p.FullName; Model model = new Model(t, shader); model.Init(); models.Add(model); var Matrix4X = new mat4(1.0F); Matrix4X = glm.translate(Matrix4X, new vec3(100 * (idx++), 0, 0)); Matrix4X = glm.scale(Matrix4X, new vec3(.2f)); mats.Add(Matrix4X.M()); } } camModelRender = glm.scale(new mat4(1.0F), new vec3(.2f)).M(); //model_rotate = scale(model_rotate, Vector3(.1F)); camera = new FPSCamera(90.0F, 1000, 800); camera.Translate(new Vector3(0, 0, 5.0f)); camera.update(); modelViewProj = camera.GetViewProj() * camModelRender; modelViewProjMatrixLocation = GL.GetUniformLocation(this.shader.GetShaderID(), "u_modelViewProj"); modelViewLocation = GL.GetUniformLocation(this.shader.GetShaderID(), "u_modelView"); invModelViewLocation = GL.GetUniformLocation(this.shader.GetShaderID(), "u_invModelView"); //GL.PolygonMode (GL_FRONT_AND_BACK,GL_LINE); float camaraSpeed = 60.0F; GL.Enable(EnableCap.DepthTest); }