Upload
ginger-allen
View
219
Download
2
Tags:
Embed Size (px)
Citation preview
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
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.
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:
Graphic with Internal Angles Greater than 180
InternalAngelsBiggerThan180
Graphic with Internal Angles Greater than 180,Cont.
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();}
Output
Tree Polygons
Just take the code of first program, e.g.code of Drawing Point
#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();
}
We just modify a little in a function:
void myInit(void)
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);
}
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();}
Geometric Primitives Used in Open GL , Cont.
Geometric Primitives Used in Open GL Summery
The End