wjakob / nanogui

Minimalistic GUI library for OpenGL
Other
4.66k stars 608 forks source link

problem about framebuffer render #42

Closed ghost closed 8 years ago

ghost commented 8 years ago

hi, I came across a problem with framebuffer. below is my rendering code in drawContents(), I initialized nanogui::GLFramebuffer and ready() return OK. If rendering directly to window, it works well. Did I missed anything about framebuffer in nanogui ?

           mFramebuffer.bind();
           glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glClearDepth(1);          
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glClearColor(1.0, 0.3, 0.3, 1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glBindVertexArray(vao);
    glUseProgram(shader_progm);
    glDrawArrays(GL_TRIANGLES, 0, 3);
    glUseProgram(0);
    mFramebuffer.release();
    //mFramebuffer.downloadTGA("tmp.tga");
    // read 
    mFramebuffer.bind();
    cv::Mat dispImg;
    unsigned char* colorDisp = new unsigned char[4 * 1024 * 768];
    glReadPixels(0, 0, 1024, 768, GL_RGBA, GL_UNSIGNED_BYTE, colorDisp);
    cv::Mat _tmp = cv::Mat(768, 1024, CV_8UC4, colorDisp);
    _tmp.copyTo(dispImg);
    delete colorDisp;
    cv::imshow("Simple", dispImg);
    cv::waitKey(10);
    mFramebuffer.release();

Besides, glDrawArrays didn't work when primitive was GL_QUADS ? glGenVertexArrays returns error when Nanogui was built as shared library, I fixed it by building it as static. Is there anything I need to take care when I used my own rendering code based vao. Thx.

wjakob commented 8 years ago

Sorry, my time for support is extremely limited. If you find a specific issue in NanoGUI then please report a minimal example without external dependencies (like OpenCV).