More Related Content More from Budditha Hettige More from Budditha Hettige (20) Viewing8. Viewpoint and the Object
• Separating the Viewpoint and the Object
• glTranslatef(0.0, 0.0, -5.0);
8Budditha Hettige
9. Using the gluLookAt()
void gluLookAt
(
GLdouble eyex, GLdouble eyey, GLdouble eyez,
GLdouble centerx, GLdouble centery, GLdouble centerz,
GLdouble upx, GLdouble upy, GLdouble upz
);
9Budditha Hettige
15. The Transformed Depth Coordinate
• void glDepthRange(GLclampd near,
GLclampd far);
15Budditha Hettige
16. Animation
• Is an important part of computer graphics
• Taking a sequence of pictures and projecting
them at 24 frames per second on the screen
• void glutSwapBuffers(void);
16Budditha Hettige
17. Example
# include <windows.h>
#include <GL/glut.h>
#include <stdlib.h>
static GLfloat spin = 0.0;
void spinDisplay(void)
{
spin = spin + 0.05;
if (spin > 360.0)
spin = spin - 360.0;
glutPostRedisplay();
}
17
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(spin, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glRectf(-25.0, -25.0, 25.0, 25.0);
glPopMatrix();
glutSwapBuffers();
spinDisplay();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}Budditha Hettige
18. Example
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
18Budditha Hettige