当前位置: 首页>>代码示例>>C++>>正文


C++ SurfaceMesh::faces方法代码示例

本文整理汇总了C++中SurfaceMesh::faces方法的典型用法代码示例。如果您正苦于以下问题:C++ SurfaceMesh::faces方法的具体用法?C++ SurfaceMesh::faces怎么用?C++ SurfaceMesh::faces使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SurfaceMesh的用法示例。


在下文中一共展示了SurfaceMesh::faces方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init

/// OpenGL initialization
void init() {
    ///----------------------- DATA ----------------------------
    auto vpoints = mesh.get_vertex_property<Vec3>("v:point");
    auto vnormals = mesh.get_vertex_property<Vec3>("v:normal");
    assert(vpoints);
    assert(vnormals);

    ///---------------------- TRIANGLES ------------------------
    triangles.clear();
    for(auto f: mesh.faces())
        for(auto v: mesh.vertices(f))
            triangles.push_back(v.idx());

    ///---------------------- OPENGL GLOBALS--------------------
    glClearColor(1.0f, 1.0f, 1.0f, 0.0f); ///< background
    glEnable(GL_DEPTH_TEST); // Enable depth test
    // glDisable(GL_CULL_FACE); // Cull back-facing

    /// Compile the shaders
    programID = load_shaders("vshader.glsl", "fshader.glsl");
    if(!programID) exit(EXIT_FAILURE);
    glUseProgram( programID );

    ///---------------------- CAMERA ----------------------------
    {
        typedef Eigen::Vector3f vec3;
        typedef Eigen::Matrix4f mat4;

        update_projection_matrix();

        /// Define the view matrix (camera extrinsics)
        vec3 cam_pos(0,0,5);
        vec3 cam_look(0,0,-1); /// Remember: GL swaps viewdir
        vec3 cam_up(0,1,0);
        view = OpenGP::lookAt(cam_pos, cam_look, cam_up);
        // cout << view << endl;

        /// Define the modelview matrix
        model = mat4::Identity();
        // cout << model << endl;

        /// Set initial matrices
        set_uniform_matrix(programID,"M",model); ///< to get world coordinates
        set_uniform_matrix(programID,"MV",view*model); ///< to get camera coordinates
        set_uniform_matrix(programID,"MVP",projection*view*model); ///< to get clip coordinates
    }

    ///---------------------- LIGHT -----------------------------
    {
        Vec3 light_dir(0,0,1);
        set_uniform_vector(programID,"LDIR",light_dir); ///< to get camera coordinates
    }

    ///---------------------- VARRAY ----------------------------
    {
        GLuint VertexArrayID;
        glGenVertexArrays(1, &VertexArrayID);
        glBindVertexArray(VertexArrayID);
    }

    ///---------------------- BUFFERS ----------------------------
    GLuint vertexbuffer, normalbuffer, trianglebuffer;
    {
        /// Load mesh vertices
        glGenBuffers(1, &vertexbuffer);
        glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
        glBufferData(GL_ARRAY_BUFFER, mesh.n_vertices() * sizeof(Vec3), vpoints.data(), GL_STATIC_DRAW);

        /// Load mesh normals
        glGenBuffers(1, &normalbuffer);
        glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
        glBufferData(GL_ARRAY_BUFFER, mesh.n_vertices() * sizeof(Vec3), vnormals.data(), GL_STATIC_DRAW);

        /// Triangle indexes buffer
        glGenBuffers(1, &trianglebuffer);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, trianglebuffer);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, triangles.size() * sizeof(unsigned int), &triangles[0], GL_STATIC_DRAW);
    }

    ///---------------------- SHADER ATTRIBUTES ----------------------------
    {
        /// Vertex positions in shader variable "vposition"
        GLuint vposition = glGetAttribLocation(programID, "vposition");
        glEnableVertexAttribArray(vposition);
        glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
        glVertexAttribPointer(vposition, 3, GL_FLOAT, DONT_NORMALIZE, ZERO_STRIDE, ZERO_BUFFER_OFFSET);

        /// Vertex normals in in shader variable "vnormal"
        GLuint vnormal = glGetAttribLocation(programID, "vnormal");
        glEnableVertexAttribArray(vnormal);
        glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
        glVertexAttribPointer(vnormal, 3, GL_FLOAT, DONT_NORMALIZE, ZERO_STRIDE, ZERO_BUFFER_OFFSET);
    }
}
开发者ID:leonsenft,项目名称:OpenGP,代码行数:95,代码来源:main.cpp


注:本文中的SurfaceMesh::faces方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。