Results 1 to 6 of 6

Thread: superimpose two different viewport and projection

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    9

    superimpose two different viewport and projection

    Hi,

    in the Draw() function of a GLForm (openGL with borland builder), I first draw an image with a SDK function called capture_card:aintGL(). And this function compells to have this projection before being called :

    glViewport(0, 0, (GLsizei)newSize.width, (GLsizei)newSize.height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
    glMatrixMode(GL_MODELVIEW);


    And on foreground of this painted image, i have to draw an other layer which has been allready coded for another viewport and another glortho projection :

    (in the MainResizeGL() called on "onResize" events) :

    glViewport(-width, -height, width * 2, height * 2);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(double(-width)*viewport_ratio, double(width)*viewport_ratio, double(-height), double(height), 1000.0, 100000.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();


    (and in the MainDraw() called by a "Ontimer") :

    glLoadIdentity();
    glTranslatef(0.0, 0.0, -50000.0);
    mpGLDrawScene->DrawScene(); //(this calls a doDrawScene() I don't understand exactly how it draws : with calling this->parent, etc.)
    glFlush();
    SwapBuffers(ghDC);


    So I transformed the MainDraw() to the following :

    // viewport and projection needed for the paintGL
    glViewport(0, 0, (GLsizei)newSize.width, (GLsizei)newSize.height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

    glMatrixMode(GL_MODELVIEW);

    // call of the paintGL
    if(capture_button_clicked) capture_card:aintGL();

    // content of the ResizeGL in order to get back to the projection desired and to matrixmode modelview
    glViewport(-width, -height, width * 2, height * 2);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(double(-width)*viewport_ratio, double(width)*viewport_ratio, double(-height), double(height), 1000.0, 100000.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // original drawscene call

    glLoadIdentity();
    glTranslatef(0.0, 0.0, -50000.0);
    mpGLDrawScene->DrawScene(); //(this calls a doDrawScene() I don't understand exactly how it draws : with calling this->parent, etc.)
    glFlush();
    SwapBuffers(ghDC);


    The result is that I see the ancient project's "drawscene" items but when I click on the "capture_button" the paintGL remains invisible and the items drawn turn into something like an alpha-channel canva.

    I tried to add glScalef(width, height, 1) after the paintGL, changed the glTranslatef(0,0,50000) with the result that I saw a small amount of pixel with the colors of the paintGL, but the overlay items then disappear.

    How could I get these two different viewport to superimpose (i.e. the drawscene above the paintGL) ?

    Thanks in advance, cheers, Arnaud.

  2. #2
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: superimpose two different viewport and projection

    You probably need to clear the depth buffer between drawing the two scenes - unless you want objects from the first scene to occlude objects from the second one?

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    4

    Re: superimpose two different viewport and projection

    I something like this as well - render some thing in ortho and some things in a frustrum, to the same window. It works ok for me. The previous poster's suggestion about clearing the depth buffer is probably the key.

    Here's my painting function. I do 2D first and then 3D. Feel free to steal whatever may apply:

    GL::FlipOnExit flipper(GL::hDC);
    glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );

    RECT r;
    GetClientRect(Windex::hWnd_, &r);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, r.right, 0, r.bottom, -1, 1);
    glViewport(0, 0, r.right, r.bottom);

    //2d objects here
    glDisable(GL_CULL_FACE);
    glDisable(GL_LIGHTING);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //Sort by depth; we need to draw back to front

    //Make sure deletes elsewhere do no harm
    Collection<Widget>::Iterator stablizer(Windex::widgets);

    //copy pointers to the valid drawables
    std::vector<Widget*> worklist;
    for (Collection<Widget>::Iterator i(Windex::widgets); i.next(); )
    {
    Windex::Widget* c = *i;
    if (c &amp;&amp; c->isVisible())
    worklist.push_back(c);
    }
    //sort by z depth
    std::sort(worklist.begin(), worklist.end(), Widget::depthSort);
    //draw
    for (std::vector<Widget*>::iterator w = worklist.begin(); w != worklist.end(); ++w)
    {
    Windex::Widget* c = *w;

    if (!c->is3D())
    c->draw();
    else
    c->drawBorder(); //only chance to put borders around 3d canvases
    }

    //do 3d objects here
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0,
    30000000000.0);

    glClear(GL_DEPTH_BUFFER_BIT);
    glDisable(GL_BLEND);
    glEnable(GL_DEPTH);
    glEnable(GL_CULL_FACE);
    for (Collection<Widget>::Iterator i(Windex::widgets); i.next(); )
    {
    Windex::Widget* c = *i;
    if (c &amp;&amp; c->is3D())
    c->draw();
    }
    //flip happens here

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    9

    Re: superimpose two different viewport and projection

    Thanks ! clearing only depth_buffer makes my viewports match !

    But I now have a problem of alpha compositing :

    Here is the background video stream (paintGL()):


    And here is the image I wish to superimpose on it (with the drawScene())


    But here is what I obtain :


    Why just calling paintGL and then drawScene() does not superimpose correctly the two images ?

    In the bSetupPixelFormat(HDC hdc), these flags are called :
    ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_TYPE_RGBA;

    Cheers, Arnaud.

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    9

    Re: superimpose two different viewport and projection

    youhRRaah !

    I found my answer in this thread, just next to mine :

    http://www.opengl.org/discussion_boards/...;gonew=1#UNREAD

    => I added this :
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_MODULATE);

    just after the glBlend and glBlendFuncSeparate calls.

    And it's perfect ... still remains the question why gl_modulate.

  6. #6
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: superimpose two different viewport and projection

    Quote Originally Posted by Arnaud
    And it's perfect ... still remains the question why gl_modulate.
    Check ZBuffer's reply to a thread 2 threads below this thread
    http://www.opengl.org/discussion_boa...689#Post292689
    Regards,
    Mobeen

Similar Threads

  1. Replies: 1
    Last Post: 03-05-2016, 09:36 AM
  2. Updating projection matrix after changing viewport aspect ratio
    By madmax1 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 06-03-2014, 01:22 PM
  3. Tweaking the projection matrix if viewport resizes
    By eyebex in forum OpenGL: General
    Replies: 7
    Last Post: 01-25-2009, 09:10 AM
  4. viewport and projection...
    By gunslinger in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-26-2005, 07:41 AM
  5. Can concatenate projection matrix with viewport transformation matrix?
    By MelvinEng in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 07-07-2002, 10:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean