#pragma once #include "GLWrappers/vao.h" #include "camera.h" #include "GLWrappers/shader.h" #include "material.h" #include #include #include #include #include "shape.h" #include "modeltransform.h" #include "light.h" #include "textrenderer.h" #include struct TextureData{ GLuint textureID; int width; int height; }; class Graphics { public: Graphics(); ~Graphics(); void initialize(); void clearScreen(GLbitfield mask); void setClearColor(glm::vec3 clearColor); TextureData loadTextureFromFile(const char *path); TextureData loadTextureFromFile_Repeat(const char *path); GLuint loadCubeMap(std::vector textureFiles); GLuint makeVAO(std::vector positions); std::pair, std::shared_ptr> makeVAOFromData(const std::vector &verts, const std::vector &faces, bool hasUV, bool needsCollisionData = true); float generateRandomNumbers(float lb, float ub); void setClipPlane(glm::vec4 plane); void setCameraData(std::shared_ptr camera); void addShader(std::string shaderName, std::vector shaderTypes, std::vector filepaths); void removeShader(std::string shaderName); void bindShader(std::string shaderName = "phong"); GLuint getShaderID(std::string shaderName); // Shape-related methods std::shared_ptr addShape(std::string shapeName, std::vector data, VAOAttrib attribs); std::vector addShape(std::string shapeName, std::string filepath, bool hasUV = true); std::vector addShape_manual(std::string shapeName, const std::vector &verts, const std::vector &faces, bool hasUV = true); std::vector addShape_withMaterial(std::string shapeName, std::string filepath, std::string mtl_file, bool hasUV); // Returns pair containing positions followed by triangles indexed into the positions vector std::pair, std::vector> getNavmeshData(std::string filepath); void removeShape(std::string shapeName); std::shared_ptr getShape(std::string shapeName); std::vector> getShapeGroup(std::string shapeName); void drawShape(std::shared_ptr myShape, std::shared_ptr modelTransform, std::shared_ptr material = nullptr); void drawShape(std::shared_ptr myShape, glm::mat4 modelMatrix, std::shared_ptr material = nullptr); // Obj-loading method std::vector getObjData(std::string filepath); // Material-related methods std::shared_ptr addMaterial(std::string materialName, glm::vec3 color, float shininess = 1.f); std::shared_ptr addMaterial(std::string materialName, float shininess = 1.f); std::shared_ptr addMaterial(std::string materialName, std::string filePath, float shininess = 1.f); void removeMaterial(std::string materialName); std::shared_ptr getMaterial(std::string materialName); // Text and Font-related methods std::shared_ptr addFont(std::string fontName, std::string filepath); void removeFont(std::string fontName); std::shared_ptr getFont(std::string fontName); void drawUIText(std::shared_ptr font, std::string text, glm::vec2 anchorPosition, AnchorPoint anchorPoint, float textBoxWidth, float fontSize, float lineSpacing, glm::vec3 textColor); void setGlobalData(glm::vec3 globalCoeffs); void setLights(std::vector> lights); void clearLights(); void initializeGLEW(); void setWindowSize(glm::ivec2 windowSize); glm::ivec2 getWindowSize(); void setFramebufferSize(glm::ivec2 framebufferSize); glm::ivec2 getFramebufferSize(); // WATER STUFF GLuint reflectionFBO, reflectionTexture, reflectionDepthBuffer; GLuint refractionFBO, refractionTexture, refractionDepthTexture; void bindRefraction(); void bindReflection(); GLuint getRefractionTexture(); GLuint getReflectionTexture(); void unbindFBO(); GLuint getReflectionRBO(); GLuint getRefractionDepth(); const int REFLECTION_W = 512; const int REFLECTION_H = 256; const int REFRACTION_W = 512; const int REFRACTION_H = 256; void setWaterHeight(float height); float getWaterHeight(); private: void initializeReflectionFBO(); void initializeRefractionFBO(); void deleteFBOS(); void bindFBO(GLuint fbo, int width, int height); GLuint createFBO(); GLuint createTextureAttachment(int width, int height); GLuint createDepthTextureAttachment(int width, int height); GLuint createDepthBuffer(int width, int height); glm::ivec2 m_windowSize; glm::ivec2 m_framebufferSize; std::shared_ptr m_textRenderer; std::map> m_shaders; std::map> m_shapes; std::map> m_shape_groups; // stores the shape names kept in m_shapes associated with object std::map> m_materials; std::map> m_fonts; std::shared_ptr m_active_shader; float m_water_height = 0.f; Eigen::Vector3f getFaceNormal(const std::vector &verts, const Eigen::Vector3i& face); };