2
在Visual C++下新建一个win32控制台程序
确定—下一步—完成
3
项目—管理Nuget程序包
4
浏览——在搜索栏输入NupenGL,安装这两个文件包
5
程序测试
#include
#include
#include
#include
static int year = 0, spin = 0, day = 0;static GLint fogMode;const int n = 100;const GLfloat R = 1.0f;const GLfloat Pi = 3.1415926536f;
void DrawCircle() {
int i;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINE_LOOP);
for (i = 0; i < n;="" ++i)="" {="" glcolor3f(1.0,="" 0.0,="" 0.0);="" glvertex2f(r*cos(2="" *="" pi="" n*i),="" r*sin(2="" *="" pi="" n*i));="" }="" glend();="" glflush();="" }="" void="" init(void)="" {="" glfloat="" position[]="{" 0.5,="" 0.5,="" 3.0,="" 0.0="" };="" glenable(gl_depth_test);="" 防止遮挡="" gllightfv(gl_light0,="" gl_position,="" position);="" glenable(gl_lighting);="" glenable(gl_light0);="" {="" glfloat="" mat[3]="{" 0.1745,="" 0.01175,="" 0.01175="" };="" glmaterialfv(gl_front,="" gl_ambient,="" mat);="" mat[0]="0.61424;" mat[1]="0.04136;" mat[2]="0.04136;" glmaterialfv(gl_front,="" gl_diffuse,="" mat);="" mat[0]="0.727811;" mat[1]="0.626959;" mat[2]="0.626959;" glmaterialfv(gl_front,="" gl_specular,="" mat);="" glmaterialf(gl_front,="" gl_shininess,="" 0.6*128.0);="" }="" glenable(gl_fog);="" {="" glfloat="" fogcolor[4]="{" 0.5,="" 0.5,="" 0.5,="" 1.0="" };="" fogmode="GL_EXP;" glfogi(gl_fog_mode,="" fogmode);="" glfogfv(gl_fog_color,="" fogcolor);="" glfogf(gl_fog_density,="" 0.35);="" glhint(gl_fog_hint,="" gl_dont_care);="" glfogf(gl_fog_start,="" 1.0);="" glfogf(gl_fog_end,="" 5.0);="" }="" glclearcolor(0.5,="" 0.9,="" 0.9,="" 1.0);="" fog="" color="" */="" }="" void="" display(void)="" {="" glclear(gl_color_buffer_bit="" |="" gl_depth_buffer_bit);="" glcolor3f(0.0,="" 1.0,="" 1.0);="" glpushmatrix();="" 记住自己的位置="" glutsolidsphere(1.0,="" 20,="" 16);="" 画太阳半径、="" 20经度、16纬度*/="" glrotatef(spin,="" 0.0,="" 1.0,="" 0.0);="" 自转,绕着一个向量以给定角度旋转(正的为逆时针)="" gltranslatef(2.0,="" 1.0,="" 0.0);="" glrotatef(spin,="" 1.0,="" 0.0,="" 0.0);="" 公转="" glrectf(0.1,="" 0.1,="" 0.5,="" 0.5);="" glcolor3f(0.0,="" 0.0,="" 1.0);="" glutwiresphere(0.2,="" 8,="" 8);="" 画第一颗小行星="" */="" glcolor3f(1.0,="" 0.0,="" 0.0);="" gltranslatef(2.0,="" 1.0,="" 0.0);="" glrotatef(2="" *="" spin,="" 0.0,="" 1.0,="" 0.0);="" glutsolidsphere(0.5,="" 16,="" 8);="" glpopmatrix();//回到原来的位置="" glutswapbuffers();="" }="" void="" spindisplay(void)="" {="" spin="spin" +="" 2;="" if="" (spin=""> 360)
spin = spin - 360;
glutPostRedisplay();
}
void mouse(int button, int state, int x, int y) {
switch (button)
{
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN)
glutIdleFunc(spinDisplay);
break;
case GLUT_MIDDLE_BUTTON:
if (state == GLUT_DOWN)
glutIdleFunc(NULL);
break;
default:
break;
}
}
void reshape(int w, int h) {
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);
}
void keyboard(unsigned char key, int x, int y) {
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;
case 27:
exit(0);
break;
default:
break;
}
}
int main(int argc, 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();
return 0;
}
除了以上方法外,也可以根据visual studio中团队资源管理器的提示安装第三方工具。不过有可能出现打不开链接的情况,所以推荐使用前面提到的方法。
安装好后,打开visual studio的工具->选项->源代码管理,选择“当前源代码管理插件”为“microsoft git 提供程序”。
将需要上传得解决方案添加到源代码管理器,可以从文件->添加到源代码管理,或者在解决方案管理器中选中解决方案,然后右键选择“将解决方案添加到源代码管理”。
点击后会弹出选择对话框,此时选择第二个选项“git”,复选框“将来创建项目时使用随选的系统”可选可不选,一般选上方便其他项目的管理。
此时,添加后的项目会在团队资源管理器中显示,此时我们先点击主页图标,打开项目管理目录,包括“更改”、“分支”、“未同步提交”和“设置”。此处我们选择“设置”,并点击“git设置”。
在git设置中,设置好用户名和电子邮件地址,使用github的用户名和邮箱即可。
设置好后,修改默认存储库的位置到该项目目录,这个很重要,如果不修改后续将推送失败。
设置好后点击更新,系统在项目目录下添加了两个文件,忽略文件“.gitignore”和属性文件“.gitattributes”。这两个文件也可以自己编辑修改,设置需要忽略的文件。
设置好以后,回到团队资源管理器主页,选择“更改”,然后输入commit消息,点击提交。
提交后便可以推送到github了,前提是在github中已经创建好了一个仓库用来存储该项目。我已经在我的github中创建了“udp”仓库,根据visual studio中的提示选择同步,或点击“未同步提交”,将仓库地址(https://开头的地址)复制到编辑框中。
最后点击"发布",此时将弹出对话框提示连接到github.com,输入即可。确定后就发布成功了。
注意事项
visual studio仅支持http and https,不支持ssh协议,所以设置仓库地址时一定要选用https的地址。