Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 3 Geometric Drawing Lab 3 Geometric Drawing.

Similar presentations


Presentation on theme: "Lab 3 Geometric Drawing Lab 3 Geometric Drawing."— Presentation transcript:

1 Lab 3 Geometric Drawing Lab 3 Geometric Drawing

2  General format of the programs  Geometric Drawing Primitives  Drawing shapes
 Drawing a point  Drawing line

3 Format Description #include < windows.h > call Library glut And all libraries #include <GL/glut.h> needed by the programmer Global variables Global variables void draw(void) Graphic data functions } Graphic data functions { void main() main function { the function be called in the } main

4 glutCreateWindow(char *name);
Create a window under the name OpenGL Example: glutCreateWindow("OpenGL");

5 glutInitWindowSize( int width, int height)
Control the height and width of the drawing window Example: glutInitWindowSize(400,400);

6 glutInitWindowPosition( int x, int y);
Determine the place of drawing window on the computer screen. It is not a requirement of writing this function because the window appear in the default point of origin. The point of origin always be in the upper left corner of the computer screen Example: glutInitWindowPosition(0,0);

7 GlutInitDisplayMode(int mode);
Determine the display mode of the window  Mode -> GLUT_RGB, GLUT_RGBA Indicate that the window will be used to display system colors  Mode -> GLUT_SINGLE Indicate that we will open a window with one memory, Always used with this mode glFlush();  Mode -> GLUT_DOUBLE Indicate that we will open a window with two memory, Is used when we have animation Always used with this mode glSwapBuffers();  Mode ->GLUT_DEPTH Indicate that we will open a window with memory depth (Three- dimensional programming )  The default value Mode -> GLUT_RGBA l GLUT_SINGLE

8 glClearColor(red, green, blue, alpa); -> RGBA
glClearColor(red, green, blue); -> RGB Determine the background color

9 R G B 190 63 218 190/255 63/255 218/255 0.74 0.24 0.85 Extract a color from any painting program such as paint or photoshop programs, then use either: glColor3f(0.74, 0.24, 0.85); RGB or glColor3ub(190, 63, 218); RGB

10 glClear(mask); mask -> The type of memory used for the Clear  mask -> GL_COLOR_BUFFER_BIT (This always used) GL_DEPTH_BUFFER_BIT Example : glClear(GL_COLOR_BUFFER_BIT);

11 glutDisplayFunc(Graphic data functions );
used to see the Graphic data functions Example: glutDisplayFunc(draw); glutMainLoop(); Does not display windows painted so we have to put at the end of the program

12 gluOrtho2D (GLdouble left , GLdouble right , GLdouble bottom ,GLdouble top);
 Left -> xmin  Right -> xmax  Bottom -> ymin  Top -> ymax

13 glOrtho (GLdouble left , GLdouble right ,
GLdouble bottom , GLdouble top , GLdouble zNear , GLdouble zFar) ;  Left -> xmin  Right -> xmax  Bottom -> ymin  Top -> ymax  Near -> zNear  Far -> zFar

14 #include <windows.h> #include <GL/glut.h>
void draw(void) { glClear(GL_COLOR_BUFFER_BIT); glFlush(); } void main() { glutInitWindowSize(200,200); glutInitDisplayMode(GLUT_RGB); glutCreateWindow("Empty Screen"); glOrtho(0.0, 100.0, 0.0, 100.0, 0.0, 1.0); glClearColor(0.95, 0.90, 0.85, 0.0); glutDisplayFunc(draw); glutMainLoop(); }

15 Any shape is drawn through the points By the function
glVertex* (); (……..) 2 d,f,i x,y 3 d,f,i x,y,z 4 d,f,i x,y,z,t

16 Points of any shape limited between two functions
glBegin(mode); glVertex* (…); glEnd();

17 After understanding how to specify vertices, you still need to tell OpenGL to create a set of points, a line, or a polygon from those vertices. To do this, you bracket each set of vertices between a call to glBegin() and a call to glEnd(). The argument passed to glBegin() mode determines what sort of geometric primitive is constructed from the vertices.

18 Mode Point GL_POINTS Line GL_LINES GL_LINE_STRIP GL_LINE_LOOP Triangle GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN Quads GL_QUADS GL_QUAD_STRIP Polygon GL_POLYGON

19

20 we will learn how to draw a point x=50 , y=50
glBegin(GL_POINTS); glVertex2i (50,50); glEnd();  glColor3f(red, green, blue); Used for coloring any point or shape  glPointSize(size); Control the size of the point

21 #include <windows.h>
#include <GL/glut.h> void draw(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.4, 0.4, 0.6); glPointSize(10); glBegin(GL_POINTS); glVertex2i(50,50); glEnd(); glFlush(); } void main() { glutInitWindowSize(160,160); glutInitDisplayMode(GLUT_RGB); glutCreateWindow("Point"); glOrtho(0.0, 100.0, 0.0, 100.0, 0.0 glClearColor(0.95, 0.90, 0.85, 0.0) glutDisplayFunc(draw); glutMainLoop(); }

22 #include <windows.h> #include <GL/glut.h>
void draw(void) { glClear(GL_COLOR_BUFFER_BIT); glPointSize(4); glBegin(GL_POINTS); glColor3f(0, 0, 1); glVertex2i(40,40); glEnd(); glPointSize(10); glBegin(GL_POINTS); glColor3f(0.8, 0.5, 0.0); glVertex2i(50,50); glEnd(); glPointSize(20); glBegin(GL_POINTS); glColor3f(0.5, 0.0, 0.2); glVertex2i(60,60); glEnd(); glFlush(); } void main() { ……………. }

23 glBegin(mode); …… glVertex* (…); glEnd(); •Mode to draw Line GL_LINES GL_LINE_STRIP GL_LINE_LOOP

24 GL_LINES pairs of vertices interpreted as individual line segments glBegin (GL_LINES); glVertex2i (p1); glVertex2i (p2); glEnd();

25 glBegin (GL_LINES); glVertex2i (V0);
glVertex2i (V2); glVertex2i (V3); glVertex2i (V4); glVertex2i (V5); glVertex2i (V6); glVertex2i (V7); glEnd();

26 GL_LINE_STRIP series of connected line segments glBegin (GL_LINE_STRIP); glVertex2i (p1); glVertex2i (p2); glVertex2i (p3); glVertex2i (p4); glVertex2i (p5); glVertex2i (p6); glEnd();

27 GL_LINE_LOOP same as above, with a segment added between last and first vertices glBegin (GL_LINE_LOOP); glVertex2i (p1); glVertex2i (p2); glVertex2i (p3); glVertex2i (p4); glVertex2i (p5); glVertex2i (p6); glEnd();

28 Void glLineWidth(GLfloat Width);  Line Color
glColor3f(red , green , blue);  Line Style Void glLineStipple(GLint factor , GLushort pattern);

29

30 How can we write this function in the program
glEnable(GL_LINE_STIPPLE) glLineStipple(factor , pattern); glDisable(GL_LINE_STIPPLE) Example: glEnable(GL_LINE_STIPPLE) glLineStipple(1 , 0XFF); glDisable(GL_LINE_STIPPLE)

31 // Font Size glLineWidth (3.0); // Line Styles Enable Function glEnable (GL_LINE_STIPPLE); // Font Color glColor3f (0.0, 0.0, 0.0); // Line Style glLineStipple (1, 0x1111); // Line Drawing Function glBegin(GL_LINES); glVertex2f (0, 0); glVertex2f (30, 0); glEnd();

32 Write c++ program to draw lines like the following window.


Download ppt "Lab 3 Geometric Drawing Lab 3 Geometric Drawing."

Similar presentations


Ads by Google