0
試圖製作一個球體。但它看起來不像3D,實際上它看起來像一張平坦的2D圖片。我在這裏錯過了什麼?OpenGL es - 不看3D,看起來更像2D
三江源
std::vector<GLfloat> ballVerts;
for(int i = 0; i <= 40; i++)
{
double lat0 = M_PI * (-0.5 + (double) (i - 1)/40);
double z0 = sin(lat0);
double zr0 = cos(lat0);
double lat1 = M_PI * (-0.5 + (double) i/40);
double z1 = sin(lat1);
double zr1 = cos(lat1);
for(int j = 0; j <= 40; j++)
{
double lng = 2 * M_PI * (double) (j - 1)/40;
double x = cos(lng);
double y = sin(lng);
// normals
glNormal3f(x * zr0, y * zr0, z0);
ballVerts.push_back(x * zr0); //X
ballVerts.push_back(y * zr0); //Y
ballVerts.push_back(z0); //Z
ballVerts.push_back(0.0f);
ballVerts.push_back(1.0f);
ballVerts.push_back(0.0f);
ballVerts.push_back(1.0f); //R,G,B,A
// normals
glNormal3f(x * zr1, y * zr1, z1);
ballVerts.push_back(x * zr1); //X
ballVerts.push_back(y * zr1); //Y
ballVerts.push_back(z1); //Z
ballVerts.push_back(0.0f);
ballVerts.push_back(1.0f);
ballVerts.push_back(0.0f);
ballVerts.push_back(1.0f); //R,G,B,A
//渲染代碼 此外,我旋轉這個圈子,旋轉正常工作,因爲我有光變化,這讓我說,它正在旋轉的想法,是逸岸一圈至少
glRotatef(Angle, 1.0f, 0.5f, 0.3f);
glBindBuffer(GL_ARRAY_BUFFER, VertexBufferObject[2]);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 7*4, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 3200);
glBindBuffer(GL_ARRAY_BUFFER, 0);
現在看起來好多了,如果不是最好的。謝謝你的幫助 :) – HungryCoder