Results 1 to 5 of 5

Thread: An odd shaped Clipped window inside a gl window

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    3

    An odd shaped Clipped window inside a gl window

    I need to create a small clipped window which is a combination of a Rectangle and a Circle and Display objects that fit inside of that window clipping.

    GL_SCISSOR_TEST will not work because it is just rectangle.

    The only other solution i can find is GL_STENCIL*.

    Is there any suggestions on how to make this peculiarly shaped polygon inclusion window can be created?

    Thank you!
    Jason

  2. #2
    Junior Member Newbie
    Join Date
    Apr 2008
    Posts
    9

    Re: An odd shaped Clipped window inside a gl window

    So are you looking for a different method of creating this clip region, or do you want help using the stencil buffer?

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    3

    Re: An odd shaped Clipped window inside a gl windo

    Here is what I've got
    Code :
    glPushAttrib(GL_ALL_ATTRIB_BITS);
     
          glClearStencil(0);
          glClear(GL_STENCIL_BUFFER_BIT);
     
          glEnable(GL_STENCIL_TEST);
     
          glStencilFunc(GL_ALWAYS, 0x1, 0x1);
          glStencilOp( GL_REPLACE, GL_REPLACE, GL_REPLACE );
     
          glBegin(GL_QUADS);
             glVertex2f(x-20 , y+20);
             glVertex2f(x+20, y+20);
             glVertex2f(x+20, y-20);
             glVertex2f(x-20 , y-20);
          glEnd();
     
          glStencilFunc(GL_EQUAL, 0x1, 0x1);
          glStencilOp(GL_REPLACE, GL_REPLACE, GL_KEEP);


    Am I to understand anything written beyond the last stencilFunc and StencilOp will be written if the StencilBuffer is not 1?

    I am drawing that square, then Anything after drawing that square should not show up inside that square.

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    3

    Re: An odd shaped Clipped window inside a gl windo

    Sorry, I was in a Rush.

    The goal of that code,disregard the glPushAttrib(GL_ALL_ATTRIB_BITS), is to make any sort of shape and make anything I draw appear only in that shape, and not outside of it.

    The final product that I will be creating is an inclusion window that is in the shape of a circle/rectangle intersected, and I need a variety of different objects able to surf through that inclusion window without leaving it.

    My code as I understand it creates a stencil_buffer setting all values to zero. I then create the square setting all the squares pixels to 1. I think change the stencil to draw if it is not equal to one. For some reason when I draw anything after the end of my code, It continues to draw right past the square and inside of it. This leads me to believe stencil_buffer isn't functioning properly.

    Any help is appreciated,
    Jason

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2008
    Posts
    9

    Re: An odd shaped Clipped window inside a gl windo

    Two things come to mind:

    First, make sure you created your window with a stencil buffer. Call glGet with GL_STENCIL_BITS to check.

    Second, you don't want to write to the stencil buffer after you draw your defining rectangle. Call glStencilMask(0), or use GL_KEEP for all parameters of glStencilOp. (In this case, the first parameter is the important one to get right since you're using GL_EQUAL.)

Similar Threads

  1. Displaying a Menu bar inside OpenGL Window C++
    By ScottDurkin in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-06-2018, 06:58 AM
  2. Window is redrawn inside the OpenGL area instead of the whole window
    By Visual act in forum OpenGL: User Software
    Replies: 0
    Last Post: 09-18-2015, 06:31 AM
  3. Glut window inside C# form
    By EthanHunt in forum OpenGL: General
    Replies: 1
    Last Post: 05-03-2011, 02:49 PM
  4. How to ensure a vertex inside the window?
    By imported_davie in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-08-2010, 05:47 AM
  5. Possible approaches to cross-platrm shaped window?
    By mallyone in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-30-2009, 12:25 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