當前位置:首頁 » 編程軟體 » 編譯安裝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。不過我編譯還是通不過,所以不好給你意見。

熱點內容
php獲取幾 發布:2025-07-14 20:22:20 瀏覽:375
舊安卓如何刷入最新安卓 發布:2025-07-14 20:16:14 瀏覽:762
伺服器或網路不給力是什麼意思 發布:2025-07-14 20:15:36 瀏覽:317
爬網站資料庫 發布:2025-07-14 20:15:20 瀏覽:519
邵雍的演算法 發布:2025-07-14 20:13:49 瀏覽:118
離線燒錄加密 發布:2025-07-14 20:12:13 瀏覽:619
奧迪怎麼查配置 發布:2025-07-14 20:12:07 瀏覽:831
java視頻編程 發布:2025-07-14 19:49:22 瀏覽:523
初始密碼是多少年 發布:2025-07-14 19:34:12 瀏覽:240
ipadair2存儲 發布:2025-07-14 19:26:58 瀏覽:620