網頁

2014年3月21日 星期五

OpenGL - Render Cube by Index Buffer

Last Update: 2014/03/21 17:28+08
Type: Note



glDrawArrays 僅是依 vertices 的順序繪
就是沒有 index buffer
要用 glDrawElements, 依 indecies 順序
std::vector vertices = std::vector(8);

PxVec3 geometry = PxVec3(2.0f,2.0f,2.0f);

vertices[0] = PxVec3(-geometry.x, geometry.y, geometry.z);//left-up-front
vertices[1] = PxVec3(geometry.x, geometry.y, geometry.z);//right-up-front
vertices[2] = PxVec3(-geometry.x, -geometry.y, geometry.z);//left-bottom-front
vertices[3] = PxVec3(geometry.x, -geometry.y, geometry.z);//right-bottom-front

vertices[4] = PxVec3(-geometry.x, geometry.y, -geometry.z);//left-up-back
vertices[5] = PxVec3(geometry.x, geometry.y, -geometry.z);//right-up-back
vertices[6] = PxVec3(-geometry.x, -geometry.y, -geometry.z);//left-bottom-back
vertices[7] = PxVec3(geometry.x, -geometry.y, -geometry.z);//right-bottom-back

unsigned int indecies[24] = {
 0,2,3,1,
 1,3,7,5,
 4,6,2,0,
 4,0,1,5,
 2,6,7,3,
 6,4,5,7
};

{
 /*Render*/
 glPointSize(5);
 glColor3f(1.0f,1.0f,1.0f);


 glEnableClientState(GL_VERTEX_ARRAY);

 glVertexPointer(3, GL_FLOAT, 0, &vertices[0].x);
 glDrawArrays(GL_POINTS, 0, vertices.size());

 GLuint indexBuffer;
 glGenBuffers(1, &indexBuffer);
 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
 glBufferData(GL_ELEMENT_ARRAY_BUFFER, 24 * sizeof(unsigned int) , indecies, GL_STATIC_DRAW);

 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
 glDrawElements(
  GL_QUADS,
  24,
  GL_UNSIGNED_INT,
  (void*)0);

 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
 glDeleteBuffers(1, &indexBuffer);


 glDisableClientState(GL_VERTEX_ARRAY);

 glPointSize(1.0f);
}

OpenGL - Render Points with glDrawArray

Last Update: 2014/03/21 16:48+08
Type: Note



std::vector vertices = std::vector(8);

PxVec3 geometry = PxVec3(1.0f,1.0f,1.0f);

vertices[0] = PxVec3(-geometry.x, geometry.y, geometry.z);//left-up-front
vertices[1] = PxVec3(geometry.x, geometry.y, geometry.z);//right-up-front
vertices[2] = PxVec3(-geometry.x, -geometry.y, geometry.z);//left-bottom-front
vertices[3] = PxVec3(geometry.x, -geometry.y, geometry.z);//right-bottom-front

vertices[4] = PxVec3(-geometry.x, geometry.y, -geometry.z);//left-up-back
vertices[5] = PxVec3(geometry.x, geometry.y, -geometry.z);//right-up-back
vertices[6] = PxVec3(-geometry.x, -geometry.y, -geometry.z);//left-bottom-back
vertices[7] = PxVec3(geometry.x, -geometry.y, -geometry.z);//right-bottom-back


{/*Render*/
 glPointSize(5);
 glColor3f(1.0f,1.0f,1.0f);


 glEnableClientState(GL_VERTEX_ARRAY);

 glVertexPointer(3, GL_FLOAT, 0, &vertices[0].x);
 glDrawArrays(GL_POINTS, 0, vertices.size());

 glDisableClientState(GL_VERTEX_ARRAY);
 
 glPointSize(1.0f);
}

2014年3月20日 星期四

Google Project with SVN

Last Update: 2014/03/20 23:30+08
Type: Note (未完)


Apply for a new Google Project

(待續...)



TortoiseSVN


tortoisesvn 下載 SVN 工具
> 照指示安裝
> 建一個資料夾
> 點右鍵 [SVN Checkout...]
   > URL of repository: "https://<google project name>.googlecode.com/svn/trunk/"
   > Click OK
有更動要 Commit 的話
用 google account, 但密碼是用 google project專用的



Eclipse Install Subclipse


先到 subclipse.tigris.org 的 subclipse Download and Install 找你要的版本(for eclipse, e.q. http://subclipse.tigris.org/update_1.10.x) 並複製起來

在 Eclipse
> Help
> Install New Software ...
   > Work with: "http://subclipse.tigris.org/update_1.10.x" (剛才複製的網址)
   > 中間的核取清單 勾選 [Subclipse]
   > [Next]
   > 其餘用 default 到安裝完, 重啟



Eclipse connect to google project


從你的 Google Project 首頁 的頁籤中, 找到 Source
它會有個 Checkout 的連結 一般為 https://<google project name>.googlecode.com/svn/trunk/

在Eclipse
> Window
> Show View
> Other
> SVN/SVN Repositories (SVN檔案庫)
> OK
> 在新開啟的window(SVN檔案庫) 空白處按右鍵
   > 新增 > 檔案庫位置
   > Url: "https://<google project name>.googlecode.com/svn/trunk/"
   > Finish


---Share Project---
將Project更新上去

在Eclipse
> 在你的 Project 上, 點擊右鍵
> Team > Share Project ...
   > 選 [SVN]
   > Click [Next]
   > 使用現有檔案庫位置(剛剛新增的)
   > 接著照指示操作


---取回專案---
(待續...)



2014年3月2日 星期日

Naming Rule of Program

Last Update: 2014/03/03 14:12+08
Type: Note (未完)



大寫=Upper, 小寫=Lower
此篇未完成


C++
  • Namespaces are expected to be all lower case, this is borrowed form Java and C++
  • Functions within namespaces are expected to be lower case, with words connected by underscores. This is borrowed from traditional C programming conventions, as well as traditional Slick-C conventions. Couldn't borrow ideas from Java here...
  • Class names are mixed case and should start with an upper case letter. This is borrowed from Java and C#
  • Function names within classes are mixed case and should start out with a lower case letter. Again, borrowed from Java style
  • Class member variables should start with "m_" and can be mixed case
  • Static class member variables should start with "s_" and can be mixed case
  • Constants, such as enumerations, should be all upper case



Java
  • package(類似namespace) 全部字母為 Lower
  • function 第一個單字(word)的第一個字母為 Lower, 而後的單字開頭為 Upper
  • class 第一個字母為 Upper



VC++(MS)
  • namespace 第一個字母為 Upper
  • function ?
  • class 第一個字母為 Upper



C#(MS)
  • namespace 第一個字母為 Upper
  • function 第一個字母為 Upper, 而後的單字開頭為 Upper
  • class 第一個字母為 Upper