一、opengl与C++环境配置

1. 下载opengl包。

2. 将压缩包解压后,

  (1)将.dll文件(GLU.DLL, GLUT.DLL, GLUT32.DLL)放到C:\Windows\System32目录下;

  (2)将.h文件(GL.H, GLAUX.H, GLU.H, GLUT.H)放到\\Microsoft Visual Studio 11.0\VC\include\gl目录下,如果gl文件夹没有就新建;

  (3)将.lib文件(glut.lib, glut32.lib, glaux.lib)放到\\Microsoft Visual Studio 11.0\VC\lib目录下;

3. 一般情况下,至此vs与opengl的环境搭建完毕,如果出现其他的问题,可能是链接库没有设置好!

4. 示例代码

 #include<GL/glut.h>
// 绘制立方体
// 将立方体的八个顶点保存到一个数组里面
static const float vertex_list[][] =
{
-0.5f, -0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
-0.5f, 0.5f, -0.5f,
0.5f, 0.5f, -0.5f,
-0.5f, -0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
};
// 将要使用的顶点的序号保存到一个数组里面
static const GLint index_list[][] =
{
{, }, {, }, {, }, {, },
{, }, {, }, {, }, {, },
{, }, {, }, {, }, {, }
};
// 绘制立方体
void DrawCube(void)
{
int i,j;
glBegin(GL_LINES);
for(i=; i<; ++i) // 12 条线段
{
for(j=; j<; ++j) // 每条线段 2个顶点
{
glVertex3fv(vertex_list[index_list[i][j]]);
}
}
glEnd();
} static float rotate = ;
static int times = ;
void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
//glTranslatef(-0.2, 0, 0); // 平移
//glScalef(2, 1, 1); // 缩放
times++;
if(times > )
times = ;
if(times % == )
rotate += 0.3;
glRotatef(rotate, , , );
glRotatef(rotate, , , );
glColor3f(, , );
DrawCube();
glPopMatrix();
glutSwapBuffers();
} void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(,);
glutInitWindowSize(, );
glutCreateWindow("GLDemo");
glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);
glutMainLoop();
}

二、opengl与C#环境配置

opengl与C#的环境配置,最流行的是tao库!以tao库配置为例!

1. 首先下载tao库。 http://www.taoframework.com,并安装在自己熟悉的目录下!方便寻找dll文件和相应的附录学习资源

2. 新建C#项目,并在引用栏导入tao库.dll。一般情况下最常使用的库有Tao.OpenGl、Tao.FreeGlut和Tao.Platform.Windows;

并在C#文件开头加入代码:

using Tao.OpenGl;
using Tao.FreeGlut;
using Tao.Platform.Windows;

3. 示例代码

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tao.OpenGl;
using Tao.FreeGlut;
namespace Okokok
{
class Program
{
static public void Display()
{ Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
Gl.glColor3d(1.0, , ); Gl.glTranslated(-,,);
Gl.glLoadIdentity();
Glu.gluLookAt(0.0,0.0,5.0, 0.0,0.0,0.0, 0.0,1.0,0.0);
//glut库中提供的画图函数
Glut.glutWireTeapot(1.5);
// Glut.glutWireIcosahedron();
// Glut.glutWireCube(1.7);
// Glut.glutWireTetrahedron();
// Glut.glutWireTorus(0.2, 1, 100, 100);
// Glut.glutWireCone(2, 1, 100, 100);
// Glut.glutWireSphere(2, 100, 100);
Glut.glutSwapBuffers(); }
static public void Reshape(int w, int h)
{
Gl.glViewport(, , w, h);
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Glu.gluPerspective(, (double)w/(double)h, , );
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity();
Glu.gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); Gl.glRotated(,, , );
}
static public void Shape()
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
Glut.glutWireTeapot(1.8);
Glut.glutWireCube(1.7);
Glut.glutWireIcosahedron();
Gl.glFlush(); }
static void Main(string[] args)
{
Glut.glutInit();
Glut.glutInitDisplayMode(Glut.GLUT_RGBA | Glut.GLUT_SINGLE);
Glut.glutInitWindowPosition(, );
Glut.glutInitWindowSize(, );
Glut.glutCreateWindow("TTTTT");
Glut.glutDisplayFunc(Display);
Glut.glutReshapeFunc(Reshape);
Glut.glutMainLoop();
}
}
}

4. 问题调试:如果运行后发现问题,确少FreeGlut.dll文件,就需要重新将这个文件添加到系统目录C:\Windows\System32下。

总结,如果还有其他问题,百度之!

window下Opengl与vs2012环境配置的更多相关文章

  1. Windows7+VS2012下OpenGL 4的环境配置

    系统环境 Windows 7 Ultimate x64,Visual Studio Ultimate 2012 Update 4,和一块支持OpenGL 4.x的显卡. 准备工作 首先用GPU Cap ...

  2. OS X 下 OpenGL 4.x 环境配置

    配置: OS X 10.10 + CMake 3.2.2 + GLFW 3.1.1 + OpenGL 4.1 + Xcode 6.0 本文主要介绍如何在 OS X 系统下进行环境配置,使得 Xcode ...

  3. OpenGL C#绘图环境配置

    OpenGL C#绘图环境配置   OpenGL简介 OpenGL作为一种图形学编程接口已经非常流行, 虽然在大型游戏方面DirectX有一定的市场占有率, 但由于OpenGL的开放性,可移植性等优点 ...

  4. Window下搭建foundation apps环境

    Window下搭建foundation apps环境 框架:AngularJS.Foundation, 构建工具:Gulp, 开发环境:node.js. 操作系统:windows (一)环境准备 1 ...

  5. window下设置定时任务及基本配置

    ### window下设置定时任务及基本配置 轉載請註明出處: https://www.cnblogs.com/funnyzpc/p/11746439.html |****************** ...

  6. LibOpenCM3(一) Linux下命令行开发环境配置

    目录 LibOpenCM3(一) Linux下命令行开发环境配置 本文使用 Linux 环境, 硬件为 STM32F103 系列开发板 LibOpenCM3 介绍 LibOpenCM3 是GPL协议( ...

  7. window下搭建c开发环境(GNU环境的安装)

    一.在windows平台上安装GNU环境 windows操作系统不自带GNU环境,如果需要开发跨平台的C语言程序,那么需要给windows安装GNU环境 windows下的两款GNU环境:MinGW和 ...

  8. 【OpenGL】VS2010环境配置 [转]

    基于OpenGL标准开发的应用程序运行时需有动态链接库OpenGL32.DLL.Glu32.DLL,这两个文件在安装Windows NT时已自动装载到C:\WINDOWS\SYSTEM32目录下(这里 ...

  9. window下eclipse搭建hadoop环境

    1 生成插件jar 1.1 安装java,ant运行环境 1.2 下载hadoop-2.5.0.tar.gz并解压到指定目录 1.3 下载hadoop2x-eclipse-plugin-master. ...

随机推荐

  1. 我的arduino theme文件

    #FUNCTIONS COLOR             #D35400 - ORANGE            KEYWORD1 #FUNCTIONS COLOR            #D3540 ...

  2. Current Sourcing (拉電流) and Current Sinking(灌電流)

    Current Sourcing and Sinking Current sourcing and sinking is often mentioned in relation to electron ...

  3. 524. Longest Word in Dictionary through Deleting

    Given a string and a string dictionary, find the longest string in the dictionary that can be formed ...

  4. VS恢复默认设置

    通过“导入和导出设置”实现VS恢复默认设置 1.快捷步骤 工具 → 导入和导出设置 → 重置所有设置 → 下一步 → 选择“是否保存当前设置”,下一步 → 选择“要重置的开发语言(如,Visual C ...

  5. AC日记——封锁阳光大学 洛谷 P1330

    封锁阳光大学 思路: bfs染色: 如果当前点能通往已染色的点则不能完成: 图不一定联通: 来,上代码: #include <queue> #include <cstdio> ...

  6. Codeforces Gym100812 L. Knights without Fear and Reproach-扩展欧几里得(exgcd)

    补一篇以前的扩展欧几里得的题,发现以前写错了竟然也过了,可能数据水??? 这个题还是很有意思的,和队友吵了两天,一边吵一边发现问题??? L. Knights without Fear and Rep ...

  7. Codeforces 912E Prime Gift(预处理 + 双指针 + 二分答案)

    题目链接 Prime Gift 题意  给定一个素数集合,求第k小的数,满足这个数的所有质因子集合为给定的集合的子集. 保证答案不超过$10^{18}$ 考虑二分答案. 根据折半的思想,首先我们把这个 ...

  8. NanoPC-T3 64位裸机编程 —— 启动和运行状态切换

    参考: https://github.com/metro94/s5p6818_spl https://github.com/trebisky/Fire3/tree/master/Boot_NSIH h ...

  9. SQLite添加列的限制

    SQLite添加列的限制   向SQLite表中添加字段,需要注意以下问题: (1)添加的列不能定义为主键. (2)添加的列为日期时间类型,不能使用CURRENT_TIME.CURRENT_DATE. ...

  10. VS如何反汇编

    1. 打开反汇编窗口:调试模式下,按Ctrl+F11.2. 术语: 2.1 ESP(Extended Stack Pointer): 堆栈指针,寄存器存放当前线程的栈顶指针: i.e: move eb ...