COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.

Slides:



Advertisements
Similar presentations
OpenGL: Simple Use Open a window and attach OpenGL to it Set projection parameters (e.g., field of view) Setup lighting, if any Main rendering loop –Set.
Advertisements

Chapter 2: Graphics Programming
CMPE 466 COMPUTER GRAPHICS
David Luebke5/16/2015 Administrivia l Back on track: canceling OpenGL lecture 2 l Assignment 1 –Greg Yukl found an alternate XForms site:
Lab 1: OpenGL Tutorial CS 282. What’s the plan for today? Go over our framework code. Learn some basic OpenGL! Reveal Lab 1 Answer questions.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
1 Lecture 4 Graphical primitives Rasterization: algorithmic approach Rasterization: geometric approach 2D discrete lines, triangles Discrete planes 3D.
Computer Graphics CS 385 February 7, Fundamentals of OpenGl and Glut Today we will go through the basics of a minimal OpenGl Glut project, explaining.
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 2.
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
1 GLUT Callback functions Event-driven: Programs that use windows  Input/Output  Wait until an event happens and then execute some pre-defined functions.
Using OpenGL. 2 What is OpenGL? A software interface to graphics hardware It is a Graphics Rendering API (Application Programmer’s Interface) that is.
Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
Triangulation Introduction to Computer Graphics and Animation (Principle of Computer Graphics) Rattapoom Waranusast.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Interactive Computer Graphics Lecture 2: The programming approach to building graphical applications using OpenGL API.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
Computer Graphics CS 385 January 31, Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
1. OpenGL/GLU/GLUT  OpenGL v4.0 (latest) is the “core” library that is platform independent  GLUT v3.7 is an auxiliary library that handles window creation,
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
P RACTICING O PEN GL- P RIMITIVES. O PEN GL O UTPUT P RIMITIVES  Each geometric object is described by a set of vertices and the type of primitive to.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
Lecture 2: Some definitions of terms 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Introduction to OpenGL. OpenGL is a low-level graphics library specification. It makes available to the programmer  a small set of geometric primitives.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net TA: Nouf Al-harbi.
NoufNaief.net 1 TA: Nouf Al-Harbi.
1 Angel: Interactive Computer Graphics5E © Addison- Wesley 2009 Image Formation Fundamental imaging notions Fundamental imaging notions Physical basis.
Lecture 2: Introduction to OpenGL
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
CS552: Computer Graphics Lecture 6: Viewing in 2D.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
OpenGL: Introduction #include main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0,
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
Introduction to Graphics Programming. Graphics API.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
Introduction to Graphics Programming. Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL Based on GL (graphics library) by Silicon Graphics Inc. (SGI) Advantages: Runs on everything, including.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL: Event-driven How in OpenGL? Programmer registers callback functions Callback function called when.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Lecture 8: Discussion of papers OpenGL programming Lecturer: Simon Winberg Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
Administrivia Back on track: canceling OpenGL lecture 2 Assignment 1
CSC Graphics Programming
Draw a Simple Object.
Real-Time Rendering Geometry and Buffers
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
גרפיקה ממוחשבת: מבוא ל-OpenGL
CSE 411 Computer Graphics Lecture #3 Graphics Output Primitives
Drawing in the plane 455.
Introduction to OpenGL
Primitive Objects Lecture 6 Wed, Sep 5, 2007.
OpenGL program.
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
CS297 Graphics with Java and OpenGL
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG

Outline Task 1:CodeBlock, GLFW & OpenGL testing Task 2:Full Screen mode Task 3:Graphical Application Structure Task 4:Alternative Structure of Graphical Application Task 5:OpneGL primitives – points, lines, triangles, squares, polygons Task 6:Cube vertices Task 7:Cube edges Task 8: Cube Size Parameterization Task 9:Concentric Cubes Task 10:Cube Center Parameterization

Learning Outcomes –Introduction to OpenGL (1.x) in level to design and implement simple 3D animations –Implementation of simple CG algorithms

Required software –OpenGL, GLU, GLFW, GCC –Code::Blocks –Information about OpenGL 1.x Alternative software –MESA, FreeGLUT, GLUT, Notepad, C compiler Software

Task №1 CodeBlock, GLFW & OpenGL Testing Let’s Begin: –Code::Blocks –GNU GCC Compiler –GLFW bit

Task №1 Create New project –File → New → Project → GLFW Project

Settings –Choose project name and browse for location –Browse to select the folder where is GLFW library stored

Hint –Code::Blocks should explicitly “know” where is GLFW 2.7 library

Result –Automatically generated GLFW project –Build and Run

Project Result

Task №2 Full Screen mode GLFW functions –GLFW Reference Manual sections 3.1.1, и Changes in glfwOpenWindow() – Parameter GLFW_FULLSCREEN

Task № 3: Graphical Application Structure Minimal Skeleton of GLFW code #include #include int main()int main(){ glfwInit(); glfwInit(); glfwOpenWindow(512,512,0,0,0,0,0,0,GLFW_WINDOW); glfwOpenWindow(512,512,0,0,0,0,0,0,GLFW_WINDOW); while(…) while(…) { { //Using OpenGL, GLU, GLFW functions //Using OpenGL, GLU, GLFW functions } } glfwTerminate(); glfwTerminate(); return 0; return 0;}

Graphical Application Structure Structure of GLFW Application –GLFW Initialization –OpenGL window opening –Animation frame (scene) generation –Termination

Graphical Application Structure Animation frame (scene) generation –Buffers Cleaning –Projection Type Setting –View Point Setting –Drawing a frame in the hidden buffer –Swapping the hidden buffer with the visible one Task –Identify these elements in generated source code in Task 1

Alternative Structure of Minimal GLFW Application Proposed in GLFW Reference Manual

Task №4 Alternative Structure of Graphical Application Define the following functions: –bool running() – to test whether to continue running –void init() – to initialize the graphical window, to set perspective, to set point of view and etc. –void finit() – to close the graphical window and to terminate the process

Alternative Structure of Minimal GLFW Application #include #include bool running() { // definition } void init() { // definition } void finit() { // definition } int main() { init(); // Initialization init(); // Initialization while( running() ) // Testing while( running() ) // Testing { glClear( GL_COLOR_BUFFER_BIT ); glClear( GL_COLOR_BUFFER_BIT ); glRotatef( 0.1, 0.4, -0.2, 0.7); // We will keep this rotation, because It will be necessary for other tasks glRotatef( 0.1, 0.4, -0.2, 0.7); // We will keep this rotation, because It will be necessary for other tasks // single frame drawing // single frame drawing // // glfwSwapBuffers(); glfwSwapBuffers(); } finit(); // Termination finit(); // Termination return 0; return 0;}

Task 5:OpenGL primitives – points, lines, triangles, squares, polygons glBegin(GLenum mode); …. // list of vertices and colors glEnd();Parameters Mode - Specifies the primitive or primitives that will be created from vertices presented between glBegin and the subsequent glEnd. Ten symbolic constants are accepted:GL_POINTS,GL_LINES,GL_LINE_STRIP,GL_LINE_LOOP,GL_TRIANGLES,GL_TRIANGLE_STRIP,GL_TRIANGLE_FAN,GL_QUADS, GL_QUAD_STRIP, and GL_POLYGON. More readings:

Vertices 2D void glVertex2i(GLint x, GLint y); void glVertex2f(GLfloat x, GLfloat y); 3D void glVertex3i(GLint x, GLint y, GLint z); void glVertex3f(GLfloat x, GLfloat y, GLfloat z);

I hope that you have no eye problem and will be able to see the result on the screen without magnifier I hope that you have no eye problem and will be able to see the result on the screen without magnifier

Color //integer values in range [0;255] void glColor3i(GLint red, GLint green, GLint blue); //floating point values in range [0.0; 1.0] void glColor3f(GLfloat red, GLfloat green, GLfloat blue);

2D Points glBegin(GL_POINTS); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1)

2D Lines glBegin(GL_LINES); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1)

Line Strip glBegin(GL_LINE_STRIP); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1)

2D Line Loop glBegin(GL_LINE_LOOP); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1)

2D Polygon glBegin(GL_POLYGON); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1) OpenGL only supports convex polygons (and really only triangles)

2D Quads glBegin(GL_QUADS); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1)

2D Quads glBegin(GL_QUADS); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glEnd(); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.);

2D Quads glBegin(GL_QUADS); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glEnd(); (-1,1) (-1,-1)(1,-1) (1,1) (-1,1) Lines should never pass through a vertex.

2D Triangles glBegin(GL_TRIANGLES); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1)

2D Triangles glBegin(GL_TRIANGLES); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.6,1.); glVertex2f(-.2,.6); glVertex2f(.6,1.); glVertex2f(-.2,.6); glVertex2f(.2,.6); glVertex2f(.6,1.); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); … glEnd(); (-1,-1)(1,-1) (1,1) (-1,1) Lines should never pass through a vertex.

2D Triangle Strip glBegin(GL_TRIANGLE_STRIP); glVertex2f(-.6,1.); glVertex2f(-.6,.6); glVertex2f(-.2,.6); glVertex2f(-.2,-.6); glVertex2f(-.6,-.6); glVertex2f(-.6,-1.); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glVertex2f(.2,-.6); glVertex2f(.2,.6); glVertex2f(.6,.6); glVertex2f(.6,1.); glEnd(); (-1,-1)(1,-1) (1,1) (-1,1)

2D Triangle Strip glBegin(GL_TRIANGLE_STRIP); glVertex2f(-.6,1.); glVertex2f(.6,1.); glVertex2f(-.2,.6); glVertex2f(.2,.6); glVertex2f(-.2,-.6); glVertex2f(.2,-.6); glVertex2f(.6,-1.); glVertex2f(.6,-.6); glEnd(); … (-1,-1)(1,-1) (1,1) (-1,1) First two vertices prime the pump, then every new vertex creates a triangle connecting it to the previous two vertices

2D Triangle Fan glBegin(GL_TRIANGLE_FAN); glVertex2f(-.2,.6); glVertex2f(-.6,.6); glVertex2f(-.6,1.); glVertex2f(.6,1.); glVertex2f(.2,.6); glVertex2f(.2,-.6); glVertex2f(-.2,-.6); glEnd(); … (-1,-1)(1,-1) (1,1) (-1,1) First two vertices prime the pump, then every new vertex creates a triangle connecting it to the previous vertex and the first vertex

Assigning Color glColor3f(0,0,1); glBegin(GL_POLYGON); glVertex2f(-1,1); glVertex2f(-1,-1); glVertex2f(1,-1); glEnd(); glColor3f(1,0,0); glBegin(GL_POLYGON); glVertex2f(-1,1); glVertex2f(-1,-1); glVertex2f(1,-1); glEnd(); glColor3f(0,0,0); glBegin(GL_LINE_LOOP); glVertex2f(-1,1); glVertex2f(-1,-1); glVertex2f(1,-1); glEnd(); glBegin(GL_POLYGON); glColor3f(0,1,0); glVertex2f(-1,1); glColor3f(0,0,1); glVertex2f(-1,-1); glColor3f(1,0,0); glVertex2f(1,-1); glEnd();

Paying with 3D coordinates: –Draw 8 vertices of a cube –Center point (0,0,0) –Cube size = 2 Task 6:Cube vertices

Result

Task 7:Cube edges Make some changes in Task 6 such that: –Draw cube edges –Each edge is drawn as separate line

Result

Task 7:Cube edges – v2 Make some changes in Task 7 such that: –Draws a connected group of line segments from the first vertex to the last, then back to the first.

Task 8: Cube Size Parameterization Write function to –Draw a cube with size а –In loop make a cube size to change randomly in predefined ranges

Task 9:Concentric Cubes Draw Concentric Cubes –Use a loop to draw 10 cubes with the same center point and different sizes

Result

Task 10: Cube Center Parameterization Add new parameter to the function for drawing a cube –Coordinates of the center point –Test this function by drawing 3 cubes next to each other

Result

Task 10: Cube Center Parameterization - v2 Draw –Big size cube and next to each of its sides 10 smaller cubes with decreasing sizes

Result

Questions?