Posts

Learn how to make a Simple 3D Rotating Cube using OpenGL

Tutorial to code "spinning cube animation" or a '3D Rotating Cube" in OpenGL C++ Computer graphics with full sourcecode.
Rajeev
Learn how to make a Simple 3D Rotating Cube using OpenGL
In this tutorial we are going to learn about "spinning cube animation" or a '3D Rotating Cube". First we think how to animate? The answer - by allowing continuously display the picture with different frames shown, little by little and giving the appearance of motion. First we declare the following - #include<GL/glut.h> #include<GL/gl.h> static GLfloat rot; The header are included to access the OpenGL libraries. Then there is variable for the angle of rotation of the cube. Next we call the display function which will have the matrix that holds the vertices as well the color values in them. static GLfloat vert[][4]={ { 1.0,  1.0,  1.0}, {-1.0,  1.0,  1.0}, {-1.0, -1.0,  1.0}, { 1.0, -1.0,  1.0}, { 1.0,  1.0, -1.0}, {-1.0,  1.0, -1.0}, {-1.0, -1.0, -1.0}, { 1.0, -1.0, -1.0}, }; static GLfloat color[][4]={ {1.0, 0.0, 0.0, 0.0}, {0.0, 1.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0}, {0.0, 1.0, 1.0, 0.0}, {1.0, 0.0, 1.0, 0.0}, {1.0, 1.0, 0.0, 0.0}, }; Rest display function will have the …

2 comments

  1. hello
    this is old method of drawing, it uses all deprecated functions.
  2. Rajeev Kumar Singh
    thaanks for the comment
    can u tell how to do in modern ways