0
只是在做我的計算機圖形分配 - 將紋理(600x400不同數量的位圖)放在一個立方體上以形成適當的骰子。我設法用「經典」紋理映射做到這一點:創建verices並添加相應的紋理座標是:opengl3中的多維數據集紋理
int arrayindex = 0;
float xpos = 0.0f;
float xposEnd = 0.32f;
float ypos = 0.0f;
float yposEnd = 0.49f;
int count = 0;
void quad(int a, int b, int c, int d) {
colors[arrayindex] = vertex_colors[a];
points[arrayindex] = vertices[a];
tex_coord[arrayindex] = new Point2(xpos, ypos);
arrayindex++;
colors[arrayindex] = vertex_colors[b];
points[arrayindex] = vertices[b];
tex_coord[arrayindex] = new Point2(xpos, yposEnd);
arrayindex++;
colors[arrayindex] = vertex_colors[c];
points[arrayindex] = vertices[c];
tex_coord[arrayindex] = new Point2(xposEnd, yposEnd);
arrayindex++;
colors[arrayindex] = vertex_colors[a];
points[arrayindex] = vertices[a];
tex_coord[arrayindex] = new Point2(xpos, ypos);
arrayindex++;
colors[arrayindex] = vertex_colors[c];
points[arrayindex] = vertices[c];
tex_coord[arrayindex] = new Point2(xposEnd, yposEnd);
arrayindex++;
colors[arrayindex] = vertex_colors[d];
points[arrayindex] = vertices[d];
tex_coord[arrayindex] = new Point2(xposEnd, ypos);
arrayindex++;
xpos = xpos + 0.34f;
xposEnd = xpos + 0.32f;
count++;
if (count == 3) {
xpos = 0.0f;
xposEnd = 0.33f;
ypos = 0.51f;
yposEnd = 1.0f;
}
}
void colorcube() {
quad(1, 0, 3, 2);
quad(2, 3, 7, 6);
quad(3, 0, 4, 7);
quad(6, 5, 1, 2);
quad(5, 4, 0, 1);
quad(4, 5, 6, 7);
pointsBuf = VectorMath.toBuffer(points);
colorsBuf = VectorMath.toBuffer(colors);
texcoord = VectorMath.toBuffer(tex_coord);
}
傳遞所有這些東西來着色器,只是把它在一起。
但審查幻燈片我注意到這種方法應該是「pre opengl3」。 有沒有其他方法可以做到這一點?
在講座的例子,我注意到把它在一起的頂點着色器,但它只是一個簡單的2D平面,而不是一個3D立方體
tex_coords = vec2(vPosition.x+0.5,vPosition.z+0.5);
,後來傳給片段着色器創建紋理。
我通過頂點,座標和紋理映射爲 //設置頂點緩衝區對象 final GLSLAttrib vertices = new GLSLAttrib(pointsBuf,「vPosition」,4); final GLSLAttrib colors = new GLSLAttrib(colorsBuf,「vColor」,4); final GLSLAttrib tex_coord = new GLSLAttrib(texcoord,「vCoord」,2); 並使用fragColor創建立方體 – mjanisz1
@ mjanisz1:無論GLSLAttrib是什麼,它都不是OpenGL本身的一部分。它肯定是3D派對的一部分。通過命名它「GLSLAttrib」,我敢打賭,這件事建立了一個頂點數組,甚至是一個頂點緩衝對象。這樣做有點奇怪,尤其是因爲這種腳手架遮擋了OpenGL,並且類和OOP不能很好地映射到OpenGL。 – datenwolf
不幸的是,我們必須使用我們的老師提供的圖書館。它與「交互式計算機圖形 帶基於Shader的OPENGL的自頂向下方法」相同,但對於java而言更是如此。仍然有希望,這是將它傳遞給着色器的正確方法。或者,也許有一種方法可以計算頂點映射,作爲着色器中的「頂點緩衝區對象」傳遞? – mjanisz1