# tinyGL **Repository Path**: itmwuma/tinygl ## Basic Information - **Project Name**: tinyGL - **Description**: openGL的封装库,针对于原生openGL提高封装度,使封装库更具有面向对象的特性(模块化),目的是使图形API更容易上手使用 - **Primary Language**: C++ - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2022-10-19 - **Last Updated**: 2023-11-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: Opengl, Cpp ## README # tinyGL #### 介绍 openGL的封装库,针对于原生openGL提高封装度,使封装库更具有面向对象的特性(模块化),目的是使图形API更容易上手使用 #### 软件架构 tinyGL依赖: - glew-2.1.0 - glfw-3.3.8 - glm-0.9.9.8 - std_image-v2.27 #### 使用说明 #### 使用案例 ```cpp // Please inlcude "tgl.h" and using namespace "tgl" #include "tgl.h" using namespace tgl; // Vertices data float vertices[] = { -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.5f, 1.0f, 0.0f, -0.5f, 0.5f, -0.5f, 1.0f, 1.0f, -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, -0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, -0.5f, 0.5f, -0.5f, 0.0f, 1.0f }; // Light Light* light = new PointLight(Vector3(1.0f, 1.0f, -1.0f)); // Material Material material("material", WHITE, Vector3(0.1f, 0.1f, 0.1f), WHITE, 32); int main() { // Create a window Window window(800, 600, "Test"); // Read and complie shader Shader shader("testVertex.shader", "testFragment.shader"); // Build a render pipeline window.BuildPipeline(vertices, sizeof(vertices), nullptr, 0, [&]() -> void { // TBO tgl::TexInfo TBO_info1 = window.GenerateTBO("wall.jpg", 0); window.SendDataToTBO(TBO_info1, RGB_MODE); tgl::TexInfo TBO_info2 = window.GenerateTBO("awesomeface.png", 1); window.SendDataToTBO(TBO_info2, RGBA_MODE); // Attribute Pointer window.SetAttributePointer(0, 3, 5, 0); window.SetAttributePointer(1, 2, 5, 3); // Set uniform shader.Use(); shader.SetUniform("wallTexture", 0); shader.SetUniform("smileTexture", 1); // Render iteration window.Render(0.0f, 0.0f, 0.0f, 1.0f, [&]() -> void { // M Matrix model = IMAT; // V Matrix view = IMAT; float timeValue = (float)glfwGetTime(); Camera camera(Vector3(0.0f, 1.0f, 3.0f), -15.0f + 15.0f * glm::sin(timeValue), 180.0f, WORLD_Y); view = camera.GetViewMatrix(); // P Matrix projection = IMAT; projection = glm::perspective(glm::radians(45.0f), 800.0f / 600.0f, 0.1f, 100.0f); // MVP Transform Matrix trans = projection * view * model; shader.Use(); shader.SetUniform("trans", trans); // Render window.DrawArrays(0, 36); }); }); return 0; } ``` #### 注意事项 1. tinyGL库依赖上述库文件,请不要删除或调整packages目录的内容,保证其与include目录同级 2. 导入"tgl.h"文件可导入全部的tinyGL库内容,即可使用全部的功能 3. tinyGL库内容全部定义在"tgl"名称空间中 #### 参与贡献 ***itmWuma***:https://gitee.com/itmwuma