Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To match your question and to draw a cube in OpenGL (compatibility profile) you can use this code:</p> <pre><code> void drawCube(float x, float y, float z) { glBegin(GL_QUADS); glVertex3f(-1.0f+x, -1.0f+y, -1.0f+z); glVertex3f(1.0f+x, -1.0f+y, -1.0f+z); glVertex3f(1.0f+x, 1.0f+y, -1.0f+z); glVertex3f(-1.0f+x, 1.0f+y, -1.0f+z); glVertex3f(-1.0f+x, -1.0f+y, -1.0f+z); glVertex3f(-1.0f+x, -1.0f+y, 1.0f+z); glVertex3f(-1.0f+x, 1.0f+y, -1.0f+z); glVertex3f(-1.0f+x, 1.0f+y, 1.0f+z); glVertex3f(-1.0f+x, -1.0f+y, -1.0f+z); glVertex3f(-1.0f+x, -1.0f+y, 1.0f+z); glVertex3f(1.0f+x, -1.0f+y, 1.0f+z); glVertex3f(1.0f+x, -1.0f+y, -1.0f+z); glVertex3f(-1.0f+x, -1.0f+y, 1.0f+z); glVertex3f(1.0f+x, -1.0f+y, 1.0f+z); glVertex3f(1.0f+x, 1.0f+y, 1.0f+z); glVertex3f(-1.0f+x, 1.0f+y, 1.0f+z); glVertex3f(-1.0f+x, -1.0f+y, 1.0f+z); glVertex3f(1.0f+x, -1.0f+y, 1.0f+z); glVertex3f(1.0f+x, 1.0f+y, 1.0f+z); glVertex3f(-1.0f+x, 1.0f+y, 1.0f+z); glVertex3f(-1.0f+x, 1.0f+y, -1.0f+z); glVertex3f(-1.0f+x, 1.0f+y, 1.0f+z); glVertex3f(1.0f+x, 1.0f+y, 1.0f+z); glVertex3f(1.0f+x, 1.0f+y, -1.0f+z); glEnd(); } </code></pre> <p><strong>I do not recommend this function</strong>, use instead the <a href="http://www.opengl.org/sdk/docs/man/xhtml/glTranslate.xml" rel="nofollow"><code>glTranslatef(x, y, z)</code></a> solution discribed in another answer. Like this function:</p> <pre><code> void drawCube(float x, float y, float z) { glPushMatrix(); glTranslatef(x, y, z); glBegin(GL_QUADS); glVertex3f(-1.0f,-1.0f ,-1.0f); glVertex3f(1.0f, -1.0f, -1.0f); glVertex3f(1.0f, 1.0f, -1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glVertex3f(1.0f, -1.0f, 1.0f); glVertex3f(1.0f, -1.0f, -1.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glVertex3f(1.0f, -1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f(-1.0f,-1.0f ,1.0f ); glVertex3f(1.0f, -1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 1.0f); glVertex3f(1.0f, 1.0f, -1.0f); glEnd(); glPopMatrix(); } </code></pre> <p>This function is far from being perfect, but it should suffice. Happy coding!</p>
 

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