当前位置:首页 » 编程软件 » 编译安装opengl教程

编译安装opengl教程

发布时间: 2023-05-16 23:17:25

㈠ 如何在VS2010配置OpenGL编译环境

刚装了win7和VS2010。看了下配置OpenGL的方法和以前不太一样。搜索得之。

glut下载地址:

http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip

glut.h ---> C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\gl

glut.dll,glut32.dll ---> C:\Windows\SysWOW64 (windows7 64位操作系统)

---> C:\Windows\System32 (windows7 32位操作系统)

glut.lib,glut32.lib ---> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib

!!无须!!用宏 #define GLUT_DISABLE_ATEXIT_HACK

好多人glut.h不知道放哪里,自己新建了一个文件夹,其实很多前辈在之前就说过,

要搜索gl这个文件夹,将glut.h放到里面包含gl.h glu.h这两个文件的gl文件夹中.

直接下面例程编译即可通过

例程如下

#include <gl\glut.h>

void myDisplay(void)

{

glClear(GL_COLOR_BUFFER_BIT);

glRectf(-0.5f, -0.5f, 0.5f, 0.5f);

glFlush();

}

int main(int argc, char *argv[])

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);

glutInitWindowPosition(100, 100);

glutInitWindowSize(400, 400);

glutCreateWindow("第一个OpenGL程序");

glutDisplayFunc(&myDisplay);

glutMainLoop();

return 0;

}

================================================

1. 把解压得到的glut.h放到"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\gl"(与具体安装位置有关,应该是 安装目录\microsoft sdks\windows\v7.0A\include\gl)

2. 把解压得到的glut.lib和glut32.lib放到"“Programfiles(x86)\Microsoft Visual studio 10.0\VC\lib" 中(与具体安装位置有关,同上)

3. 把解压得到的glut.dll放到"C:\Windows\System32"

4. 把glut32.dll放到“Programfiles(x86)\Microsoft Visual studio 10.0\VC\bin”下(注意这个,网上有人说放到system32里,但是我试过,会报错)(与具体安装位置有关,同上)

5. 打开vs2010,随便打开或新建一个项目。 选择 project->project property-> Configuration Properties->Linker->Input->Additional Dependencies 在其中添加opengl32.lib glu32.lib glut32.lib

如果这样还报错的话应该注意以下几点:

有时候在建console application 的时候添加的cpp文件将后缀句改为 .c

有的程序需要glaux工具包,这个下载了,可以按上述步骤添加(操作基本相同)

=========================================================================

VS较老版本格式转换后

general error c101008a错误。

手动添加lib和头文件,然后project clean一下即可。

㈡ 如何运行opengl红宝书中的源码,傻瓜版

如何运行opengl红宝书中的源码
一、安装GLUT工具包
1下载OpenGL需要的库文件 ,一般可以选择下载glut库(内含所有必须文件)

2解压后将得到的glut.lib和glut32.lib这两个静态函数库复制到文件目录的lib文件夹下
X:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib

3将glut.dll,glut32.dll这两个动态库文件放到操作系统目录下面的C:\Windows\system32文件夹内(32位系统)或‪C:\Windows\SysWOW64(64位系统)。
为了兼容性考虑,最好在这两个目录下都复制相应的文件。行枝

4将解压得到的头文件glut.h复制到目录如下目录下:
X:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\GL
提示:如果在incluce目录下没有GL文件夹,则需要手动创建

二、VS2013中的配置
创建一个空白的Win32控制台应用程序
在代码最前面添加包含目录
#include <GL/glut.h>
然后就可以编辑自己的OpenGL程序了
例如:复制如下代码到刚配置段简好的VS中
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
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;
}

5编译后能正确运行说明配置成功!

㈢ 在linux上怎么安装OpenGl

1.安装IDE: 这里使用链搭雀的是codeblocksx0dx0asudo apt-get install codeblocksx0dx0a2.配置Linux下的openGLx0dx0a下载并安装openGL所需要棚早的库x0dx0asudo apt-get install mesa-common-dev libgl1-mesa-dev libglu1-mesa-devx0dx0asudo apt-get install freeglut3-devx0dx0asudo apt-get install build-essential gdb subversionx0dx0asudo apt-get install automake autoconf libtoolx0dx0asudo apt-get install libgtk2.0-dev libxmu-dev libxxf86vm-devx0dx0a3.配置codeblocks IDEx0dx0a在Settings->compiler and debugger settings->link settingsx0dx0a添加:x0dx0a/usr/枝扮lib/libGL.so

㈣ 编译qt5怎么配置opengl

下载opengl源码。交叉编译opengl。然后把opengl的头文件,库文件包含到Qt配置的路径里,再交叉编译Qt

㈤ Ubuntu11.10 下编译openGL的问题

在windows下好像从来不用调glutInit。
你在glutCreateWindow("Simple");之前加这么两句吧。
glutInit( &argc, argv );
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

㈥ (解决追加200分)在ubuntu上怎么安装openGL

什么叫 Linux无法独立安装OpenGl??

需要用到的软件包有两个,glut
和tmake,分别可以从以下两个网址下载:
http://www.opengl.org/resources/libraries/glut/glut-3.7.tar.gz
ftp://ftp.trolltech.com/freebies/tmake/tmake-1.8.tar.gz

下载后的文件假设都放在/usr/src中

首先是安装glut库,以下是从www.linux.com找到的编译glut库的手册。

Install GLUT 3.7 Distribution (optional)

If you installed the MesaDemos/MesaLib package, then
you have already installed GLUT 3.7 since it is
included with MesaDemos. However, you may be
interested in installing the GLUT

manpages and you can skip right to the "Install GLUT
manual pages", below ...

Installing GLUT is a bit tricky. I'm not too familiar
with imake, the program that it uses to manage the
Makefiles, and didn't quite see how to get GLUT to
install to where I wanted it (/usr/lib,

but MesaDemos will do this without any trouble
though). It can be done manually anyhow:

cd /usr/src
tar -xvzf glut-3.7.tar.gz
cd glut-3.7

Read the file: README.linux
cd linux
READ the file: README
cp Glut.cf ..
cd ..
Edit Glut.cf: remove any Mesa references.
Replace any -lMesaGL -lMesaGLU with -lGL -lGLU if
needed.
In particular, replace:
OPENGL = $(TOP)/../lib/libMesaGL.so
GLU = $(TOP)/../lib/libMesaGLU.so
with:
OPENGL = -lGL
GLU = -lGLU

./mkmkfiles.imake
cd lib/glut
cp /usr/src/glut-3.7/linux/Makefile .
Edit the Makefile: remove any Mesa references.
Replace any -lMesaGL -lMesaGLU with -lGL -lGLU if
needed.
In particular, replace:
OPENGL = $(TOP)/../lib/libMesaGL.so
GLU = $(TOP)/../lib/libMesaGLU.so
with:
OPENGL = -lGL
GLU = -lGLU

make
ln -s libglut.so.3.7 libglut.so
ln -s libglut.so.3.7 libglut.so.3
cp -d libglut.* /usr/lib
cd ..
cd gle
# make a shared lib for libgle
make
gcc -shared -o libgle.so.3.7 *.o
ln -s libgle.so.3.7 libgle.so
ln -s libgle.so.3.7 libgle.so.3
cp -d libgle.* /usr/lib
cd ..
cd mui
# make a shared lib for libmui
make
gcc -shared -o libmui.so.3.7 *.o
ln -s libmui.so.3.7 libmui.so
ln -s libmui.so.3.7 libmui.so.3
cp -d libmui.* /usr/lib

# Install the GLUT manual pages (not included
with MesaDemos)
cd /usr/src/glut-3.7
make SUBDIRS=man Makefile
cd man/glut
make install.man
ldconfig

cd ../../progs/demos/ideas
# edit the Makefile, change OPENGL = -lGL and GLU =
-lGLU
make
./ideas
# test compiling some demos
# take a look at which libraries have to be linked
(-lX11 ...) in
# the Makefiles. Qt's tmake program available at
www.troll.no
# is a quick way to make a Makefile but you have to
edit it
# and add the -l needed.
ideas如果运行成功的话,说明glut已经可以用了,这时可以将include/GL下的glut等头文件复制到/usr/include中去。

上面的几步中,下载的glut包放在/usr/src目录下,如果放在其他目录下,将/usr/src改为相应的目录即可。
此外应该注意的是两个Makefile文件的修改

· OPENGL = $(TOP)/../lib/libMesaGL.so
GLU = $(TOP)/../lib/libMesaGLU.so

OPENGL = -lGL
GLU = -lGLU
因为所指定的目录中没有libMesaGL.so和libMesaGLU.so。

之后是tmake的配置,后面我们可以用它来生成pro工程文件和makefile文件。

先将下载的tmake解压缩,tar -zxvf tmake-1.8.tar.gz
得到tmake-1.8目录,之后设置两个环境变量:PATH和TMAKEPATH
PATH=$PATH:/usr/src/tmake-1.8/bin
export PATH
TMAKEPATH=/usr/src/tmake-1.8/lib/linux-g++
export TMAKEPATH

新建一个测试目录test,将glut-3.7目录下的progs/redbook目录下的hello.c复制到test目录中

之后生成一个pro文件:progen -o hello.pro

然后生成makefile文件:tmake hello.pro "CONFIG+=opengl"
-o Makefile

编辑生成的Makefile文件,在加载动态连接库的行里面加入
-lglut -lXi -lXmu

保存,make。

./hello 可以看到运行结果就可以了。

PS。不过我编译还是通不过,所以不好给你意见。

热点内容
文件夹如何批量替换文件名 发布:2025-07-15 01:19:15 浏览:67
ftp上传网页 发布:2025-07-15 01:13:09 浏览:181
音乐文件夹图标 发布:2025-07-15 01:03:41 浏览:494
安卓机怎么反向充电 发布:2025-07-15 01:03:40 浏览:500
电脑使用华为云服务器 发布:2025-07-15 00:48:10 浏览:533
中考应该如何排解压力 发布:2025-07-15 00:17:54 浏览:362
安卓第三方应用软件是什么 发布:2025-07-15 00:12:06 浏览:149
程序业务配置存储 发布:2025-07-14 23:52:16 浏览:685
csdn编程挑战 发布:2025-07-14 23:52:08 浏览:791
国外乘法算法 发布:2025-07-14 23:51:14 浏览:11