CSC 307 1.0 Graphic Programming Lecture 2 OpenGL Lightning.

Slides:



Advertisements
Similar presentations
CHAPTER 5 3D Graphics Programming Color, Material, and Lighting Vivian by Richard S. Wright Jr.
Advertisements

1 MAE152 Computer Graphics for Scientists and Engineers Lighting in OpenGL.
Chapter 3. Drawing primitives in Space Presented by Garrett Yeh.
Shading in OpenGL CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
What is OpenGL The OpenGL graphics system is a software interface to graphics hardware. (The GL stands for Graphics Library.) It allows you to create interactive.
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Hidden Surfaces and Shading CS BSP Tree T1T1 T2T2 E if (f 1 (E) < 0) then draw T 1 draw T 2 else draw T 2 draw T 1 f 1 (p) = 0 is the.
Normals Specifying the normal –void glNormal3d( GLdouble nx, GLdouble ny, GLdouble nz ); When using lighting effects, normals must be defined for each.
1 Lecture 10 Lighting in OpenGL. 2 Sources of light GLfloat myLightPosition[] = {3.0, 6.0, 5.0, 1.0}; GLLightfv(GL_LIGHT0, GL_POSITION, myLightPosition);
Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3
Surface Rendering With OpenGL CS460 Project by Rui Yu 11/30/03.
CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red.
OpenGL Tutorial Jason Lawrence COS426 Precept Notes 2/16/04.
Introduction to OpenGL Pipeline From Programmer View Tong-Yee Lee.
Lighting & Material. Example 1/5 #include ” glut.h ” void display(); void reshape(int, int); void lighting(); int main(int argc, char** argv) { glutInit(&argc,
Development of Interactive 3D Virtual World Applications
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
Introduction to OpenGL Jian Huang This set of slides are extracted from the Interactive OpenGL Programming course given by Dave Shreine, Ed Angel and Vicki.
CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 CSE 872 Advanced Computer Graphics Charles B. Owen (Instructor) – 1138 E. B., MW 12:30-1:50pm.
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
Shading in OpenGL.
Computer Graphics, KKU. Lecture 131 Transformation and Viewing in OpenGL.
Computer Graphics I, Fall 2010 Shading in OpenGL.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Programming for Virtual Reality Applications Projection in OpenGL Lighting and Shading Lecture 17.
Introduction to OpenGL 1. 2 OpenGL A Graphics rendering API introduced in 1992 by Silicon Graphics Inc Provide the low-level functions to access graphics.
CG1 Labs Wei Li. Back Face Culling // enable back-face culling glEnable( GL_CULL_FACE ); // orientation of front-facing polygons glFrontFace( GL_CCW );
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Computer Graphics Bing-Yu Chen National Taiwan University.
OpenGL Color and Lighting 2003 Spring Keng Shih-Ling.
OpenGL Lighting Jian-Liang Lin 2002 Hidden-Surface Removal -1 Original Code: while (1) { get_viewing_point_from_mouse_position(); glClear(GL_COLOR_BUFFER_BIT);
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Intro to OpenGL: Vertices and Drawing
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
David Luebke1/5/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
Chap 3 Viewing and Transformation
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
OpenGL & OpenSceneGraph Graphics Programming Katia Oleinik:
Illumination CSE 410. Basic steps of lighting Enable smooth shading Set global ambient light glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); GLfloat.
Implement of transformation,projection, viewing Hanyang University Jungsik Park.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Graphics Graphics Korea University kucg.korea.ac.kr 1 Lights & Material 고려대학교 컴퓨터 그래픽스 연구실.
CSC Graphics Programming
CSC Graphics Programming
Lighting.
CS418 Computer Graphics John C. Hart
Shading To determine the correct shades of color on the surface of graphical objects.
Jason Lawrence COS426 Precept Notes 2/16/04
Reference1. [OpenGL course slides by Rasmus Stenholt]
@ 2017 by Jim X. Chen George Mason University
Understanding of OpenGL
Shading in OpenGL Ed Angel
Lighting and Shading Lab 8:.
Computer Graphics, KKU. Lecture 13
CSC461: Lecture 24 Lighting and Shading in OpenGL
Lighting Phong's Lighting Model normals
Lighting and Materials
Type of View Perspective View COP(Center of Plane) Diminution of size
Lighting – Material Properties
Lighting and Shading Lab 8:.
Chapter 3 Viewing.
Transformation Back-face culling View frustum culling
HW-swgl-1 transformation & projection
Presentation transcript:

CSC Graphic Programming Lecture 2 OpenGL Lightning

Set color of the light  ///spotlight  GLfloat ambientLight[]={0.3f,0.3f,0.3f,1.0f};  GLfloat diffuseLight[]={0.7f,0.7f,0.7f,1.0f};  GLfloat specular[]={1.0f,1.0f,1.0f,1.0f};

Setup and enable light 0  glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);  glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);  glLightfv(GL_LIGHT0, GL_SPECULAR, specular);

Enable Lightings  glEnable(GL_LIGHTING);  glEnable(GL_LIGHT0);

Points in 2D  GLfloat lightPos[]={-1.5f, 2.0f, 5.5f, 1.0f};  glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

Enable color tracking glEnable(GL_COLOR_MATERIAL); // set material properties to follow glColor values glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

// Bright white light – full intensity RGB values GLfloat ambientLight[] = { 1.0f, 1.0f, 1.0f, 1.0f }; // Enable lighting glEnable(GL_LIGHTING); // Set light model to use ambient light specified by ambientLight[] glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);

Glfloat gray[] = { 0.75f, 0.75f, 0.75f, 1.0f }; glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray); glBegin(GL_TRIANGLES); glVertex3f(-15.0f,0.0f,30.0f); glVertex3f(0.0f, 15.0f, 30.0f); glVertex3f(0.0f, 0.0f, -56.0f); glEnd();

// Enable color tracking glEnable(GL_COLOR_MATERIAL); // Front material ambient and diffuse colors track glColor glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glcolor3f(0.75f, 0.75f, 0.75f); glBegin(GL_TRIANGLES); glVertex3f(-15.0f,0.0f,30.0f); glVertex3f(0.0f, 15.0f, 30.0f); glVertex3f(0.0f, 0.0f, -56.0f); glEnd();

void glCullFace(GLenum mode);  Indicates which polygons should be discarded (culled) before they’re converted to screen coordinates.  The mode is either GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK to indicate front−facing,  back−facing, or all polygons. To take effect, culling must be enabled using glEnable() with  GL_CULL_FACE; it can be disabled with glDisable() and the same argument.

void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);

Viewport Transformation  gluPerspective(myFovy, 2.0, myNear, myFar);  glViewport (0, 0, 400, 400);  To avoid the distortion, this line could be used:  glViewport(0, 0, 400, 200);  void glDepthRange(GLclampd near, GLclampd far);

void Resize(GLsizei w, GLsizei h) { GLfloat nRange = 100.0f; if(h == 0) h = 1; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Establish clipping volume (left, right, bottom, top, near, far) if (w <= h) glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, - nRange, nRange); else glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, - nRange, nRange); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }

void Reshape(GLsizei w, GLsizei h) {if(h == 0) h = 1; // Prevent a divide by zero glViewport(0, 0, w, h); // Set viewport to window size Glfloat fAspect = (GLfloat)w/(GLfloat)h; glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Field of view of 45 degrees, near and far planes 1.0 and 425 gluPerspective(45.0f, fAspect, 1.0, 425.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }

Reshape  glutReshapeFunc(reshape); void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0); glOrtho(100.0,-100.0,150.0,-150.0,100.0,-100.0); // glFrustum (-4.0, 4.0, -4.0, 4.0, 2, 10.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //gluLookAt(0.0, 0.0, , 0.0, 0.0, , 0.0, 1.0, 0.0); }