Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.

Slides:



Advertisements
Similar presentations
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Building Models modified by Ray Wisman Ed Angel Professor of Computer Science,
Advertisements

1 Building Models. 2 Objectives Introduce simple data structures for building polygonal models ­Vertex lists ­Edge lists OpenGL vertex arrays.
2IV60 Computer graphics Graphics primitives and attributes Jack van Wijk TU/e.
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,
1 Lecture 4 Graphical primitives Rasterization: algorithmic approach Rasterization: geometric approach 2D discrete lines, triangles Discrete planes 3D.
ITEPC 06 - Workshop on Fractal Creation Chiew-Lan Tai and Oscar Au.
OpenGL and WebGL Drawing Functions CSCI 440 Day Five.
CSC 461: Lecture 6 1 CSC461 Lecture 6: 2D Programming in OpenGL Objectives:  Fundamental OpenGL primitives  Attributes  Viewport.
Reference1. [OpenGL course slides by Rasmus Stenholt]
Programming in OpenGL Ryan Holmes CSE 570 February 12 th, 2003.
JOGL in MS Windows GDI – Graphics Device Interface (Windows-specific) OpenGL Lib JOGL Commands GDI Processor Graphics Hardware JOGL Lib.
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
Using OpenGL. 2 What is OpenGL? A software interface to graphics hardware It is a Graphics Rendering API (Application Programmer’s Interface) that is.
INTRO TO COMPUTER GRAPHICS TEXT EDWARD ANGEL: EDITION 5 CS770/870
Interactive Computer Graphics Lecture 2: The programming approach to building graphical applications using OpenGL API.
Computer Graphics CS 385 January 31, Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
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,
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.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
Computer Graphics Bing-Yu Chen National Taiwan University.
Lecture 2: Some definitions of terms 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Introduction to OpenGL. OpenGL is a low-level graphics library specification. It makes available to the programmer  a small set of geometric primitives.
Intro to OpenGL: Vertices and Drawing
NoufNaief.net TA: Nouf Al-harbi.
NoufNaief.net 1 TA: Nouf Al-Harbi.
What are Computer Graphics Basically anything that is on you Monitor – This includes the text that you will see Text isn’t Advanced Graphics But…. Understanding.
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
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
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,
CIS 681 Review: OpenGL. CIS 681 Command Syntax OpenGL commands start with a gl. This is followed by the base command such as Color. Followed by the number.
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
Introduction to OpenGL (INF 250) Veronika Solteszova et al., UiB Dept. of Informatics,
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL Based on GL (graphics library) by Silicon Graphics Inc. (SGI) Advantages: Runs on everything, including.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL: Event-driven How in OpenGL? Programmer registers callback functions Callback function called when.
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
Administrivia Back on track: canceling OpenGL lecture 2 Assignment 1
CSC Graphics Programming
Introduction to OpenGL
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
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.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Starting to draw dealing with Windows which libraries? clipping
Drawing in the plane 455.
Introduction to OpenGL
Primitive Objects Lecture 6 Wed, Sep 5, 2007.
Line and Curve Drawing Algorithms
Color and Shading Lecture 9 Mon, Sep 26, 2005.
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
Introduction to OpenGL
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003

OpenGL Functions OpenGL function names always begin with gl, glu, or glut, depending on the library. Names of functions that allow a variable number of arguments are followed by a digit indicating the number. Names of functions that allow various argument types are followed by a letter indicating the type.

State Variables OpenGL maintains a large number of state variables. These state variables are global – they are in effect and accessible within all functions. Some states are Colors used in various situations. Shading effects. Lighting effects.

Setting the Color One of the states maintained is the current color used for drawing. The color is a combination of red, green, and blue. Use glColor*() to set the current color. glColor3f(1.0, 0.0, 0.0) – bright red. glColor3f(1.0, 1.0, 0.0) – bright yellow. glColor3f(0.5, 0.5, 0.5) – medium gray.

Drawing Dots To color a single pixel, use the glVertex*() function. glVertex2i(int, int). glVertex3f(float, float, float), etc. The pixel is colored with the current color, as set by glColor(). The coordinates are in “world” coordinates, not screen coordinates.

Primitive Objects The pixel-drawing function is called glVertex() because the pixel is typically a vertex in a polygon. The programmer must indicate to the GPU whether the point is an isolated point or part of a line or polygon. To do this, use glBegin() and glEnd() to enclose the vertices of the primitive objects.

Primitive Objects glBegin(type) defines the type of object to be drawn. Some values of type aretype GL_POINTS GL_LINES GL_TRIANGLES GL_POLYGON glEnd() marks the end of the object.

Creating Points The following program segment will draw three pixels. glBegin(GL_POINTS); glVertex2i(10, 20); glVertex2i(50, 20); glVertex2i(50, 50); glEnd():

Creating Triangles The following program segment will draw and fill a triangle. glBegin(GL_TRIANGLES); glVertex2i(10, 20); glVertex2i(50, 20); glVertex2i(50, 50); glEnd():

Creating Triangles The following program segment will draw, but not fill, a triangle. glBegin(GL_LINE_LOOP); glVertex2i(10, 20); glVertex2i(50, 20); glVertex2i(50, 50); glEnd():

Drawing Primitives For points, the size of the drawing pen is set by the function glPointSize(size). For lines, the pen width is defined by the function glLineWidth(width). The size and width are measured in pixels.

Example: DrawDots DrawDots.cpp Why does each dot disappear when the next dot is drawn? How could we modify the program so that all the dots remained?  Do not clear the buffer, but keep adding to it?  Store all the points in a list and draw each one every time? What happens when the window is resized?

Making Line Drawings Drawing lines is similar to drawing points and triangles. Use glBegin(GL_LINES); Every pair of points drawn between glBegin() and glEnd() is rendered as a line. We may list many pairs of points.

Example: Draw an X The following program segment will draw two line segments that form an X. glBegin(GL_LINES); glVertex2i(50, 50); glVertex2i(100, 100); glVertex2i(50, 100); glVertex2i(100, 50); glEnd();

Example: Draw an X DrawX.cpp

Drawing Polygons If we use GL_POLYGON in the glBegin() function, then the entire list of points is used to draw a single polygon. What would the last example look like? Why not use GL_POLYGON to draw several polygons in one group, just as with GL_LINES?

Example: Draw an Octagon The following program segment will draw a regular octagon. int cx = 100, cy = 100; glBegin(GL_POLYGON); for (int i = 0; i < 8; i++) { float dx = cos(i*PI/4); float dy = sin(i*PI/4); glVertex2i(x + 100*dx, y + 100*dy); } glEnd();

Example: Draw an Octagon DrawOctagon.cpp