#include <GL/glut.h>
float angle = 0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotated(angle, 1,1,0);
glutWireSphere(0.3,10,10);
glPopMatrix();
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
if(key==' ') angle += 10;
glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
-------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
#include <GL/glut.h>
#include "glm.h"
GLMmodel* pmodel = NULL;
float angle = 0;
void display()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
float pos[] = {0, 0, -1, 0};
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotated(angle, 1,1,1);
//glutWireSphere(0.3,10,10);
glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
glPopMatrix();
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
if(key==' ') angle += 10;
glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05");
glutDisplayFunc(display);
pmodel = glmReadOBJ("data/porsche.obj");
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
沒有留言:
張貼留言