## Archive Pages Design\$type=blogging

We are going to demonstrate the 3D spinning Cube gl programming in this blog post with free source code.

OpenGL programming is also know as gl programming. OpenGL is not a programming language rather it is API which allow other programming languages ton exploit and develop computer graphics objects.

## Overview of  gl programming

Before going to talk about the main project we are first talk the following question. This question comes in mind of all opengl learners.
What is  gl programming?
gl programming is the use of opengl api to develop games, 3 objects etc via computer graphics. The  gl programming is to create the program with the help existing language and rendering the objects with api provide in OpenGL. The base of  gl programming is Opengl - open computer graphics library. With the help of  gl programming we can do things like developing a games for pc, mobiles and other devices. It also helps in different sectors for research and implementation like scientific research, weather, medicines, card and architecture designs.

## 3D spinning Cube

In this post we will cover the 3D spinning cube. As we all know that a cube has 6 faces, we will color the different faces in different colors. The 3d spinning cube will be fully colorful. The cube will look good and it will make full use of computer graphics.
Note - VTU students have two programs on Cubes in the syllabus.

### Design the Cube and Spinning

To design the cube in opengl we need to make use of simple functions. Let go to code a cube in OpenGL. First we need to define the vertices of the cube and then color for each of it sides.

/*Matrix for the vertices of Cubes*/
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},
};
/*Matrix for the color of sides of Cubes*/
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},
};
Next is to give translate and rotation to the cube. We code that like -
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();//push on stack
glTranslatef(0.0, 0.0, -15.0); //move
glRotatef(rot, 0.0, 1.0, 0.0); //rotation
glTranslatef(0.0, 0.0, -5.0); //move
glRotatef(rot*2, 1.0, 0.0, 0.0); //rotation
Till know cube is not designed yet for that we have used the GL_QUADS and glVertex. We utilized the vertices and color matrix as defined above to render the 3d cube.
glColor3fv(color[0]);
glVertex3fv(vert[0]);
glVertex3fv(vert[1]);
glVertex3fv(vert[2]);
glVertex3fv(vert[3]);
glColor3fv(color[1]);
glVertex3fv(vert[4]);
glVertex3fv(vert[5]);
glVertex3fv(vert[6]);
glVertex3fv(vert[7]);
glColor3fv(color[2]);
glVertex3fv(vert[0]);
glVertex3fv(vert[1]);
glVertex3fv(vert[5]);
glVertex3fv(vert[4]);
glColor3fv(color[3]);
glVertex3fv(vert[2]);
glVertex3fv(vert[3]);
glVertex3fv(vert[7]);
glVertex3fv(vert[6]);
glColor3fv(color[4]);
glVertex3fv(vert[3]);
glVertex3fv(vert[0]);
glVertex3fv(vert[4]);
glVertex3fv(vert[7]);
glColor3fv(color[5]);
glVertex3fv(vert[1]);
glVertex3fv(vert[2]);
glVertex3fv(vert[6]);
glVertex3fv(vert[5]);
glEnd();
In this gl programming example we are not using any keyboard function, nor do we used the mouse function. On execution of the program we will get the colorful cube which rotates or spins around in a path on screen.
Give suggestion or any query to us via email to openglprojects@gmail.com.

Name

3D Bi-Cycle 3D Game 3D Laptop 3D Objects 3D Projects 3D Zoo Algorithm Android Aquarium Bellman-Ford Algorithm BÃ©zier curves Block Breaker Blockshooting Bucket Sort C# Chess Clock Code Blocks Colors Complex Project Complex Projects Crab Pong Cross Zero Doll DSAV Escapa Fighter Jet First Come First Serve Flag Flag Hoisting flag of usa Fluids Font Demo Games Gear Motion GlutDino Glutplane Graphics Editor iOS iPhone Java Java OpenGL Graphics Programming Light Torus Linked List Ludo Board Game Mancala board games Martyr’s Monument Memory blocks game Memory Game Menu Mickey Mouse Minesweeper Miniature Steam Engine moth Motion Blur MoveLight moving car Moving Ship Multiplex Networking Based Project Nuclear Power Plant Olympic opengl c++ examples OpenGL ES OpenGL Programming OpenGL Tutorial Origami OS Based Projects Paint Paper Folding Particles Drop Path Finding ping pong Pong Game Project Report Projects Report Puzzles qix like Queuqe Random Flowing lines Ray Rigid Body Rings Robot sample c++ opengl code Screen Saver Screen Saver Ship Shadow Cube Shadowfun Shaheed Minar Ship Iceberg Simple Drawing Simple Haloed Lined Wireframe Simple Move Light Simple Project Simulation SNAKE XENZIA GAME Solar system Sorting Space Invaders Sphere Spot Light Swing Stack Stars Taj Mahal The Edge Game Tic Tac Toe Tower of Hanoi Traffic Signal Transformation Triangular Animation Trippy Tutorial water ripple effects Whirlpool
false
ltr
item
OpenGL Projects: 3D spinning Cube gl programming
3D spinning Cube gl programming
We are going to demonstrate the 3D spinning Cube gl programming in this blog post with free source code.
https://2.bp.blogspot.com/-mqH0Gz9otkc/Vs3rnFp8WvI/AAAAAAAAHkA/Vb2mM8qlwkw/s320/3d%2Bspinning%2Bcube.PNG
https://2.bp.blogspot.com/-mqH0Gz9otkc/Vs3rnFp8WvI/AAAAAAAAHkA/Vb2mM8qlwkw/s72-c/3d%2Bspinning%2Bcube.PNG
OpenGL Projects
https://www.openglprojects.in/2016/02/3d-spinning-cube-gl-programming.html
https://www.openglprojects.in/
https://www.openglprojects.in/
https://www.openglprojects.in/2016/02/3d-spinning-cube-gl-programming.html
true
2020194800836807725
UTF-8