NoufNaief.net 1 TA: Nouf Al-Harbi.

Slides:



Advertisements
Similar presentations
Line and Curve Drawing Algorithms. Line Drawing x0x0 y0y0 x end y end.
Advertisements

Chapter 2: Graphics Programming
OPENGL.
© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
What is OpenGL? Low level 2D and 3D Graphics Library Competitor to Direct3D (the rendering part of DirectX) Used in: CAD, virtual reality, scientific.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
Draw a Simple Object. Example 1/4 #include “ glut.h ” void display(); void reshape(GLsizei w, GLsizei h); void main(int argc, char** argv){ glutInit(&argc,
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
1 Lecture 5 Rendering 3D graphical primitives. 2 3D Rendering Example:
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. [
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
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,
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);
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.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Review.
Lecture 2: Some definitions of terms 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net TA: Nouf Al-harbi.
Color spaces. Draw Buffers Color models. Mathmatical Protocols for defining colors with numbers  RGB Red, Green, Blue  HSV Hue, Saturation, Value(Brightness)‏
Graphics: Conceptual Model
Geometric Primitives Used in Open GL Drawing Triangles glBegin(GL_TRIANGELS); glVertex2i(p0); glVertex2i(p1); glVertex2i(p2); glVertex2i(p3); glVertex2i(p4);
Introduction to OpenGL Programming
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
CS552: Computer Graphics Lecture 6: Viewing in 2D.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
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.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL: Event-driven How in OpenGL? Programmer registers callback functions Callback function called when.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
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.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
CSC Graphics Programming
The Human Visual System vs The Pinhole camera
Draw a Simple Object.
LAB 5 Drawing Objects Lab 5 Drawing Objects.
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
גרפיקה ממוחשבת: מבוא ל-OpenGL
Introduction to OpenGL
LAB 5 Drawing Objects Lab 5 Drawing Objects.
LAB 5 Drawing Objects Lab 5 Drawing Objects.
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 2: Complete Programs
Presentation transcript:

NoufNaief.net 1 TA: Nouf Al-Harbi

Computer graphics lab 2 Using colors & Changing Settings..

Review of Lab 1 - Prepare the graphics work environment - Include OpenGL Files to your computer - Link libraries to your project - Writing the 1 st graphics program - Initialize GLUT - Create the window - Display the drawing 3

Lab 2 objectives  By the end of this lab you will be able to :  Know Examples of primitive shapes  Use Colors in OpenGL  Change the default settings of the window  Draw 3D objects 4

Part 1 Examples of primitive shapes 5

OpenGL Geometric Primitives 6

 Primitives are specified using glBegin( type ); … glEnd(); 7

Exercise  Add to the previous program the following shapes  GL_LINE_STRIP  4 lines  GL_POINTS  3 points 8

Change some properties  Points:  Size glPointSize( 4.0); //cann’t place it between Begin & end  Lines:  Width glLineWidth( 4.0); //cann’t place it between Begin & end 9

Part 2 Using colors in OpenGL 10

Exercise 11  Create the following shape  Windows application coordinates

Exercise.. 12 #include "GL\glut.h" void display() { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glVertex2f( 0,1); glVertex2f(1,0); glVertex2f(0,-1); glVertex2f(-1,0); glEnd(); glFlush(); } int main(int argc,char** argv) { glutInit(&argc,argv); glutCreateWindow("colorizing Shapes"); glutDisplayFunc(display); glutMainLoop(); }

Using RGB to Define a Color 13  There are many ways to specify a color in computer graphics  the RGB color model  one of the simplest and most widely used methods  RGB stands for the colors red, green and blue  Each of these colors is given a value  In OpenGL usually a value between 0 and 1  1 means as much of that color as possible  0 means none of that color

Using RGB to Define a Color  We can mix these three colors together to give us a complete range of colors..  pure red is represented as (1, 0, 0)  Full blue is (0, 0, 1)  White is the combination of all three (1, 1, 1)  Black is the absence of all three (0, 0, 0)  Yellow is the combination of red and green (1, 1, 0)  Orange is yellow with slightly less green (1, 0.5, 0) 14

Exercise..  Modify the previous code 15 #include "GL\glut.h" void display() { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glColor3f(0.5,0.5,1); glVertex2f( 0.0, 1); glVertex2f( 1, 0); glVertex2f(0, -1); glVertex2f(-1,0); glEnd(); glFlush(); } int main(int argc,char** argv) { glutInit(&argc,argv); glutCreateWindow("colorizing Shapes"); glutDisplayFunc(display); glutMainLoop(); }

Exercise..  Try different values for R,G,B 16

Using glColor3f Function NameParametersFunction Job Void glColor3f(Glfloat red, Glfloat green, GLfloat blue) takes 3 arguments: the red, green and blue components of the color you want. Sets the current color. After you use glColor3f, everything you draw will be in that color. 17  glcolor has two major variants  glcolor3f specify new red, green, and blue values explicitly set the current alpha value to 1.0 (full intensity) implicitly. ex: glColor3ub  its values range between 0,255  Glcolor4f specify all four color components explicitly

Giving Individual Vertices Different Colors  glColor3f can be used to give each vertex it's own color 18 #include "GL\glut.h" void display() { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glColor3f(1,0,0); glVertex2f( 0.0, 1); glColor3f(0,0,1); glVertex2f( 1, 0); glColor3f(0,1,0); glVertex2f(0, -1); glColor3f(0,0,0.3); glVertex2f(-1,0); glEnd(); glFlush(); } int main(int argc,char** argv) { glutInit(&argc,argv); glutCreateWindow("colorizing Shapes"); glutDisplayFunc(display); glutMainLoop(); }

Background Color  To Setting the Background Color we use  glClearColor(R,G,B,A)  Exercise:  Set the Background color of the previous program to GREEN 19

Graphical Tip How we can draw any shape with border.. By using just what we learned until now..?? 20

Part 3 Change the default settings of the window 21

Changing GLUT defaults in Window Size 22 Function NameParametersFunction Job void glutInitWindowSize ( int width, int height ); Width of the window Height of the window Specifies the initial height and width, in pixels, of the window `` Application Window Screen `` Application Window Screen

Changing GLUT defaults in Window Position 23 Function NameParametersFunction Job void glutInitWindowPositio n ( int x, int y ); x - the number of pixels from the left of the screen y - the number of pixels from the top of the screen. Set window position (0, 0) `` (x, y) y Application Window Screen x

When these functions should be called  All functions that change the settings of the window and the mode of display should be called before creating the window 24

Exercise  Modify the previous program to change the default settings as follows:  Window position:  100,100  Window size:  320,400 25

Exercise Solution.. 26 : int main(int argc,char** argv) { glutInit(&argc,argv); glutInitWindowPosition(100,100); glutInitWindowSize(320,400); glutCreateWindow("colorizing Shapes"); glutDisplayFunc(display); glutMainLoop(); }

Part 3 Drawing 3D Shapes 27

Drawing 3-D Objects 28  GLUT has a series of drawing routines that are used to create three dimensional models.  Each object comes in two modes  wire  solid.

Drawing 3-D Objects 29  Available objects are:  glutWireSphere (GLdouble radius, GLint slices, GLint stacks)  glutSolidSphere (GLdouble radius, GLint slices, GLint stacks)  glutWireCube (GLdouble size )  glutSolidCube (GLdouble size)  glutWireCone (GLdouble base, GLdouble height, GLint slices, GLint stacks)  glutSolidCone (GLdouble base, GLdouble height, GLint slices, GLint stacks)  glutWireTeapot (GLdouble size)  glutSolidTeapot (GLdouble size)

Drawing 3d objects.. 30

Drawing 3d objects..  We can’t differentiate between 2D objects and 3D objects without making some transformations.. (to be the topic of the next lab) 31

HW1  Write a program using OpenGL to make a simple drawing.  All details will be available on the website 32

Examples of Simple OpenGL Programs 33

REFERENCES:  Materials of this lab are prepared using:  An Introduction to Graphics Programming with OpenGL by : Toby Howard, School of Computer Science, University of Manchester  Lighthouse3d: php?1  OpenGL Programming Guide 'The Red Book’  Computer Graphics Lab -1st semester – by : Ins. Ruwaida Al-harbi & Ins. Nouf Al-harbi  g/Basics/Color 34