3
繼承人的問題的PIC:麻煩與OpenGL的頂點數組球ç
這裏是線框:
正如你從照片上可以看到上面,我有一些奇怪的圖形問題,我不知道如何解決,我認爲有些代碼與代碼有問題,儘管沒有其他人遇到代碼問題。
代碼:從(Creating a 3D sphere in Opengl using Visual C++)採取
unsigned int rings = 12, sectors = 24;
float const R = 1./(float)(rings-1);
float const S = 1./(float)(sectors-1);
int r, s;
vertices.resize(rings * sectors * 3);
normals.resize(rings * sectors * 3);
texcoords.resize(rings * sectors * 2);
std::vector<GLfloat>::iterator v = vertices.begin();
std::vector<GLfloat>::iterator n = normals.begin();
std::vector<GLfloat>::iterator t = texcoords.begin();
for(r = 0; r < rings; r++) for(s = 0; s < sectors; s++) {
float const y = sin(-M_PI_2 + M_PI * r * R);
float const x = cos(2*M_PI * s * S) * sin(M_PI * r * R);
float const z = sin(2*M_PI * s * S) * sin(M_PI * r * R);
*t++ = s*S;
*t++ = r*R;
*v++ = x * getR();
*v++ = y * getR();
*v++ = z * getR();
*n++ = x;
*n++ = y;
*n++ = z;
}
indices.resize(rings * sectors * 4);
std:vector<GLushort>::iterator i = indices.begin();
for(r = 0; r < rings; r++) for(s = 0; s < sectors; s++) {
*i++ = r * sectors + s;
*i++ = r * sectors + (s+1);
*i++ = (r+1) * sectors + (s+1);
*i++ = (r+1) * sectors + s;
}
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices.data());
glNormalPointer(GL_FLOAT, 0, normals.data());
glTexCoordPointer(2, GL_FLOAT, 0, texcoords.data());
glDrawElements(GL_QUADS, indices.size(), GL_UNSIGNED_SHORT, indices.data());
代碼
如果我不得不猜測,也許你沒有填充你的一個頂點,所以它重新用未初始化的數據。旋轉相機並查看有多少點不好確認。 – 2013-04-10 20:35:57
其他人沒有遇到問題,所以不知道問題是什麼:S Heres在線框模式下的外觀 http://img687.imageshack.us/img687/5849/globe2.png – Split 2013-04-10 22:27:28
它看起來像是關閉一個錯誤或一個驅動程序錯誤。你確定你的「矢量」是空的嗎? – 2013-04-11 14:46:43