opengl 学习(三)-----着色器

小明 2025-05-06 07:14:45 5

着色器

  • 分类
  • demo
  • 效果
  • 解析
  • index.php/tags-41973.html" class="superseo">���程

    分类

    OPengl C++

    demo

    #include "glad/glad.h"
    #include "glfw3.h"
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    using namespace std;
    /******************************************************/
    class Shader
    {
    public:
        unsigned int ID;
        // constructor generates the shader on the fly
        // ------------------------------------------------------------------------
        Shader(const char* vertexPath, const char* fragmentPath)
        {
            // 1. retrieve the vertex/fragment source code from filePath
            std::string vertexCode;
            std::string fragmentCode;
            std::ifstream vShaderFile;
            std::ifstream fShaderFile;
            // ensure ifstream objects can throw exceptions:
            vShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
            fShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
            try
            {
                // open files
                vShaderFile.open(vertexPath);
                fShaderFile.open(fragmentPath);
                std::stringstream vShaderStream, fShaderStream;
                // read file's buffer contents into streams
                vShaderStream 
                std::cout 
The End
微信