Thursday, September 29, 2011

Figure 70


$40 off Craftsman 5 Drawer Homeowner Tool Center with Riser and Parts Bins $99.99 on sale 10/2-10/8
Sears Deal of the Day: Thule Car Top Carrier, Quest
Wholesale Fleece Blankets
400950_BuddhaGroove.com-Culture Infused Living: Home Accents, Jewelry, Accessories from around the world!
400948_Culture Infused Living: Home Accents, Jewelry, and accessories from around the world. CulturalElemen
504427_Save up to 75% on batteries and accessories at Brooklyn Battery Works!
504080_10% OFF Orders of $75 or More from Journelle.com! Use Promo Code: NOV11 (Valid 11/1 - 11/30/11)
502239_Brand names, bargain prices at shoezoo.com. If you don't love your new shoes, return them for free!

400949_GaneshMall.com-Culture Infused Living: Home Accents, Jewelry, and accessories from around the world!



Figure 70
===============
Note: The two square numbers keep flipping.
===============


/*
//Author: Cheikh Drame
//To support, please do one of the following
//- Visit irap123.com many times a day
//- Join irap123.com
//- Buy my app irap123 (rhyming dictionary) available for android, and iphone. On windows phone, it is called iLyrics. If not, you can get the desktop version at www.irap123.com/apps/webstore/
//- Include irap123.com in your blogs, forums, facebook walls, email footers, comments
//- send a donation at my paypal address at cbdsigned.vevo@gmail.com
//- Buy a story at http://shop.pparzygnat.com
*/
// TextNumber.cpp : Defines the entry point for the console application.
//




/* texobj.c */

/*
* Example of using the 1.1 texture object functions.
* Also, this demo utilizes Mesa's fast texture map path.
*
* Brian Paul June 1996
*/

/* Conversion to GLUT by Mark J. Kilgard */

#include
#include
#include
#include
#include

static GLuint TexObj[2];
static GLfloat Angle = 0.0f;
static GLboolean HaveTexObj = GL_FALSE;

#if defined(GL_VERSION_1_1)
#define TEXTURE_OBJECT 1
#elif defined(GL_EXT_texture_object)
#define TEXTURE_OBJECT 1
#define glBindTexture(A,B) glBindTextureEXT(A,B)
#define glGenTextures(A,B) glGenTexturesEXT(A,B)
#define glDeleteTextures(A,B) glDeleteTexturesEXT(A,B)
#endif

static void
draw(void)
{
/* glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); */
glClear(GL_COLOR_BUFFER_BIT);

glColor3f(1.0, 1.0, 1.0);

/* draw first polygon */
glPushMatrix();
glTranslatef(-1.0, 0.0, 0.0);
glRotatef(Angle, 0.0, 0.0, 1.0);
if (HaveTexObj) {
#ifdef TEXTURE_OBJECT
glBindTexture(GL_TEXTURE_2D, TexObj[0]);
#endif
} else {
glCallList(TexObj[0]);
}
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 0.0);
glVertex2f(-1.0, -1.0);
glTexCoord2f(1.0, 0.0);
glVertex2f(1.0, -1.0);
glTexCoord2f(1.0, 1.0);
glVertex2f(1.0, 1.0);
glTexCoord2f(0.0, 1.0);
glVertex2f(-1.0, 1.0);
glEnd();
glPopMatrix();

/* draw second polygon */
glPushMatrix();
glTranslatef(1.0, 0.0, 0.0);
glRotatef(Angle - 90.0, 0.0, 1.0, 0.0);
if (HaveTexObj) {
#ifdef TEXTURE_OBJECT
glBindTexture(GL_TEXTURE_2D, TexObj[1]);
#endif
} else {
glCallList(TexObj[0]);
}
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 0.0);
glVertex2f(-1.0, -1.0);
glTexCoord2f(1.0, 0.0);
glVertex2f(1.0, -1.0);
glTexCoord2f(1.0, 1.0);
glVertex2f(1.0, 1.0);
glTexCoord2f(0.0, 1.0);
glVertex2f(-1.0, 1.0);
glEnd();
glPopMatrix();

glutSwapBuffers();
}

static void
idle(void)
{
Angle += 2.0;
glutPostRedisplay();
}

/* exit upon ESC */
/* ARGSUSED1 */
static void
key(unsigned char k, int x, int y)
{
switch (k) {
case 27: /* Escape */
#ifdef TEXTURE_OBJECT
glDeleteTextures(2, TexObj);
#endif
exit(0);
}
}

/* new window size or exposure */
static void
reshape(int width, int height)
{
glViewport(0, 0, (GLint) width, (GLint) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
/* glOrtho( -3.0, 3.0, -3.0, 3.0, -10.0, 10.0 ); */
glFrustum(-2.0, 2.0, -2.0, 2.0, 6.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -8.0);
}

static void
init(void)
{
static int width = 8, height = 8;
static GLubyte tex1[] =
{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0};

static GLubyte tex2[] =
{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 2, 2, 0, 0, 0,
0, 0, 2, 0, 0, 2, 0, 0,
0, 0, 0, 0, 0, 2, 0, 0,
0, 0, 0, 0, 2, 0, 0, 0,
0, 0, 0, 2, 0, 0, 0, 0,
0, 0, 2, 2, 2, 2, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0};

GLubyte tex[64][3];
GLint i, j;

glDisable(GL_DITHER);

/* Setup texturing */
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);

/* generate texture object IDs */
if (HaveTexObj) {
#ifdef TEXTURE_OBJECT
glGenTextures(2, TexObj);
#endif
} else {
TexObj[0] = glGenLists(2);
TexObj[1] = TexObj[0] + 1;
}

/* setup first texture object */
if (HaveTexObj) {
#ifdef TEXTURE_OBJECT
glBindTexture(GL_TEXTURE_2D, TexObj[0]);
#endif
} else {
glNewList(TexObj[0], GL_COMPILE);
}
/* red on white */
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int p = i * width + j;
if (tex1[(height - i - 1) * width + j]) {
tex[p][0] = 255;
tex[p][1] = 0;
tex[p][2] = 0;
} else {
tex[p][0] = 255;
tex[p][1] = 255;
tex[p][2] = 255;
}
}
}
glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0,
GL_RGB, GL_UNSIGNED_BYTE, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if (!HaveTexObj) {
glEndList();
}
/* end of texture object */

/* setup second texture object */
if (HaveTexObj) {
#ifdef TEXTURE_OBJECT
glBindTexture(GL_TEXTURE_2D, TexObj[1]);
#endif
} else {
glNewList(TexObj[1], GL_COMPILE);
}
/* green on blue */
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int p = i * width + j;
if (tex2[(height - i - 1) * width + j]) {
tex[p][0] = 0;
tex[p][1] = 255;
tex[p][2] = 0;
} else {
tex[p][0] = 0;
tex[p][1] = 0;
tex[p][2] = 255;
}
}
}
glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0,
GL_RGB, GL_UNSIGNED_BYTE, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if (!HaveTexObj) {
glEndList();
}
/* end texture object */
}

void
visible(int vis)
{
if (vis == GLUT_VISIBLE)
glutIdleFunc(idle);
else
glutIdleFunc(NULL);
}

int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);

glutCreateWindow("Texture Objects by irap123.com");

/* check that renderer has the GL_EXT_texture_object
extension * or supports OpenGL 1.1 */
#ifdef TEXTURE_OBJECT
{
char *exten = (char *) glGetString(GL_EXTENSIONS);
char *version = (char *) glGetString(GL_VERSION);
if (strstr(exten, "GL_EXT_texture_object")
|| strncmp(version, "1.1", 3) == 0) {
HaveTexObj = GL_TRUE;
}
}
#endif

if (!HaveTexObj) {
printf("\nThis program doesn't really work the way it is supposed\n");
printf("to if you lack OpenGL 1.1 or the EXT_texture_object extension.\n");
printf("Each textured object should have a different numbered image.\n\n");
}

init();

glutReshapeFunc(reshape);
glutKeyboardFunc(key);
glutVisibilityFunc(visible);
glutDisplayFunc(draw);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}

Figure 69


$40 off Craftsman 5 Drawer Homeowner Tool Center with Riser and Parts Bins $99.99 on sale 10/2-10/8
Sears Deal of the Day: Thule Car Top Carrier, Quest
Wholesale Fleece Blankets
400950_BuddhaGroove.com-Culture Infused Living: Home Accents, Jewelry, Accessories from around the world!
400948_Culture Infused Living: Home Accents, Jewelry, and accessories from around the world. CulturalElemen
504427_Save up to 75% on batteries and accessories at Brooklyn Battery Works!
504080_10% OFF Orders of $75 or More from Journelle.com! Use Promo Code: NOV11 (Valid 11/1 - 11/30/11)
502239_Brand names, bargain prices at shoezoo.com. If you don't love your new shoes, return them for free!

400949_GaneshMall.com-Culture Infused Living: Home Accents, Jewelry, and accessories from around the world!



Figure 69
===============================


/*
//Author: Cheikh Drame
//To support, please do one of the following
//- Visit irap123.com many times a day
//- Join irap123.com
//- Buy my app irap123 (rhyming dictionary) available for android, and iphone. On windows phone, it is called iLyrics. If not, you can get the desktop version at www.irap123.com/apps/webstore/
//- Include irap123.com in your blogs, forums, facebook walls, email footers, comments
//- send a donation at my paypal address at cbdsigned.vevo@gmail.com
//- Buy a story at http://shop.pparzygnat.com
*/
// texgen.cpp : Defines the entry point for the console application.
//



/**/

/* texgen.c
* This program draws a texture mapped teapot with
* automatically generated texture coordinates. The
* texture is rendered as stripes on the teapot.
* Initially, the object is drawn with texture coordinates
* based upon the object coordinates of the vertex
* and distance from the plane x = 0. Pressing the 'e'
* key changes the coordinate generation to eye coordinates
* of the vertex. Pressing the 'o' key switches it back
* to the object coordinates. Pressing the 's' key
* changes the plane to a slanted one (x + y + z = 0).
* Pressing the 'x' key switches it back to x = 0.
*/

#include
#include
#include

#define stripeImageWidth 32
GLubyte stripeImage[4*stripeImageWidth];

#ifdef GL_VERSION_1_1
static GLuint texName;
#endif

void makeStripeImage(void)
{
int j;

for (j = 0; j < stripeImageWidth; j++) {
stripeImage[4*j] = (GLubyte) ((j<=4) ? 255 : 0);
stripeImage[4*j+1] = (GLubyte) ((j>4) ? 255 : 0);
stripeImage[4*j+2] = (GLubyte) 0;
stripeImage[4*j+3] = (GLubyte) 255;
}
}

/* planes for texture coordinate generation */
static GLfloat xequalzero[] = {1.0, 0.0, 0.0, 0.0};
static GLfloat slanted[] = {1.0, 1.0, 1.0, 0.0};
static GLfloat *currentCoeff;
static GLenum currentPlane;
static GLint currentGenMode;

void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);

makeStripeImage();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

#ifdef GL_VERSION_1_1
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_1D, texName);
#endif
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
#ifdef GL_VERSION_1_1
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, stripeImageWidth, 0,
GL_RGBA, GL_UNSIGNED_BYTE, stripeImage);
#else
glTexImage1D(GL_TEXTURE_1D, 0, 4, stripeImageWidth, 0,
GL_RGBA, GL_UNSIGNED_BYTE, stripeImage);
#endif

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
currentCoeff = xequalzero;
currentGenMode = GL_OBJECT_LINEAR;
currentPlane = GL_OBJECT_PLANE;
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, currentGenMode);
glTexGenfv(GL_S, currentPlane, currentCoeff);

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_1D);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glFrontFace(GL_CW);
glCullFace(GL_BACK);
glMaterialf (GL_FRONT, GL_SHININESS, 64.0);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix ();
glRotatef(45.0, 0.0, 0.0, 1.0);
#ifdef GL_VERSION_1_1
glBindTexture(GL_TEXTURE_1D, texName);
#endif
glutSolidTeapot(2.0);
glPopMatrix ();
glFlush();
}

void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho (-3.5, 3.5, -3.5*(GLfloat)h/(GLfloat)w,
3.5*(GLfloat)h/(GLfloat)w, -3.5, 3.5);
else
glOrtho (-3.5*(GLfloat)w/(GLfloat)h,
3.5*(GLfloat)w/(GLfloat)h, -3.5, 3.5, -3.5, 3.5);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 'e':
case 'E':
currentGenMode = GL_EYE_LINEAR;
currentPlane = GL_EYE_PLANE;
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, currentGenMode);
glTexGenfv(GL_S, currentPlane, currentCoeff);
glutPostRedisplay();
break;
case 'o':
case 'O':
currentGenMode = GL_OBJECT_LINEAR;
currentPlane = GL_OBJECT_PLANE;
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, currentGenMode);
glTexGenfv(GL_S, currentPlane, currentCoeff);
glutPostRedisplay();
break;
case 's':
case 'S':
currentCoeff = slanted;
glTexGenfv(GL_S, currentPlane, currentCoeff);
glutPostRedisplay();
break;
case 'x':
case 'X':
currentCoeff = xequalzero;
glTexGenfv(GL_S, currentPlane, currentCoeff);
glutPostRedisplay();
break;
case 27:
exit(0);
break;
default:
break;
}
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(256, 256);
glutInitWindowPosition(100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

Figure 68


$40 off Craftsman 5 Drawer Homeowner Tool Center with Riser and Parts Bins $99.99 on sale 10/2-10/8
Sears Deal of the Day: Thule Car Top Carrier, Quest
Wholesale Fleece Blankets
400950_BuddhaGroove.com-Culture Infused Living: Home Accents, Jewelry, Accessories from around the world!
400948_Culture Infused Living: Home Accents, Jewelry, and accessories from around the world. CulturalElemen
504427_Save up to 75% on batteries and accessories at Brooklyn Battery Works!
504080_10% OFF Orders of $75 or More from Journelle.com! Use Promo Code: NOV11 (Valid 11/1 - 11/30/11)
502239_Brand names, bargain prices at shoezoo.com. If you don't love your new shoes, return them for free!

400949_GaneshMall.com-Culture Infused Living: Home Accents, Jewelry, and accessories from around the world!



Figure 68
===================


/*
//Author: Cheikh Drame
//To support, please do one of the following
//- Visit irap123.com many times a day
//- Join irap123.com
//- Buy my app irap123 (rhyming dictionary) available for android, and iphone. On windows phone, it is called iLyrics. If not, you can get the desktop version at www.irap123.com/apps/webstore/
//- Include irap123.com in your blogs, forums, facebook walls, email footers, comments
//- send a donation at my paypal address at cbdsigned.vevo@gmail.com
//- Buy a story at http://shop.pparzygnat.com
*/

// teapots2.cpp : Defines the entry point for the console application.
//


/* */

/*
* teapots.c
* This program demonstrates lots of material properties.
* A single light source illuminates the objects.
*/
#include
#include

GLuint teapotList;

/*
* Initialize depth buffer, projection matrix, light source, and lighting
* model. Do not specify a material property here.
*/
void init(void)
{
GLfloat ambient[] = {0.0, 0.0, 0.0, 1.0};
GLfloat diffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat position[] = {0.0, 3.0, 3.0, 0.0};

GLfloat lmodel_ambient[] = {0.2, 0.2, 0.2, 1.0};
GLfloat local_view[] = {0.0};

glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view);

glFrontFace(GL_CW);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
/* be efficient--make teapot display list */
teapotList = glGenLists(1);
glNewList (teapotList, GL_COMPILE);
glutSolidTeapot(1.0);
glEndList ();
}

/*
* Move object into position. Use 3rd through 12th
* parameters to specify the material property. Draw a teapot.
*/
void renderTeapot(GLfloat x, GLfloat y,
GLfloat ambr, GLfloat ambg, GLfloat ambb,
GLfloat difr, GLfloat difg, GLfloat difb,
GLfloat specr, GLfloat specg, GLfloat specb, GLfloat shine)
{
GLfloat mat[4];

glPushMatrix();
glTranslatef(x, y, 0.0);
mat[0] = ambr; mat[1] = ambg; mat[2] = ambb; mat[3] = 1.0;
glMaterialfv(GL_FRONT, GL_AMBIENT, mat);
mat[0] = difr; mat[1] = difg; mat[2] = difb;
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat);
mat[0] = specr; mat[1] = specg; mat[2] = specb;
glMaterialfv(GL_FRONT, GL_SPECULAR, mat);
glMaterialf(GL_FRONT, GL_SHININESS, shine * 128.0);
glCallList(teapotList);
glPopMatrix();
}

/**
* First column: emerald, jade, obsidian, pearl, ruby, turquoise
* 2nd column: brass, bronze, chrome, copper, gold, silver
* 3rd column: black, cyan, green, red, white, yellow plastic
* 4th column: black, cyan, green, red, white, yellow rubber
*/
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderTeapot(2.0, 17.0, 0.0215, 0.1745, 0.0215,
0.07568, 0.61424, 0.07568, 0.633, 0.727811, 0.633, 0.6);
renderTeapot(2.0, 14.0, 0.135, 0.2225, 0.1575,
0.54, 0.89, 0.63, 0.316228, 0.316228, 0.316228, 0.1);
renderTeapot(2.0, 11.0, 0.05375, 0.05, 0.06625,
0.18275, 0.17, 0.22525, 0.332741, 0.328634, 0.346435, 0.3);
renderTeapot(2.0, 8.0, 0.25, 0.20725, 0.20725,
1, 0.829, 0.829, 0.296648, 0.296648, 0.296648, 0.088);
renderTeapot(2.0, 5.0, 0.1745, 0.01175, 0.01175,
0.61424, 0.04136, 0.04136, 0.727811, 0.626959, 0.626959, 0.6);
renderTeapot(2.0, 2.0, 0.1, 0.18725, 0.1745,
0.396, 0.74151, 0.69102, 0.297254, 0.30829, 0.306678, 0.1);
renderTeapot(6.0, 17.0, 0.329412, 0.223529, 0.027451,
0.780392, 0.568627, 0.113725, 0.992157, 0.941176, 0.807843,
0.21794872);
renderTeapot(6.0, 14.0, 0.2125, 0.1275, 0.054,
0.714, 0.4284, 0.18144, 0.393548, 0.271906, 0.166721, 0.2);
renderTeapot(6.0, 11.0, 0.25, 0.25, 0.25,
0.4, 0.4, 0.4, 0.774597, 0.774597, 0.774597, 0.6);
renderTeapot(6.0, 8.0, 0.19125, 0.0735, 0.0225,
0.7038, 0.27048, 0.0828, 0.256777, 0.137622, 0.086014, 0.1);
renderTeapot(6.0, 5.0, 0.24725, 0.1995, 0.0745,
0.75164, 0.60648, 0.22648, 0.628281, 0.555802, 0.366065, 0.4);
renderTeapot(6.0, 2.0, 0.19225, 0.19225, 0.19225,
0.50754, 0.50754, 0.50754, 0.508273, 0.508273, 0.508273, 0.4);
renderTeapot(10.0, 17.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.01,
0.50, 0.50, 0.50, .25);
renderTeapot(10.0, 14.0, 0.0, 0.1, 0.06, 0.0, 0.50980392, 0.50980392,
0.50196078, 0.50196078, 0.50196078, .25);
renderTeapot(10.0, 11.0, 0.0, 0.0, 0.0,
0.1, 0.35, 0.1, 0.45, 0.55, 0.45, .25);
renderTeapot(10.0, 8.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0,
0.7, 0.6, 0.6, .25);
renderTeapot(10.0, 5.0, 0.0, 0.0, 0.0, 0.55, 0.55, 0.55,
0.70, 0.70, 0.70, .25);
renderTeapot(10.0, 2.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.0,
0.60, 0.60, 0.50, .25);
renderTeapot(14.0, 17.0, 0.02, 0.02, 0.02, 0.01, 0.01, 0.01,
0.4, 0.4, 0.4, .078125);
renderTeapot(14.0, 14.0, 0.0, 0.05, 0.05, 0.4, 0.5, 0.5,
0.04, 0.7, 0.7, .078125);
renderTeapot(14.0, 11.0, 0.0, 0.05, 0.0, 0.4, 0.5, 0.4,
0.04, 0.7, 0.04, .078125);
renderTeapot(14.0, 8.0, 0.05, 0.0, 0.0, 0.5, 0.4, 0.4,
0.7, 0.04, 0.04, .078125);
renderTeapot(14.0, 5.0, 0.05, 0.05, 0.05, 0.5, 0.5, 0.5,
0.7, 0.7, 0.7, .078125);
renderTeapot(14.0, 2.0, 0.05, 0.05, 0.0, 0.5, 0.5, 0.4,
0.7, 0.7, 0.04, .078125);
glFlush();
}

void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho(0.0, 16.0, 0.0, 16.0*(GLfloat)h/(GLfloat)w,
-10.0, 10.0);
else
glOrtho(0.0, 16.0*(GLfloat)w/(GLfloat)h, 0.0, 16.0,
-10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
}

void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}

/*
* Main Loop
*/
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 600);
glutInitWindowPosition(50,50);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutKeyboardFunc (keyboard);
glutMainLoop();
return 0;
}

Figure 67


$40 off Craftsman 5 Drawer Homeowner Tool Center with Riser and Parts Bins $99.99 on sale 10/2-10/8
Sears Deal of the Day: Thule Car Top Carrier, Quest
Wholesale Fleece Blankets
400950_BuddhaGroove.com-Culture Infused Living: Home Accents, Jewelry, Accessories from around the world!
400948_Culture Infused Living: Home Accents, Jewelry, and accessories from around the world. CulturalElemen
504427_Save up to 75% on batteries and accessories at Brooklyn Battery Works!
504080_10% OFF Orders of $75 or More from Journelle.com! Use Promo Code: NOV11 (Valid 11/1 - 11/30/11)
502239_Brand names, bargain prices at shoezoo.com. If you don't love your new shoes, return them for free!

400949_GaneshMall.com-Culture Infused Living: Home Accents, Jewelry, and accessories from around the world!


Figure 67
======================


/*
//Author: Cheikh Drame
//To support, please do one of the following
//- Visit irap123.com many times a day
//- Join irap123.com
//- Buy my app irap123 (rhyming dictionary) available for android, and iphone. On windows phone, it is called iLyrics. If not, you can get the desktop version at www.irap123.com/apps/webstore/
//- Include irap123.com in your blogs, forums, facebook walls, email footers, comments
//- send a donation at my paypal address at cbdsigned.vevo@gmail.com
//- Buy a story at http://shop.pparzygnat.com
*/
// Teapots.cpp : Defines the entry point for the console application.
//


/* */

/**
* fog.c
* This program draws 5 red teapots, each at a different
* z distance from the eye, in different types of fog.
* Pressing the left mouse button chooses between 3 types of
* fog: exponential, exponential squared, and linear.
* In this program, there is a fixed density value, as well
* as fixed start and end values for the linear fog.
*/

#include
#include
#include

#include "addfog.h"

GLint fogMode;

#define TPF_LINEAR 1
#define TPF_EXP 2
#define TPF_EXP2 3

int addfog = 0;

void
selectFog(int mode)
{
switch (mode) {
case GL_LINEAR:
glFogf(GL_FOG_START, 1.0);
glFogf(GL_FOG_END, 5.0);
/* falls through */
case GL_EXP2:
case GL_EXP:
glFogi(GL_FOG_MODE, mode);
glEnable(GL_FOG);
addfog = 0;
glutPostRedisplay();
break;
case TPF_LINEAR:
afFogStartEnd(0.0, 10.0);
afFogMode(GL_LINEAR);
glDisable(GL_FOG);
addfog = 1;
glutPostRedisplay();
break;
case TPF_EXP:
afFogMode(GL_EXP);
glDisable(GL_FOG);
addfog = 1;
glutPostRedisplay();
break;
case TPF_EXP2:
afFogMode(GL_EXP2);
glDisable(GL_FOG);
addfog = 1;
glutPostRedisplay();
break;
case 0:
exit(0);
}
}

/* Initialize z-buffer, projection matrix, light source, * and lighting
model. Do not specify a material property here. */
void
myinit(void)
{
GLfloat position[] =
{0.0, 3.0, 3.0, 0.0};
GLfloat local_view[] =
{0.0};
GLfloat fogColor[4] =
{0.5, 0.5, 0.5, 1.0};

glEnable(GL_DEPTH_TEST);
glEnable(GL_FOG);
glDepthFunc(GL_LESS);

glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view);

glFrontFace(GL_CW);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);

fogMode = GL_EXP;
glFogi(GL_FOG_MODE, fogMode);
glFogfv(GL_FOG_COLOR, fogColor);
afFogColor(0.5, 0.5, 0.5);
glFogf(GL_FOG_DENSITY, 0.35);
afFogDensity(0.35);
glHint(GL_FOG_HINT, GL_DONT_CARE);
glClearColor(0.5, 0.5, 0.5, 1.0);
}

void
renderRedTeapot(GLfloat x, GLfloat y, GLfloat z)
{
float mat[4];

glPushMatrix();
glTranslatef(x, y, z);
mat[0] = 0.1745;
mat[1] = 0.01175;
mat[2] = 0.01175;
mat[3] = 1.0;
glMaterialfv(GL_FRONT, GL_AMBIENT, mat);
mat[0] = 0.61424;
mat[1] = 0.04136;
mat[2] = 0.04136;
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat);
mat[0] = 0.727811;
mat[1] = 0.626959;
mat[2] = 0.626959;
glMaterialfv(GL_FRONT, GL_SPECULAR, mat);
glMaterialf(GL_FRONT, GL_SHININESS, 0.6 * 128.0);
glutSolidTeapot(1.0);
glPopMatrix();
}

int width, height;

/* display() draws 5 teapots at different z positions. */
void
display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderRedTeapot(-4.0, -0.5, -1.0);
renderRedTeapot(-2.0, -0.5, -2.0);
renderRedTeapot(0.0, -0.5, -3.0);
renderRedTeapot(2.0, -0.5, -4.0);
renderRedTeapot(4.0, -0.5, -5.0);
if (addfog) {
afDoFinalFogPass(0, 0, width, height);
}
glFlush();
}

void
myReshape(int w, int h)
{
width = w;
height = h;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= (h * 3))
glOrtho(-6.0, 6.0, -2.0 * ((GLfloat) h * 3) / (GLfloat) w,
2.0 * ((GLfloat) h * 3) / (GLfloat) w, 0.0, 10.0);
else
glOrtho(-6.0 * (GLfloat) w / ((GLfloat) h * 3),
6.0 * (GLfloat) w / ((GLfloat) h * 3), -2.0, 2.0, 0.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
afEyeNearFar(0.0, 10.0);
}

int
main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(450, 150);
glutCreateWindow("fogged teapots via post-rendering pass");
myinit();
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutCreateMenu(selectFog);
glutAddMenuEntry("Fog EXP", GL_EXP);
glutAddMenuEntry("Fog EXP2", GL_EXP2);
glutAddMenuEntry("Fog LINEAR", GL_LINEAR);
glutAddMenuEntry("Two Pass Fog EXP", TPF_EXP);
glutAddMenuEntry("Two Pass Fog EXP2", TPF_EXP2);
glutAddMenuEntry("Two Pass Fog LINEAR", TPF_LINEAR);
glutAddMenuEntry("Quit", 0);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}


================addfog.h

extern void afEyeNearFar(GLfloat fnear, GLfloat ffar);
extern void afFogStartEnd(GLfloat start, GLfloat end);
extern void afFogMode(GLenum mode);
extern void afFogDensity(GLfloat density);
extern void afFogColor(GLfloat red, GLfloat green, GLfloat blue);
extern void afDoFinalFogPass(GLint x, GLint y, GLsizei width, GLsizei height);

=========================addfog.cpp

/**/

/** Using the "addfog" routines:

1) Given your near and far ranges (generally from glOrtho, glFrustum, or
gluPerspective), call:

afEyeNearFar(near, far);

Careful since "near" and "far" are reserved words on PC compilers.

2) Instead calling glFog to set fog parameters, use the corresponding
"addfog" routines as shown below:

Instead of:

glFogf(GL_FOG_START, start); glFogf(GL_FOG_END, end);

Use:

afFogStartEnd(start, end);

Instead of:

glFogi(GL_FOG_MODE, mode);

Use:

afFogMode(mode);

Instead of:

glFogf(GL_FOG_DENSITY, density);

Use:

afFogDensity(density);

Instead of:

GLfloat fogcolor[4] = { red, green, blue, alpha };
glFogfv(GL_FOG_COLOR, fog_color);

Use:

afFogColor(red, green, blue);

3) Draw you scene *without* OpenGL fog enabled.

4) Assuming you want to fog the entire window of size width by
height, call:

afDoFinalFogPass(0, 0, width, height);

Note: x & y are OpenGL-style lower-left hand window coordinates.

5) Call glFinish or do a buffer swap.

That's it. View your fogged scene. */

#ifdef __sgi /* SGI has a good alloca; many other machines don't. */
#define HAS_ALLOCA
#endif

#include "stdafx.h"
#include
#ifdef HAS_ALLOCA
#include
#endif
#ifdef WIN32
#include
#endif
#include
#include

static GLfloat eye_near = 0.0, eye_far = 1.0;
static GLfloat fog_start = 0.0, fog_end = 1.0;
static GLenum fog_mode = GL_EXP;
static GLfloat fog_density = 1.0;
static int valid = 0;
static GLfloat fog_red, fog_green, fog_blue;

void
afEyeNearFar(GLfloat fnear, GLfloat ffar)
{
eye_near = fnear;
eye_far = ffar;
valid = 0;
}

void
afFogStartEnd(GLfloat start, GLfloat end)
{
fog_start = start;
fog_end = end;
valid = 0;
}

void
afFogMode(GLenum mode)
{
fog_mode = mode;
valid = 0;
}

void
afFogDensity(GLfloat density)
{
fog_density = density;
valid = 0;
}

void
afFogColor(GLfloat red, GLfloat green, GLfloat blue)
{
fog_red = red;
fog_green = green;
fog_blue = blue;
}

#define LEN 256

void
afDoFinalFogPass(GLint x, GLint y, GLsizei width, GLsizei height)
{
static GLfloat alpha_scale, alpha_bias;
static GLfloat fog_map[LEN];
int i;

#ifdef HAS_ALLOCA
void *buffer = alloca((unsigned int) sizeof(GLushort) * width * height);
#else
static void *buffer = NULL;
static int last_width, last_height;

if (width * height != last_width * last_height) {
buffer = realloc(buffer, sizeof(GLushort) * width * height);
last_width = width;
last_height = height;
}
#endif

if (!valid) {
switch (fog_mode) {
case GL_LINEAR:
/* Figure out linear fog blending from "f = (e-z)/(e-s)". */
alpha_scale = (eye_far - eye_near) / (fog_end - fog_start);
alpha_bias = (eye_near - fog_start) / (fog_end - fog_start);
break;
case GL_EXP:
/* Setup fog_map to be "f = exp(-d*z)". */
for (i = 0; i < LEN; i += 1) {
float fi, z, dz;

fi = i * 1.0 / (LEN - 1);
z = eye_near + fi * (eye_far - eye_near);
dz = fog_density * z;
fog_map[i] = 1.0 - exp(-dz);
}
break;
case GL_EXP2:
/* Setup fog_map to be "f = exp(-(d*z)^2)". */
for (i = 0; i < LEN; i += 1) {
float fi, z, dz;

fi = i * 1.0 / (LEN - 1);
z = eye_near + fi * (eye_far - eye_near);
dz = fog_density * z;
fog_map[i] = 1.0 - exp(-dz * dz);
}
break;
}
}

/* XXX Careful, afDoFinalFogPass makes no attempt to preserve your
pixel store state and assumes the initial pixel store state! */
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);

/* Preserve the current raster position, viewport, matrix mode,
blend function, enable state, and pixel path state. */
/* XXX This is pretty expensive. A real application should just
"know" to reload all the OpenGL state mucked with by afDoFinalFogPass
and then you could get rid of all this glPushAttrib and glPopMatrix
garbage. */
glPushAttrib(GL_PIXEL_MODE_BIT | GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT |
GL_TRANSFORM_BIT | GL_VIEWPORT_BIT | GL_CURRENT_BIT);

/* Reposition the current raster position as location (x,y). */
glMatrixMode(GL_MODELVIEW);
glViewport(x-1, y-1, 2, 2);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glRasterPos2i(0, 0);

/* Definitely don't want fog or depth enabled. */
glDisable(GL_FOG);
glDisable(GL_DEPTH_TEST);

/* The alpha on the glDrawPixels after the pixel path transformation
will be "1 - f" where f is the blending factor described in Section
3.9 of the OpenGL 1.1 specification. */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

switch (fog_mode) {
case GL_LINEAR:
/* Force red, green, and blue to the fog color. */
glPixelTransferf(GL_RED_SCALE, 0);
glPixelTransferf(GL_GREEN_SCALE, 0);
glPixelTransferf(GL_BLUE_SCALE, 0);
glPixelTransferf(GL_RED_BIAS, fog_red);
glPixelTransferf(GL_GREEN_BIAS, fog_green);
glPixelTransferf(GL_BLUE_BIAS, fog_blue);

glPixelTransferf(GL_ALPHA_SCALE, alpha_scale);
glPixelTransferf(GL_ALPHA_BIAS, alpha_bias);
break;
case GL_EXP:
case GL_EXP2:
/* Force red, green, and blue to the fog color. */
glPixelMapfv(GL_PIXEL_MAP_R_TO_R, 1, &fog_red);
glPixelMapfv(GL_PIXEL_MAP_G_TO_G, 1, &fog_green);
glPixelMapfv(GL_PIXEL_MAP_B_TO_B, 1, &fog_blue);

glPixelMapfv(GL_PIXEL_MAP_A_TO_A, LEN, fog_map);
glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
break;
}

/* Read out the depth buffer... */
glReadPixels(x, y, width, height,
GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, buffer);

/* ... and write it back as alpha. */
glDrawPixels(width, height, GL_ALPHA,
GL_UNSIGNED_SHORT, buffer);

/* Restore state saved earlier. */
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPopAttrib();
}

Figure 66


$40 off Craftsman 5 Drawer Homeowner Tool Center with Riser and Parts Bins $99.99 on sale 10/2-10/8
Sears Deal of the Day: Thule Car Top Carrier, Quest
Wholesale Fleece Blankets
400950_BuddhaGroove.com-Culture Infused Living: Home Accents, Jewelry, Accessories from around the world!
400948_Culture Infused Living: Home Accents, Jewelry, and accessories from around the world. CulturalElemen
504427_Save up to 75% on batteries and accessories at Brooklyn Battery Works!
504080_10% OFF Orders of $75 or More from Journelle.com! Use Promo Code: NOV11 (Valid 11/1 - 11/30/11)
502239_Brand names, bargain prices at shoezoo.com. If you don't love your new shoes, return them for free!

400949_GaneshMall.com-Culture Infused Living: Home Accents, Jewelry, and accessories from around the world!



Figure 66
==========================


/*
//Author: Cheikh Drame
//To support, please do one of the following
//- Visit irap123.com many times a day
//- Join irap123.com
//- Buy my app irap123 (rhyming dictionary) available for android, and iphone. On windows phone, it is called iLyrics. If not, you can get the desktop version at www.irap123.com/apps/webstore/
//- Include irap123.com in your blogs, forums, facebook walls, email footers, comments
//- send a donation at my paypal address at cbdsigned.vevo@gmail.com
//- Buy a story at http://shop.pparzygnat.com
*/

// surface.cpp : Defines the entry point for the console application.
//



/* */

/*
* surface.c
* This program draws a NURBS surface in the shape of a
* symmetrical hill. The 'c' keyboard key allows you to
* toggle the visibility of the control points themselves.
* Note that some of the control points are hidden by the
* surface itself.
*/
#include
#include
#include

#ifndef CALLBACK
#define CALLBACK
#endif

GLfloat ctlpoints[4][4][3];
int showPoints = 0;

GLUnurbsObj *theNurb;

/*
* Initializes the control points of the surface to a small hill.
* The control points range from -3 to +3 in x, y, and z
*/
void init_surface(void)
{
int u, v;
for (u = 0; u < 4; u++) {
for (v = 0; v < 4; v++) {
ctlpoints[u][v][0] = 2.0*((GLfloat)u - 1.5);
ctlpoints[u][v][1] = 2.0*((GLfloat)v - 1.5);

if ( (u == 1 || u == 2) && (v == 1 || v == 2))
ctlpoints[u][v][2] = 3.0;
else
ctlpoints[u][v][2] = -3.0;
}
}
}

void CALLBACK nurbsError(GLenum errorCode)
{
const GLubyte *estring;

estring = gluErrorString(errorCode);
fprintf (stderr, "Nurbs Error: %s\n", estring);
exit (0);
}

/* Initialize material property and depth buffer.
*/
void init(void)
{
GLfloat mat_diffuse[] = { 0.7, 0.7, 0.7, 1.0 };
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 100.0 };

glClearColor (0.0, 0.0, 0.0, 0.0);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);

init_surface();

theNurb = gluNewNurbsRenderer();
gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);
// gluNurbsCallback(theNurb, GLU_ERROR,
// nurbsError);
}

void display(void)
{
GLfloat knots[8] = {0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0};
int i, j;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glRotatef(330.0, 1.,0.,0.);
glScalef (0.5, 0.5, 0.5);

gluBeginSurface(theNurb);
gluNurbsSurface(theNurb,
8, knots, 8, knots,
4 * 3, 3, &ctlpoints[0][0][0],
4, 4, GL_MAP2_VERTEX_3);
gluEndSurface(theNurb);

if (showPoints) {
glPointSize(5.0);
glDisable(GL_LIGHTING);
glColor3f(1.0, 1.0, 0.0);
glBegin(GL_POINTS);
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
glVertex3f(ctlpoints[i][j][0],
ctlpoints[i][j][1], ctlpoints[i][j][2]);
}
}
glEnd();
glEnable(GL_LIGHTING);
}
glPopMatrix();
glFlush();
}

void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective (45.0, (GLdouble)w/(GLdouble)h, 3.0, 8.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef (0.0, 0.0, -5.0);
}

void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 'c':
case 'C':
showPoints = !showPoints;
glutPostRedisplay();
break;
case 27:
exit(0);
break;
default:
break;
}
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutKeyboardFunc (keyboard);
glutMainLoop();
return 0;
}

Figure 65


$40 off Craftsman 5 Drawer Homeowner Tool Center with Riser and Parts Bins $99.99 on sale 10/2-10/8
Sears Deal of the Day: Thule Car Top Carrier, Quest
Wholesale Fleece Blankets
400950_BuddhaGroove.com-Culture Infused Living: Home Accents, Jewelry, Accessories from around the world!
400948_Culture Infused Living: Home Accents, Jewelry, and accessories from around the world. CulturalElemen
504427_Save up to 75% on batteries and accessories at Brooklyn Battery Works!
504080_10% OFF Orders of $75 or More from Journelle.com! Use Promo Code: NOV11 (Valid 11/1 - 11/30/11)
502239_Brand names, bargain prices at shoezoo.com. If you don't love your new shoes, return them for free!

400949_GaneshMall.com-Culture Infused Living: Home Accents, Jewelry, and accessories from around the world!



Figure 65
=====================================


/*
//Author: Cheikh Drame
//To support, please do one of the following
//- Visit irap123.com many times a day
//- Join irap123.com
//- Buy my app irap123 (rhyming dictionary) available for android, and iphone. On windows phone, it is called iLyrics. If not, you can get the desktop version at www.irap123.com/apps/webstore/
//- Include irap123.com in your blogs, forums, facebook walls, email footers, comments
//- send a donation at my paypal address at cbdsigned.vevo@gmail.com
//- Buy a story at http://shop.pparzygnat.com
*/
// stroke.cpp : Defines the entry point for the console application.
//


/* */

/*
* stroke.c
* This program demonstrates some characters of a
* stroke (vector) font. The characters are represented
* by display lists, which are given numbers which
* correspond to the ASCII values of the characters.
* Use of glCallLists() is demonstrated.
*/
#include
#include
#include

#define PT 1
#define STROKE 2
#define END 3

typedef struct charpoint {
GLfloat x, y;
int type;
} CP;

CP Adata[] = {
{ 0, 0, PT}, {0, 9, PT}, {1, 10, PT}, {4, 10, PT},
{5, 9, PT}, {5, 0, STROKE}, {0, 5, PT}, {5, 5, END}
};

CP Edata[] = {
{5, 0, PT}, {0, 0, PT}, {0, 10, PT}, {5, 10, STROKE},
{0, 5, PT}, {4, 5, END}
};

CP Pdata[] = {
{0, 0, PT}, {0, 10, PT}, {4, 10, PT}, {5, 9, PT}, {5, 6, PT},
{4, 5, PT}, {0, 5, END}
};

CP Rdata[] = {
{0, 0, PT}, {0, 10, PT}, {4, 10, PT}, {5, 9, PT}, {5, 6, PT},
{4, 5, PT}, {0, 5, STROKE}, {3, 5, PT}, {5, 0, END}
};

CP Sdata[] = {
{0, 1, PT}, {1, 0, PT}, {4, 0, PT}, {5, 1, PT}, {5, 4, PT},
{4, 5, PT}, {1, 5, PT}, {0, 6, PT}, {0, 9, PT}, {1, 10, PT},
{4, 10, PT}, {5, 9, END}
};

/* drawLetter() interprets the instructions from the array
* for that letter and renders the letter with line segments.
*/
static void drawLetter(CP *l)
{
glBegin(GL_LINE_STRIP);
while (1) {
switch (l->type) {
case PT:
glVertex2fv(&l->x);
break;
case STROKE:
glVertex2fv(&l->x);
glEnd();
glBegin(GL_LINE_STRIP);
break;
case END:
glVertex2fv(&l->x);
glEnd();
glTranslatef(8.0, 0.0, 0.0);
return;
}
l++;
}
}

/* Create a display list for each of 6 characters */
static void init (void)
{
GLuint base;

glShadeModel (GL_FLAT);

base = glGenLists (128);
glListBase(base);
glNewList(base+'A', GL_COMPILE); drawLetter(Adata); glEndList();
glNewList(base+'E', GL_COMPILE); drawLetter(Edata); glEndList();
glNewList(base+'P', GL_COMPILE); drawLetter(Pdata); glEndList();
glNewList(base+'R', GL_COMPILE); drawLetter(Rdata); glEndList();
glNewList(base+'S', GL_COMPILE); drawLetter(Sdata); glEndList();
glNewList(base+' ', GL_COMPILE); glTranslatef(8.0, 0.0, 0.0); glEndList();
}

char *test1 = "A SPARE SERAPE APPEARS AS";
char *test2 = "APES PREPARE RARE PEPPERS";

static void printStrokedString(char *s)
{
GLsizei len = strlen(s);
glCallLists(len, GL_BYTE, (GLbyte *)s);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glPushMatrix();
glScalef(2.0, 2.0, 2.0);
glTranslatef(10.0, 30.0, 0.0);
printStrokedString(test1);
glPopMatrix();
glPushMatrix();
glScalef(2.0, 2.0, 2.0);
glTranslatef(10.0, 13.0, 0.0);
printStrokedString(test2);
glPopMatrix();
glFlush();
}

void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
}

void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case ' ':
glutPostRedisplay();
break;
case 27:
exit(0);
}
}

/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, and handle input events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (440, 120);
glutCreateWindow ("stroke by irap123.com");
init ();
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}