18

Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

Embed Size (px)

Citation preview

Page 1: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave
Page 2: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

Geometric Primitives Used in Open GL

Page 3: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

Polygons

• Polygon is : Flat shape with three or more straight sides.

• It could be either : convex or concave .

Page 4: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

Examples of polygons

Page 5: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

The Gl_POLYGON Argument

• The Gl_POLYGON argument : draw close convex polygon which has n points and n>=3.

• To draw a graphic with internal angles greater than 180

degree: we need to separate it to many convex polygons.

Page 6: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

Drawing Polygon

glBegin(GL_POLYGON);

glVertex2i(p0);

glVertex2i(p1);

glVertex2i(p2); glVertex2i(p3);

glVertex2i(p4); glVertex2i(p5);

glVertex2i(p6); glVertex2i(p7);

glEnd( );

• There are one glBegin () arguments to draw polygons:

Page 7: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

Graphic with Internal Angles Greater than 180

InternalAngelsBiggerThan180

Page 8: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

Graphic with Internal Angles Greater than 180,Cont.

Page 9: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

Example Tree Polygons#include<windows.h>#include<gl/Gl.h>#include<gl/glut.h>void myInit(void);void myDisplay(void);void main(int argc,char** argv) {

glutInit(&argc,argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(200,200); glutInitWindowPosition(100,100); glutCreateWindow(”Tree"); glutDisplayFunc(myDisplay); myInit(); glutMainLoop();

}void myInit(void) {

glClearColor(1.0,1.0,1.0,1.0); gluOrtho2D(0,600,0,600);}

void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT);

األخضر دالة الشجرة رأس ويمثل المضلع رسم // glColor3f(0.0,0.5,0.2) glBegin(GL_POLYGON); glVertex2i(40,80); glVertex2i(60,80); glVertex2i(80,60); glVertex2i(60,40); glVertex2i(40,40); glVertex2i(20,60); glEnd();

البني الشجرة جذع وهو المضلع رسم // دالة glColor3f(0.3,0.2,0.2) glBegin(GL_POLYGON); glVertex2i(60,40); glVertex2i(40,40); glVertex2i(40,10); glVertex2i(60,10); glEnd(); glFlush();}

Page 10: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

Output

Tree Polygons

Page 11: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

Just take the code of first program, e.g.code of Drawing Point

Page 12: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

#include<windows.h>#include<gl/Gl.h>#include<gl/glut.h>

void myInit(void);void myDisplay(void);void main(int argc,char** argv) {

glutInit(&argc,argv);

//argc= arg count, specifies no. of arguments//argv= arg values, specifies values of those arguments

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(600,600); glutInitWindowPosition(100,100); glutCreateWindow("My first program");

glutDisplayFunc(myDisplay); myInit(); glutMainLoop();

}

void myInit(void) {

glClearColor(1.0,1.0,1.0,1.0); glColor3f(0.0,0.0, 0.0); glPointSize(50.0); gluOrtho2D(0,600,0,600);

}

void myDisplay(void) {

glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); glVertex2i(300,300); glEnd(); glFlush();

}

Page 13: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

We just modify a little in a function:

void myInit(void)

Page 14: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

Code for point

void myDisplay(void)

{

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_POINTS);

glVertex2i(300,300);

glEnd();

glFlush();

}

Code for simple triangle

void myDisplay(void)

{

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_TRIANGLES);

glVertex2i(0,0);

glVertex2i(300,600);

glVertex2i(600,0);

glEnd();

glFlush();

}

Code for drawing a point Code for simple triangle

void myInit(void)

{

glClearColor(1.0,1.0,1.0,1.0);

glColor3f(0.0,0.0, 0.0);

glPointSize(50);

gluOrtho2D(0,600,0,600);

}

void myInit(void)

{

glClearColor(1.0,1.0,1.0,1.0);

glColor3f(0.0,0.0, 0.0);

nothing

gluOrtho2D(0,600,0,600);

}

Page 15: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

Code for point

void myDisplay(void)

{

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_POINTS);

glVertex2i(300,300);

glEnd();

glFlush();

}

Code for simple triangle

void myDisplay(void)

{

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_TRIANGLES);

glVertex2i(0,0);

glVertex2i(300,600);

glVertex2i(600,0);

glEnd();

glFlush();

}

Code for drawing a point Code for simple line

void myDisplay(void) {

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_POINTS);

glVertex2i(300,300);

glEnd();

glFlush();}

void myDisplay(void) {

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_POLYGON);

glVertex2i(P1); : : :

glVertex2i(Pn);

glEnd();

glFlush();}

Page 16: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

Geometric Primitives Used in Open GL , Cont.

Page 17: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

Geometric Primitives Used in Open GL Summery

Page 18: Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave

The End