Lab 3 Geometric Drawing Lab 3 Geometric Drawing.

Slides:



Advertisements
Similar presentations
© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
Advertisements

OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
Drawing Geometric Objects
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
CSE 494/598 Intro to Applied Computer Graphics Anshuman Razdan DCST AR's Web Page AR's Web Page
Computer Graphics CS 385 February 7, Fundamentals of OpenGl and Glut Today we will go through the basics of a minimal OpenGl Glut project, explaining.
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 2.
Graphics openGL and glut.
JOGL in MS Windows GDI – Graphics Device Interface (Windows-specific) OpenGL Lib JOGL Commands GDI Processor Graphics Hardware JOGL Lib.
Drawing in OpenGL CSC 2141 Introduction to Computer Graphics.
Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.
Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave.
Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 2 Initial Steps in Drawing Figures Ureerat Suksawatchon Faculty of Informatics.
Computer Graphics CS 385 January 31, Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
State Management and Drawing Geometry Objects
1. OpenGL/GLU/GLUT  OpenGL v4.0 (latest) is the “core” library that is platform independent  GLUT v3.7 is an auxiliary library that handles window creation,
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
P RACTICING O PEN GL- P RIMITIVES. O PEN GL O UTPUT P RIMITIVES  Each geometric object is described by a set of vertices and the type of primitive to.
Computer Graphics Bing-Yu Chen National Taiwan University.
Intro to OpenGL: Vertices and Drawing
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net 1 TA: Nouf Al-Harbi.
Geometric Primitives Used in Open GL Drawing Triangles glBegin(GL_TRIANGELS); glVertex2i(p0); glVertex2i(p1); glVertex2i(p2); glVertex2i(p3); glVertex2i(p4);
CSCE 441: Computer Graphics
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
OpenGL: Introduction #include main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0,
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
2002 by Jim X. Chen: Drawing Geometric Models.1. Objectives –OpenGL drawing primitives and attributes –OpenGL polygon face.
Introduction to Graphics Programming. Graphics API.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
Introduction to Graphics Programming. Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics -practical- Lecture 6. (visual c++) open gl library To use open GL with VC++ we add these files:- 1)Glut.h C:\program files\ Microsoft.
Computer Graphics Lecture 34. OpenGL Programming II Taqdees A. Siddiqi
OpenGL Programming Guide Chapter 2 Korea Univ. Graphics Labs. Ji Jun Yong Korea Univ. Graphics Labs. Ji Jun Yong.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
CSC Graphics Programming
The Human Visual System vs The Pinhole camera
CS380 Lab Spring Myungbae Son.
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
Programming with OpenGL Part 3: Three Dimensions
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Objectives OpenGL drawing primitives and attributes
Starting to draw dealing with Windows which libraries? clipping
Drawing in the plane 455.
Programming with OpenGL Part 3: Three Dimensions
Introduction to OpenGL
Line and Curve Drawing Algorithms
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Interactive Computer Graphics Graphics Programming
OpenGL program.
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Starting to draw dealing with Windows which libraries? clipping
Programming with OpenGL Part 3: Three Dimensions
Programming with OpenGL Part 2: Complete Programs
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Presentation transcript:

Lab 3 Geometric Drawing Lab 3 Geometric Drawing

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

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

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

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

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);

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

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

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

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);

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

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

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

#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(); }

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

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

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.

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

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

#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(); }

#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() { ……………. }

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

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

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

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();

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();

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

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)

// 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();

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