color models 9/12/20151a.aruna/assistant professor/snsce

83
COLOR MODELS 03/27/22 1 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Upload: brianna-campbell

Post on 27-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

COLOR MODELS

04/19/23 1A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 2: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

INTRODUCTION

• Mechanisms for generating color displays with combinations of red, green, and blue light

• understanding how color is represented on a video monitor

• Color model is a method for explaining the properties or behavior of color within some particular context.

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

2

Page 3: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

PROPERTIES OF LIGHT

• Light, or different colors, is a narrow frequency band within the electromagnetic spectrum

• Other frequency bands within this spectrum are called

– radio waves, – microwaves, – infrared wave– X-rays

• Each frequency value within the visible band corresponds to a distinct color

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

3

Page 4: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

4

Page 5: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

PROPERTIES OF LIGHT

• Low frequency end is a red color (4.3 X 10" hertz) reds through orange and yellow

• Highest Frequency end is a violet color (7.5 X 10" hertz). green, blue, and violet

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

5

Page 6: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

PROPERTIES OF LIGHT

• Light is an electro magnetic wave

• Various colors are described in terms of either the frequency f or wave length λ of the wave.

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

6

Page 7: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

PROPERTIES OF LIGHT

• wavelength and frequency of the

monochromatic wave are inversely proportional

to each other

with the proportionality constant as the speed of

light c where c = fλ

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

7

Page 8: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

• Frequency component is constant(for all material)

• Speed of light and wavelength is dependent(based on materials)

• In a Vacuum, c = 3 x 10 10 cm.

• Wavelength are very small, units can be calculated in terms of Angstroms( 1Å = 10 -8 cm ) or nanometres ( 1 nm = 10 -7 cm)

• Equivalent term of nanometre is millimicron

• More convenient to deal with frequency units (Spectral colors specified in Wave lenght)

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

8

Page 9: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

9

Page 10: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

PROPERTIES OF LIGHT

• A light source such as the sun or a light bulb emits all frequencies within the visible range to produce white light.

• When white light is incident upon an object, some frequencies are reflected and some are absorbed by the object.

• The combination of frequencies present in the reflected light determines what we perceive as the color of the object

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

10

Page 11: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

PROPERTIES OF LIGHT

• If low frequencies are predominant in the reflected light, the object is described as red.

• In this case, the perceived light has the dominant frequency at the red end of the spectrum.

• The dominant frequency is also called the hue, or simply the color of the light

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

11

Page 12: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

PROPERTIES OF LIGHT

• Brightness is another property, which in the perceived intensity of the light.

• Intensity in the radiant energy emitted per limit time, per unit solid angle, and per unit projected area of the source.

• Radiant Energy is related to the luminance of the source

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

12

Page 13: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

• The next property in the purity or saturation of the light.Purity describes how washed out or how

pure the color of the light appears.Pastels and Pale colors are described as

less pure.

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

13

Page 14: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Physical properties of light

Energy spectrum for a light source with a dominant frequency near the red color

04/19/23 14A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 15: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

• The term chromaticity is used to refer collectively to the two properties, purity and dominant frequency.

• Two different color light sources with suitably chosen intensities can be used to produce a range of other colors.

• If the 2 color sources combine to produce white light, they are called complementary colors.

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

15

Page 16: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

• Color models that are used to describe combinations of light in terms of dominant frequency use 3 colors to obtain a wide range of colors, called the color gamut.

• The 2 or 3 colors used to produce other colors in a color model are called primary colors.

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

16

Page 17: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Color definitions

Complementary colors - two colors combine to produce white light

Primary colors - (two or) three colors used for describing other colors

Two main principles for mixing colors:

• additive mixing

• subtractive mixing

04/19/23 17A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 18: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Additive mixing

• pure colors are put close to each other => a mix on the retina of the human eye (cp. RGB)

• overlapping gives yellow, cyan, magenta and white

• the typical technique on color displays

04/19/23 18A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 19: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Subtractive mixing

• color pigments are mixed directly in some liquid, e.g. ink

• each color in the mixture absorbs its specific part of the incident light

• the color of the mixture is determined by subtraction of colored light, e.g. yellow absorbs blue => only red and green, i.e. yellow, will reach the eye (yellow because of addition)

04/19/23 19A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 20: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Subtractive mixing,cont’d

• primary colors: cyan, magenta and yellow, i.e. CMY

• the typical technique in printers/plotters

• connection between additive and subtractive primary colors (cp. the color models RGB and CMY)

04/19/23 20A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 21: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Additive/subtractive mixing

04/19/23 21A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 22: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

RED GREEN BLUE MODEL

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

22

Page 23: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

HUMAN COLOR SEEING

The retina of the human eye consists of cones (7-8M),”tappar”, and rods (100-120M), ”stavar”, which are connected with nerve fibres to the brain

04/19/23 23A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 24: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

HUMAN COLOR SEEING CONT’D

Theory: the cones consist of various light absorbing materialThe light sensitivity of the cones and rods varies with the wavelength, and between personsThe ”sum” of

• the energy spectrum of the light• the reflection spectrum of the object• the response spectrum of the eye

decides the color perception for a person

04/19/23 24A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 25: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

RGB model

• all colors are generated from the three primaries• various colors are obtained by changing the

amount of each primary• additive mixing (r,g,b), 0≤r,g,b≤1

04/19/23 25A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 26: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

RGB MODEL CONT’D

• the RGB cube

• 1 bit/primary => 8 colors, 8 bits/primary => 16M colors

04/19/23 26A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 27: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

YIQ COLOR MODEL

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

27

Page 28: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

INTRODUCTION

• National Television System Committee (NTSC)

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

28

luminance (brightness) Y

chromaticity information (hue and purity) I and Q

Y Luminanceblack and white

TV monitors – use only Y Signal

I hueorange-cyan

flash-tone shadingbandwidth of 1.5 MHz

Q hue informationgreen-magenta

bandwidth of about 0.6 MHz

Page 29: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

29

Page 30: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

CMY MODEL

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

30

Page 31: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

CMY model

• cyan, magenta and yellow are complementary colors of red,green and blue, respectively

• subtractive mixing• Typical printer technique

04/19/23 31A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 32: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

CMY MODEL CONT’D

• almost the same cube as with RGB; only black<-> white

• the various colors are obtained by reducing light, e.g. if red is absorbed => green and blue are added, i.e cyan

04/19/23 32A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 33: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

HSV MODEL

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

33

Page 34: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

HSV MODEL

• HSV stands for Hue-Saturation-Value

• described by a hexcone derived from the RGB cube

04/19/23 34A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 35: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

HSV model,cont’d

• Hue (0-360°); ”the color”, cp. the dominant wave-length (128)

• Saturation (0-1); ”the amount of white” (130)

• Value (0-1); ”the amount of black” (23)

04/19/23 35A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 36: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

36

Page 37: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

HSV model,cont’d

The numbers given after each ”primary” are estimates of how many levels a human being is capable to distinguish between, which (in theory) gives the total number of color nuances:

128*130*23 = 382720

In Computer Graphics, usually enough with:

128*8*15 = 16384

04/19/23 37A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 38: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

HLS model

Another model similar to HSV

L stands for Lightness

04/19/23 38A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Page 39: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

ANIMATION

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

39

Page 40: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Introduction

• Time sequence of visual changes in a scene

• Generated by changing camera parameters such as position, orientation and focal length.

• Applications Entertainment Advertising training education

Example : Advertising animations often transition one object shape into another

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

40

Page 41: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

ANIMATION DEMO

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

41

Page 42: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

ANIMATION DEMO

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

42

Page 43: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

FRAME-BY-FRAME ANIMATION

• Each frame of the scene is separately generated and stored.

• Frames can be recoded on film or they can be consecutively displayed in "real-time playback" mode

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

43

Page 44: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

FRAME-BY-FRAME ANIMATION

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

44

Page 45: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

DESIGN OF ANIMATION SEQUENCES

Animation sequence in designed with the following steps:

•Story board layout

•Object definitions

•Key-frame specifications

•Generation of in-between frames

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

45

Page 46: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

STORY BOARD LAYOUT

• Outline of the action.

• Motion sequences : set of basic events that are to take place.

• Rough sketches or a list of the basic ideas for the motion.

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

46

Page 47: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

STORY BOARD LAYOUT

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

47

Page 48: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

STORY BOARD LAYOUT

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

48

Page 49: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

OBJECT DEFINITION

• Each participant in the action

• Movements of each object are specified along with the shape

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

49

Page 50: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

KEY FRAME

• Detailed drawing of the scene at a certain time in the animation sequence.

• Each object is positioned according to the time for that frame.

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

50

Page 51: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

KEY FRAME

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

51

Page 52: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

KEY FRAME

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

52

Page 53: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

IN-BETWEENS

• Intermediate frames between the key frames.

• Film requires 24 frames per second and graphics terminals are refreshed at the rate of 30 to 60 frames per seconds.

• Time intervals for the motion are setup so there are from 3 to 5 in-between for each pair of key frames.

• Depending on the speed of the motion, some key frames can be duplicated.

• For a 1 min film sequence with no duplication, 1440 frames are needed.

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

53

Page 54: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

IN-BETWEENS

Other required tasks are

•Motion verification

•Editing

•Production and synchronization of a sound track.

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

54

Page 55: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

GENERAL COMPUTER ANIMATION FUNCTIONS

• Steps in the development of an animation sequence are Object manipulation and rendering Camera motion Generation of in-betweens

• Animation packages wave front for designing and processing

individual objects store and manage the object database Object shapes and associated parameter are

stored and updated in the database

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

55

Page 56: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

GENERAL COMPUTER ANIMATION FUNCTIONS

• Motion : generated according to specified constraints using 2D and 3D transformations.

• Standard functions : applied to identify visible surfaces and apply the rendering algorithms.

• Camera movement functions such as zooming, panning and tilting are used for motion simulation.

• Given the specification for the key frames, the in-betweens can be automatically generated.

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

56

Page 57: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

RASTER ANIMATIONS

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

57

Page 58: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Introduction

• On raster systems, real-time animation in limited applications can be generated using raster operations.

• To produce real time animation of either 2D or 3D objects.

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

58

Page 59: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Introduction

• Animate objects along 2D motion paths using the color-table transformations. Predefine the object as successive positions along the

motion path : set the successive blocks of pixel values to color table entries.

Set the pixels at the first position of the object to „on‟ values, and set the pixels at the other object positions to the background color.

The animation is accomplished by changing the color table values

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

59

Page 60: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Computer Animation Languages

• Graphics editor

• Scene description includes the positioning of objects and light sources defining the photometric parameters and setting the camera parameters.

• Action specification involves the layout of motion paths for the objects and camera.

• Keyframe systems are specialized animation languages designed dimply to generate the in-betweens from the user specified keyframes

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

60

Page 61: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Computer Animation Languages

• Parameterized systems allow object motion characteristics to be specified as part of the object definitions.

• Scripting systems allow object specifications and animation sequences to be defined with a user input script.

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

61

Page 62: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

KEYFRAME SYSTEMS

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

62

Page 63: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Introduction

• Each set of in-betweens are generated from the specification of two keyframes.

• For complex scenes, we can separate the frames into individual components or objects called cells, an acronym from cartoon animation.

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

63

Page 64: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Morphing

• Transformation of object shapes from one form to another is called Morphing

• Morphing methods can be applied to any motion or transition involving a change in shape.

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

64

Page 65: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Simulating Accelerations

• Curve-fitting techniques are often used to specify the animation paths between key frames Given the vertex positions at the key frames :

with linear or nonlinear paths.

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

65

Page 66: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Motion Specification

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

66

• Direct Motion Specification

Page 67: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

GRAPHICS PROGRAMMING USING OPENGL

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

67

Page 68: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Introduction

• OpenGL is a software interface that allows you to access the graphics hardware

• set of geometric primitives - points, lines, polygons, images, and bitmaps

• Libraries OpenGL Utility Library (GLU) : viewing

orientations and projections and rendering surfaces.

OpenGL Utility Toolkit (GLUT): hide the complexities of differing window APIs

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

68

Page 69: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Include Files

#include <GL/gl.h>

#include <GL/glu.h>

managing your window manager tasks

#include <GL/glut.h>

To run a OpenGL Program

Libraries (place in the lib\ subdirectory of Visual C++) opengl32.lib glu32.lib glut32.lib

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

69

Page 70: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Include Files

• Include files (place in the include\GL\ subdirectory of Visual C++) gl.h glu.h glut.h

• Dynamically-linked libraries (place in the \Windows\System subdirectory) opengl32.dll glu32.dll glut32.dll

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

70

Page 71: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Working with OpenGL

• Opening a window for Drawing glutInit(&argc, argv) : initializes the GLUT library glutInitDisplayMode(GLUT_SINGLE |

GLUT_RGB) : display mode for a window glutInitWindowSize(640,480) : indicate the height

and width (in pixels) of the requested window. glutInitWindowPosition(100,15) : specify the

screen location glutCreateWindow(“Example”) : parameter which

may appear in the title bar glutMainLoop() : have to call the function

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

71

Page 72: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Event Driven Programming

• Four Glut functions glutDisplayFunc(mydisplay) : GLUT determines

that the contents of the window needs to be redisplayed.

glutReshapeFunc(myreshape) : window is resized or moved.

glutKeyboardFunc(mykeyboard) : keyboard inputs is handled

glutMouseFunc(mymouse) : Mouse input is handled

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

72

Page 73: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

73

GLUT_KEY_UP Up Arrow

GLUT_KEY_RIGHT Right Arrow

GLUT_KEY_DOWN Down Arrow

GLUT_KEY_PAGE_UP Page Up

GLUT_KEY_PAGE_DOWN Page Down

GLUT_KEY_HOME Home

GLUT_KEY_END End

GLUT_KEY_INSERT Insert

Page 74: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Example : Skeleton for OpenGL Code

int main(int argc, char** argv) { glutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(465, 250);glutInitWindowPosition(100, 150); glutCreateWindow("My First Example"); glutDisplayFunc(mydisplay); glutReshapeFunc(myreshape); glutMouseFunc(mymouse); glutKeyboardFunc(mykeyboard); myinit(); glutMainLoop(); return 0; }

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

74

Page 75: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

BASIC GRAPHICS PRIMITIVES

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

75

Page 76: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Introduction

• OpenGL Provides tools for drawing all the output primitives such as points, lines, triangles, polygons, quads etc and it is defined by one or more vertices

• These functions are glBegin(int mode); glEnd( void );

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

76

Page 77: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

• The parameter mode of the function glBegin can be one of the following:

GL_POINTS

GL_LINES

GL_LINE_STRIP

GL_LINE_LOOP

GL_TRIANGLES

GL_TRIANGLE_STRIP

GL_TRIANGLE_FAN

GL_QUADS

GL_QUAD_STRIP

GL_POLYGON

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

77

Page 78: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

glVertex( )

• Main function used to draw objects

• defines a point (or a vertex) and it can vary from receiving 2 up to 4 coordinates

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

78

Page 79: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

OpenGL Datatypes

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

79

Page 80: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

Examples//the following code plots three dots glBegin(GL_POINTS); glVertex2i(100, 50); glVertex2i(100, 130); glVertex2i(150, 130); glEnd( )// the following code draws a triangle glBegin(GL_TRIANGLES); glVertex3f(100.0f, 100.0f, 0.0f); glVertex3f(150.0f, 100.0f, 0.0f); glVertex3f(125.0f, 50.0f, 0.0f); glEnd( ); // the following code draw a lines glBegin(GL_LINES); glVertex3f(100.0f, 100.0f, 0.0f); // origin of the line glVertex3f(200.0f, 140.0f, 5.0f); // ending point of the line glEnd( ); ;

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

80

Page 81: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

• OpenGl State : current size of a point, the current color of a drawing, the current ba

• The value of a state variable remains active until new value is given ckground color, etc. Example : glPointSize(4.0);

• glClearColor() : set the back groudcolor is set with glClearColor(red, green, blue, alpha), where alpha specifies a degree of transparency Example : glClearColor (0.0, 0.0, 0.0, 0.0);

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

81

Page 82: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

• glClear() : To clear the entire window to the background color Example :glClear(GL_COLOR_BUFFER_BIT)

• glColor3f() : establishes to use for drawing objects Example:

•glColor3f(0.0, 0.0, 0.0); //black •glColor3f(1.0, 0.0, 0.0); //red •glColor3f(0.0, 1.0, 0.0); //green •glColor3f(1.0, 1.0, 0.0); //yellow •glColor3f(0.0, 0.0, 1.0); //blue •glColor3f(1.0, 0.0, 1.0); //magenta •glColor3f(0.0, 1.0, 1.0); //cyan •glColor3f(1.0, 1.0, 1.0); //white

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

82

Page 83: COLOR MODELS 9/12/20151A.ARUNA/ASSISTANT PROFESSOR/SNSCE

• gluOrtho2D(): specifies the coordinate system in two dimension void gluOrtho2D (GLdouble left, GLdouble right,

GLdouble bottom,GLdouble top); Example : gluOrtho2D(0.0, 640.0, 0.0, 480.0);

• glOrtho() : specifies the coordinate system in three dimension Example : glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

• glFlush() : OpenGL commands to be executed• glMatrixMode(GL_PROJECTION) : For

orthographic projection • glLoadIdentity() : To load identity matrix• glShadeModel : Sets the shading model

04/19/23 A.ARUNA/ASSISTANT PROFESSOR/SNSCE

83