Download presentation
Presentation is loading. Please wait.
1
Basic Program with OpenGL and GLUT
2
Outline Development Environment What is GLUT? Set up a GLUT Project
Overview of GLUT Programs A Basic Program Example Some GLUT Functions API Documentation
3
Development Environment
OS IDE Library Windows 10 Windows 8 Windows 7 GLUT (includes OpenGL and GLU) Visual Studio 2013 Community version 系計中為win7 + visual studio 2013
4
What is GLUT? (1 / 2) OpenGL Utility Toolkit (GLUT)
Window system independent toolkit Simple windowing API for OpenGL Functions start with a prefix of “glut” (e.g., glutInit, glutMainLoop)
5
What is GLUT? (2 / 2) What can GLUT do?
Initializing and creating window Handling window and input events Drawing preset 3D objects Running the program
6
Set up a GLUT Project (1 / 9)
include lib dll glut.h gl.h (glut.h) glu.h (glut.h) glut32.lib glut32.dll
7
Set up a GLUT Project (2 / 9)
8
Set up a GLUT Project (3 / 9)
9
Set up a GLUT Project (4 / 9)
10
Set up a GLUT Project (5 / 9)
11
Set up a GLUT Project (6 / 9)
12
Set up a GLUT Project (7 / 9)
13
Set up a GLUT Project (8 / 9)
把實際需要使用的library列出
14
Set up a GLUT Project (9 / 9)
15
Overview of GLUT Programs
Point to Call Callback functions Initialization Set function pointers while(true){ if(funcBool){ funcBool = false; (*funcPtr)(…); } Main loop
16
A Basic Program Example (1 / 3)
17
A Basic Program Example (2 / 3)
18
A Basic Program Example (3 / 3)
19
Some GLUT Functions This section includes the following:
Initialization and window Callback Registration Geometric Object Rendering Beginning Event Processing
20
Initialization and Window (1 / 3)
void glutInit(int *argcp, char **argv); Initializing the GLUT library Should be called before any GLUT functions void glutInitDisplayMode(unsigned int mode); Specify a display mode for windows created Color: GLUT_RGBA, GLUT_RGB or GLUT_INDEX Framebuffer: GLUT_SINGLE or GLUT_DOUBLE Buffer: GLUT_DEPTH, GLUT_STENCIL and GLUT_ACCUM
21
Initialization and Window (2 / 3)
void glutInitWindowSize(int width, int height); Set the initial window size void glutInitWindowPosition(int x, int y); Set the initial window position The actual position is left to the window system to determine int glutCreateWindow(char *name); Create and open a window with previous settings
22
Initialization and Window (3 / 3)
void glutPostRedisplay(void); Mark the current window as needing to be redisplayed The window‘s display callback will be called void glutSwapBuffers(void); Swap the buffers of the current window if double buffered An implicit glFlush is done by glutSwapBuffers
23
Callback Registration (1 / 5)
void glutDisplayFunc(void (*func)(void)); Put whatever you want to render in the callback The callback is called when the window need to be redisplayed Call glutPostRedisplay() to trigger the callback void glutReshapeFunc(void (*func)(int width, int height)); The callback is called when a window is created, resized or moved Always call glViewport() to resize your viewport
24
Callback Registration (2 / 5)
void glutKeyboardFunc(void (*func)(unsigned char key, int x, int y)); Each key press generating a keyboard callback key: The ASCII character generated by the pressed key x and y: The mouse location in window relative coordinates when the key was pressed
25
Callback Registration (3 / 5)
void glutMouseFunc(void (*func)(int button, int state, int x, int y)); Each press and each release mouse button in a window generates a mouse callback button: GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON or GLUT_RIGHT_BUTTON state: GLUT_UP or GLUT_DOWN x and y: The mouse location in window relative coordinates when the mouse button state changed
26
Callback Registration (4 / 5)
void glutMotionFunc(void (*func)(int x, int y)); The callback is called when the mouse moves within the window while any mouse buttons are pressed x and y: the mouse location in window relative coordinates void glutPassiveMotionFunc(void (*func)(int x, int y)); The callback is called when the mouse moves within the window while no mouse buttons are pressed
27
Callback Registration (5 / 5)
void glutIdleFunc(void (*func)(void)); Perform background processing tasks or continuous animation when window system events are not being received The idle callback is continuously called when events are not being received
28
Geometric Object Rendering
Provide many objects such as sphere, cube, cone, torus All objects have wireframe and solid versions void glutSolidCube(GLdouble size); void glutWireTeapot(GLdouble size);
29
Beginning Event Processing
void glutMainLoop(void); Enter the GLUT event processing loop Once called, this routine will never return while(true){ if(funcBool){ funcBool = false; (*funcPtr)(…); } Call Callback functions
30
API Documentation (1 / 2) OpenGL 2.1 Reference Pages OpenGL and GLU
This course use legacy OpenGL (1.0 – 2.1)
31
API Documentation (2 / 2) GLUT API Version 3 For GLUT 3.x
32
Thanks for listening! Any questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.