visual studio 2010 的openGL环境的搭建
来源:互联网 发布:php冒泡排序是什么意思 编辑:程序博客网 时间:2024/05/14 17:22
一. 首先你要有一个glut包,(如果没有请到网上下载一个),里面会有这么一些文件:(如图)
二. 接下来的事情就是你要把对应的文件放到对应的位置:
(1) glut.h
这个文件放目目录C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\gl
这个目录不用你考虑你的软件安装在哪个文件夹
将解压得到的头文件glut.h复制到目录如下目录下:
X:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\GL
提示:如果在incluce目录下没有GL文件夹,则需要手动创建
(2) glut.dll,glut32.dll
这两个dll放在目录C:\Windows\SysWOW64(64位)
C:\Windows\System32(32位)
这个目录也不用你考虑你的软件安装在哪个文件夹
(3) glut.lib,glut32.lib
这两个文件放在目录 (XXXXXXXXXXX)\VC\lib
请注意,这两个文件放的位置跟你vs2010安装在哪里有关,比如我的安装在G:\编程工具\VS 2010 旗舰版\vs2010安装
这个目录下那么就放在目录 G:\编程工具\VS 2010 旗舰版\vs2010安装\VC\lib目录下面
三.在vs2010中的设置:
- 打开VS2010 ,按照下面的步骤新建一个win32控制台程序我们来测试一下我们刚刚配置的环境
新建项目àwin32控制台应用程序-->输入名称为:openGL(如图)
点击“确定”--->“下一步”--->“空项目”--->“完成”
这样一个空的控制台项目就建好了
2.按ctrl+Shift+A,添加一个cpp文件到该解决方案,名称为openGL(如下图)
3.设置目录
①包含目录:
点项目—>openGL属性(根据工程名不同)--->配置属性(点开)--->VC++目录-->包含目录(用鼠标选中它,然后最右边会有一个向下的三角形,点它)--->编辑--->点
图标,输入 你刚刚放入 glut.h文件的目录 即C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\gl(如下图)
②库目录:
就在包含目录下面,点开“库目录”,输入你刚刚放入glut.lib,glut32.lib的目录即(XXXXXXXXXXX)\VC\lib
向我的就是G:\编程工具\VS 2010 旗舰版\vs2010安装\VC\lib
四.运行测试程序:
把下面这个简单的程序输入到刚刚新建的openGL.cpp中,然后运行,成功的话就会一个正方形移动的图:
// Bounce.cpp
#include<windows.h>
#include<glut.h>
#include<GLU.h>
#include<GL.h>
// Initial square position and size
GLfloat x = 0.0f;
GLfloat y = 0.0f;
GLfloat rsize = 25;
// Step size in x and y directions
// (number of pixels to move each time)
GLfloat xstep = 1.0f;
GLfloat ystep = 1.0f;
// Keep track of windows changing width and height
GLfloat windowWidth;
GLfloat windowHeight;
///////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);
// Set current drawing color to red
// R G B
glColor3f(1.0f, 0.0f, 0.0f);
// Draw a filled rectangle with current color
glRectf(x, y, x + rsize, y - rsize);
// Flush drawing commands and swap
glutSwapBuffers();
}
///////////////////////////////////////////////////////////
// Called by GLUT library when idle (window not being
// resized or moved)
void TimerFunction(int value)
{
// Reverse direction when you reach left or right edge
if(x > windowWidth-rsize || x < -windowWidth)
xstep = -xstep;
// Reverse direction when you reach top or bottom edge
if(y > windowHeight || y < -windowHeight + rsize)
ystep = -ystep;
// Actually move the square
x += xstep;
y += ystep;
// Check bounds. This is in case the window is made
// smaller while the rectangle is bouncing and the
// rectangle suddenly finds itself outside the new
// clipping volume
if(x > (windowWidth-rsize + xstep))
x = windowWidth-rsize-1;
else if(x < -(windowWidth + xstep))
x = -windowWidth -1;
if(y > (windowHeight + ystep))
y = windowHeight-1;
else if(y < -(windowHeight - rsize + ystep))
y = -windowHeight + rsize - 1;
// Redraw the scene with new coordinates
glutPostRedisplay();
glutTimerFunc(33,TimerFunction, 1);
}
///////////////////////////////////////////////////////////
// Setup the rendering state
void SetupRC(void)
{
// Set clear color to blue
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}
///////////////////////////////////////////////////////////
// Called by GLUT library when the window has chanaged size
void ChangeSize(int w, int h)
{
GLfloat aspectRatio;
// Prevent a divide by zero
if(h == 0)
h = 1;
// Set Viewport to window dimensions
glViewport(0, 0, w, h);
// Reset coordinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Establish clipping volume (left, right, bottom, top, near, far)
aspectRatio = (GLfloat)w / (GLfloat)h;
if (w <= h)
{
windowWidth = 100;
windowHeight = 100 / aspectRatio;
glOrtho (-100.0, 100.0, -windowHeight, windowHeight, 1.0, -1.0);
}
else
{
windowWidth = 100 * aspectRatio;
windowHeight = 100;
glOrtho (-windowWidth, windowWidth, -100.0, 100.0, 1.0, -1.0);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
///////////////////////////////////////////////////////////
// Main program entry point
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(800,600);
glutCreateWindow("Bounce");
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
glutTimerFunc(33, TimerFunction, 1);
SetupRC();
glutMainLoop();
return 0;
}
- visual studio 2010 的openGL环境的搭建
- visual studio 2010 的openGL环境的搭建
- OpenGL+Visual Studio 2010开发环境搭建
- 在Visual Studio 2010上搭建Opengl环境
- Visual Studio 2015下OpenGL环境搭建
- Microsoft Visual Studio 2010搭建NUnit的.net单元测试环境
- 【OpenGL】000 Visual Studio 2015 搭建OpenGL环境
- 在Visual C++下搭建OpenGL的开发环境
- 使用Visual Studio 2005搭建opengl开发环境
- OpenGL 入门学习-—Visual Studio 2010环境配置,及过程出现的问题与解决方案
- QT For WinCE Visual Studio 2008环境的搭建
- Qt5 FOR WINCE7, Visual Studio 2008环境的搭建
- 【cocos2dx】基于visual studio 2013 的环境搭建
- OpenCV在Visual Studio开发环境的搭建
- Linux 上搭建Visual Studio Code 调试C++的环境
- qt的环境搭建(一) Visual Studio
- Visual Studio 2010 集成环境下配置OpenGL环境
- Visual Studio 2010搭建QT开发环境
- XML 数据请求与JSON 数据请求
- MapReduce案例学习(7) 列出名字以J开头的员工姓名及其所属部门名称
- java 值传递跟引用传递在内存中怎么分配的
- Linux中的sleep函数
- 段式存储管理 Vs 页式存储管理 Vs 段页式存储管理
- visual studio 2010 的openGL环境的搭建
- GCC参数含义
- Web开发常见的几个漏洞解决方法
- python代码覆盖率工具——coverage
- 幂等性
- A child container failed during start, tomcat的阿帕奇问题
- MapReduce案例学习(8) 列出工资最高的头三名员工姓名及其工资
- 旧项目适配 iOS9 时 .dylib 系统库文件的链接报错的问题处理
- Java并发编程:深入剖析ThreadLocal