處理了一下,終於設定完成了~ YA~
於是來做個筆記,也可以當教學
OS: Win 7 64位元
( 資料修改及取自上列網站~ 感謝發文者!! )
一開始,說明一下為什麼要挑Dev C++ with OpenGL當開發環境?
原因是Visual系列太胖,想解又解不乾淨 ...
而Dev C++ 除了是我自己習慣的Programming Tool,而且輕薄短小容易取得
於是乎使用這個組合!
安裝過程主要分為以下步驟
1. 下載及安裝 Dev-C++
2. 下載及安裝 GLUT
3. 測試環境設定結果
沒錯~ 跟泡泡麵一樣簡單,三個步驟就搞定!!
Let's START !!
1. 下載及安裝 Dev-C++
我是點選這個檔案: Dev-C++ 5.0 beta 9.2 (4.9.9.2) (9.0 MB) with Mingw/GCC 3.4.2
下載完成之後,
可依照指示保留預設設定完成安裝即可,不需要其他改變
這部分很簡單就不多做說明了
安裝完成之後
可打個簡單的 printf("Hello World\n"); 檢查安裝結果是否有錯誤
hello.c --
#include
main ( int argc, char ** argv )
{
printf("Hello World\n");
system("pause");
}
順利由Dos視窗print出結果就可以前往下一步囉!!
沒有的話,看一下程式碼有沒有錯誤,沒有的話,解除安裝再重新安裝一次看看
2. 下載及安裝 GLUT
直接點擊下載或右鍵另存,是zip壓縮檔
接著可以解壓縮或是將"GLUTMingw32"這個資料夾拉出來
接下來有三個檔案需要移動(複製貼上):
2.1. glut.h:
檔案位置:..\GLUTMingw32\include\GL
目標位置:C:\Dev-Cpp\include\GL
2.2. libglut32.a
2.3. glut32.dll
檔案位置:..\GLUTMingw32\
目標位置:C:\WINDOWS\System32
接著有一些小~問題會發生
等執行完範例檔後,再行說明!
3. 測試環境設定結果
接著開啟Dev-C++程式 ...
3.1. Open New Project then 存檔~(Open as Empty Project, C Project)
3.2. 加個檔案進入Project中:File/New/Source File
3.3. Project設定:
Project/Project Options pop-up 一個視窗,切換到"Parameters"標籤
依下列列順序點擊"Add Library or Object"連結GLUT檔案(三個檔案都位於C:/Dev-Cpp/lib):libopengl32.a > libglu32.a > libglut32.a
Click OK
3.3. 貼上以下程式碼 (Code來自文章開頭所附網站的程式碼)
rectangle.c --
#include
const int A = 500; /* length of a side of the monitor window */
const float B = 500; /* length of a side of the clipping rectangle */
const float C = 200; /* length of a side of the square the program draws */
void myinit(void)
{
glClearColor(0.7, 0.7, 0.7, 0.0); /* gray background */
glMatrixMode(GL_PROJECTION); /* In World coordinates: */
glLoadIdentity(); /* position the "clipping rectangle" */
gluOrtho2D( -B/2, B/2, -B/2, B/2);/* at -B/2, its right edge at +B/2, its bottom */
glMatrixMode(GL_MODELVIEW); /* edge at -B/2 and its top edge at +B/2 */
}
void display( void )
{
glClear(GL_COLOR_BUFFER_BIT); /* clear the window */
glMatrixMode(GL_MODELVIEW); /* The following coordinates are expressed */
glLoadIdentity(); /* in terms of World coordinates */
glBegin(GL_POLYGON) ; /* draw a filled polygon */
glColor3f ( 1.0, 0.3, 0.2); /* draw in light red */
glVertex2f( -C/2, -C/2 ); /* (x,y) */
glVertex2f( C/2, -C/2 ); /* (x,y) */
glVertex2f( C/2, C/2 ); /* (x,y) */
glVertex2f( -C/2, C/2 ); /* (x,y) */
glEnd();
glFlush(); /* send all commands */
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitWindowSize( A, A ); /* A x A pixel screen window */
glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE);
glutCreateWindow("My Rectangle"); /* window title */
glutDisplayFunc(display); /* tell OpenGL main loop what */
myinit(); /* set attributes */
glutMainLoop(); /* pass control to the main loop */
}
到此基本上大部分應該是沒有問題,都能跑出圖形來
那再來講一下那個非大部分的人大概有什麼問題
按F9Run的時候跳出來說你沒有"glut32.dll"
像我是以64位元的Win 7 為作業系統,那麼當把glut32.dll覆蓋到System 32裡面是正常的,那程式就一直告訴我沒有glut32.dll
解決方式
打開Windows資料夾在System32 下面有個資料夾是*****64
代表是64位元所需要的原件
開起之後將glut32.dll移動進去就OK了~!
到了這邊,環境也設定完成了,應該是滿容易的 !!
Let's Dancing with OpenGL ~~ !!!
↓↓ Any Question or I'm wrong in this page, Leave Comment Below ↓↓