public override void Render(Camera camera) { UseShader("j3d"); //State Muckin' GL.Enable(EnableCap.DepthTest); //Clear any previously bound buffer GL.BindBuffer(BufferTarget.ArrayBuffer, 0); //Build a View Projection Matrix out of camera settings. _viewProjMatrix = camera.GetViewProjMatrix(); /* Because the J3D models are very complex, we're going to * allow them to completely render themselves, including * binding buffers, enabling vertex attribs, etc. */ foreach (var renderable in _renderList) { renderable.Bind(); GL.VertexAttribPointer((int)ShaderAttributeIds.Position, 3, VertexAttribPointerType.Float, false, 9 * 4, 0); GL.VertexAttribPointer((int)ShaderAttributeIds.Color, 4, VertexAttribPointerType.Float, false, 9 * 4, 3 * 4); GL.VertexAttribPointer((int)ShaderAttributeIds.TexCoord, 2, VertexAttribPointerType.Float, false, 9 * 4, 7 * 4); renderable.Draw(this); } GL.Flush(); }
public override void Render(Camera camera) { UseShader("debug"); //State Muckin' GL.Enable(EnableCap.DepthTest); //Clear any previously bound buffer GL.BindBuffer(BufferTarget.ArrayBuffer, 0); Matrix4 viewProjMatrix = camera.GetViewProjMatrix(); foreach (var meshType in _renderList) { //Bind the objects buffer, enable attribs and set layout. meshType.Key.Bind(); GL.VertexAttribPointer((int)ShaderAttributeIds.Position, 3, VertexAttribPointerType.Float, false, 3 * 4, 0); GL.EnableVertexAttribArray((int)ShaderAttributeIds.Position); foreach (var instance in meshType.Value) { Matrix4 worldMatrix = Matrix4.CreateScale(instance.Scale) * Matrix4.CreateFromQuaternion(instance.Rotation) * Matrix4.CreateTranslation(instance.Position); Matrix4 finalMatrix = worldMatrix * viewProjMatrix; //Upload the WVP to the GPU GL.UniformMatrix4(_currentShader.UniformMVP, false, ref finalMatrix); //Upload this primitives color. GL.Uniform3(_currentShader.UniformColor, new Vector3(instance.Color.X, instance.Color.Y, instance.Color.Z)); meshType.Key.Draw(this); } GL.DisableVertexAttribArray((int)ShaderAttributeIds.Position); } //Now draw all of our debug lines //Upload the WVP to the GPU GL.UniformMatrix4(_currentShader.UniformMVP, false, ref viewProjMatrix); foreach (LineInstance instance in _lineRenderList) { //Bind the object buffer, enable attribs and set layout. instance.Bind(); GL.VertexAttribPointer((int)ShaderAttributeIds.Position, 3, VertexAttribPointerType.Float, false, 3 * 4, 0); GL.EnableVertexAttribArray((int)ShaderAttributeIds.Position); //Upload the primitives color. GL.Uniform3(_currentShader.UniformColor, new Vector3(instance.Color.X, instance.Color.Y, instance.Color.Z)); instance.Draw(this); GL.DisableVertexAttribArray((int)ShaderAttributeIds.Position); } }
public abstract void Render(Camera camera);