Glut

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

OpenGL/GLUT API

Cac API su dung trong OpenGL

============================

1. Khoi tao chuong trinh dung GLUT

void glutInit(int *argc, char **argv);

Tham so: argc va argv truyen vao tu ham 'main()'

2. Thiet lap vi tri cua so

void glutInitWindowPosition(int x, int y)

Tham so: toa do cua so tu goc trai tren cung

3. Thiet lap kich thuoc cua so

void glutInitWindowSize(int width, int height)

Tham so:

width - chieu rong cua so

height - chieu dai cua so

4. Thiet lap che do man hinh

void glutInitDisplayMode(int mode)

Tham so:

mode - che do man hinh

Cac kieu che do mode duoc dinh nghia san


a. Che do mau sac

GLUT_RGBA (mac dinh)

GLUT_RGB

GLUT_INDEX

b. Che do rai (buffer mode)

GLUT_SINGLE

GLUT_DOUBLE

c. Che do cac kieu rai

GLUT_ACCUM

GLUT_STENCIL

GLUT_DEPTH

De su dung ket hop cac che do voi nhau, su dung toan tu bitwise OR (|).

Vi du: glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA );

tuc la thiet lap man hinh che so sau kieu rai kep o che do RGBA

5. Thiet lap cua so

void glutCreateWindow(char* title)

Tham so:

title - tieu de cua cua so

6. Quy dinh ham xu ly ve man hinh (rendering)

void glutDisplayFunc(void (*func)(void))


Tham so:

(*func)() - con tro toi ham xu ly render

Chu y: bat buoc phai co, khong duoc truyen vao tham so NULL (gay ra crash)

7. Giu chuong trinh chay lien tuc

void glutMainLoop()

8. Ham xu ly khi cua so bi thay doi

void glutReshapeFunc(void (*func)(void))

Tham so:

(*func)() - con tro toi ham xu ly cua so

9. Ham xu ly khi cua so o che do tinh (Idle)

void glutIdleFunc(void (*func)(void))

Tham so:

(*func)() - con tro toi ham xu ly

10. Ham goi trinh xu ly rai doi (double buffering)

void glutSwapBuffers();

11. Ham xu ly tu ban phim voi cac ki tu nhan biet duoc duoi ma ASCII

void glutKeyboardFunc(void (*func) (unsigned char key, int x, int y))

Tham so
(*func)(unsigned char key, int x, int y) - con tro toi ham xu ly

key - ki tu vao

x - toa do x cua chuot (hoanh do)

y - toa do y cua chuot (tung do)

12. Ham xu ly cac ki tu tren ban phim ma nhan biet duoc duoi ma ASCII

void glutSpecialFunc(void (*func)(int key, int x, int y)

Tham so:

tuong tu glutKeyboardFunc() nhung key duoc dinh nghia san la 1 trong so

nhung ma sau:

GLUT_KEY_F1 F1

GLUT_KEY_F2 F2

...

GLUT_KEY_F12 F12

GLUT_KEY_LEFT Left function key

GLUT_KEY_RIGHT Up function key

GLUT_KEY_UP Right function key

GLUT_KEY_DOWN Down function key

GLUT_KEY_PAGE_UP Page Up function key

GLUT_KEY_PAGE_DOWN Page Down function key

GLUT_KEY_HOME Home function key

GLUT_KEY_END End function key

GLUT_KEY_INSERT Insert function key


13. Ham xu li cac ki tu tren ban phim duoi dang to hop (combination keys)

int glutGetModifiers();

Gia tri tra ve la 1 trong 3 phim duoc dinh nghia san

GLUT_ACTIVE_SHIFT

GLUT_ACTIVE_CTRL

GLUT_ACTIVE_ALT

14. Thiet lap che do lap di lap lai cho ban phim (repeat key mode)

int glutSetKeyRepeat(int repeatMode)

Tham so:

repeatMode - duoc dinh nghia san voi 3 che do sau

GLUT_KEY_REPEAT_OFF

GLUT_KEY_REPEAT_ON

GLUT_KEY_REPEAT_DEFAULT

15. Mot ham khac tuong tu glutSetKeyRepeat() va an toan hon

int glutIgnoreKeyRepeat(int repeatMode)

Tham so

repeatMode - duoc dinh nghia voi 2 gia tri

1 - tu dong lap (auto-repeat)

0 - dung qua trinh lap (non-repeat)


16. Ham kiem tra neu phim thuong duoc nha ra (key release)

void glutKeyboardUpFunc(void (*func)(unsigned char key, int x, int y))

17. Tuong tu glutKeyboardUpFunc() nhung voi cac phim dac biet

void glutSpecialUpFunc(void (*func)(int key, int x, int y))

18. Ham xu ly su kien chuot

void glutMouseFunc(void (*func)(int button, int state, int x, int y))

Tham so:

(*func)(int button, int state, int x, int y) - con tro toi ham xu ly chuot

button - nut chuot duoc an, duoc dinh nghia voi 3 kieu sau

GLUT_LEFT_BUTTON

GLUT_RIGHT_BUTTON

GLUT_MIDDLE_BUTTON

state - trang thai nut chuot duoc dinh nghia voi 2 kieu

GLUT_DOWN

GLUT_UP

x - hoanh do cua chuot

y - tung do cua chuot

19. Ham xu ly chuyen dong chuot o trang thai dong va trang thai tinh

void glutMotionFunc(void (*func)(int x, int y))

void glutPassiveMotionFunc(void (*func)(int x, int y))


20. Ham kiem tra hanh vi chuot vao cua so hay roi cua so

void glutEntryFunc(void (*func)(int state))

Tham so:

(*func)(int state) - con tro xu ly trang thai chuot

state - trang thai chuot so voi cua so, duoc dinh nghia voi 2 kieu

GLUT_LEFT

GLUT_ENTERED

21. Tao menu

int glutCreateMenu(void (*func)(int value))

Tham so:

(*func)(int value) - con tro toi ham xu ly su kien tao menu

22. Them mot item vao menu

void glutAddMenuEntry(char* name, int value)

Tham so:

name - ten menu

value - gia tri thiet lap de su dung khi goi

23. Gan menu vao nut chuot

void glutAttachMenu(int button)

Tham so:
button - nut chuot duoc gan menu vao, duoc dinh nghia voi 3 kieu nut o tren

24. Go menu ra khoi nut

void glutDetachMenu(int button)

tuong tu glutAttachMenu()

25. Xoa menu di

void glutDestroyMenu(int menuIdentifier)

Tham so:

menuIdentifier - id cua menu khi tao qua glutCreateMenu()

You might also like