Documente Academic
Documente Profesional
Documente Cultură
Reshape 2
In nearly all windowing environments, the user can at any time
change the size and dimensions of the window.
Even if you are writing a game that always runs in full-screen
mode, the window is still considered to change size once—when
it is created.
When this happens, the window usually responds by redrawing its
contents, taking into consideration the window’s new dimensions.
Sometimes, you might want to simply clip the drawing for smaller
windows or display the entire drawing at its original size in a
larger window.
Aspect Ratio ( width / height) - II 4
Initialization :
1. Initialize OpenGL & GLUT
Initialization
2. Load models.
3. Load animation file.
Set Timer function Set Timer function :
1. Use glutTimerFunc() to set Timer function.
#include <stdlib.h>
#include <GL/glut.h>
void init(void) {
glClearColor (0.0, 0.0, 0.0, 0.0);
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(spin, 0.0, 0.0, 1.0);
glColor3f(1.0, 0.0, 0.0);
glRectf(-25.0, -25.0, 25.0, 25.0);
glPopMatrix();
glutSwapBuffers(); // instead of glFlush()
}
Example 2/4 12
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutIdleFunc(update);
glutMainLoop();
return 0;
}
What is next? 15
Arguments
• msecs : ms.
• Func : Timer function pointer.
• Value : argument pass to Timer function.
Ex.
• glutTimerFunc(5000, TimerFunc, 0);
call TimerFunc(0) 5000 ms later.
Example 1/4 17
#include <GL/glut.h>
#include <stdlib.h>
static GLfloat spin = 0.0;
int timer_milliseconds = 34; // 34 milliseconds are approx. fps = 29.97
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(spin, 0.0, 0.0, 1.0);
glColor3f(1.0, 0.0, 0.0);
glRectf(-25.0, -25.0, 25.0, 25.0);
glPopMatrix();
glutSwapBuffers();
}
Example 2/4 18
1. Donald Hearn, M. Pauline Baker, Computer Graphics with OpenGL, Third Edition, Prentice Hall,
2004.
2. Hill, F. S., Kelly S. M., Computer Graphics Using OpenGL, Third Edition, Pearson Education, 2007,
http://www.4twk.com/shill/
3. http://ironbark.bendigo.latrobe.edu.au/~fran/int32gp/2006/wk04/tt_02.html