Archive Pages Design$type=blogging

3D Primtives in OpenGL

Learn about 3d OpenGL primitives These code help quickly draw the 3d objects without writing alots of code for them.

OpenGl Graphics library or OpenGl toolkit provides different API and methods to draw various 2d and 3d objects. In this post we will able show case you the basic 3d shapes. These 3d primitive can be drawn by calling the predefined methods or function in OpenGL.

What are 3D Primtives in OpenGL?

Like points,lines , traingle and polyogn in 2d we have primitives in 3d as well written in OpenGL itself. The library provide us easy access to draw the 2d Objects with one line of code. We can  use 2d primitives to draw the 3d objects but in OpenGL we have predefined code for 3d objects. We can overrides them as well. These code help quickly draw the 3d objects without writing alots of code for them.

There are many 3D objects defined but we mentioned you the 3d basics ones - Sphere, Cube (cuboid), Cone, Torus,  Icosahedron and Teapot.  These 3d objects can be drawn easily by calling the function from OPenGL graphics library, with some input likes radius, length, height and width etc.

Draw the 3D Primtives

Here we will se how to simply call the function for each 3D objects mentioned in the above para. We will also discuss about the parameter they need. In our case we are using wired 3d Objects and not solid ones.

1. Sphere

 void glutWireSphere(GLdouble radius,GLint slices, GLint stacks);

Radius, not need explanation, while slices are no of subdivisions around z-axis, stacks are no of subdivisions along the z-axis. You may consider the slices and stacks to be like of  longitude and latitudes.

2. Cube

void glutWireCube(GLdouble size);

Cube requied one parameter and that's its size.

3. Cone

void glutWireCone(GLdouble base, GLdouble height, GLint slices,
GLint stacks);

Cone is an objects with triangular face and circular bottom. The base here denotes for radius of the circular base or bottom, height is the height of cone. Similar to Sphere, slices are no of subdivisions around z-axis, stacks are no of subdivisions along the z-axis.

4. Torus

void glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius,
GLint nsides, GLint rings);

A torus is an objects that is flat with hole in it's inner part and outer part to be circular. Tours examples are the tubes. The innerRadius and outerRadius represent the inner and outer radii. The nsides represent the no of sides that each radial section contains, while rings represent the no of radial divisions. These two can be understand as sections formed by cutting up to down and left to right respectively, along a fixed axis.

5. Icosahedron

void glutWireIcosahedron(void);

Icosahedron is a solid body with 20 sides. Other solid body are terahedron (4 sides), octahedron(8 sides), dodecahedron(12 sides) etc. These can be also drawn by just replacing name in above like - glutWireTetrahedron.

The GLUT provides functions for these objects with no parameters and with preassigned radii. The preassigned radii of Dodecahedron, Octahedron, Tetrahedron and Icosahedrons are, respectively, sqrt(3), 1, sqrt(3), 1.

One thing you need to do, while rendering set the raddi for them with scaling or translating.

6. Teapot

void glutWireTeapot(GLdouble size);

Here size is relative size of Teapot, which is generated with OpenGL evaluators. Both surface normals and texture coordinates for the teapot are generated.

Below is simple example of drawing these objects with a sample input data.

void drawSphere(void) {

void drawCube(void) {

void drawCone(void) {
 glutWireCone(6.0, 8.0, 10, 20);

void drawTorus(void) {
 glutWireTorus(1.0, 6.0, 10, 20);

void drawIcos(void) {

Now, if you want to draw the solid objects insted of wired just replace wire word to solid like - glutWireCube to glutSolidCube.

You can download the source code for wired 3d primitives and solid 3d primitives.



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
OpenGL Projects: 3D Primtives in OpenGL
3D Primtives in OpenGL
Learn about 3d OpenGL primitives These code help quickly draw the 3d objects without writing alots of code for them.
OpenGL Projects
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago