// ---------------------------------------------------------------- // From Game Programming in C++ by Sanjay Madhav // Copyright (C) 2017 Sanjay Madhav. All rights reserved. // // Released under the BSD License // See LICENSE in root directory for full details. // ---------------------------------------------------------------- #pragma once #include #include #include #include #include "Math.h" struct DirectionalLight { // Direction of light Vector3 mDirection; // Diffuse color Vector3 mDiffuseColor; // Specular color Vector3 mSpecColor; }; class Renderer { public: Renderer(class Game* game); ~Renderer(); bool Initialize(float screenWidth, float screenHeight); void Shutdown(); void UnloadData(); void Draw(); void AddSprite(class SpriteComponent* sprite); void RemoveSprite(class SpriteComponent* sprite); void AddMeshComp(class MeshComponent* mesh); void RemoveMeshComp(class MeshComponent* mesh); class Texture* GetTexture(const std::string& fileName); class Mesh* GetMesh(const std::string& fileName); void SetViewMatrix(const Matrix4& view) { mView = view; } void SetAmbientLight(const Vector3& ambient) { mAmbientLight = ambient; } DirectionalLight& GetDirectionalLight() { return mDirLight; } float GetScreenWidth() const { return mScreenWidth; } float GetScreenHeight() const { return mScreenHeight; } private: bool LoadShaders(); void CreateSpriteVerts(); void SetLightUniforms(class Shader* shader); // Map of textures loaded std::unordered_map mTextures; // Map of meshes loaded std::unordered_map mMeshes; // All the sprite components drawn std::vector mSprites; // All mesh components drawn std::vector mMeshComps; // Game class Game* mGame; // Sprite shader class Shader* mSpriteShader; // Sprite vertex array class VertexArray* mSpriteVerts; // Mesh shader class Shader* mMeshShader; // View/projection for 3D shaders Matrix4 mView; Matrix4 mProjection; // Width/height of screen float mScreenWidth; float mScreenHeight; // Lighting data Vector3 mAmbientLight; DirectionalLight mDirLight; // Window SDL_Window* mWindow; // OpenGL context SDL_GLContext mContext; };