CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [http://nehe.gamedev.net/]http://nehe.gamedev.net/

Slides:



Advertisements
Similar presentations
Department of nskinfo i-education
Advertisements

OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
OPEN GL. Install GLUT Download package di sini Dari devcpp, buka Tools->PackageManager-
Chapter 2: Graphics Programming
Computer Graphics CSCE 441
#include int line_width = 1; void Display( void ) { glEnable( GL_LINE_STIPPLE ); glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT);
OpenGL Basics.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
Draw a Simple Object. Example 1/4 #include “ glut.h ” void display(); void reshape(GLsizei w, GLsizei h); void main(int argc, char** argv){ glutInit(&argc,
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
#4: OpenGL Implementation & Project 2 CSE167: Computer Graphics TAs: Alex Kozlowski & Cameron Chrisman UCSD, Winter 2006.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
Device Independent Graphics and OpenGL
CENG477 Introduction to Computer Graphics Introduction to OpenGL, GLUT and GLUI.
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.
Write a Simple Program with OpenGL & GLUT. Books and Web Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible.
Chapter 03: Graphics Primitives Course web page: Chapter #3.
Reference1. [OpenGL course slides by Rasmus Stenholt]
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.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 2 Initial Steps in Drawing Figures Ureerat Suksawatchon Faculty of Informatics.
2 COEN Computer Graphics I Introductions n Brad Grantham lecturer lab dude n Dave Shreiner lecturer slave driver.
Lecture 3 OpenGL.
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.
Modeling with OpenGL Practice with OpenGL transformations.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
NoufNaief.net TA: Nouf Al-harbi.
NoufNaief.net 1 TA: Nouf Al-Harbi.
CSCE 441: Computer Graphics
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
Chap 2 Write a Simple OpenGL Program. Preparing 1/2 environment : Microsoft Visual C 、 Microsoft Visual C++.Net Also need : GLUT
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
CIS 681 Review: OpenGL. CIS 681 Command Syntax OpenGL commands start with a gl. This is followed by the base command such as Color. Followed by the number.
Introduction to Graphics Programming. Graphics API.
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: Event-driven How in OpenGL? Programmer registers callback functions Callback function called when.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics -practical- Lecture 6. (visual c++) open gl library To use open GL with VC++ we add these files:- 1)Glut.h C:\program files\ Microsoft.
OpenGL and GLUT Review Daniel Ritchie Monday, October 3 rd, 2011.
CSC Graphics Programming
Introduction to OpenGL (IDE: Eclipse)
The Human Visual System vs The Pinhole camera
CS380 Lab Spring Myungbae Son.
Reference1. [OpenGL course slides by Rasmus Stenholt]
Programming with OpenGL Part 2: Complete Programs
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Starting to draw dealing with Windows which libraries? clipping
גרפיקה ממוחשבת: מבוא ל-OpenGL
Drawing in the plane 455.
Introduction to OpenGL
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Starting to draw dealing with Windows which libraries? clipping
Programming with OpenGL Part 2: Complete Programs
University of North Carolina at Greensboro
Presentation transcript:

CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [

Goal Introduce OpenGL programming Help you do CS380 homework by yourself 2

Outline Set up OpenGL development environments on Visual Studio  Download and dll/libs setting Start with the OpenGL framework  Draw a OpenGL primitive  Address keyboard and mouse input 3

Starting with an empty project Create an empty Win32 Console Application 4

Starting with an empty project Create an empty Win32 Console Application 5

Starting with an empty project Download PA1 source files & move into project directory 6

Starting with an empty project Add to the current project 7

Visual Studio Functions Press F7 to build solution Press Ctrl + F5 to run program 8

Download GLUT 9

Troubleshooting : LIB Error Solution 1  Copy glut32.lib to $(SolutionDir) or $(SolutionDir)\$(Configuration) e.g., C:\CS380\OpenGL_Tutorial\Release 10

Troubleshooting : LIB Error Solution 2  Set project specific lib path 11

Troubleshooting : DLL Error Solution 1  Copy glut32.dll to C:\Windows\System32 or to $(SolutionDir)\$(Configuration) e.g., C:\CS380\OpenGL_Tutorial\Release 12

Troubleshooting : DLL Error Solution 2  Set project specific PATH 13 PATH=%PATH%;path-to-dll-files e.g., C:\Downloads\glut bin\glut bin

Done! 14

Outline Install Dev-C++ and OpenGL environments  Run an empty window  Note: Visual C++ with OpenGL is similar Reference: course slides “Basic OpenGL structure” Start with the OpenGL framework  Draw a OpenGL primitive  Address keyboard and mouse input 15

Install Dev-C++ Download Dev-C++ beta 9 release  Click

Install Dev-C++ Just click “Next” 17

Dev-C++ starts up Click File/New/Project 18

Dev-C++ starts up Click “Console Application” 19

Dev-C++ starts up Make a new folder, save the project file 20

Dev-C++ starts up Click Execute/Compile (Ctrl + F9) Click Execute/Run (Ctrl + F10) 21

Download and install GLUT Download GLUT files from wnloads.php wnloads.php Extract glutming.zip 22

Download and install GLUT Copy GLUT files to the install folder of DEV-C++  glut.h: copy this file to C:\Dev-Cpp\include\GL  libglut32.a: copy (or replace) this file to C:\DEV- Cpp\lib  glut32.dll: copy this file to C:\Windows\System32 Check whether there is “opengl32.dll” in this folder 23

Download and install GLUT Project setting in DEV-C++  Click Project/Project Options 24

Download and install GLUT Project setting in DEV-C++  Click Project/Project Options 25

Download and install GLUT Project setting in DEV-C++  Click Parameters, and Add Library or Object 26

Download and install GLUT Project setting in DEV-C++  Add three library files in this order C:/Dev-Cpp/lib/libopengl32.a C:/Dev-Cpp/lib/libglu32.a C:/Dev-Cpp/lib/libglut32.a 27

Creating an empty window #include void display() { } int main( int argc, char* argv[] ) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(512, 512); glutCreateWindow("CS380 LAB"); glutDisplayFunc( display ); glutMainLoop(); return 0; } 28

Draw your first polygon void display()  Main display function where we can do all the drawing 29

Draw your first polygon Clear your screen  void display() {  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  glFlush();  } glClear(parameters) // clear input buffers glFlush() // forces all pending commands to be executed 30

Draw your first polygon void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // Reset our view glBegin(GL_TRIANGLES); // Draw a triangle glVertex3f( 0.0f, 1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glEnd(); glFlush(); } 31 (0,0,0)

Draw your first polygon 32 In OpenGL, geometry is specified by vertices Vertices must be specified between glBegin(primitive type) and glEnd() function calls The primitive type represents how vertices are to be connected glBegin(GL_TRIANGLES); glVertex3f( 0.0f, 1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glEnd();

33 OpenGL Primitives Triangles  There are 3 ways of making triangles with OpenGL Individual triangles  Type is GL_TRIANGLES  Each triangle requires 3 explicit vertices  Sets of unconnected triangles are often called polygon soups Strips of connected triangles  Type is GL_TRIANGLE_STRIP  The first triangle requires 3 vertices, the rest use 1 new vertex and the 2 most recently defined vertices  Complex objects are often built from Fans of connected triangles  Type is GL_TRIANGLE_FAN  Every triangle use the first, the previous, and a new vertex  Useful for creating polygons or approximating circles/ellipses GL_TRIANGLE_STRIP GL_TRIANGLES GL_TRIANGLE_FAN

34 OpenGL Primitives Quadrilaterals (quads)  Individual quads Type is GL_QUADS A quad is defined by 4 vertices Quads can be decomposed into two triangles Quads are not necessarily plane or convex  Be careful with the vertex sequence  Strips of connected quads Type is GL_QUAD_STRIP Uses the most recent 2 vertices and 2 new vertices GL_QUADS GL_QUAD_STRIP

35 OpenGL Primitives Polygons  Type is GL_POLYGON  Polygons need 3 or more vertices I.e. can be used for any polygon  Polygons are divided into triangles by the graphics card GL_POLYGON

36 OpenGL Primitives Points  Type is GL_POINTS  Points are 0-D  Points represent the simplest drawable primitive  1 vertex is used per point  Points are rendered as small, unconnected dots on the screen  Theoretically points have no area GL_POINTS

37 OpenGL Primitives Lines  Type is GL_LINES  Lines are 1-D  Each line needs 2 vertices  Lines have no area Open series of lines  Type is GL_LINE_STRIP Closed series of lines  Type is GL_LINE_LOOP GL_LINES GL_LINE_STRIP GL_LINE_LOOP

38 OpenGL functions OpenGL functions all follow the same naming conventions  Function names have gl, glu, or glut as prefix depending on their package of origin  The name of the function follows the prefix  The parameter type of the function is placed as a postfix

39 OpenGL functions 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 )

Tutorial Draw this rectangle 40

Tutorial Drawing a red rectangle glBegin(GL_QUADS); glVertex3f( -0.5f, -0.5f, 0.0f); glVertex3f(-0.5f, 0.5f, 0.0f); glVertex3f( 0.5f, 0.5f, 0.0f); glVertex3f( 0.5f,-0.5f, 0.0f); glEnd(); 41

Adding colours glColor3f(red, green, blue) Drawing a red rectangle glBegin(GL_QUADS); glColor3f(1.0f,0.0f,0.0f); glVertex3f( -0.5f, -0.5f, 0.0f); glVertex3f(-0.5f, 0.5f, 0.0f); glVertex3f( 0.5f, 0.5f, 0.0f); glVertex3f( 0.5f,-0.5f, 0.0f); glEnd(); 42

43 Colours in OpenGL Colours are modelled using the red-green- blue (RGB) system

44 Colours in OpenGL There are several ways of representing colour in OpenGL  Directly as RGB-tuples  Extended RGBA-tuples  Indexed mode The RGBA mode has an extra component, alpha, which does not affect the colour directly  Alpha is used when blending colours E.g. transparency effects

45 Colours in OpenGL Colours are specified by the glColor*() family of functions Example: glColor3f()  Specifies a colour by three floating point values in the range [0.0;1.0]  The parameters represent R, G, and B, respectively

Keyboard input int main( int argc, char* argv[] ) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize( width, height ); glutCreateWindow("CS380"); glutDisplayFunc( display ); glutMouseFunc( mouse ); glutKeyboardFunc( keyboard ); glutReshapeFunc( reshape ); glutMainLoop(); return 0; } 46

Keyboard input void keyboard(unsigned char key, int x, int y) { if (key == 'r') { // todo } glutPostRedisplay(); } 47

Tutorial Change the color of your rectangle  Press ‘r’: change it to a red rectangle  Press ‘g’: change it to a green rectangle  Press ‘b’: change it to a blue rectangle 48

Tutorial void display() { … glColor3f(r,g,b); … } 49 void keyboard(unsigned char key, int x, int y){ if (key == 'r') { r = 1.0, g = 0.0, b = 0.0; } else if (key == 'g') { r = 0.0, g = 1.0, b = 0.0; } else if (key == 'b') { r = 0.0, g = 0.0, b = 1.0; } glutPostRedisplay(); }

Mouse input int main( int argc, char* argv[] ) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize( width, height ); glutCreateWindow("CS380"); glutDisplayFunc( display ); glutMouseFunc( mouse ); glutKeyboardFunc( keyboard ); glutReshapeFunc( reshape ); glutMainLoop(); return 0; } 50

Mouse input void mouse( int button, int state, int mx, int my ) button  GLUT_LEFT_BUTTON  GLUT_MIDDLE_BUTTON  GLUT_RIGHT_BUTTON state  GLUT_DOWN  GLUT_UP mx, my  positions 51

Mouse input void mouse( int button, int state, int mx, int my ) { if((button == GLUT_LEFT_BUTTON) && (state == GLUT_DOWN) ) { r = 1.0, g = 1.0, b = 1.0; display(); } 52

53 Next time Transformation in OpenGL