顯示具有 openFramworks 標籤的文章。 顯示所有文章
顯示具有 openFramworks 標籤的文章。 顯示所有文章

2012年9月1日 星期六

[oF] Workshop 讀取圖片練習

以下內容使用範例可至of_v0071_win_cb_release\examples\graphics\imageLoaderExample查看



Graphic範例練習

依照滑鼠大小改變圖片尺寸

l   撰寫OF程式碼
1.      開啟empty資料夾(of_v0071_win_cb_release\examples\empty)
2.      app資料夾下新增一個資料夾,名稱自訂(of_v0071_win_cb_release\apps)
3.      複製emptyExample資料夾到新增的資料夾中
4.      開啟資料夾中的emptyExample.cbp
5.      執行且編譯(F9)

l   從原始範例複製需要的圖片(of_v0071_win_cb_release\examples\graphics\imageLoaderExample\bin\data)
emptyExampledata資料夾底下(emptyExample\bin\data)
若檔案沒有編譯過,不會產生bindata資料夾

l   開啟testApp.h
1.      定義一個變數,型態為ofImage,名稱為bikers

l   開啟testApp.cpp,在setup中寫入初始設定
1.      設定背景色為白色
ofBackground(255,255,255);
2.      bikers中讀取一張圖片
bikers.loadImage("images/bikers.jpg");

3.      若圖片名稱錯誤會出現


4.      讀取後要顯示圖片,在draw中打入
bikers.draw(0,0,mouseX,mouseY);

5.      若要更改色調,使用ofSetColor(R,G,B)
ofSetColor(255,0,0);



讀取圖片練習二
1.      testApp.h定義ofImage變數,名稱為gear
ofImage gear;


2.      讀取圖片,在setup中寫入
gear.loadImage("images/gears.gif");

3.      顯示圖片,在draw中寫入程式,並把先前的滑鼠控制註解掉
bikers.draw(0,0,bikers.getWidth()/2,bikers.getHeight()/2);
//擺放圖片在0,0的位置,長寬為自己的一半
gear.resize(bikers.getWidth()/2,bikers.getHeight()/2);
 //gear的尺寸縮放跟biker一樣
gear.draw(bikers.getWidth()/2,0);
 //擺放圖片在bike旁,y0             

4.      若要使圖片有透明度,讀取的圖片需為具透明屬性的圖片,ex.png


讀取有透明度圖片

1.      testApp.h中定義ofImage型態的變數transparency
ofImage transparency;


2.      testApp.cpp中的setup將含有透明圖層的圖片讀取至transparency
transparency.loadImage("images/transparency.png");


3.      draw中,顯示transparency,因含透明度,需使用ofEnableAlphaBlending()ofDisableAlpahBlending()
ofEnableAlphaBlending(); //開啟透明圖層效果
float wave = sin(ofGetElapsedTimef()); //定義一個變數wave,使用sin函數,ofGetElapsedTimef取得程式執行經過時間(浮點數)
transparency.draw(mouseX+(wave*100),mouseY);//transparaency這圖將會跟著滑鼠座標,且做左右幅度為100的來回震盪
  ofDisableAlphaBlending(); //關閉透明圖層效果

2012年8月31日 星期五

[oF] Workshop範例練習


撰寫OF程式碼
1.      開啟empty資料夾(of_v0071_win_cb_release\examples\empty)
2.      app資料夾下新增一個資料夾,名稱自訂(of_v0071_win_cb_release\apps)
3.      複製emptyExample資料夾到新增的資料夾中
4.      開啟資料夾中的emptyExample.cbp

使用滑鼠控制圓形解析度
1.      開啟main.cpp,可更改視窗大小
ofSetupOpenGL(&window, 1024, 768, OF_WINDOW)
1024為視窗寬、768為視窗高

2.      開啟testApp.cpp
3.      可看到
void testApp::setup(){
//初始設定值
}

//--------------------------------------------------------------
void testApp::update(){
//資料更新
}

//--------------------------------------------------------------
void testApp::draw(){
//繪製圖形
}




4.      撰寫程式碼
setup函式中只會在開啟程式時執行一次,updatedraw則是依照ofSetFrameRate的設定不斷執行函式中的程式

void testApp::setup(){
    ofBackground(0,0,0); //設定背景色為黑色
    ofSetFrameRate(30);  //每秒更新速度為三十次一秒
}

//--------------------------------------------------------------
void testApp::update(){
    ofSetCircleResolution(mouseX/32); //設定圓的邊數為滑鼠座標/32
}

//--------------------------------------------------------------
void testApp::draw(){
    ofColor(255,0,0); //設定顏色為紅色
    ofCircle(300,300,50,50);  //畫一個圓,位置在300,300,直徑30

    string s = "resolution = "+ofToString(mouseX/32,3);
    //定義一變數s,型態為字串,
    //ofToString函式將mouseX/32的數值轉換為字串,3為可顯示最大位數
    ofDrawBitmapString(s,mouseX,mouseY); //顯示字串s,位置在mouseX,mouseY
}




讓圓的解析度不斷累加,大於一百遍從頭
1.      開啟testApp.h,此檔案宣告各種全域變數

2.      定義變數r,型態為整數
int r;


3.      回到testApp.cpp底下的setup給定初始值
r=0;

4.        update中寫入,並且把ofSetCircleResolution(mouseX/32)改成ofSetCircleResolution(r)
r=r+1;
if(r>100
  r=0;
}



5.        讓畫面顯示的數值也為r,改寫draw
string s = "resolution = "+ofToString(mouseX/32,3);
改寫為
string s = "resolution = "+ofToString(r);



[oF] 新版0071


下載Openframework

1.      前往Openframework官方網站(http://www.openframeworks.cc/download/)
2.      下載並安裝CodeBlocks(http://www.codeblocks.org/downloads/26)


5.      解壓縮檔內有兩個資料夾,分別把資料夾中的檔案複製到cb的資料夾中
Ÿ   add_to_codeblocks_mingw_include 內容複製到
 "C:\Program Files\CodeBlocks\MinGW\include"
Ÿ   add_to_codeblocks_mingw_lib 內容複製到
 "C:\Program Files\CodeBlocks\MinGW\lib"



開啟Openframework範例
1.      開啟of_v0071_win_cb_release資料夾
2.      選擇example / gl / billboardExample
3.      開啟檔案billboardExample.cbp
4.      建立並執行檔案,選擇Build / Build and Run (F9)
5.      程式編譯完後便可看到執行畫面



2012年4月8日 星期日

[oF] Tutorials - Chapter 1 - Getting Started

以下參考http://www.openframeworks.cc/tutorials/introduction/001_chapter1.html

1.開啟code blocks
2.file→open→openFrameWorks資料夾中的\apps\examples\graphicsExample.cbp   (cbp為code block的專案副檔名)




3.build檔案並run執行







4.執行結果












5.如果出現warning
mingw32-g++.exe: ../../../libs/openFrameworksCompiled/lib/win_cb/openFrameworks.lib: No such file or directory
直接開啟\apps\examples\中的graphicsExample.workspace  build過一次即可

[oF] 使用code blocks運行openFrameworks

1.下載code blocks
http://www.codeblocks.org/downloads

2.安裝openFrameworks的libray到code blocks
http://www.openframeworks.cc/setup/codeblocks/

    a)下載codeblocks_additions.zip(http://www.openframeworks.cc/content/files/codeblocks_additions.zip)
    b)下載完後,將add_to_codeblocks_mingw_include資料夾中的東西解壓縮到C:\Program Files\CodeBlocks\MinGW\include(或者自訂位置中的\MinGW\include)
    c)將add_to_codeblocks_mingw_lib資料夾中的東西解壓縮到C:\Program Files\CodeBlocks\MinGW\lib(或者自訂位置中的\mingw\lib)






3.下載openFrameWorks
http://www.openframeworks.cc/download/
將of_preRelease_v007_win_cb.zip解壓縮有幾個主要資料夾



addons
The "core" openFrameworks contains only the most essential functionality. Everything in the addons folder can be added to an application piecemeal. This includes stuff like reading an XML file, loading a 3D model, or using the computer vision library, openCV.
apps
This is where the applications that you make will be stored, and where you will be working most of the time. You will notice that there are already 2 folders in "apps": "examples" and "addonExamples".
libs
This folder contains all the libraries that openFramworks uses as well as the oF core.