vs怎么写opengl

1.如何在visualstudio2017中写OPENGL1.打开vs2015,运行—devenv2在VisualC++下新建一个win32控制台程序确定—下一步—完成3项目—管理Nuget程序包4浏览——在搜索栏输入NupenGL,安装这两个文件包5程序测试#include#include#include#includestaticintyear=0,spin=0,day=0;staticGLintfogMode;constintn=100;constGLfloatR=1.0f;constGLfloatPi=3.1415926536f;voidDrawCircle(){inti;glClear(GL_COLOR_BUFFER_BIT);glBegin(GL_LINE_LOOP);for(i=0;i360)spin=spin-360;glutPostRedisplay();}voidmouse(intbutton,intstate,intx,inty){switch(button){caseGLUT_LEFT_BUTTON:if(state==GLUT_DOWN)glutIdleFunc(spinDisplay);break;caseGLUT_MIDDLE_BUTTON:if(state==GLUT_DOWN)glutIdleFunc(NULL);break;default:break;}}voidreshape(intw,inth){glViewport(0,0,(GLsizei)w,(GLsizei)h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(60.0,(GLfloat)w/(GLfloat)h,0.5,20.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(0.0,10.0,10.0,0.0,0.0,0.0,0.0,1.0,0.0);}voidkeyboard(unsignedcharkey,intx,inty){switch(key){case'd':day=(day+10)%360;glutPostRedisplay();break;case'D':day=(day-10)%360;glutPostRedisplay();break;case'y':year=(year+5)%360;glutPostRedisplay();break;case'Y':year=(year-5)%360;glutPostRedisplay();break;case27:exit(0);break;default:break;}}intmain(intargc,char**argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);glutInitWindowSize(400,400);glutInitWindowPosition(100,100);glutCreateWindow("OpengGL程序设计测试");init();//glutDisplayFunc(DrawCircle);glutDisplayFunc(display);glutReshapeFunc(reshape);//glutKeyboardFunc(keyboard);glutMouseFunc(mouse);glutMainLoop();return0;} 。
2.用Visual Studio写一个OpenGL程序:实现立方体的转动#define GLUT_DISABLE_ATEXIT_HACK#include #include static float day=360;void myDisplay(void){ glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(75,1,1,400); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,-2,2,0,0,0,0,0,1); glRotatef(day/30.0*360.0-day/360.0*360.0,0.0f,0.0f,-1.0f); glTranslatef(1,0.0f,0.0f); glBegin( GL_QUADS ); //top glColor3f( 1.0f, 0.0f, 0.0f ); glNormal3f( 0.0f, 1.0f, 0.0f ); glVertex3f( 0.5f, 0.5f, 0.5f ); glVertex3f( 0.5f, 0.5f, -0.5f ); glVertex3f( -0.5f, 0.5f, -0.5f ); glVertex3f( -0.5f, 0.5f, 0.5f ); glEnd(); glBegin( GL_QUADS ); //forward glColor3f( 0.0f, 1.0f, 0.0f ); glNormal3f( 0.0f, 0.0f, 1.0f ); glVertex3f( 0.5f, 0.5f, 0.5f ); glVertex3f( -0.5f, 0.5f, 0.5f ); glVertex3f( -0.5f, -0.5f, 0.5f ); glVertex3f( 0.5f, -0.5f, 0.5f ); glEnd(); glBegin( GL_QUADS ); //right glColor3f( 0.0f, 0.0f, 1.0f ); glNormal3f( 1.0f, 0.0f, 0.0f ); glVertex3f( 0.5f, 0.5f, 0.5f ); glVertex3f( 0.5f, -0.5f, 0.5f ); glVertex3f( 0.5f, -0.5f, -0.5f ); glVertex3f( 0.5f, 0.5f, -0.5f ); glEnd(); glBegin( GL_QUADS ); //left glColor3f( 1.0f, 1.0f, 0.0f ); glNormal3f( -1.0f, 0.0f, 0.0f ); glVertex3f( -0.5f, 0.5f, 0.5f ); glVertex3f( -0.5f, 0.5f, -0.5f ); glVertex3f( -0.5f, -0.5f, -0.5f ); glVertex3f( -0.5f, -0.5f, 0.5f ); glEnd(); glBegin( GL_QUADS ); //bottom glColor3f( 1.0f, 0.0f, 1.0f ); glNormal3f( 0.0f, -1.0f, 0.0f ); glVertex3f( -0.5f, -0.5f, 0.5f ); glVertex3f( -0.5f, -0.5f, -0.5f ); glVertex3f( 0.5f, -0.5f, -0.5f ); glVertex3f( 0.5f, -0.5f, 0.5f ); glEnd(); glBegin( GL_QUADS ); glColor3f( 0.0f, 1.0f, 1.0f ); //back glNormal3f( 0.0f, 0.0f, -1.0f ); glVertex3f( 0.5f, -0.5f, -0.5f ); glVertex3f( -0.5f, -0.5f, -0.5f ); glVertex3f( -0.5f, 0.5f, -0.5f ); glVertex3f( 0.5f, 0.5f, -0.5f ); glEnd(); glFlush(); glutSwapBuffers();}void myIdle(){ day = day + 0.1; if (day>=360) { day=0; } myDisplay();}int main(int argc, char* argv[]){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE); glutInitWindowPosition(100,100); glutInitWindowSize(600,600); glutCreateWindow("第一个OpenGL程序"); glutDisplayFunc(&myDisplay); glutIdleFunc(&myIdle); glutMainLoop(); return 0;} 。
3.怎么在visual studio 2010中配置openGL编程的环境啊OpenGL需要两种东西:GLUT和GLEW
【vs怎么写opengl】FreeGLUT,GLUT的替代版: