#include<windows.h>
#include<GL/glut.h>
int angx=0;
int angy=0;
int angz=0;
void display()
{
GLfloat mat_solid[] = {0.75, 0.75, 0.0, 1.0};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angx, 1.0, 0.0, 0.0);
glRotatef(angy, 0.0, 1.0, 0.0);
glRotatef(angz, 0.0, 0.0, 1.0);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_solid);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthMask(0);
glutWireCube(0.61);
glDepthMask(1);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
glEnable(GL_LIGHTING);
glutSolidCube(0.6);
glFrontFace(GL_CCW);
glDisable(GL_LIGHTING);
glDisable(GL_BLEND);
glPopMatrix();
glFlush();
}
void init()
{
glClearColor(0.0, 0.0, 0.0, 1.0);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
void reshape(int w, int h)
{
glViewport(0, 0,(GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
glOrtho(-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0);
else
glOrtho(-1.5*(GLfloat)w/(GLfloat)h,1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 'a':
angx+=10;
angx=angx%360;
break;
case 's':
angy+=10;
angy=angy%360;
break;
case 'd':
angz+=10;
angz=angz%360;
break;
case 'z':
exit(0);
break;
}
glutPostRedisplay();
}
int main(int grac, char** agrv)
{
glutInit(&grac, agrv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB |GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100,100);
glutCreateWindow("OUTLINE TEST");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
- 1
- 2
- 3
- 4
前往页