Presentation is loading. Please wait.

Presentation is loading. Please wait.

OpenGL Basics Donghui Han. Assignment Grading Visual Studio Glut Files of four types needed: – Source code:.cpp,.h – Executable file:.exe (build in release.

Similar presentations


Presentation on theme: "OpenGL Basics Donghui Han. Assignment Grading Visual Studio Glut Files of four types needed: – Source code:.cpp,.h – Executable file:.exe (build in release."— Presentation transcript:

1 OpenGL Basics Donghui Han

2 Assignment Grading Visual Studio Glut Files of four types needed: – Source code:.cpp,.h – Executable file:.exe (build in release mode) – Solution file:.sln – Project file:.proj

3 How to learn OpenGL? Build something OpenGL Programming Guide Search online

4 OpenGL does NOT do… windowing tasks Obtaining user input No high-level commands for describing models of three-dimensional objects

5 OpenGL Utility Toolkit (GLUT) For prototyping Compatible with many window systems Light (No sliders, No dialog box, No button, No menu). Need other API if more interaction is necessary, GLUI, Qt, etc.

6 OpenGL Utility Toolkit (GLUT) int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); init (); glutDisplayFunc(display); glutMainLoop(); return 0; /* ISO C requires main to return int. */ }

7 OpenGL Utility Toolkit (GLUT) int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); init (); glutDisplayFunc(display); glutMainLoop(); return 0; /* ISO C requires main to return int. */ } Initialize the GLUT library and specify the display mode: single/double buffer, RGB/color index, Depth on/off

8 OpenGL Utility Toolkit (GLUT) int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); init (); glutDisplayFunc(display); glutMainLoop(); return 0; /* ISO C requires main to return int. */ } Create a window with name “hello” with res 250*250 at window coordinate (100, 100)

9 OpenGL Utility Toolkit (GLUT) int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); init (); glutDisplayFunc(display); glutMainLoop(); return 0; /* ISO C requires main to return int. */ } OpenGL initialization: clear color, clear depth, enable functions, lighting, blending, viewport, projection matrix, etc.

10 OpenGL Utility Toolkit (GLUT) int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); init (); glutDisplayFunc(display); glutMainLoop(); return 0; /* ISO C requires main to return int. */ } Register callback functions here: display, keyboard, mouse, idle, window resize, etc.

11 OpenGL Utility Toolkit (GLUT) int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); init (); glutDisplayFunc(display); glutMainLoop(); return 0; /* ISO C requires main to return int. */ } Program goes into event driven mode (infinite loop waiting for something to happen).

12 OpenGL Utility Toolkit (GLUT) int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); init (); glutDisplayFunc(display); glutMainLoop(); return 0; /* ISO C requires main to return int. */ }

13 OpenGL does NOT do… http://en.wikipedia.org/wiki/Ray_tracing_%28graphics%29

14 OpenGL does NOT do… http://cg.alexandra.dk/?p=1307

15 OpenGL does NOT do… http://en.wikipedia.org/wiki/Radiosity_%28computer_graphics%29

16 OpenGL does NOT do… http://www.peterkutz.com/computergraphics/images/path_tracer/AmbientOcclusionMuscleCar.png

17 What does OpenGL do? https://cuboidzone.wordpress.com/tag/opengl/

18 What does OpenGL do? http://media.moddb.com/images/mods/1/3/2097/6416.jpg

19 OpenGL http://cdn.themetapicture.com/media/funny-people-taking-photos-drowning-person.jpg

20 void glMatrixMode(GLenum mode); void glLoadIdentity(void); void glLoadMatrix{fd}(const TYPE *m); void glMultMatrix{fd}(const TYPE *m); Viewing

21 void glPushMatrix(void); void glPopMatrix(void); Viewing

22 http://www.glprogramming.com/red/chapter03.html

23 Viewing void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdoubleupx, GLdouble upy, GLdouble upz);

24 Viewing void glTranslate{fd}(TYPEx, TYPE y, TYPEz); void glRotate{fd}(TYPE angle, TYPE x, TYPE y, TYPE z); void glScale{fd}(TYPEx, TYPE y, TYPEz);

25 Viewing void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); void gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top);

26 Viewing void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);

27 Viewing void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far);

28 Viewing void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);

29 Viewing

30 Drawing Geometric Objects #define PI 3.1415926535898 GLint circle_points = 100; glBegin(GL_LINE_LOOP); for (i = 0; i < circle_points; i++) { angle = 2*PI*i/circle_points; glVertex2f(cos(angle), sin(angle)); } glEnd();

31 Lighting void glLight{if}(GLenum light, GLenum pname, TYPEparam); void glLight{if}v(GLenum light, GLenum pname, TYPE *param);

32 Blending void glBlendFunc(GLenum sfactor, GLenum dfactor);

33 Drawing Pixels, Bitmaps void glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);

34 Other topics Display list Selection and Feedback Texture Mapping OpenGL Shading Language GPGPU …

35 Thanks for coming Office: ETB 2016 (knock on door) Email: donghui@cs.tamu.edu Office hours: TR: 3:00pm-5:00pm


Download ppt "OpenGL Basics Donghui Han. Assignment Grading Visual Studio Glut Files of four types needed: – Source code:.cpp,.h – Executable file:.exe (build in release."

Similar presentations


Ads by Google