【问题标题】:incorporating "tinyobjloader" in my OpenGL project在我的 OpenGL 项目中加入“tinyobjloader”
【发布时间】:2015-03-18 15:09:48
【问题描述】:

这样我就可以加载 OBJ 文件并将它们呈现在我的 openGL 窗口中。到目前为止,我已经做到了:

我想在我的 openGL 窗口中直观地渲染这些顶点,所以我想这涉及到将两者结合起来,但问题是什么?我假设我的 openGL 上下文同化了 obj 导入器,而不是相反,而是它在代码中的位置:

#include <GLFW/glfw3.h>
#include <GLUT/glut.h>
int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */

        /* clearing */
        glClear(GL_COLOR_BUFFER_BIT);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

还是我必须从外部链接到它?

【问题讨论】:

    标签: opengl glfw .obj


    【解决方案1】:

    在 glfwMakeContextCurrent 和 while 循环之间,您应该读取 obj 并将值放入 VBO。

    它的形式是

    std::string err = tinyobj::LoadObj(shapes, materials, objStream, matSSReader);
    if (!err.empty()) {
        glfwTerminate();
        return 1;
    }
    

    然后为每个形状中的每个网格创建一个 VAO 和 VBO 放入数据中,设置 vertexAttributePointers 并保持网格中有多少个顶点。

    然后在渲染期间绑定 VAO 并绑定正确的材质并绘制。

    【讨论】:

    • 代码及其放置位置,回答了我的部分问题。然而,我希望OBJ loader 能够自动化导入复杂几何的过程,绕过将数据组织到 VB0 和 VA0 中的需要——“它可以在中等内存和时间的情况下解析 10M 以上的多边形”。此外,“Test.cc”没有提到 VB0s/VA0s。也许“obj_writer”会提供一些线索。
    猜你喜欢
    • 2021-08-10
    • 1970-01-01
    • 1970-01-01
    • 2011-01-02
    • 2019-06-12
    • 2014-07-12
    • 1970-01-01
    • 2016-01-22
    • 1970-01-01
    相关资源
    最近更新 更多