Starting an OpenGL project in VS 2015 is really easy, thanks to the NupenGL.Core nuget package.

Here are really quick steps to start your first OpenGL project using the FreeGlut library to provide a Window toolkit.

Open Visual Studio 2015 Community Edition and create a new Visual Studio C++ Windows Console Application.

Keep it simple. Choose an empty project template.

Install the NupenGL.Core nuget package. From Visual Studio, Go to Tools \ NuGet Package Manager \ Manage Nuget Packages for this solution. Search for “NupenGL” and install the package.

测试代码:

// source: http://jingyan.baidu.com/article/d5c4b52bca5005da560dc5d6.html
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h> static int year = , spin = , day = ;
static GLint fogMode;
const int n = ;
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 = ; i < n; ++i)
{
glColor3f(1.0, 0.0, 0.0);
glVertex2f(R*cos( * Pi / n*i), R*sin( * 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[] = { 0.1745, 0.01175, 0.01175 };
glMaterialfv(GL_FRONT, GL_AMBIENT, mat);
mat[] = 0.61424; mat[] = 0.04136; mat[] = 0.04136;
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat);
mat[] = 0.727811; mat[] = 0.626959; mat[] = 0.626959;
glMaterialfv(GL_FRONT, GL_SPECULAR, mat);
glMaterialf(GL_FRONT, GL_SHININESS, 0.6*128.0);
} glEnable(GL_FOG); {
GLfloat fogColor[] = { 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纬度*/
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, , ); /* 画第一颗小行星 */
glColor3f(1.0, 0.0, 0.0);
glTranslatef(2.0, 1.0, 0.0);
glRotatef( * spin, 0.0, 1.0, 0.0);
glutSolidSphere(0.5, , );
glPopMatrix();//回到原来的位置
glutSwapBuffers();
} void spinDisplay(void) {
spin = spin + ;
if (spin > )
spin = spin - ;
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(, , (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 + ) % ;
glutPostRedisplay();
break;
case 'D':
day = (day - ) % ;
glutPostRedisplay();
break;
case 'y':
year = (year + ) % ;
glutPostRedisplay();
break;
case 'Y':
year = (year - ) % ;
glutPostRedisplay();
break;
case :
exit();
break;
default:
break;
}
} int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(, );
glutInitWindowPosition(, );
glutCreateWindow("OpengGL 程序设计--这段代码是我抄的");
init();
//glutDisplayFunc(DrawCircle);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
//glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop(); return ;
}

在Visual Studio 2015中运行OPENGL的更多相关文章

  1. ASP.NET 5系列教程 (五):在Visual Studio 2015中使用Grunt、Bower开发Web程序

    基于Visual Studio 2015,你可以: 方便的管理前端包,如jQuery, Bootstrap, 或Angular. 自动运行任务,如LESS.JavaScript压缩.JSLint.Ja ...

  2. Grunt和Gulp构建工具在Visual Studio 2015中的高效的应用

    Grunt和Gulp构建工具在Visual Studio 2015中的高效的应用 Grunt和Gulp是Javascript世界里的用来做自动压缩.Typescript编译.代码质量lint工具.cs ...

  3. ASP.NET5之客户端开发:Grunt和Gulp构建工具在Visual Studio 2015中的高效的应用

    Grunt和Gulp是Javascript世界里的用来做自动压缩.Typescript编译.代码质量lint工具.css预处理器的构建工具,它帮助开发者处理客户端开发中的一些烦操重复性的工作.Grun ...

  4. [.net 面向对象程序设计进阶] (27) 团队开发利器(六)分布式版本控制系统Git——在Visual Studio 2015中使用Git

    [.net 面向对象程序设计进阶] (26) 团队开发利器(六)分布式版本控制系统Git——在Visual Studio 2015中使用Git 本篇导读: 接上两篇,继续Git之旅 分布式版本控制系统 ...

  5. GitHub在Visual Studio 2015中获得TFS/VSO同等地位

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 在Visual Studio 2015中微软为GitHub提供了扩展插件,从而让GitHub ...

  6. Visual Studio 2015中的常用调试技巧分享

    .NET 技术交流群:337901356 欢迎您的加入! 为什么要学习调试? 调试(Debug)是作为一个程序员必须要学会的东西,学会调试可以极大的提高开发效率,排错时间,很多人不喜欢调试,但我认为这 ...

  7. 微软移除Visual Studio 2015中的UML

    微软已经在Visual Studio 2015中移除了UML(Unified Modeling Language,统一建模语言),原因是该语言使用率过低.因此微软要优化产品结构,把好钢用在刀刃上. V ...

  8. WebApi-路由机制 Visual Studio 2015中的常用调试技巧分享

    WebApi-路由机制   一.WebApi路由机制是什么? 路由机制通俗点来说:其实就是WebApi框架将用户在浏览器中输入的Url地址和路由表中的路由进行匹配,并根据最终匹配的路由去寻找并匹配相应 ...

  9. 在Visual Studio 2015 中添加SharePoint 2016 开发模板

    前言 SharePoint 2016已经发布很久了,然而,默认安装VS2015以后,却没有SharePoint 2016的开发模板.其实问题很简单,和VS2012开发SharePoint 2013一样 ...

随机推荐

  1. VBS发送邮件-1

    Set objMail = Server.CreateObject("CDO.Message") Set objCDOSYSCon = Server.CreateObject(&q ...

  2. 为什么我不再用 .NET 框架(转)

    NET平台很棒.真的很棒.直到它不再那么棒.我为什么不再用.NET?简单来说,它限制了我们选择的能力(对我来说很重要),转移了我们的注意力,使得我们向内认知它的安全性,替代了帮助我们认知外面广阔世界的 ...

  3. OS | 哲学家问题

    哲学家进餐问题: (1) 在什么情况下5 个哲学家全部吃不上饭?考虑两种实现的方式,如下:A.算法描述: void philosopher(int i) {/*i:哲学家编号,从0 到4*/ whil ...

  4. 按月将Windows日志导出至CSV文件

    # 这个月的第一天 #..........................................到这里之前是取当年第一天 #(Get-Date 0).AddYears((Get-Date). ...

  5. Js组件的一些写法【转】

    首先看下Prototype里的写法: var Class = { create: function() { return function() { this.init.apply(this, argu ...

  6. HDU 3555 数位dp入门

    开始想用dp[i][j]来记录第i位j开头含有49的数的个数 但是init后并不知道如何进行cal 想了想可以用不要62的思想 当作不要49来做 然后减一下 就好 看网上的代码 不要62和这道题用的d ...

  7. cURL 学习笔记与总结(4)使用 cURL 从 ftp 上下载文件与上传文件到 ftp

    下载: <?php $curlobj = curl_init(); curl_setopt($curlobj, CURLOPT_URL, "ftp://192.***.*.***/文件 ...

  8. ThinkPHP 学习笔记 ( 一 ) 项目部署:应用部署方式与模块分组部署方式

    /** * ThinkPHP version 3.1.3 */ ThinkPHP ( 官方网站:http://www.thinkphp.cn/ ) 目前最新版本是 3.2.2,它要求 PHP 的版本高 ...

  9. php调用empty出现错误Can't use function return value in write context

    php调用empty出现错误Can't use function return value in write context 2012-10-28 09:33:22 | 11391次阅读 | 评论:0 ...

  10. javascript Math.pow 函数 详解

    语法 Math.pow(x,y) 定义和用法 pow() 方法可返回 x 的 y 次幂的值. 处理简单数学问题 6的4次方等于1296,记作:64=1296; 求值: Math.pow(6,4)=12 ...