資源簡介
里面有幾個計算機圖形學的基礎實例都是根據opengl+shader一起實現的。實例有:三角形,鏤空圖形,koch曲線課實現多邊形多遞歸,還有colorcube

代碼片段和文件信息
//
//?Display?a?color?cube
//
//?Colors?are?assigned?to?each?vertex?and?then?the?rasterizer?interpolates
//???those?colors?across?the?triangles.??We?us?an?orthographic?projection
//???as?the?default?projetion.
#include?“Angel.h“
typedef?Angel::vec4??color4;
typedef?Angel::vec4??point4;
const?int?NumVertices?=?36;?//(6?faces)(2?triangles/face)(3?vertices/triangle)
point4?points[NumVertices];
color4?colors[NumVertices];
//?Vertices?of?a?unit?cube?centered?at?origin?sides?aligned?with?axes
point4?vertices[8]?=?{
????point4(?-0.5?-0.5??0.5?1.0?)
????point4(?-0.5??0.5??0.5?1.0?)
????point4(??0.5??0.5??0.5?1.0?)
????point4(??0.5?-0.5??0.5?1.0?)
????point4(?-0.5?-0.5?-0.5?1.0?)
????point4(?-0.5??0.5?-0.5?1.0?)
????point4(??0.5??0.5?-0.5?1.0?)
????point4(??0.5?-0.5?-0.5?1.0?)
};
//?RGBA?olors
color4?vertex_colors[8]?=?{
????color4(?0.0?0.0?0.0?1.0?)??//?black
????color4(?1.0?0.0?0.0?1.0?)??//?red
????color4(?1.0?1.0?0.0?1.0?)??//?yellow
????color4(?0.0?1.0?0.0?1.0?)??//?green
????color4(?0.0?0.0?1.0?1.0?)??//?blue
????color4(?1.0?0.0?1.0?1.0?)??//?magenta
????color4(?1.0?1.0?1.0?1.0?)??//?white
????color4(?0.0?1.0?1.0?1.0?)???//?cyan
};
//?Array?of?rotation?angles?(in?degrees)?for?each?coordinate?axis
enum?{?Xaxis?=?0?Yaxis?=?1?Zaxis?=?2?NumAxes?=?3?};
int??????Axis?=?Xaxis;
GLfloat??theta[NumAxes]?=?{?0.0?0.0?0.0?};
GLint?matrix_loc;??//?The?location?of?the?“rotation“?shader?uniform?variable
//----------------------------------------------------------------------------
//?quad?generates?two?triangles?for?each?face?and?assigns?colors
//????to?the?vertices
int?Index?=?0;
void
quad(?int?a?int?b?int?c?int?d?)
{
????colors[Index]?=?vertex_colors[a];?points[Index]?=?vertices[a];?Index++;
????colors[Index]?=?vertex_colors[b];?points[Index]?=?vertices[b];?Index++;
????colors[Index]?=?vertex_colors[c];?points[Index]?=?vertices[c];?Index++;
????colors[Index]?=?vertex_colors[a];?points[Index]?=?vertices[a];?Index++;
????colors[Index]?=?vertex_colors[c];?points[Index]?=?vertices[c];?Index++;
????colors[Index]?=?vertex_colors[d];?points[Index]?=?vertices[d];?Index++;
}
//----------------------------------------------------------------------------
//?generate?12?triangles:?36?vertices?and?36?colors
void
colorcube()
{
????quad(?1?0?3?2?);
????quad(?2?3?7?6?);
????quad(?3?0?4?7?);
????quad(?6?5?1?2?);
????quad(?4?5?6?7?);
????quad(?5?4?0?1?);
}
//----------------------------------------------------------------------------
//?OpenGL?initialization
void
init()
{
????colorcube();
????//?Create?a?vertex?array?object
????GLuint?vao;
????glGenVertexArrays(?1?&vao?);
????glBindVertexArray(?vao?);
????//?Create?and?initialize?a?buffer?object
????GLuint?buffer;
????glGenBuffers(?1?&buffer?);
????glBindBuffer(?GL_ARRAY_BUFFER?buffer?);
????glBufferData(?GL_ARRAY_BUFFER?sizeof(
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2079??2013-04-17?11:23??hello\hello.cpp
?????文件?????429568??2013-04-17?18:00??hello\hello.exe
?????文件?????????90??2013-03-25?00:15??hello\hello.fs
?????文件???????9265??2013-04-07?17:51??hello\hello.vcxproj
?????文件????????143??2013-03-24?21:12??hello\hello.vcxproj.user
?????文件?????????79??2010-11-07?19:23??hello\hello.vs
?????文件???????3400??2013-04-17?16:46??koch\koch.cpp
?????文件?????438784??2013-04-17?18:00??koch\koch.exe
?????文件?????????90??2013-04-07?16:57??koch\koch.fs
?????文件???????9258??2013-04-07?16:59??koch\koch.vcxproj
?????文件????????143??2013-03-24?23:39??koch\koch.vcxproj.user
?????文件?????????79??2010-11-07?19:23??koch\koch.vs
?????文件?????????94??2013-04-07?17:51??single_double\Debug\single_double.log
?????文件???????2643??2013-03-31?23:01??single_double\single_double.cpp
?????文件?????218112??2013-04-17?18:00??single_double\single_double.exe
?????文件???????9150??2013-04-07?17:51??single_double\single_double.vcxproj
?????文件????????143??2013-03-31?23:00??single_double\single_double.vcxproj.user
?????文件?????????94??2013-04-07?17:51??single_double\Template\single_double.log
?????文件????????178??2010-03-16?10:59??clean.cmd
?????文件???????5480??2013-04-14?22:06??my_example.sln
?????文件???????5800??2013-04-17?17:58??colorcube\colorcube.cpp
?????文件?????433152??2013-04-17?18:00??colorcube\colorcube.exe
?????文件?????????84??2010-11-10?14:14??colorcube\colorcube.fs
?????文件???????9293??2013-04-14?21:54??colorcube\colorcube.vcxproj
?????文件????????143??2013-04-14?21:55??colorcube\colorcube.vcxproj.user
?????文件????????182??2013-04-17?17:46??colorcube\colorcube.vs
?????文件???????2176??2013-03-24?19:18??common\include\Angel.h
?????文件???????1290??2010-11-07?19:23??common\include\CheckError.h
?????文件????????681??2003-10-21?19:41??common\include\GL\freeglut.h
?????文件???????8797??2011-09-05?03:38??common\include\GL\freeglut_ext.h
............此處省略73個文件信息
- 上一篇:QTP飛機訂票測試報告
- 下一篇:三參數坐標轉換
評論
共有 條評論