1 / 34

Computer Graphics

Computer Graphics. Lee Byung-Gook. OpenGL. Most Widely Adopted Graphics Standard High Visual Quality and Performance Industry standard, Reliable and portable Stable, Easy to use and Well-documented. OpenGL software libraries. Software libraries.

jana
Download Presentation

Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Graphics Lee Byung-Gook Computer Graphics, Lee Byung-Gook, Dongseo Univ.

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

  3. OpenGL software libraries Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  4. 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 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  5. 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 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  6. Installing glut for Windows • http://www.opengl.org/developers/documentation/glut.html?glut#first_hit • 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 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  7. 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 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  8. lab00.cpp // lab00.cpp, Computer Graphics, lbg@dongseo.ac.kr #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(); } Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  9. 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. 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) 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. Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  12. 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 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  13. 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 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  14. 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 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  15. 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. Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  16. 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. Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  17. 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. Computer Graphics, Lee Byung-Gook, Dongseo Univ.

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

  19. 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. Computer Graphics, Lee Byung-Gook, Dongseo Univ.

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

  21. Basic primitives • GL_LINES, GL_LINE_STRIP Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  22. Basic primitives • GL_LINE_LOOP, GL_TRIANGLES Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  23. Basic primitives • GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  24. Basic primitives • GL_QUADS, GL_POLYGON Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  25. 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 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  26. 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) Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  27. lab01.cpp // lab01.cpp, Computer Graphics, lbg@dongseo.ac.kr #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(); } Computer Graphics, Lee Byung-Gook, Dongseo Univ.

  28. 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(); } Computer Graphics, Lee Byung-Gook, Dongseo Univ.

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

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

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

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

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

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

More Related