Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics, Lee Byung-Gook, Dongseo Univ.

Similar presentations


Presentation on theme: "Computer Graphics, Lee Byung-Gook, Dongseo Univ."— Presentation transcript:

1 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
13 January 2019 Computer Graphics Lee Byung-Gook 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

2 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
13 January 2019 OpenGL Most Widely Adopted Graphics Standard High Visual Quality and Performance Industry standard, Reliable and portable Stable, Easy to use and Well-documented 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

3 OpenGL software libraries
13 January 2019 OpenGL software libraries This course makes use of several popular libraries to help build sophisticated portable graphics applications with minimal effort. The following diagram gives an overview of the packages and how they interact. For the purposes of this course, one can think of the GLU and glut libraries as being part of the OpenGL library or the OpenGL API (application programmer's interface), even though this is not really the case. The Tcl/Tk library will only be used for some assignments and in these cases is used to provide a reasonable command-line interface and graphical interface to the graphics code. It provides easy-to-use scripting functionality and a graphical user interface toolkit 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

4 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
13 January 2019 Software libraries OpenGL : provides most of the graphics functionality GLU : provides support for some additional operations and primitive types, and is implemented using OpenGL function calls glut : designed specifically to be used with OpenGL and it takes care of things like opening windows, redraw events, and keyboard and mouse input. It effectively hides all the windowing system dependencies for OpenGL 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

5 Installing OpenGL for Windows
13 January 2019 Installing OpenGL for Windows bundled with Win98, Win95, WinNT or download** it look for dynamically-linked libraries (dlls): C:\Winnt\system32\Opengl32.dll on Windows NT C:\Windows\system\Opengl32.dll on Windows 95 look for header files, e.g., for Visual C++: C:\Program Files\Microsoft Visual Studio\VC98\include\gl\*.h OpenGL v1.1 software runtime is included as part of operating system for Windows 2000, Windows 98, Windows 95 (OSR2) and Windows NT. So you only need to download this if you think your copy is somehow missing . The OpenGL v1.1 libraries are also available as the self-extracting archive file from the Microsoft Site via HTTP or FTP. 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

6 Installing glut for Windows
glut.h C:\Program Files\Microsoft Visual Studio\VC98\include\gl\glut.h glut32.lib C:\Program Files\Microsoft Visual Studio\VC98\lib\glut32.lib glut32.dll C:\Windows\system32\glut32.dll on Windows 95, 98 C:\WINNT\system32\glut32.dll on Windows 2000, NT 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

7 Compiling with Visual C++
13 January 2019 Compiling with Visual C++ Start Visual C++ Choose File  new, then from the Projects tab select Win32 Console Application Assign the project a name (`lab00' for example), and choose a directory where the project files will be stored Choose File  new, then from the Files tab select  C++ Source File Assign the file a name, ‘lab00' for example. The .cpp extension will be added for you. Fill in the file lab00.cpp Now, Let’s begin OpenGL program. The following steps describe how to write and compile a simple OpenGL application in the Visual C++ environment. They assume that the OpenGL and glut libraries have been properly installed. The example was tested with Microsoft Visual C++ v5.0, although I expect that any version after and including v4.0 to work identically. The following example code draws a barney purple rectangle on a light gray background. 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

8 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
13 January 2019 lab00.cpp // lab00.cpp, Computer Graphics, #include <GL/glut.h> void myDisplay(void) { glClearColor (.75, .75, .75, 0.0); glMatrixMode(GL_PROJECTION); glOrtho(0, 500, 0, 500, -1, 1); glMatrixMode(GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.60, .40, .70); glBegin(GL_POLYGON); glVertex2i(450, 250); glVertex2i(412, 367); glVertex2i(312, 440); glVertex2i(188, 440); glVertex2i(88, 368); glVertex2i(50, 250); glVertex2i(88, 132); glVertex2i(188, 60); glVertex2i(312, 60); glVertex2i(412, 132); glEnd(); glFlush(); } void main(int argc, char** argv) { glutInit(&argc,argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutCreateWindow("lab00"); glutDisplayFunc(myDisplay); glutMainLoop(); } 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

9 Compiling with Visual C++
13 January 2019 Compiling with Visual C++ Choose Project  Settings and select the C/C++ panel. Enable Generate browse info. Select the Link panel. At the beginning (or anywhere) of the Object/library modules entry, add the libraries opengl32.lib and glut32.lib. Accept all the project setting changes by choosing OK. This will later enable you to easily track where functions are defined and where they are referenced, much like the `tags' feature in emacs.  Leave the other entries in the panel as they are. Don't hit OK just yet. 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

10 Compiling with Visual C++
Choose Build  Build lab00.exe, or simply hit the F7 key in order to compile and link. A successful compilation would have produced the following output in your 'build' window: Configuration: lab00 - Win32 Debug Compiling... lab00.cpp Linking... lab00.exe - 0 error(s), 0 warning(s) 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

11 Compiling with Visual C++
If there are errors, hitting F4 will take you to the location of the first error message in the code, and thereafter always take you to the next error message.  Or, one can double click on any error message to jump to the relevant source code. Once the code has successfully compiled and linked, Build-Execute or Ctrl-F5 will run the code, as will double-clicking on the test.exe icon (found in the Debug directory) from a file browsing window. 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

12 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Basic drawing OpenGL is a "state" machine : Once it is in a state, it stays in that state until the state is changed. Basic commands glClearColor(red, green, blue, 0.0); // sets background color glClear(GL_COLOR_BUFFER_BIT); // clears the window to the background color glColor3f(red, green, blue); // values between 0.0 (no color) & 1.0 (full color) glBegin(*); // determines how vertices are interpreted 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

13 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Basic drawing glVertex2i(412, 367); glVertex2i(312, 440); glVertex2i(188, 440); glVertex2i(88, 368); glVertex2i(50, 250); glVertex2i(88, 132); glVertex2i(188, 60); glVertex2i(312, 60); glVertex2i(412, 132); glEnd(); // clears the state initiated by 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

14 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
13 January 2019 Colors {1.0f, 0.0f, 0.0f} //red {0.0f, 1.0f, 0.0f} //green {0.0f, 0.0f, 1.0f} //blue {1.0f, 1.0f, 0.0f} //yellow {1.0f, 0.0f, 1.0f} //magenta {0.0f, 1.0f, 1.0f} //cyan {1.0f, 1.0f, 1.0f} //white {.25f, .25f, .25f} //dark gray {.75f, .75f, .75f} //light gray {.60f, .40f, .12f} //brown {.60f, .40f, .70f} //barney purple {.98f, .625f, .12f} //pumpkin orange {.98f, .04f, .70f} //pastel pink This is famous color values. 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

15 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
13 January 2019 Drawing primitives OpenGL supports several basic primitive types, including points, lines, quadrilaterals, and general polygons. All of these primitives are specified using a sequence of vertices. glBegin and glEnd delimit the vertices that define a primitive or a group of like primitives. GL_POINTS Treats each vertex as a single point. Vertex n defines point n. N points are drawn. glBegin accepts a single argument that specifies in which of ten ways the vertices are interpreted. Taking n as an integer count starting at one, and N as the total number of vertices specified, the interpretations are as follows: 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

16 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Drawing primitives GL_LINES Treats each pair of vertices as an independent line segment. Vertices 2n-1 and 2n define line n. N/2 lines are drawn. GL_LINE_STRIP Draws a connected group of line segments from the first vertex to the last. Vertices n and n+1 define line n. N-1 lines are drawn. GL_LINE_LOOP Draws a connected group of line segments from the first vertex to the last, then back to the first. Vertices n and n+1 define line n. The last line, however, is defined by vertices N and 1. N lines are drawn. 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

17 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Drawing primitives GL_TRIANGLES Treats each triplet of vertices as an independent triangle. Vertices 3n-2, 3n-1, and 3n define triangle n. N/3 triangles are drawn. GL_TRIANGLE_STRIP Draws a connected group of triangles. One triangle is defined for each vertex presented after the first two vertices. For odd n, vertices n, n+1, and n+2 define triangle n. For even n, vertices n+1, n, and n+2 define triangle n. N-2 triangles are drawn. GL_TRIANGLE_FAN Draws a connected group of triangles. One triangle is defined for each vertex presented after the first two vertices. Vertices 1, n+1, and n+2 define triangle n. N-2 triangles are drawn. 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

18 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Triangle 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

19 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Drawing primitives GL_QUADS Treats each group of four vertices as an independent quadrilateral. Vertices 4n-3, 4n-2, 4n-1, and 4n define quadrilateral n. N/4 quadrilaterals are drawn. GL_QUAD_STRIP Draws a connected group of quadrilaterals. One quadrilateral is defined for each pair of vertices presented after the first pair. Vertices 2n-1, 2n, 2n+2, and 2n+1 define quadrilateral n. N/2-1 quadrilaterals are drawn. Note that the order in which vertices are used to construct a quadrilateral from strip data is different from that used with independent data. GL_POLYGON Draws a single, convex polygon. Vertices 1 through N define this polygon. 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

20 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Quad 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

21 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
13 January 2019 Basic primitives GL_LINES, GL_LINE_STRIP All of the closed primitives shown below are solid-filled, with the exception of GL_LINE_LOOP, which only draws lines connecting the vertices. 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

22 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Basic primitives GL_LINE_LOOP, GL_TRIANGLES 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

23 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Basic primitives GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

24 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Basic primitives GL_QUADS, GL_POLYGON 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

25 OpenGL Naming Convension
13 January 2019 OpenGL Naming Convension gl : gl library Vertex : command 2f : number and type of parameters OpenGL Data Type Presentation C-language GLbyte 8-bit integer signed char b GLshort 16-bit integer short s GLint, GLsizei 32-bit integer long l GLfloat,GLclampf 32-bit float float f GLdouble,GLclampd 64-bit float double d GLubyte,GLboolean 8-bit unsigned unsigned char ub GLushort 16-bit unsigned unsigned short us GLuint,GLenum 32-bit unsigned unsigned long ui GL commands are functions or procedures. Various groups of commands perform the same operation but differ in how arguments are supplied to them. To conveniently accommodate this variation, we adopt a notation for describing commands and their arguments. 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

26 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
13 January 2019 glVertex[234][b s i f d ub us ui]{v}(*) // allows 2 (x,y), 3 (x,y,z), or 4 (x,y,z,w) values // allows the following data types // b signed char; 8 bit integer // s short; 16 bit integer // i integer; 32 bit integer // f float; 32 bits // d double; 64 bits // ub unsigned byte; 8 bits // us unsigned short; 16 bits // ui unsigned int; 32 bits // optional v  defined in an array (vector) GL commands are formed from a name followed, depending on the particular command, by up to 4 characters. The first character indicates the number of values of the indicated type that must be presented to the command. The second character or character pair indicates the specific type of the arguments: 8-bit integer, 16-bit integer, 32-bit integer, single-precision floating-point, or double-precision floating-point. The final character, if present, is v, indicating that the command takes a pointer to an array (a vector) of values rather than a series of individual arguments. Two specific examples come from the Vertex command to sends a vertex to be drawn void Vertex3f( float x, float y, float z ); and void Vertex2sv( short v[2] ); 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

27 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
13 January 2019 lab01.cpp // lab01.cpp, Computer Graphics, #include <stdio.h> #include <stdlib.h> #include <GL/glut.h> GLint windowWidth, windowHeight, N=4; void myAxis(void) { int i; glColor3f(0.98, .04, .70); glBegin(GL_LINES); for(i=1; i<N; i++) { glVertex2i(i*windowWidth/N, 0); glVertex2i(i*windowWidth/N, windowHeight); glVertex2i(0, i*windowHeight/N); glVertex2i(windowWidth, i*windowHeight/N); } glEnd(); void myDraw(void) { glColor3f(0.60, .40, .70); glBegin(GL_POLYGON); glVertex2i(windowWidth/N, windowHeight/N); glVertex2i(3*windowWidth/N, windowHeight/N); glVertex2i(3*windowWidth/N, 3*windowHeight/N); glVertex2i(windowWidth/N, 3*windowHeight/N); glEnd(); } void myDisplay(void) glClear(GL_COLOR_BUFFER_BIT); myAxis(); myDraw(); glFlush(); 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

28 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
13 January 2019 lab01.cpp void myReshape(int width, int height) { glClearColor (.75, .75, .75, 0.0); glViewport(0,0,width,height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, width, 0, height, -1, 1); windowWidth=width; windowHeight=height; glMatrixMode(GL_MODELVIEW); } void main(int argc, char** argv) glutInit(&argc,argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutCreateWindow("lab01"); glutReshapeFunc(myReshape); glutDisplayFunc(myDisplay); glutMainLoop(); 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

29 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Lab 01 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

30 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Lab 0101, 0102 Homework1 : in two weeks 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

31 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Lab 0103, 0104 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

32 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Lab 0105, 0106 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

33 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Lab 0107, 0108 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

34 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Lab 0109 13 January 2019 Computer Graphics, Lee Byung-Gook, Dongseo Univ.


Download ppt "Computer Graphics, Lee Byung-Gook, Dongseo Univ."

Similar presentations


Ads by Google