IntMu.Lab5. Download all the files available from

Similar documents
Introduction to OpenGL

Lecture 22 Sections 8.8, 8.9, Wed, Oct 28, 2009

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

CSC 240 Computer Graphics. Fall 2015 Smith College

Shading and Illumination

Computer graphics MN1

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

1 /* 4 C:\opencv\build\include. 6 C:\opencv\build\x86\vc10\lib

Computer graphics Labs: OpenGL (1/3) Geometric transformations and projections

Illumination Model. The governing principles for computing the. Apply the lighting model at a set of points across the entire surface.

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M

Computer graphics MN1

Graphics. Texture Mapping 고려대학교컴퓨터그래픽스연구실.

FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI BITM INTERACTIVE COMPUTER GRAPHICS LAB SESSION 4. C++ - OpenGL

5.2 Shading in OpenGL

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

Texture Mapping. Mike Bailey.

三維繪圖程式設計 3D Graphics Programming Design 第七章基礎材質張貼技術嘉大資工系盧天麒

Illumination and Shading

Shading in OpenGL. Outline. Defining and Maintaining Normals. Normalization. Enabling Lighting and Lights. Outline

Computer graphics MN1

CS 148, Summer 2012 Introduction to Computer Graphics and Imaging

CT5510: Computer Graphics. Texture Mapping

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

QUESTION 1 [10] 2 COS340-A October/November 2009

Assignment #6 2D Vector Field Visualization Arrow Plot and LIC

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

Lighting. CSC 7443: Scientific Information Visualization

Computer Graphics. Bing-Yu Chen National Taiwan University

Lecture 4 Advanced Computer Graphics (CS & SE )

Lecture 5b. Transformation

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

+ = Texturing: Glue n-dimensional images onto geometrical objects. Texturing. Texture magnification. Texture coordinates. Bilinear interpolation

CS 4731: Computer Graphics Lecture 16: Phong Illumination and Shading. Emmanuel Agu

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt

Illumination & Shading I

OpenGL & Visualization

CS4202: Test. 1. Write the letter corresponding to the library name next to the statement or statements that describe library.

Shading/Texturing. Dr. Scott Schaefer

Department of Computer Sciences Graphics Spring 2013 (Lecture 19) Bump Maps

Letterkenny Institute of Technology

Computer Graphics. OpenGL

Understand how real-world lighting conditions are approximated by OpenGL

Lecture 07: Buffers and Textures

Lecture 4 of 41. Lab 1a: OpenGL Basics

Grafica Computazionale

Exercise 1 Introduction to OpenGL

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010)

Lecture 2 2D transformations Introduction to OpenGL

An Introduction to 3D Computer Graphics, Stereoscopic Image, and Animation in OpenGL and C/C++ Fore June

Chapter 9 Texture Mapping An Overview and an Example Steps in Texture Mapping A Sample Program Specifying the Texture Texture Proxy Replacing All or

Outline. Other Graphics Technology. OpenGL Background and History. Platform Specifics. The Drawing Process

Graphics and Computation Introduction to OpenGL

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

3D Graphics and OpenGl. First Steps

Lighting. Chapter 5. Chapter Objectives. After reading this chapter, you'll be able to do the following:

20 GLuint objects; 36 Scale += 0.1; 37 break; 38 case GLUT_KEY_DOWN:

Discussion 3. PPM loading Texture rendering in OpenGL

Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,

Assignment #5: Scalar Field Visualization 3D: Direct Volume Rendering

SE313: Computer Graphics and Visual Programming. Computer Graphics Notes Gazihan Alankus, Fall 2011

CSE 167: Introduction to Computer Graphics Lecture #7: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018

Why Do We Care About Lighting? Computer Graphics Lighting. The Surface Normal. Flat Shading (Per-face) Setting a Surface Normal in OpenGL

Computer Graphics. Transformations. CSC 470 Computer Graphics 1

ก ก ก.

OpenGL Texture Mapping. Objectives Introduce the OpenGL texture functions and options

Assignment #3: Scalar Field Visualization 3D: Cutting Plane, Wireframe Iso-surfacing, and Direct Volume Rendering

CMSC 425: Lecture 12 Texture Mapping Thursday, Mar 14, 2013

Using GLU/GLUT Objects

COMPSCI 373 S1 C - Assignment 2 Sample Solution

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

Visualizing Molecular Dynamics

Two possible ways to specify transformations. Each part of the object is transformed independently relative to the origin

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

Ambient reflection. Jacobs University Visualization and Computer Graphics Lab : Graphics and Visualization 407

Computer Graphics Programming

VR-programming tools (procedural) More VRML later in this course! (declarative)

CSCI E-74. Simulation and Gaming

Rendering Pipeline/ OpenGL

THE AUSTRALIAN NATIONAL UNIVERSITY Final Examinations(Semester 2) COMP4610/COMP6461 (Computer Graphics) Final Exam

Introduction to Computer Graphics with OpenGL/GLUT

Texture Mapping. Texture Mapping. Map textures to surfaces. Trompe L Oeil ( Deceive the Eye ) The texture. Texture map

Shading. Flat shading Gouraud shading Phong shading

CS212. OpenGL Texture Mapping and Related

Scene Graphs. CS4620/5620: Lecture 7. Announcements. HW 1 out. PA 1 will be out on Wed

CSE 167: Introduction to Computer Graphics Lecture #8: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

OpenGL. 1 OpenGL OpenGL 1.2 3D. (euske) 1. Client-Server Model OpenGL


Methodology for Lecture

OpenGL. Toolkits.

Textures. Datorgrafik 2006

Today s class. Simple shadows Shading Lighting in OpenGL. Informationsteknologi. Wednesday, November 21, 2007 Computer Graphics - Class 10 1

Computational Strategies

Lectures Display List

CSE 167: Lecture #8: Lighting. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Graphics Processing Units (GPUs) V1.2 (January 2010) Outline. High-Level Pipeline. 1. GPU Pipeline:

Transcription:

IntMu.Lab5 0. Download all the files available from http://www.dee.isep.ipp.pt/~jml/intmu/lab5: wget http://www.dee.isep.ipp.pt/~jml/intmu/lab5/makefile make getall Analyze the program windmill.c. Compile it and run the resulting application (windmill). make./windmill An empty window is shown. 0.1. Base The Display() function is automaticly called whenever the window requires a redraw. Inside this function, add an horizontal square (in the xy plan) with sides of 6 units. glcolor3f(0., 0.7, 0.); glbegin(gl_quads); glvertex3f(-3., -3., 0.); glvertex3f(-3., 3., 0.); glvertex3f( 3., 3., 0.); glvertex3f( 3., -3., 0.); 1. Windmill The windmill() function is allways called from the Display() function. Here, a graphical representation of a traditional windmill will be produced. 1.1. Cone Inside the windmill() function, apply the tool glutsolidcone to create a cone based on the xy plan, with red color, a base radius of 1 unit and height of 1 unit. glcolor3f(0.9, 0., 0.); glutsolidcone(1., 1., 32, 1); Change the cone s position by applying a vertical translation of 3 units. gltranslatef(0., 0., 3.); Also apply a scale to increase its base radius in 20%. glscalef(1.2, 1.2, 1.);

1.2. Cylinder Add a vertical cylinder to reproduce the windmill body. glcolor3f(0.9, 0.9, 0.); glpushmatrix(); glscalef(1., 1., 3.); glutsolidcylinder(1., 1., 32, 1); glpopmatrix(); 1.3. Arm Add a triangular polygon to reproduce one of the windmill arms. glcolor3f(1.,1.,1.); glpushmatrix(); gltranslatef(0., -1.25, 2.4); glnormal3f(0., -1., 0.); glbegin(gl_triangles); glvertex3f( 0., 0., 0.); glvertex3f( -1.8, -0.1, 1.3); glvertex3f( -1.8, 0., 0.); glpopmatrix(); 1.4. Arms Reuse the last arm specification to create the other arms, applying successive rotations for( i=0 ; i<4 ; i++ ) glbegin(gl_triangles); glvertex3f( 0., 0., 0.); glvertex3f( 1.8, 0., 1.5); glvertex3f( 1.8, 0., 0.); glrotatef(90., 0., 1., 0.); 2. Animation Apply a rotation transformation around the y axis with constant rotation speed to the arms group. glrotatef(0.05*timenow, 0., 1., 0.); Verify that the arms position is changed each time the window is updated.

In order to force a constant window update, define a new callback function: void Redisplay(void) glutpostredisplay(); Register this new function as the callback tio be used in the idle state. glutidlefunc(redisplay); 3. Illumination All objects should be reproduced using the flat shaded color specified width the glcolor3f() function. In order to achieve a more realistic viewing, the illumination calculus can be implemented through the graphics pipeline. Enable the illumination calculus. glenable (GL_LIGHTING); Verify that all the objects lost their colors. 3.1 Light source Create a point light source (GL_LIGHT0) in the Init() function: float light_ambient[] = 0.2, 0.2, 0.2, 1.0 ; float light_diffuse[] = 0.35, 0.35, 0.35, 1.0 ; float light_specular[] = 1.0, 1.0, 1.0, 1.0 ; float light_position[] = 30.0, -10.0, 30.0, 1.0 ; gllightfv (GL_LIGHT0, GL_AMBIENT, light_ambient); gllightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse); gllightfv (GL_LIGHT0, GL_SPECULAR, light_specular); gllightfv (GL_LIGHT0, GL_POSITION, light_position); Turn the light source on. glenable (GL_LIGHT0); Verify that the illumination calculus is now working. 3.2 Materiais Prepare a function to define the optical properties of the used materials. void SetMaterial(float r, float g, float b) float mat_dif[] = r, g, b, 1.0 ;

float mat_amb[] = r, g, b, 1.0 ; float mat_spe[] = 0.2, 0.2, 0.2, 1.0 ; float mat_shi = 10.; glmaterialfv(gl_front, GL_AMBIENT, mat_amb); glmaterialfv(gl_front, GL_DIFFUSE, mat_dif); glmaterialfv(gl_front, GL_SPECULAR, mat_spe); glmaterialf( GL_FRONT, GL_SHININESS, mat_shi); Apply this function to define the properties of all used materials, replacing al the references to the function glcolor3f(): 4. Textures SetMaterial(0.9, 0., 0.); Use the SOIL (Simple OpenGL Image Loader) library to load an image that will be mapped over the base polygon. #include <SOIL/SOIL.h> unsigned char* image = SOIL_load_image("grass.jpg", &width, &height, 0, SOIL_LOAD_RGB); glbindtexture(gl_texture_2d, 0); gltexparameteri(gl_texture_2d, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gltexparameteri(gl_texture_2d, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glteximage2d(gl_texture_2d, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image); SOIL_free_image_data(image); Inside the Display() function, enable the use of this texture to colorize the base polygon. glenable(gl_texture_2d); gltexenvf(gl_texture_env, GL_TEXTURE_ENV_MODE, GL_DECAL); glbindtexture(gl_texture_2d, 0); For each vertex, specify the texture coordinates, pointing to a corner of the image. glbegin(gl_quads); gltexcoord2f(0.0, 0.0); glvertex3f(-6., -6., 0.); gltexcoord2f(0.0, 1.0); glvertex3f(-6., 6., 0.); gltexcoord2f(1.0, 1.0); glvertex3f( 6., 6., 0.); gltexcoord2f(1.0, 0.0); glvertex3f( 6., -6., 0.); After the redraw of the base polygon, turn off the texture mapping, so that the other objects are not affected. gldisable(gl_texture_2d);

5. Submission To submit your work, copy the files windmill.c and windmill to the directory intmu/lab5/ under your WWW area in the ave server. make submit Verify that both files became available from the URL: www.dee.isep.ipp.pt/~student_nr/intmu/lab5/ 6. Bibliographic info The OpenGL Programming Guide: The Official Guide to Learning OpenGL, Versions 3.0 and 3.1 (7th Edition), Dave Shreiner, ISBN 978-0-321-55262-4 OpenGLBook.com, http://openglbook.com/ 7. Requirements SOIL (Sample OpenGL Image Loader) Source: http://www.lonesock.net/soil.html SOIL installing: yum install SOIL SOIL-devel or: make instsoil 8. History V1, 2000, jml V2, 2004, jml V3, 2013, jml V3.1, 2014, jml V4.1, 2016, jml V4.1e, 2017, jml