WEEK15
Work01-攝影機
第一步:和過去相同開啟新專案,選擇Console application,在選擇C++
第二步:撰寫程式碼
//------------------------------------------------------程式碼-------------------------------------------------
#include <stdio.h>
#include <GL/glut.h>
void display()
{
//glClearColor(1,0,0,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glutSolidTeapot(1);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y)
{
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt(x / 100.0, y / 100.0, 5.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0 );
glutPostRedisplay();
}
void resize(int w,int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h );
glMatrixMode( GL_PROJECTION);
glLoadIdentity();
gluPerspective( 65.0, (GLdouble) w / h , 1.0 , 100.0);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0 );
}
int main(int argc,char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Crama");
glutMotionFunc(motion);
glutDisplayFunc(display);
glutReshapeFunc(resize);
glutMainLoop();
}
沒有留言:
張貼留言