Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Real Noob question

  1. #1
    Newbie Newbie
    Join Date
    Aug 2016
    Posts
    1

    Real Noob question

    so i have some points to draw a shape using GL_Polygon it gives right result for convex shape i want to make concave polygon shape there are many methods written on the internet i have difficulty understanding it some one help me it will be very appreciated.


    Code :
    #include <windows.h>   // use as needed for your system
     
    #include <glut.h>
     
    //<<<<<<<<<<<<<<<<<<<<<<< myInit >>>>>>>>>>>>>>>>>>>>
    void mydisplay(void)
    {
    	glClearColor(1.0, 1.0, 1.0, 0.0);      // set the bg color to a bright white
    	glColor3f(0.0f, 1.0f, 1.0f);           // set the drawing color to black 
    	glPointSize(4.0);
    	//glutSolidCube(0.5);
    	//glutWireTeapot(1.5);
    	//set the point size to 4 by 4 pixels
    	glMatrixMode(GL_PROJECTION);// set up appropriate matrices- to be explained 
    	glLoadIdentity();// to be explained
    	gluOrtho2D(0.0, 640.0, 0.0, 480.0);// to be explained
    }
     
    //<<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>
    // the redraw function
    void myDisplay(void)
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    	glEnable(GL_STENCIL_TEST);    // clear the screen 
    	glBegin(GL_POLYGON);
     
    	glColor3f(0.0f, 1.5f, 2.5f);
     
     
     
     
     
     
    	glVertex2i(0 + 100, 0 + 100);
    	glVertex2i(2 + 100, 0 + 100);
    	glVertex2i(2 + 100, 2 + 100);
    	glVertex2i(4 + 100, 2 + 100);
    	glVertex2i(4 + 100, 0 + 100);
    	glVertex2i(6 + 100, 0 + 100);
    	glVertex2i(6 + 100, 0 + 100);
    	glVertex2i(6 + 100, 4 + 100);
    	glVertex2i(0 + 100, 4 + 100);
     
     
    	glEnd();
     
     
     
    	glFlush();		                 // send all output to display 
    }
    //<<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>
    void main(int argc, char **argv)
    {
    	glutInit(&argc, argv);          // initialize the toolkit
    	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set the display mode
    	glutInitWindowSize(800, 600);     // set the window size
    	glutInitWindowPosition(100, 150); // set the window position on the screen
    	glutCreateWindow("my Pangey"); // open the screen window(with its exciting title)
    	glutDisplayFunc(myDisplay);     // register the redraw function
    	mydisplay();
    	glutMainLoop(); 		     // go into a perpetual loop
    }

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,476
    See:

    * Drawing Filled, Concave Polygons Using the Stencil Buffer

    Basically, you draw a triangle fan using the polygon's vertices and use the stencil buffer to keep track of "inside" vs. "outside" for each pixel (or sample).

Posting Permissions

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