340 likes | 707 Views
computer graphics. NoufNaief.net nouf200@hotmail.com . 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
E N D
computer graphics NoufNaief.net nouf200@hotmail.com TA: Nouf Al-Harbi
Computer graphicslab 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 1st graphics program • Initialize GLUT • Create the window • Display the drawing
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 • Draw3D objects
Part 1 Examples of primitive shapes
OpenGL Geometric Primitives • Primitives are specified using glBegin( type ); … glEnd();
Exercise • Add to the previous program the following shapes • GL_LINE_STRIP 4 lines • GL_POINTS 3 points
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
Part 2 Using colors in OpenGL
Exercise • Windows application coordinates • Create the following shape (0,1) x (-1,0) (0,0) (1,0) (0, -1)
Using RGB to Define a Color • 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)
Exercise.. • Modify the previous code
Exercise.. • Try different values for R,G,B
Using glColor3f • 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
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
Graphical Tip How we can draw any shape with border.. By using just what we learned until now ..??
Part 3 Change the default settings of the window
Changing GLUT defaults in Window Size `` `` Application Window Application Window Screen Screen
Changing GLUT defaults in Window Position (0, 0) `` y x Application Window (x, y) Screen
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
Exercise • Modify the previous program to change the default settings as follows: • Window position: • 100,100 • Window size: • 320,400
Part 3 Drawing 3D Shapes
Drawing 3-D Objects • 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 • 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 .. • We can’t differentiate between 2D objects and 3D objects without making some transformations.. (to be the topic of the next lab)
HW1 • Write a program using OpenGL to make a simple drawing. • All details will be available on the website
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: http://www.lighthouse3d.com/opengl/glut/index.php?1 • OpenGL Programming Guide 'The Red Book’ • Computer Graphics Lab -1st semester – 2010-2011 by : Ins. Ruwaida Al-harbi & Ins. Nouf Al-harbi • http://en.wikibooks.org/wiki/OpenGL_Programming/Basics/Color