Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. (PARTIALLY SOLVED ) OpenGL stencil in 2D - need some help with implementation

(PARTIALLY SOLVED ) OpenGL stencil in 2D - need some help with implementation

Scheduled Pinned Locked Moved Graphics
tutorialgraphicsgame-devdata-structureshelp
1 Posts 1 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    Addendum The "black" torroid solved! glEnable( GL_LIGHTING ); kills the display turns on "black light !!" Now working on actual stencil rendering... I am trying to implement 2D graph - Smith chart - using stencil buffer. I understand the stencil concept, but I am having issues with implementation. I found some examples, but all of them are way to complicated for my purpose. Here is my current (code) attempt , I culled from tutorial. It is very dated , so chances of discussion are nill. For test purposes I am trying to draw "torroid" and "cirle (outline)" to show only the "matching" parts. Since the "torroid" is draw in black I can see it overriding x,y coordinates lines / cross I have in my window. I sure would like somebody to help me with the actual rendering the stencil, but at present I cannot figure out HOW to change the "stencil" color from black. BTW the red circle is always draw in full - no stencil. This is "work in progress code" so pay no attention to comments or commented out code.

    void OpenGL_CodeProject(void)
    {
    // enable depth and stencil buffers
    glutInitDisplayMode(
    GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL);
    // Push the GL attribute bits so that we don't wreck any settings
    glPushAttrib( GL_ALL_ATTRIB_BITS );
    glEnable( GL_LIGHTING ); kills the display
    // Set the clear value for the stencil buffer, then clear it
    glClearStencil(0);
    glClear( GL_STENCIL_BUFFER_BIT );
    glEnable( GL_STENCIL_TEST );
    // glStencilMask is initially enable - where (?)
    glStencilMask (0xFFFFFFFFFF); // added - has no effect
    // Set the stencil buffer to write a 1 in every time
    // a pixel is written to the screen
    glStencilFunc( GL_ALWAYS, 1, 0xFFFF );
    glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
    // Render the object in black - where is "black" set ? defuult ??
    // glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
    // glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // do allow change colors in ANY (??) buffer
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // allow change colors in ANY buffer

    // draw green torroid 
    

    // glColor3f( 0.0f, 1.0f, 0.0f ); // original code - has no effect
    // RenderMesh3(); original code
    // glutSolidCube(1);
    // glutWireCube(10);

    GLfloat x, y, angle;
    //glClear( GL\_COLOR\_BUFFER\_BIT);
    glColor3f(1.0, 0.0, 0.0);       no effect    
    // window size in pixels / points
    GLint m\_viewport\[4\];
    
    glGetIntegerv( GL\_VIEWPORT, m\_viewport);
    printf(" m\_viewport
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups