#include "stdafx.h" #include<GLglut.h> void Init() { glClearColor(0.0f,0.0f,0.0f,0.0f); } void ChangeSize(int w,int h) { if (h==0) { h=1; } glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w<=h) { gluOrtho2D(-100.0,100.0,-100.0*h/w,100.0*h/w); } else { gluOrtho2D(-100.0*w/h,100.0*w/h,1-100.0,100.0); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void MyDisplay() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0,1.0,0.0); glBegin(GL_POLYGON); glVertex2f(-50.0f,-50.0f); glVertex2f(50.0f,-50.0f); glVertex2f(50.0f,50.0f); glVertex2f(-50.0f,50.0f); glEnd(); glutSwapBuffers(); } int main(int argc,char ** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE); glutInitWindowSize(500,500); glutInitWindowPosition(500,100); glutCreateWindow("Hello World"); Init(); glutDisplayFunc(MyDisplay); glutReshapeFunc(ChangeSize); glutMainLoop(); return 0; }
相关知识点
1.包含文件:gl,glu,glut,glee等等
2.命名规范
3.其他