Sunday, September 25, 2011

Figure 19


$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 19

==============
// colorcube1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
///////////////////////////////////////////////
// In class color cube program //
// Written by Glen Granzow, February 8, 2011 //
///////////////////////////////////////////////

#include
#include
#include

//////////////////////
// Global Variables //
//////////////////////

GLfloat vertex[7][3] = {{0,0,1}, {1,0,1}, {0,0,0}, {1,0,0},
{1,1,0}, {0,1,0}, {0,1,1}};

/////////////////////////////////
// Display Callback Function //
/////////////////////////////////

void display()
{
int i, j;
char string[40];
GLenum errorCode;

GLint side[6][3] = {{0,1,2},{1,3,2},{3,4,2},
{4,5,2},{5,6,2},{6,0,2}};

//GLint top[6] = ;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Modified for 3D

glLoadIdentity();
glRotatef( 15.0, 0.0, 0.0, 1.0);
glRotatef( 45.0, 1.0, 0.0, 0.0);
glRotatef(-45.0, 0.0, 1.0, 0.0);
glTranslatef(-0.5, -0.5, -0.5);

glBegin(GL_LINE_STRIP);

for (i=0; i<6; i++)
for (j=0; j<3; j++)
{
glColor3fv( vertex[side[i][j]]);
glVertex3fv(vertex[side[i][j]]);
}

glEnd();

sprintf(string, "RED: %4.2f GREEN: %4.2f BLUE: %4.2f",
vertex[7][0], vertex[7][1], vertex[7][2]);

glColor3fv(vertex[7]);
glLoadIdentity();
glRasterPos3f(-0.90, -0.95, 0.0);
for (i=0; i glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string[i]);

glFlush();
// glPopMatrix();
if ((errorCode = glGetError()) != GL_NO_ERROR)
printf("\nOpenGL ERROR %d: %s\n", errorCode, gluErrorString(errorCode));
}

//////////////////////////////////
// Keyboard Callback Function //
//////////////////////////////////

void keyboard(unsigned char key, int x, int y)
{
int i;

if (key == 'q') exit(0);
if (key == 'a') glEnable(GL_LINE_SMOOTH);
if (key == 'A') glDisable(GL_LINE_SMOOTH);

if (key == 'r')
for (i=0; i<8; i++)
if (vertex[i][0] > 0.15)
vertex[i][0] -= 0.10;

if (key == 'R')
for (i=0; i<8; i++)
if (0.0 < vertex[i][0] && vertex[i][0] < 0.95)
vertex[i][0] += 0.10;

if (key == 'g')
for (i=0; i<8; i++)
if (vertex[i][1] > 0.15)
vertex[i][1] -= 0.10;

if (key == 'G')
for (i=0; i<8; i++)
if (0.0 < vertex[i][1] && vertex[i][1] < 0.95)
vertex[i][1] += 0.10;

if (key == 'b')
for (i=0; i<8; i++)
if (vertex[i][2] > 0.15)
vertex[i][2] -= 0.10;

if (key == 'B')
for (i=0; i<8; i++)
if (0.0 < vertex[i][2] && vertex[i][2] < 0.95)
vertex[i][2] += 0.10;

glutPostRedisplay();
}

/////////////////////////////////
// Reshape Callback Function //
/////////////////////////////////

void reshape(int width, int height)
{
GLdouble ratio;

glViewport(0, 0, width, height);

ratio = (GLdouble) width / (GLdouble) height;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (width > height)
glOrtho(-ratio, ratio, -1.0, 1.0, -1.0, 1.0);
else
glOrtho(-1.0, 1.0, -1.0/ratio, 1.0/ratio, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
}

////////////////////
// Main Program //
////////////////////

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); // New for 3D!
glutCreateWindow("Color Cube");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutReshapeFunc(reshape);
glEnable(GL_DEPTH_TEST); // New for 3D!
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// glLineWidth(5.0);
// glCullFace(GL_BACK);
// glEnable(GL_CULL_FACE);
// glEnable(GL_LINE_SMOOTH);
// glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
// glEnable(GL_BLEND);
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// glShadeModel(GL_FLAT);
glutMainLoop();
return 0;
}


No comments:

Post a Comment