1 / 34

computer graphics

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

alanna
Télécharger la présentation

computer graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. computer graphics NoufNaief.net nouf200@hotmail.com TA: Nouf Al-Harbi

  2. Computer graphicslab 2 Using colors & Changing Settings ..

  3. 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

  4. 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

  5. Part 1 Examples of primitive shapes

  6. OpenGL Geometric Primitives

  7. OpenGL Geometric Primitives • Primitives are specified using glBegin( type ); … glEnd();

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

  9. 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

  10. Part 2 Using colors in OpenGL

  11. Exercise • Windows application coordinates • Create the following shape (0,1) x (-1,0) (0,0) (1,0) (0, -1)

  12. Exercise..

  13. 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

  14. 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)

  15. Exercise.. • Modify the previous code

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

  17. 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

  18. Giving Individual Vertices Different Colors • glColor3f can be used to give each vertex it's own color

  19. 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

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

  21. Part 3 Change the default settings of the window

  22. Changing GLUT defaults in Window Size `` `` Application Window Application Window Screen Screen

  23. Changing GLUT defaults in Window Position (0, 0) `` y x Application Window (x, y) Screen

  24. 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

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

  26. Exercise Solution ..

  27. Part 3 Drawing 3D Shapes

  28. 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.

  29. 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)

  30. Drawing 3d objects ..

  31. 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)

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

  33. Examples of Simple OpenGL Programs

  34. 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

More Related