// Computer Graphics - Amir Hesami // This program shows how to draw different shapes of polygons //polygonstipples.cpp #include #pragma comment(lib, "opengl32.lib") // Link OpenGL32.lib #pragma comment(lib, "glu32.lib") // Link Glu32.lib #pragma comment(lib, "glut32.lib") // Link Glut32.lib #pragma comment(linker, "/entry:\"mainCRTStartup\"" ) // set the entry point to be main() #pragma comment(linker, "/subsystem:\"Windows\"" ) // set the entry point to be main() void display(); void init( ); int main(int argc, char** argv) { //Initialize glut and specifies command line options glutInit(&argc, argv); //Initializes opreation's mode and coloring system glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //Specifying the window's size glutInitWindowSize(500,500); //Specifying the window's position glutInitWindowPosition(100,100); //Create the window glutCreateWindow("POLYGON STIPPLES"); //Calling the drawing function glutDisplayFunc(display); init(); //Runing the program glutMainLoop(); return 0; } void display() { //Clear the window glClear(GL_COLOR_BUFFER_BIT); //Set the drawing color to red glColor3f(1.0,0.0,0.0); //specify the pattern GLubyte fillPattern[]={ 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00, 0xFF,0x00,0xFF,0x00 }; glPolygonStipple(fillPattern); glEnable(GL_POLYGON_STIPPLE); //draw unit square polygon glBegin(GL_POLYGON); glVertex2f(0.1f,0.1f); glVertex2f(0.1f,0.2f); glVertex2f(0.2f,0.2f); glVertex2f(0.2f,0.1f); glEnd(); glColor3f(1.0,1.0,0.0); glBegin(GL_QUADS); glVertex2f(0.05f,0.35f); glVertex2f(0.15f,0.3f); glVertex2f(0.25f,0.4f); glVertex2f(0.25f,0.5f); glVertex2f(0.35f,0.4f);//This will not be executed glEnd(); glColor3f(0.0,1.0,0.0); glBegin(GL_TRIANGLES); glVertex2f(0.05f,0.45f); glVertex2f(0.25f,0.6f); glVertex2f(0.15f,0.65f); glVertex2f(0.25f,0.5f);//This will not be executed glVertex2f(0.35f,0.4f);//This will not be executed glEnd(); glBegin(GL_TRIANGLE_STRIP); glVertex2f(0.4f,0.7f); glVertex2f(0.5f,0.8f); glVertex2f(0.55f,0.7f); glColor3f(1.0,0.0,0.0); glVertex2f(0.65f,0.8f);//This will not be executed glEnd(); glBegin(GL_QUAD_STRIP); glVertex2f(0.5f,0.45f); glVertex2f(0.6f,0.55f); glVertex2f(0.6f,0.45f); glVertex2f(0.7f,0.55f); glColor3f(0.0,0.0,1.0); glVertex2f(0.75f,0.45f); glVertex2f(0.85f,0.55f); glEnd(); glBegin(GL_TRIANGLE_FAN); glVertex2f(0.5f,0.15f); glVertex2f(0.65f,0.35f); glVertex2f(0.75f,0.3f); glVertex2f(0.8f,0.25f); glVertex2f(0.85f,0.15f); glEnd(); glDisable(GL_POLYGON_STIPPLE); //Flush the buffer glFlush(); } void init() { //Set the background color glClearColor(1.0,1.0,1.0,1.0); //Sets the mode of matrix operation glMatrixMode(GL_PROJECTION); //Initalizes the transformation matrix to Identity matrix glLoadIdentity(); //Viewing the image in the screen gluOrtho2D(0,1.0,0,1.0); }