private static void RenderInstance(ModelInstance inst) { ModelAsset asset = inst.Asset; Program shaders = asset.Shaders; // bind the shaders shaders.Use(); // set the shader uniforms Matrix m = _gCamera.CombinedMatrix; shaders.SetUniform("camera", ref m); shaders.SetUniform("model", ref inst.Transform); shaders.SetUniform("tex", 0); // set to 0 because the texture will be bound to GL_TEXTURE0 shaders.SetUniform("light.position", _gLight.Position); shaders.SetUniform("light.intensities", _gLight.Intensities); //bind the texture GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, asset.Texture.GLObject); // bind VAO and draw GL.BindVertexArray(asset.Vao); GL.DrawArrays(asset.DrawType, asset.DrawStart, asset.DrawCount); // unbind everything GL.BindVertexArray(0); GL.BindTexture(TextureTarget.Texture2D, 0); shaders.StopUsing(); }
//create all the `instance` structs for the 3D scene, and add them to `gInstances` private static void CreateInstances() { ModelInstance dot = new ModelInstance(); dot.Asset = _gWoodenCrate; dot.Transform = new Matrix(); _gInstances.Add(dot); ModelInstance i = new ModelInstance(); i.Asset = _gWoodenCrate; i.Transform = Scale(1, 2, 1) * Translate(0, -4, 0); _gInstances.Add(i); ModelInstance hLeft = new ModelInstance(); hLeft.Asset = _gWoodenCrate; hLeft.Transform = Scale(1, 6, 1) * Translate(-8, 0, 0); _gInstances.Add(hLeft); ModelInstance hRight = new ModelInstance(); hRight.Asset = _gWoodenCrate; hRight.Transform = Scale(1, 6, 1) * Translate(-4, 0, 0); _gInstances.Add(hRight); ModelInstance hMid = new ModelInstance(); hMid.Asset = _gWoodenCrate; hMid.Transform = Scale(2, 1, 0.8f) * Translate(-6, 0, 0); _gInstances.Add(hMid); }
private static void RenderInstance(ModelInstance inst) { ModelAsset asset = inst.Asset; Program shaders = asset.Shaders; // bind the shaders shaders.Use(); // set the shader uniforms Matrix m = _gCamera.CombinedMatrix; shaders.SetUniform("camera", ref m); shaders.SetUniform("model", ref inst.Transform); shaders.SetUniform("material.tex", 0); // set to 0 because the texture will be bound to GL_TEXTURE0 shaders.SetUniform("material.shininess", asset.Shininess); shaders.SetUniform("material.specularColor", asset.SpecularColor); shaders.SetUniform("light.position", _gLight.Position); shaders.SetUniform("light.intensities", _gLight.Intensities); shaders.SetUniform("light.attenuation", _gLight.Attenuation); shaders.SetUniform("light.ambientCoefficient", _gLight.AmbientCoefficient); shaders.SetUniform("cameraPosition", _gCamera.Position); //bind the texture GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, asset.Texture.GLObject); // bind VAO and draw GL.BindVertexArray(asset.Vao); GL.DrawArrays(asset.DrawType, asset.DrawStart, asset.DrawCount); // unbind everything GL.BindVertexArray(0); GL.BindTexture(TextureTarget.Texture2D, 0); shaders.StopUsing(); }
private static void RenderInstance(ModelInstance inst) { ModelAsset asset = inst.Asset; Program shaders = asset.Shaders; // bind the shaders shaders.Use(); // set the shader uniforms Matrix m = _gCamera.CombinedMatrix; shaders.SetUniform("camera", ref m); shaders.SetUniform("model", ref inst.Transform); shaders.SetUniform("tex", 0); // set to 0 because the texture will be bound to GL_TEXTURE0 //bind the texture GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, asset.Texture.GLObject); // bind VAO and draw GL.BindVertexArray(asset.Vao); GL.DrawArrays(asset.DrawType, asset.DrawStart, asset.DrawCount); // unbind everything GL.BindVertexArray(0); GL.BindTexture(TextureTarget.Texture2D, 0); shaders.StopUsing(); }