public void OnUpdate(TimeStep ts) { cameraController.OnUpdate(ts); //Render RenderingAPI.SetClearColor(0.2f, 0.2f, 0.2f); RenderingAPI.Clear(); Renderer.BeginScene(cameraController.GetCamera()); { //Square for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { Vector3 pos = new Vector3(x * 1.1f, y * 1.1f, 0); Matrix4x4 transform = Matrix4x4.CreateTranslation(pos) * Scale; Renderer.Submit(shaderLibrary.GetShader("Square"), squareVertexArray, transform); } } birdiTexture.Bind(); Renderer.Submit(shaderLibrary.GetShader("Texture"), squareVertexArray, Matrix4x4.Identity); faceTexture.Bind(); Renderer.Submit(shaderLibrary.GetShader("Texture"), squareVertexArray, Matrix4x4.Identity); } Renderer.EndScene(); }
/// <summary> /// Draws a quad using a texture /// </summary> /// <param name="transform"></param> /// <param name="texture"></param> /// <param name="tintColor"></param> /// <param name="tillingFactor"></param> public static void DrawQuad(Transform transform, I2DTexture texture, Vector4 tintColor, float tillingFactor = 1.0f) { rendererData.TextureShader.SetVec4("u_Color", tintColor); rendererData.TextureShader.SetFloat("u_TilingFactor", tillingFactor); texture.Bind(); Matrix4x4 shaderTransform = Matrix4x4.CreateTranslation(transform.Position) * Matrix4x4.CreateScale(transform.Scale.X, transform.Scale.Y, 1.0f); rendererData.TextureShader.SetMat4("u_Transform", shaderTransform); rendererData.QuadVertexArray.Bind(); RenderingAPI.DrawIndexed(rendererData.QuadVertexArray); }
/// <summary> /// Draws a quad rotated /// </summary> /// <param name="transform"></param> /// <param name="tintColor"></param> /// <param name="texture"></param> /// <param name="tillingFactor"></param> public static void DrawRotatedQuad(Transform transform, Vector4 tintColor, I2DTexture texture, float tillingFactor = 1.0f) { //If the rotation is only 0, we will call the regular draw quad, to save performance on the rotation calculations if (transform.Rotation == 0.0f) { DrawQuad(transform, texture, tintColor, tillingFactor); return; } rendererData.TextureShader.SetVec4("u_Color", tintColor); rendererData.TextureShader.SetFloat("u_TilingFactor", tillingFactor); texture.Bind(); Matrix4x4 shaderTransform = Matrix4x4.CreateTranslation(transform.Position) * Matrix4x4.CreateRotationZ(transform.Rotation.ToRadian()) * Matrix4x4.CreateScale(transform.Scale.X, transform.Scale.Y, 1.0f); rendererData.TextureShader.SetMat4("u_Transform", shaderTransform); rendererData.QuadVertexArray.Bind(); RenderingAPI.DrawIndexed(rendererData.QuadVertexArray); }