Documente Academic
Documente Profesional
Documente Cultură
Roma
r e t u r n EXIT SUCCESS ;
}
Problem anyone?
But Empty Windows Are Pointless
Just like we have callbacks for the keyboard, we have similar ones
for the mouse. Much like how the keyboard can see the mouse,
calling glutGetModifiers() is used in the mouse callback function to
find out about the state of certain keyboard keys.
...
gluMouseFunc ( mouse ) ;
...
v o i d mouse ( i n t b u t t o n , i n t s t a t e , i n t x , i n t y
){
i f ( b u t t o n == GLUT LEFT BUTTON && s t a t e ==
GLUT DOWN) {
p r i n t f ( ”The mouse i s a t %d %d\n” , x , y ) ;
}
}
What About Mouse Movement
The previous function told us only when mouse buttons are
pushed. We need two different functions in order to track when
the mouse is moving
...
g l u t M o t i o n F u n c ( mouseMove ) ;
glutPassiveMotionFunc ( passiveMove ) ;
...
v o i d mouseMove ( i n t x , i n t y ) {
p r i n t f ( ”A b u t t o n i s down and t h e mouse i s a t
%d %d\n” , x , y ) ;
}
void passiveMove ( i n t x , i n t y ) {
p r i n t f ( ”No b u t t o n s a r e down and t h e mouse i s
a t %d %d\n” , x , y ) ;
}
Déjà Vu?
i n t menu = g l u t C r e a t e M e n u ( mainMenu ) ;
glutAddMenuEntry ( ” F i s h ” , 0 ) ;
glutAddMenuEntry ( ”Meat” , 1 ) ;
glutAddMenuEntry ( ” C h i c k e n ” , 2 ) ;
glutAddSubMenu ( ” E x t r a F u n c t i o n s ” , submenu ) ;
Stroke fonts are pretty much like everything else with GL. You use
a transform to set where you want them to be drawn, and draw as
normal. They will draw from where the translation moved to, and
drawing each character translates the model view matrix to fit the
next characted into place.
void display () {
g l T r a n s l a t e f ( 0 , 10 , 0 ) ;
g l S c a l e f ( 0 . 05 , 0 . 0 5 , 0 . 0 5 ) ;
glColor 3f (0 ,1 . 0 ,0) ;
f o r ( u n s i g n e d i n t i = 0 ; i < l e n g t h ; i ++) {
g l u t S t r o k e C h a r a c t e r (GLUT STROKE ROMAN, s [ i ] ) ;
}
glutPostRedisplay () ;
}
Stroke Fonts Killed Santa
We can also draw raster text to the screen. Raster cooridinates are
transformed the same way that normal vertex coordinates are using
the model view and projection matricies. Raster coordinates are
however tracked independantly.
glColor 3f (1 . 0 ,0 ,0) ;
glRasterPos 2 f (0 , 0) ;
f o r ( u n s i g n e d i n t i = 0 ; i < l e n g t h ; i ++) {
g l u t B i t m a p C h a r a c t e r ( GLUT BITMAP TIMES ROMAN
24 , s [ i ] ) ;
}
Life in Flatland