Introduction to OpenGL

Similar documents
Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

Computer graphics MN1

Computer Graphics. Bing-Yu Chen National Taiwan University

IntMu.Lab5. Download all the files available from

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

CS 4204 Computer Graphics

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

Lecture 4 of 41. Lab 1a: OpenGL Basics

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

Lecture 2 2D transformations Introduction to OpenGL

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

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

Exercise 1 Introduction to OpenGL

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

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 MN1

Precept 2 Aleksey Boyko February 18, 2011

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

to OpenGL Introduction Pipeline Graphics pipeline OpenGL pipeline OpenGL syntax Modeling Arrays Conclusion 1 Introduction Introduction to OpenGL

Computer Graphics (Basic OpenGL)

Computer Graphics Course 2005

Computer Graphics. OpenGL

Graphics Pipeline & APIs

Lectures OpenGL Introduction

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

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

OpenGL/GLUT Intro. Week 1, Fri Jan 12

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

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

Graphics Pipeline & APIs

Introduction to Computer Graphics with OpenGL/GLUT

DONALD HOUSE: CPSC 8170, FALL 2018 DESIGN OF A REAL-TIME ANIMATION PROGRAM

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

Graphics and Computation Introduction to OpenGL

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

Introduction to OpenGL

C OMPUTER G RAPHICS Thursday

Basic Graphics Programming

Rendering Pipeline/ OpenGL

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field

Cheating: In case of cheating, all parts involved (source(s) and receiver(s)) get zero.

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Programming using OpenGL: A first Introduction

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

Computer graphics MN1

Illumination and Reflection in OpenGL CS 460/560. Computer Graphics. Shadows. Photo-Realism: Ray Tracing. Binghamton University.

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

OpenGL refresher. Advanced Computer Graphics 2012

COMPUTER GRAPHICS LAB # 3

CS559: Computer Graphics. Lecture 12: OpenGL Transformation Li Zhang Spring 2008

Graphics Programming

Visualizing Molecular Dynamics

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

Drawing Primitives. OpenGL basics

Lecture 07: Buffers and Textures

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

Computer Graphics, Chapt 08

Basic Graphics Programming

5.2 Shading in OpenGL

GLUT Tutorial. Keyboard

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

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

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)

Lecture 3. Understanding of OPenGL programming

Computer Graphics 1 Computer Graphics 1

GLUT Tutorial. John Tsiombikas (Nuclear / The Lab Demos) May 6, Introduction to GLUT (OpenGL Utility Toolkit)

Computer Graphics. Transformations. CSC 470 Computer Graphics 1

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

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson

RECITATION - 1. Ceng477 Fall

Computer graphic -- Programming with OpenGL 2

Computer graphic -- Programming with OpenGL I

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

COMP 371/4 Computer Graphics Week 1

LECTURE 02 OPENGL API

Scientific Visualization Basics

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

Programming with OpenGL Part 3: Three Dimensions

Duc Nguyen CSE 420 Computer Graphics 10/10/2018 Homework 1

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

API Background. Prof. George Wolberg Dept. of Computer Science City College of New York

by modifying the glutinitwindowsize() function you can change the screen size to whatever you please.

OpenGL and X, Column 1: An OpenGL Toolkit

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3

Interaction. CSCI 420 Computer Graphics Lecture 3

Grafica Computazionale

Announcements OpenGL. Computer Graphics. Spring CS4815

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12

Lecture 3 Advanced Computer Graphics (CS & SE )

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

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

2. OpenGL -I. 2.1 What is OpenGL? Things OpenGL can do: -23-

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

Transcription:

Introduction to OpenGL Banafsheh Azari http://www.uni-weimar.de/cms/medien/cg.html

What You ll See Today What is OpenGL? Related Libraries OpenGL Command Syntax B. Azari http://www.uni-weimar.de/cms/medien/cg.html 2

What is OpenGL? Software interface to graphics hardware Hardware independent No commands for performing windowing tasks Provides commands to draw geometric primitivespoints, lines and polygons. http://fly.cc.fer.hr/~unreal/theredbook/ B. Azari http://www.uni-weimar.de/cms/medien/cg.html 3

Related Libraries Glu OpenGL Utility Library Standard part of OpenGL implementation Glut OpenGL Utility Toolkit Window system-independent toolkit http://www.opengl.org/developers/documentatio n/glut/glut-3.spec.pdf B. Azari http://www.uni-weimar.de/cms/medien/cg.html 4

OpenGL Command Syntax Prefix gl and initial capital letters for each word making up the command name (e.g. glclear() ) Constants begin always with GL_, use all capital letters, and use underscores to separate words (e.g. GL_COLOR_BUFFER_BIT) OpenGL brings its own data types (e.g. GLbyte, GLint) B. Azari http://www.uni-weimar.de/cms/medien/cg.html 5

OpenGL Command Formats glvertex3fv( v ) Number of components 2 - (x,y) 3 - (x,y,z) 4 - (x,y,z,w) Data Type b - byte ub - unsigned byte s - short us - unsigned short i - int ui - unsigned int f - float d - double Vector omit v for scalar form glvertex2f( x, y ) 6

Header Files B. Azari http://www.uni-weimar.de/cms/medien/cg.html 7

Additional Dependencies the glut32.lib is needed it is located in../../lib B. Azari http://www.uni-weimar.de/cms/medien/cg.html 8

GLUT Callback Functions whenever you want to use GLUT you need this functions void initglut(int argc, char **argv); void displayfunc(void); void idlefunc(void); void reshapefunc(int width, int height); void mousefunc(int button, int state, int x, int y); void mousemotionfunc(int x, int y); void keyboardfunc(unsigned char key, int x, int y); void specialfunc(int key, int x, int y); B. Azari http://www.uni-weimar.de/cms/medien/cg.html 9

OpenGL Initialization glutinit: Initializes GLUT must be called first glutinitwindowsize: Specifies the size of the window in pixels glutinitwindowposition: Specifies the screen location glutinitdisplaymode: Specifies color model, buffer, etc. glutcreatewindow: Create a window B. Azari http://www.uni-weimar.de/cms/medien/cg.html 10

User Input Callbacks (mouse) mouse function: queries button states and positions mouse motion function: tells GLUT what to do when the mouse moves B. Azari http://www.uni-weimar.de/cms/medien/cg.html 11

User Input Callbacks(keyboard) keyboard function: tells GLUT what to do when keys are pressed B. Azari http://www.uni-weimar.de/cms/medien/cg.html 12

Rendering Callback Do all of our drawing here glutdisplayfunc(displayfunc); void displayfunc(void) { glutswapbuffers(); } B. Azari http://www.uni-weimar.de/cms/medien/cg.html 13

OpenGL as a state machine you can put OpenGL into various states which remain in effect until changed states are things like: current color viewing and projection transformations void displayfunc(void) { // set clear color to white glclearcolor(0.0f, 0.0f, 0.7f, 1.0f); // clear color and depth buffer glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); // we enable the depth test glenable(gl_depth_test); // and set our depth function gldepthfunc(gl_less); glutswapbuffers(); B. Azari http://www.uni-weimar.de/cms/medien/cg.html 14

let s add an object GLUT provides some simple ones. Let s add a pyramid. glbegin(gl_triangles); glcolor3f(1.0f,0.0f,0.0f); glvertex3f( 0.0f, 10.0f, 0.0f); glvertex3f(-10.0f,-10.0f, 10.0f); glvertex3f( 10.0f,-10.0f, 10.0f); // Red // Top Of Triangle (Front) // Left Of Triangle (Front) // Right Of Triangle (Front)... glcolor3f(1.0f,0.0f,1.0f); glvertex3f( 0.0f, 10.0f, 0.0f); glvertex3f(-10.0f,-10.0f,-10.0f); glvertex3f(-10.0f,-10.0f, 10.0f); // pink // Top Of Triangle (Left) // Left Of Triangle (Left) // Right Of Triangle (Left) glend(); // Done Drawing The Pyramid Where is our object???????? B. Azari http://www.uni-weimar.de/cms/medien/cg.html 15

OpenGL s coordinate system OpenGL provides a lefthanded coordinate system By default OpenGL s virtual camera is placed at the origin of this coordinate system looking in negative z-direction camera we placed our teapot at this point as well so, yet the camera is inside the teapot y y x x z z B. Azari http://www.uni-weimar.de/cms/medien/cg.html 16

OpenGL s coordinate system we activate the model view matrix and reset it now translate the camera 50 units // switch to modelview matrix glmatrixmode(gl_modelview); // reset current matrix glloadidentity(); // translate scene gltranslatef(0.0f, 0.0f, -50.0f); // draw scene drawscene(); B. Azari http://www.uni-weimar.de/cms/medien/cg.html 17

OpenGL s coordinate system Let s add a white teapot. void drawscene() { //set color glcolor3f(1.0f,1.0f,1.0f); } // draw teapot glutsolidteapot(10.0); glpopmatrix(); B. Azari http://www.uni-weimar.de/cms/medien/cg.html 18

Lighting there is no spatial illumination and the teapot looks kinda flat we will use OpenGL s lights to illuminate the teapot. take a look at the setlights() function Just press l to active lighting B. Azari http://www.uni-weimar.de/cms/medien/cg.html 19

void setlights() { glenable(gl_lighting); // Setup light GLfloat light0_ambient[4] = {1.0f, 1.0f, 1.0f, 1.0f}; GLfloat light0_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f}; GLfloat light0_specular[4] = {1.0f, 1.0f, 1.0f, 1.0f}; GLfloat light0_position[4] = {-10.0f, 10.0f, 10.0f, 0.0f}; gllightfv(gl_light0, GL_AMBIENT, light0_ambient); gllightfv(gl_light0, GL_DIFFUSE, light0_diffuse); gllightfv(gl_light0, GL_SPECULAR, light0_specular); gllightfv(gl_light0, GL_POSITION, light0_position); B. Azari http://www.uni-weimar.de/cms/medien/cg.html 20

Model Transformations in mousemotionfunc() an array stores mouse motion in x a this values can be used as angle of rotation in y direction // reset current matrix glloadidentity(); // translate scene gltranslatef(0.0f, 0.0f, -50.0f); // add rotation glrotatef( rotation[0], 1.0f, 0.0f, 0.0f ); glrotatef( rotation[1], 0.0f, 1.0f, 0.0f ); // set lights setlights(); glenable(gl_light0); glenable(gl_light1); // draw scene drawscene(); glutswapbuffers(); B. Azari http://www.uni-weimar.de/cms/medien/cg.html 21

Texturing there is a texture we can apply to our teapot. take a look at texturegenerator () and drawscene(). just press t to active texturing, the texture is already loaded // loading a random image glgentextures(2, &image);// Create The Texture // Typical Texture Generation Using Data from the raw... glbindtexture(gl_texture_2d, image); glpixelstorei (GL_UNPACK_ALIGNMENT, 1); texture_bytes = loadtexture("../../images/rock.raw", 3, 512,512); glteximage2d(gl_texture_2d, 0, // 0 for now // GL_TEXTURE_2D GL_RGB, // format OpenGL uses for image 512,512, // width and height 0, // border of the image GL_RGB, GL_UNSIGNED_BYTE, texture_bytes); // because pixels are stored in RGB format // because pixels are stored as unsigned numbers // our check board pixel data B. Azari http://www.uni-weimar.de/cms/medien/cg.html 22

void drawscene() { //set color glcolor3f(1.0f,1.0f,1.0f); //enable texturing if(!texture) glenable(gl_texture_2d); else gldisable(gl_texture_2d); // draw teapot glutsolidteapot(10.0); B. Azari http://www.uni-weimar.de/cms/medien/cg.html 23

References The Official Guide to Learning OpenGL, Dave Shreiner, Mason Woo, Jackie Neider, Addison- Wesley Longman, ISBN: 0321335732, 2005 http://glprogramming.com/red/ http://opengl.org http://www.khronos.org/opengl/ http://wiki.delphigl.com/ B. Azari http://www.uni-weimar.de/cms/medien/cg.html 24