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. QLineEdit 使用方法

    在Qt中,QLineEdit是文本编辑框控件,是比较基础且常用的控件的之一,下面是其的一些基本操作. 比如: 禁用或启用该控件 // lineedit is the object name of QL ...

  2. android之数据库SQLite(一)

    创建数据库 首先定义SQLiteOpenHelper的子类 代码如下: package com.example.myandroid; import android.content.Context; i ...

  3. memcached与spring

    key的生成规则 update 与 query 的参数不一样,如何让其生成一样的key 列表缓存如何定义key及失效 最近同事推荐了一个开源项目:Simple-Spring-Memcached(简称s ...

  4. NBOJv2 1034 Salary Inequity(DFS序+线段树区间更新区间(最值)查询)

    Problem 1034: Salary Inequity Time Limits:  10000 MS   Memory Limits:  200000 KB 64-bit interger IO ...

  5. CodeForces 625A 思维

    题意是说一个人喝酒 有两种办法 买塑料瓶的 a块钱 喝了就没了 或者是买玻璃瓶的b块钱 喝完还能卖了瓶子c块钱 求最多能喝多少瓶 在开始判断一次 a与b-c的关系 即两种方式喝酒的成本 如果a< ...

  6. Javascript 笔记与总结(1-2)词法分析

    词法分析,按顺序分析 3 样: 第 1 步:先分析参数 第 2 步:再分析变量声明 第 3 步:再分析函数声明 一个函数能使用的局部变量,就从上面 3 步分析而来. 具体步骤: 0:函数运行前的瞬间, ...

  7. C# Xml文件操作,解释见注释

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. How to Write a Spelling Corrector

    http://norvig.com/spell-correct.html Feb 2007to August 2016 How to Write a Spelling Corrector One we ...

  9. linux 输入java 出现中文乱码

    http://jingyan.baidu.com/article/ab69b270de8b4f2ca7189f1d.html 1.查看当前linux的编码 没设置之前是:zh_CN.UTF_8 输入 ...

  10. db link的查看创建与删除(转)

    1.查看dblink select owner,object_name from dba_objects where object_type='DATABASE LINK'; 或者 select * ...