Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with OpenGL Vertex Array Sphere C
    primarykey
    data
    text
    <p>Heres a pic of the problem:</p> <p><img src="https://i.stack.imgur.com/Di13k.png" alt="enter image description here"></p> <p>And here is the wireframe:</p> <p><img src="https://i.stack.imgur.com/siS8j.png" alt="wireframe"></p> <p>As you can see from the pictures above, I have some sort of weird graphical issue and am not sure how to fix, I think somethings wrong with the code although noone else has had trouble with the code.</p> <p>Code:</p> <pre><code> 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&lt;GLfloat&gt;::iterator v = vertices.begin(); std::vector&lt;GLfloat&gt;::iterator n = normals.begin(); std::vector&lt;GLfloat&gt;::iterator t = texcoords.begin(); for(r = 0; r &lt; rings; r++) for(s = 0; s &lt; 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&lt;GLushort&gt;::iterator i = indices.begin(); for(r = 0; r &lt; rings; r++) for(s = 0; s &lt; 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()); </code></pre> <p>Code taken from (<a href="https://stackoverflow.com/questions/5988686/how-do-i-create-a-3d-sphere-in-opengl-using-visual-c/5989676#5989676">Creating a 3D sphere in Opengl using Visual C++</a>)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload