Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Draw a border around a 3d subwindow

  1. #1
    Intern Contributor
    Join Date
    Mar 2008
    Posts
    91

    Draw a border around a 3d subwindow

    I would like to have a border around a subwindow. If I use ortho2D for the subwindow, then it's simple to draw a rectangle around the window (it's just a 2d rectangle). But if I use a projective subwindow, then it would be pretty hard to figure out which rectangle to draw. Is there anyway to say "for this object, forget about the current matrix stack and just draw directly to these pixels"? (writing directly to the frame buffer, i guess?)

    Thanks,

    Dave

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Draw a border around a 3d subwindow

    You can change the projection multiple times while drawing, before swpbuffers.

  3. #3
    Member Regular Contributor
    Join Date
    Jan 2004
    Posts
    322

    Re: Draw a border around a 3d subwindow

    Since that's perhaps a bit short, here's what you would do:

    1) clear the backbuffer (assuming you're using a doublebuffered window, which you should)
    2) set your projection matrix for the 3D stuff, using depth test and depth write etc
    3) render the scene
    4) disable depth test and depth write, set your orthogonal projection
    5) draw your 2D stuff (the borders)
    6) call swapbuffers and you're done

  4. #4
    Intern Contributor
    Join Date
    Mar 2008
    Posts
    91

    Re: Draw a border around a 3d subwindow

    I don't really follow.

    I have the window setup using:
    Code :
    TopViewID = glutCreateSubWindow(MainID, 700, 0, 300, 200);
    	glutSetWindow(TopViewID);
    	glutDisplayFunc(DisplayTopView);
    	gluPerspective(50, 3./2., 1, 100);
    	gluLookAt(0, 10, 0, 0, 0, 0, 1, 0, 0);

    so in the display function
    Code :
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    	DrawScene();
     
    // if i change the projection here, then it will change the view, no?
     
    	//draw the outline	
    	SetColor('w');
    	DrawRectangle(300, 200, 0, 0);
     
    	glutSwapBuffers();

    What I'm saying is that I want to leave the view however it is, and just draw a rectangle around it.

    How do you specify which buffer to draw to - and why do you need two buffers to do this?

    Thanks,

    Dave

  5. #5
    Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008
    Location
    Italy
    Posts
    352

    Re: Draw a border around a 3d subwindow

    Quote Originally Posted by David Doria
    // if i change the projection here, then it will change the view, no?
    You will change the view for the object you have to draw, but the object you have drawn are already in the framebuffer.
    ~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~

  6. #6
    Intern Contributor
    Join Date
    Mar 2008
    Posts
    91

    Re: Draw a border around a 3d subwindow

    ah of course.

    now the question is, how do I get the coords of the edge of the current view?

    If I set the view with glLookAt or gluPerspective, then I don't know what the border of the window is currently corresponding to, so I don't know how to draw a rectangle there!

    Thanks,

    Dave

  7. #7
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: Draw a border around a 3d subwindow

    Set the position and size of your subwindow with glViewport and then draw into it setting perspective projection for your 3D stuff and 2D projection for 2D stuff.

    before window transformation, coordinates are normalized coordinates and completly independant of your viewport position and size. This is you that set the rasterization area.

  8. #8
    Intern Contributor
    Join Date
    Mar 2008
    Posts
    91

    Re: Draw a border around a 3d subwindow

    From my understanding of the documentation, this should draw a rectangle around my window no matter what orientation the view currently is in:

    Code :
    glViewport(0, 0, 1, 1);
    glColor3f(1,1,1);
    glBegin(GL_LINE_LOOP);
    glVertex3f(.2, .2, 0);
    glVertex3f(.8, .2, 0);
    glVertex3f(.8, .8, 0);
    glVertex3f(.2, .8, 0);
    glEnd();

    However, it doesn't draw anything. What have I done wrong?

    Dave

  9. #9
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: Draw a border around a 3d subwindow

    glViewport take position and size in pixels and you set a 1 by 1 window size, I think it is a bit small.

  10. #10
    Intern Contributor
    Join Date
    Mar 2008
    Posts
    91

    Re: Draw a border around a 3d subwindow

    Code :
    gluPerspective(50, 3./2., 1, 20);
    gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
     
    glViewport(0,0,300,200);
    double w = 300, h = 200, x = 0, y = 0;
    glBegin(GL_LINE_LOOP);
    glVertex3f(x+1, y+1, 0);
    glVertex3f(x+1, y+h-1, 0);
    glVertex3f(x+w-1, y+h-1, 0);
    glVertex3f(x+w-1, y+1, 0);
    glEnd();

    What I get is the bottom left corner of a rectangle drawn in the top right corner of the window.

    Code :
    	//gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);//if i use this one, it draws a rectangle
    	gluLookAt(0, 10, 10, 0, 0, 0, 0, 1, 0);//if i use this one, it skews the rectangle by the perspective, just as I thought it would
     
    glViewport(0,0,300,200);
    double w = 300, h = 200, x = 0, y = 0;
    glBegin(GL_LINE_LOOP);
    glVertex3f(-x/2+1, -y/2+1, 0);
    glVertex3f(x/2-1, -y/2+1, 0);
    glVertex3f(x/2-1, y/2-1, 0);
    glVertex3f(-x/2+1, y/2-1, 0);
    glEnd();

    This does not accomplish the goal of trying to draw a rectangle around the window no matter what the perspective is. Any other suggestions?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •