0

So that i can load OBJ files and have them rendered in my openGL window. So far i've managed to:

I would like to visually render these vertices in my openGL window, so i guess this involves combining the two, but how is the question? I assuming my openGL context assimilates the obj importer, not the other way round, but where in the code would it go:

#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;
}

or do I have to link to it externally?

ratchet freak
  • 47,288
  • 5
  • 68
  • 106
user4397892
  • 105
  • 2
  • 6

1 Answers1

2

between glfwMakeContextCurrent and the while loop you should read the obj and put the values into VBOs.

It would be of the form

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

then for each mesh in each shape create a VAO and VBO put in the data, setup the vertexAttributePointers and keep how many vertices are in the mesh.

Then during rendering you bind the VAO and bind the correct material and draw.

ratchet freak
  • 47,288
  • 5
  • 68
  • 106
  • The code & where to put it, answers the part of my question. However, I'd hoped the [OBJ loader](https://github.com/syoyo/tinyobjloader) would automate the process of importing complex geometry, bypassing the need to organise data into VB0s and VA0s – “It can parse 10M over polygons with moderate memory and time”. Additionally “Test.cc” doesn’t mention VB0s/VA0s. Perhaps “obj_writer” would provide some clues. – user4397892 Jan 20 '15 at 16:51