I Doc
I Doc
S. M. Shahriar Nirjon
University of Virginia
email: [email protected]
Date: August 8, 2008
Abstract
1. Setup
Just copy the iGraphics folded in your PC. The folder contains the following files- GLUT.H,
GLUT32.LIB, GLUT32.DLL, iGraphics.h, iMain.cpp and iDoc.pdf.
2. Description of iMain.cpp
Users of iGraphics only have to edit, compile and run iMain.cpp using Vsual C++ 6. See the listing
of iMain.cpp.
# include "iGraphics.h"
/*
Function iDraw() is called again and again by the system.
*/
void iDraw()
{
//place your drawing codes here
}
/*
Function iMouseMove() is called when the user presses and drags
the mouse.(mx, my) is the position where the mouse pointer is.
*/
void iMouseMove(int mx, int my)
{
//place your codes here
}
/*
Function iMouse() is called when the user presses/releases the mouse.
(mx, my) is the position where the mouse pointer is.
*/
void iMouse(int button, int state, int mx, int my)
{
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
//place your codes here
}
if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
{
//place your codes here
}
}
/*
Function iKeyboard() is called whenever the user hits a key in
keyboard. key- holds the ASCII value of the key pressed.
*/
void iKeyboard(unsigned char key)
{
if(key == 'q')
{
//do something with 'q'
}
//place your codes for other keys here
}
/*
Function iSpecialKeyboard() is called whenver user hits special keys
like- function keys, home, end, pg up, pg down, arraows etc. you have
to use appropriate constants to detect them. A list is:
GLUT_KEY_F1, GLUT_KEY_F2, GLUT_KEY_F3, GLUT_KEY_F4, GLUT_KEY_F5,
GLUT_KEY_F6, GLUT_KEY_F7, GLUT_KEY_F8, GLUT_KEY_F9, GLUT_KEY_F10,
GLUT_KEY_F11, GLUT_KEY_F12, GLUT_KEY_LEFT, GLUT_KEY_UP, GLUT_KEY_RIGHT,
GLUT_KEY_DOWN, GLUT_KEY_PAGE UP, GLUT_KEY_PAGE DOWN, GLUT_KEY_HOME,
GLUT_KEY_END, GLUT_KEY_INSERT.
*/
void iSpecialKeyboard(unsigned char key)
{
if(key == GLUT_KEY_END)
{
exit(0);
}
//place your codes for other keys here
}
int main()
{
//place your own initialization codes here before iInitialize().
iInitialize(400, 400, "demooo");
return 0;
}
Fig: iMain.cpp
3. Functions in iGraphics.h
void iClear()
Description: Clears the screen. You should always call this function as
the first line of iDraw() to avoid flickering problem (িঝরিঝর সমসয্া) while
drawing.
Parameters: none
Q4. How to show a .bmp file whose size is not integral power of 2?
Ans. Best way is to resize the file using Paint. If you do not want to resize the .bmp
then still there is a way. [Think: every integer can be written as a sum of some integers
which are all powers of 2. Like, 100 = 64 + 36. So a picture with size 100 x 100 can be
divided into 4 pictures with dimensions 36 x 64, 36 x 36, 64 x 64 and 36 x 64]
Q4. Where should I can iSetTimer( ) and I do not understand the parameters and return
values of it? How can I control the timer?
Ans. We must call iSetTimer( ) only at the beginning of main( ) function, i.e. it
should be called before calling iInitialize( ). You must supply a time interval and you must
also supply a function of this type: void any_func(void) as a parameter to iSetTimer( ).
This function will be called again and again after the predefined time interval. Once
started, a timer cannot be stopped completely. It can be paused or resumed. There can be
maximum 10 timers in your program. These are numbered sequentially from 0 to 9.