Friday, May 11, 2012

Font rendering in GLUT using bitmap fonts with Sample example.

GLUT supports two type of font rendering: stroke fonts, meaning each character is rendered as a set of line segments; and bitmap fonts, where each character is a bitmap generated with glBitmap. Stroke fonts have the advantage that because they are geometry, they can be arbitrarily scale and rendered. Bitmap fonts are less flexible since they are rendered as bitmaps but are usually faster than stroke fonts. In this tutorial I will explain about Bitmap fonts. The function that renders bitmap character using OpenGL is glutBitmapCharacter. The syntax is

glutBitmapCharacter (void *font, int character);

font –> bitmap font to use and character –> Character to render.
For example,
glutBitmapCharacter(GLUT_HELVETICA_10,'a');
outputs a single character ‘a’ at the current raster position.
There are 7 bitmap fonts available in GLUT. They are
  • GLUT_BITMAP_8_BY_13
  • GLUT_BITMAP_9_BY_15
  • GLUT_BITMAP_TIMES_ROMAN_10
  • GLUT_BITMAP_TIMES_ROMAN_24
  • GLUT_BITMAP_HELVETICA_10
  • GLUT_BITMAP_HELVETICA_12
  • GLUT_BITMAP_HELVETICA_18
You can render the character in any raster position of the window. The raster position can be set using family of functions glRasterPos from OpenGL library. The syntax of the functions are:

void glRasterPos2f(float x, float y);
void glRasterPos3f(float x, float y, float z);

GLUT Tutorial - Creating Menus and Submenus in GLUT

GLUT supports simple cascading pop-up menus. They are designed to let a user select various modes within a program. The functionality is simple and minimalistic and is meant to be that way. Do not mistake GLUT’s pop-up menu facility with an attempt to create a full-featured user interface. glutCreateMenu creates a Menu in GLUT. The syntax of glutCreateMenu is

int glutCreateMenu(void (*func)(int value));

This function defines the callback that has to be called when a menu item was selected. This callback function has one parameter, the value. This function returns an int, this is the menu identifier. This identifier is needed when you would want to attach this menu as a submenu. This is illustrated in sample example later.

Thursday, May 10, 2012

Rendering Teapot glutSolidTeapot and glutWireTeapot using GLUT in C

GLUT provides function glutSolidTeapot to render a Solid Torus and glutWireTeapot to render a Wire Frame Torus. glutSolidTeapot and glutWireTeapot render a solid or wireframe teapot respectively. Both surface normals and texture coordinates for the teapot are generated. The teapot is generated with OpenGL evaluators. Here are the syntax of both the above functions

void glutSolidTeapot (GLdouble size);
void glutWireTeapot(GLdouble size);

Where, size –> Relative size of Teapot

Rendering Dodecahedron, Octahedron, Tetrahedron and Icosahedrons using GLUT in C

GLUT provides functions with no parameters and pre – assigned radii for these Objects. The pre – assigned radii of Dodecahedron, Octahedron, Tetrahedron and Icosahedrons are, respectively, sqrt(3), 1, sqrt(3), 1.  The syntax of each object is given below

Dodecahedron
void glutSolidDodecahedron (void);
void glutWireDodecahedron (void);
Octahedron
void glutSolidOctahedron (void);
void glutWireOctahedron (void);
Tetrahedron
void glutSolidTetrahedron (void);
void glutWireTetrahedron (void);
Icosahedrons
void glutSolidIcosahedron (void);
void glutWireIcosahedron (void);

Rendering Torus glutSolidTorus and glutWireTorus using GLUT in C

GLUT provides function glutSolidTorus to render a Solid Torus and glutWireTorus to render a Wire Frame Torus. glutSolidTorus and glutWireTorus render a solid or wireframe torus (doughnut) respectively centered at the modeling coordinates origin whose axis is aligned with the Z axis. Here are the syntax of both the above functions

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

Where, innerRadius –> Inner Radius of the Torus, outerRadius –> Outer Radius of the Torus,  nsides –> Number of sides for each radial section, rings –> Number of radial divisions for torus.

Wednesday, May 9, 2012

Rendering Cones glutSolidCone and glutWireCone using GLUT in C

GLUT provides function glutSolidCone to render a Solid Cone and glutWireCone to render a Wire Frame Cone. glutSolidCone and glutWireCone render a solid or wireframe cone respectively oriented along the Z axis. The base of the cone is placed at Z = 0, and the top at Z = height. The cone is subdivided around the Z
axis into slices, and along the Z axis into stacks. Here are the syntax of both the above functions

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

Where, base –> The radius of base of the  cone, height –> height of the cone,  slices –> The number of subdivision around the Z-axis and stacks –> The number of subdivisions along the Z-axis.

Tuesday, May 8, 2012

Rendering Spheres glutSolidSphere and glutWireSphere using GLUT in C – A sample program

GLUT provides function glutSolidSphere to render a Solid Sphere and glutWireSphere to render a Wire Frame Sphere. They Render the spheres centered at the modeling coordinates origin of the specified radii. The sphere is subdivided around the Z axis into slices and along the Z axis into stacks. Here are the syntax of both the above functions

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

Where, radius –> The radius of the spheres, slices –> The number of subdivision around the Z-axis and stacks –> The number of subdivisions along the Z-axis.

Monday, May 7, 2012

PHP with MySQL: How to connect to MySQL database using PHP?

Connection to MySQL database using PHP is very simple and includes only few steps. First of all we establish a connection to database using username and password. Then we select the database that is already created using MySQL console or PhpMyAdmin. Then some operations are performed on data and finally we close the connection.
For the connection to MySQL, we need a database. So lets create a database with name testDB having one table user with three fields id, username and password  using MySQL console. Enter the following command in MySQL console and hit Enter. (MySQL console is generally located in C:\wamp\bin\mysql\mysql5.1.36\bin in WAMP server, the mysql version may be different in your case)
mysql> CREATE DATABASE testDB;
It creates a database with name testDB. In order to perform the operations on a database we must use the database. So to use the database testDB, insert the following command and hit enter.
mysql> USE testDB;
Now we create a table with fields id, username and password.