# how to shade triangles and make transparent

This topic is 2783 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

ok so if you have read one of my recent posts then you know im trying to make a few shapes like an icosahedron. well now i have got that part down pretty well i just want to be able to make them transparent and have shading but i dont know how to do this. here's my code


#include <windows.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <stdlib.h>
#include <stdio.h>
#include <cmath>

const GLfloat G_RATIO = (1 - sqrt(5))/2;

GLfloat		rtri;

const GLfloat P1[] =        {0.0f, 1.0f, G_RATIO};

const GLfloat P2[] =		{0.0f,-1.0f, G_RATIO};

const GLfloat P3[] =		{ 0.0f,-1.0f, -G_RATIO};

const GLfloat P4[] =		{0.0f, 1.0f, -G_RATIO};

const GLfloat P5[] =		{1.0f,G_RATIO, 0.0f};

const GLfloat P6[] =		{ -1.0f,G_RATIO, 0.0f};

const GLfloat P7[] =		{ -1.0f, -G_RATIO, 0.0f};

const GLfloat P8[] =		{1.0f,-G_RATIO, 0.0f};

const GLfloat P9[] =		{ G_RATIO,0.0f, 1.0f};

const GLfloat P10[] =		{ -G_RATIO, 0.0f, 1.0f};

const GLfloat P11[] =		{-G_RATIO,0.0f, - 1.0f};

const GLfloat P12[] =		{ G_RATIO,0.0f, -1.0f};

char *one;

char *two;

char *three;

char *four;

char *five;

char *six;

char *seven;

char *eight;

char *nine;

char *ten;

char *eleven;

char *twelve;

static void resize(int width, int height)
{
const float ar = (float) width / (float) height;
glDisable(GL_CULL_FACE);
glEnable(GL_BLEND);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
glMatrixMode(GL_MODELVIEW);
}
static void display(void)
{
const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
const double a = t*90.0;
one = "1";
two = "2";
three = "3";
four = "4";
five = "5";
six = "6";
seven = "7";
eight = "8";
nine = "9";
ten = "t";
eleven = "e";
twelve = "w";
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glTranslatef(0.0f,0.0f,-5.0f);
glRotatef(rtri,0.0f,1.0f,0.0f);

glBegin(GL_TRIANGLES);

glRasterPos3fv(P1);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *one);
glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P1);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P4);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P7);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P1);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P4);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P8);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P1);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P11);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P12);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P4);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P9);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P10);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P4);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P9);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P7);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P1);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P11);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P8);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P1);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P12);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P7);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P4);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P10);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P8);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P8);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P5);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P10);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P8);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P11);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P5);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P7);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P12);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P6);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P7);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P9);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P6);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P12);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P11);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P2);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P12);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P2);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P6);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P9);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P10);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P3);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P11);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P5);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P2);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P5);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P10);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P3);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P5);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P2);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P3);

glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
glVertex3fv( P9);			// First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
glVertex3fv(P6);			// Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
glVertex3fv( P3);

glEnd();
glRasterPos3fv(P1);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *one);
glRasterPos3fv(P2);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *two);
glRasterPos3fv(P3);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *three);
glRasterPos3fv(P4);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *four);
glRasterPos3fv(P5);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *five);
glRasterPos3fv(P6);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *six);
glRasterPos3fv(P7);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *seven);
glRasterPos3fv(P8);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *eight);
glRasterPos3fv(P9);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *nine);
glRasterPos3fv(P10);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *ten);
glRasterPos3fv(P11);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *eleven);
glRasterPos3fv(P12);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *twelve);
rtri+=1.0f;
glutSwapBuffers();
}
void renderBitmapString(
float x,
float y,
float z,
void *font,
char *string) {
char *c;
glRasterPos3f(x, y,z);
for (c=string; *c != '\0'; c++) {
glutBitmapCharacter(font, *c);
}
}

static void key(unsigned char key, int x, int y)
{
switch (key)
{

}

glutPostRedisplay();
}

static void idle(void)
{
glutPostRedisplay();
}

const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };

const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };

/* Program entry point */

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

glutCreateWindow("GLUT Shapes");

glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutIdleFunc(idle);

glClearColor(1,1,1,1);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);

glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);

glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);

glutMainLoop();

return 1;
}



##### Share on other sites
Do a search for alpha blending. Its fairly easy, once you setup the blend func (1 line, can't recall right now but its soemthign like glBlendFunc(gl_src_alpha, gl_one_minus_src_alpha)) you just need to give your triangles an alpha value, you can do that when you set their color

glColor(r,g,b, alpha).

It gets slightly more complicated in that you might need to sort triangles manually by distance from the camera or they won't render correctly (some may appear infront when they should be ebhind etc).

##### Share on other sites
thanks for the glblendfunc() it works grate!!!! but i still want distinct shading or lighting to give the shape a more realistic feel. here is my current code.

 #include <windows.h>#include <GL/glut.h>#include <GL/gl.h>#include <GL/glu.h>#include <stdlib.h>#include <stdio.h>#include <cmath>const GLfloat G_RATIO = (1 - sqrt(5))/2;GLfloat		rtri;const GLfloat P1[] =        {0.0f, 1.0f, G_RATIO};const GLfloat P2[] =		{0.0f,-1.0f, G_RATIO};const GLfloat P3[] =		{ 0.0f,-1.0f, -G_RATIO};const GLfloat P4[] =		{0.0f, 1.0f, -G_RATIO};const GLfloat P5[] =		{1.0f,G_RATIO, 0.0f};const GLfloat P6[] =		{ -1.0f,G_RATIO, 0.0f};const GLfloat P7[] =		{ -1.0f, -G_RATIO, 0.0f};const GLfloat P8[] =		{1.0f,-G_RATIO, 0.0f};const GLfloat P9[] =		{ G_RATIO,0.0f, 1.0f};const GLfloat P10[] =		{ -G_RATIO, 0.0f, 1.0f};const GLfloat P11[] =		{-G_RATIO,0.0f, - 1.0f};const GLfloat P12[] =		{ G_RATIO,0.0f, -1.0f};const GLfloat purple[] =	{ 1.0f,0.0f,1.0f,0.4f};const GLfloat green[] =	{ 0.0f,1.0f,0.0f,0.4f};const GLfloat blue[] =	{ 0.0f,0.0f,1.0f,0.4f};char *one;char *two;char *three;char *four;char *five;char *six;char *seven;char *eight;char *nine;char *ten;char *eleven;char *twelve;const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat high_shininess[] = { 100.0f };static void resize(int width, int height){    const float ar = (float) width / (float) height;    glDisable(GL_CULL_FACE);    glEnable(GL_BLEND);    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);    glViewport(0, 0, width, height);    glShadeModel(GL_SMOOTH);    glEnable(GL_LIGHT1);    glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);    glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);    glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);    glLightfv(GL_LIGHT1, GL_POSITION, light_position);    glMatrixMode(GL_PROJECTION);    glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);    glMatrixMode(GL_MODELVIEW);    glLoadIdentity() ;}static void display(void){    const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;    const double a = t*90.0;    one = "1";    two = "2";    three = "3";    four = "4";    five = "5";    six = "6";    seven = "7";    eight = "8";    nine = "9";    ten = "t";    eleven = "e";    twelve = "w";        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    glLoadIdentity();	glTranslatef(0.0f,0.0f,-5.0f);    glRotatef(rtri,0.0f,1.0f,0.0f);    glBegin(GL_TRIANGLES);		glColor4fv(blue);			// Set Top Point Of Triangle To Red		glVertex3fv( P1);			// First Point Of The Triangle		glColor4fv(green);				// Set Left Point Of Triangle To Green		glVertex3fv(P4);			// Second Point Of The Triangle		glColor4fv(purple);				// Set Right Point Of Triangle To Blue		glVertex3fv( P7);        glColor4fv(blue);			// Set Top Point Of Triangle To Red		glVertex3fv( P1);			// First Point Of The Triangle		glColor4fv(green);				// Set Left Point Of Triangle To Green		glVertex3fv(P4);			// Second Point Of The Triangle	    glColor4fv(purple);			// Set Right Point Of Triangle To Blue		glVertex3fv( P8);        glColor4fv(blue);			// Set Top Point Of Triangle To Red		glVertex3fv( P1);			// First Point Of The Triangle		glColor4fv(green);					// Set Left Point Of Triangle To Green		glVertex3fv(P11);			// Second Point Of The Triangle		glColor4fv(purple);			// Set Right Point Of Triangle To Blue		glVertex3fv( P12);        glColor4fv(blue);			// Set Top Point Of Triangle To Red		glVertex3fv( P4);			// First Point Of The Triangle	    glColor4fv(green);					// Set Left Point Of Triangle To Green		glVertex3fv(P9);			// Second Point Of The Triangle	    glColor4fv(purple);			// Set Right Point Of Triangle To Blue		glVertex3fv( P10);        glColor4fv(blue);				// Set Top Point Of Triangle To Red		glVertex3fv( P4);			// First Point Of The Triangle		glColor4fv(green);					// Set Left Point Of Triangle To Green		glVertex3fv(P9);			// Second Point Of The Triangle	    glColor4fv(purple);			// Set Right Point Of Triangle To Blue		glVertex3fv( P7);        glColor4fv(blue);				// Set Top Point Of Triangle To Red		glVertex3fv( P1);			// First Point Of The Triangle		glColor4fv(green);					// Set Left Point Of Triangle To Green		glVertex3fv(P11);			// Second Point Of The Triangle		glColor4fv(purple);				// Set Right Point Of Triangle To Blue		glVertex3fv( P8);        glColor4fv(blue);				// Set Top Point Of Triangle To Red		glVertex3fv( P1);			// First Point Of The Triangle		glColor4fv(green);					// Set Left Point Of Triangle To Green		glVertex3fv(P12);			// Second Point Of The Triangle		glColor4fv(purple);				// Set Right Point Of Triangle To Blue		glVertex3fv( P7);        glColor4fv(blue);				// Set Top Point Of Triangle To Red		glVertex3fv( P4);			// First Point Of The Triangle		glColor4fv(green);					// Set Left Point Of Triangle To Green		glVertex3fv(P10);			// Second Point Of The Triangle		glColor4fv(purple);				// Set Right Point Of Triangle To Blue		glVertex3fv( P8);        glColor4fv(blue);				// Set Top Point Of Triangle To Red		glVertex3fv( P8);			// First Point Of The Triangle		glColor4fv(green);					// Set Left Point Of Triangle To Green		glVertex3fv(P5);			// Second Point Of The Triangle		glColor4fv(purple);				// Set Right Point Of Triangle To Blue		glVertex3fv( P10);        glColor4fv(blue);				// Set Top Point Of Triangle To Red		glVertex3fv( P8);			// First Point Of The Triangle		glColor4fv(green);				// Set Left Point Of Triangle To Green		glVertex3fv(P11);			// Second Point Of The Triangle		glColor4fv(purple);				// Set Right Point Of Triangle To Blue		glVertex3fv( P5);        glColor4fv(blue);				// Set Top Point Of Triangle To Red		glVertex3fv( P7);			// First Point Of The Triangle		glColor4fv(green);					// Set Left Point Of Triangle To Green		glVertex3fv(P12);			// Second Point Of The Triangle		glColor4fv(purple);				// Set Right Point Of Triangle To Blue		glVertex3fv( P6);        glColor4fv(blue);			// Set Top Point Of Triangle To Red		glVertex3fv( P7);			// First Point Of The Triangle		glColor4fv(green);					// Set Left Point Of Triangle To Green		glVertex3fv(P9);			// Second Point Of The Triangle		glColor4fv(purple);				// Set Right Point Of Triangle To Blue		glVertex3fv( P6);        glColor4fv(blue);			// Set Top Point Of Triangle To Red		glVertex3fv( P12);			// First Point Of The Triangle		glColor4fv(green);					// Set Left Point Of Triangle To Green		glVertex3fv(P11);			// Second Point Of The Triangle		glColor4fv(purple);				// Set Right Point Of Triangle To Blue		glVertex3fv( P2);        glColor4fv(blue);				// Set Top Point Of Triangle To Red		glVertex3fv( P12);			// First Point Of The Triangle		glColor4fv(green);				// Set Left Point Of Triangle To Green		glVertex3fv(P2);			// Second Point Of The Triangle		glColor4fv(purple);				// Set Right Point Of Triangle To Blue		glVertex3fv( P6);        glColor4fv(blue);				// Set Top Point Of Triangle To Red		glVertex3fv( P9);			// First Point Of The Triangle		glColor4fv(green);				// Set Left Point Of Triangle To Green		glVertex3fv(P10);			// Second Point Of The Triangle		glColor4fv(purple);				// Set Right Point Of Triangle To Blue		glVertex3fv( P3);        glColor4fv(blue);				// Set Top Point Of Triangle To Red		glVertex3fv( P11);			// First Point Of The Triangle		glColor4fv(green);					// Set Left Point Of Triangle To Green		glVertex3fv(P5);			// Second Point Of The Triangle		glColor4fv(purple);				// Set Right Point Of Triangle To Blue		glVertex3fv( P2);        glColor4fv(blue);			// Set Top Point Of Triangle To Red		glVertex3fv( P5);			// First Point Of The Triangle		glColor4fv(green);					// Set Left Point Of Triangle To Green		glVertex3fv(P10);			// Second Point Of The Triangle		glColor4fv(purple);				// Set Right Point Of Triangle To Blue		glVertex3fv( P3);        glColor4fv(blue);				// Set Top Point Of Triangle To Red		glVertex3fv( P5);			// First Point Of The Triangle		glColor4fv(green);					// Set Left Point Of Triangle To Green		glVertex3fv(P2);			// Second Point Of The Triangle		glColor4fv(purple);				// Set Right Point Of Triangle To Blue		glVertex3fv( P3);        glColor4fv(blue);				// Set Top Point Of Triangle To Red		glVertex3fv( P9);			// First Point Of The Triangle		glColor4fv(green);				// Set Left Point Of Triangle To Green		glVertex3fv(P6);			// Second Point Of The Triangle		glColor4fv(purple);				// Set Right Point Of Triangle To Blue		glVertex3fv( P3);	glEnd();	glColor4f(0.0f,1.0f,0.0f,1.0f);	glRasterPos3fv(P1);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *one);    glRasterPos3fv(P2);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *two);    glRasterPos3fv(P3);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *three);    glRasterPos3fv(P4);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *four);    glRasterPos3fv(P5);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *five);    glRasterPos3fv(P6);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *six);    glRasterPos3fv(P7);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *seven);    glRasterPos3fv(P8);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *eight);    glRasterPos3fv(P9);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *nine);    glRasterPos3fv(P10);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *ten);    glRasterPos3fv(P11);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *eleven);    glRasterPos3fv(P12);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *twelve);	rtri+=1.0f;    glutSwapBuffers();}void renderBitmapString(		float x,		float y,		float z,		void *font,		char *string) {  char *c;  glRasterPos3f(x, y,z);  for (c=string; *c != '\0'; c++) {    glutBitmapCharacter(font, *c);  }}static void key(unsigned char key, int x, int y){    switch (key)    {    }    glutPostRedisplay();}static void idle(void){    glutPostRedisplay();}int main(int argc, char *argv[]){    glutInit(&argc, argv);    glutInitWindowSize(640,480);    glutInitWindowPosition(10,10);    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);    glutCreateWindow("GLUT Shapes");    glutReshapeFunc(resize);    glutDisplayFunc(display);    glutKeyboardFunc(key);    glutIdleFunc(idle);    glutMainLoop();    return 1;}

##### Share on other sites
I'm not sure what it is exactly that you want but for lighting you need normals for your vertices. In order to get hard edges between the triangles you'd either have to duplicate your vertices (since only one normal per vertex is possible) or use flat shading glShadeModel(GL_FLAT). Note that flat shading would mean that each triangle gets only one color (i.e. you can have gradients).

##### Share on other sites
As Lord Evil said, your just missing normals. I see you've already setup a light so that should be fine. Where you have:

glColor3f();
glVertex3fv();

Add glNormal3fv() just before glVertex3fv(), if you want the faces to be flat then you only need to specify the normal once for each face. Of course you still have to calculate your normals but thats relativly simple.

glNormal:
http://www.khronos.org/opengles/documentation/opengles1_0/html/glNormal.html

##### Share on other sites
Nanoha is right. You just need to call glNormal once per triangle for flat shading.

If you're planning to use indexed VBOs or vertex arrays later on, you need to duplicate your vertices.

##### Share on other sites
ok grate, is there a function in OpenGL i can call on that will return the value of the Normal of a face EXAPLE: void GetNormalFace(GLfloat p1[], GLfloat p2[], GLfloat p3[])

##### Share on other sites
or in other words a function for OpenGL that returns the Normal of Three GLfloat arrays. might be something like glGetNormalfv(P1,P2,P3) so that that could be called on like glNormalfv(glGetNormalfv(P1,P2,P3))

##### Share on other sites
Quote:
 Original post by ishkabibleok grate, is there a function in OpenGL i can call on that will return the value of the Normal of a face EXAPLE: void GetNormalFace(GLfloat p1[], GLfloat p2[], GLfloat p3[])

There isn't but you can do it like this:

GetNormalFace(Vector3 p1, Vector3 p2, Vector3 p3){      Vector3 side1 = p2 - p1;      Vector3 side2 = p3 - p1;      Vector3 normal = crossProduct(side1, side2);      normal.Normalize();            return normal;}

Google up the cross product and you're all set.
Normalize does this:

void Normalize(){   float magnitude = sqrtf(x*x + y*y + z*z);   x /= magnitude;   y /= magnitude;   z /= magnitude;}

Good luck!

##### Share on other sites
ok i think i only need one last thing if i'm right. am i to understand that since the unit vector is always equal to 1 of what ever unit your in it doesn't matter in this case (i just don't understand why they would talk about something that did not matter, i am assuming i'm wrong and this wont be the last thing)

here is the link to site i found

http://mathworld.wolfram.com/CrossProduct.html

##### Share on other sites
also i get the error "no operator found for p1-p3" well when i really looked at it that made sense so i'm guessing now that i need a different function to do that

##### Share on other sites
ok here's what i came up with on my own, it doesn't seem to work with GL_SMOOTH and defiantly doesn't work with GL_FLAT.

#ifdef __APPLE__#include <GLUT/glut.h>#else#include <windows.h>#endif#include <stdlib.h>#include <GL/glut.h>#include <GL/gl.h>#include <GL/glu.h>#include <stdlib.h>#include <stdio.h>#include <cmath>const GLfloat G_RATIO = (1 - sqrt(5))/2;GLfloat	rx;GLfloat	ry;GLfloat	rz;GLfloat size;int i;int j;int k;const GLfloat P1[] =    {0.0f, 1.0f, G_RATIO};const GLfloat P2[] =	{0.0f,-1.0f, G_RATIO};const GLfloat P3[] =	{ 0.0f,-1.0f, -G_RATIO};const GLfloat P4[] =	{0.0f, 1.0f, -G_RATIO};const GLfloat P5[] =	{1.0f,G_RATIO, 0.0f};const GLfloat P6[] =	{ -1.0f,G_RATIO, 0.0f};const GLfloat P7[] =	{ -1.0f, -G_RATIO, 0.0f};const GLfloat P8[] =	{1.0f,-G_RATIO, 0.0f};const GLfloat P9[] =	{ G_RATIO,0.0f, 1.0f};const GLfloat P10[] =	{ -G_RATIO, 0.0f, 1.0f};const GLfloat P11[] =	{-G_RATIO,0.0f, - 1.0f};const GLfloat P12[] =	{ G_RATIO,0.0f, -1.0f};const GLfloat purple[] =	{ 1.0f,0.0f,1.0f,0.4f};const GLfloat green[] =	{ 0.0f,1.0f,0.0f,0.4f};const GLfloat blue[] =	{ 0.0f,0.0f,1.0f,0.4f};//const GLfloat red[] = {1.0f,0.0f,0.0f,1.0f};//const GLfloat org[] = {1.0f,1.0f,0.0f,1.0f};//const GLfloat yellow[] = {1.0f,0.0f,1.0f,1.0f};const GLfloat red[] = { 1.0f,0.0f,1.0f,0.4f};const GLfloat org[] = { 0.0f,1.0f,0.0f,0.4f};const GLfloat yellow[] = { 0.0f,0.0f,1.0f,0.4f};const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat high_shininess[] = { 100.0f }; GLfloat RP1[3]; GLfloat RP2[3]; GLfloat RP3[3]; GLfloat RP4[3]; GLfloat RP5[3]; GLfloat RP6[3]; GLfloat RP7[3]; GLfloat RP8[3]; GLfloat RP9[3]; GLfloat RP10[3]; GLfloat RP11[3]; GLfloat RP12[3];char *one;char *two;char *three;char *four;char *five;char *six;char *seven;char *eight;char *nine;char *ten;char *eleven;char *twelve;static void resize(int width, int height){    const float ar = (float) width / (float) height;    glDisable(GL_CULL_FACE);    glEnable(GL_BLEND);    glViewport(0, 0, width, height);    glShadeModel(GL_SMOOTH);    glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);    glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);    glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);    glLightfv(GL_LIGHT1, GL_POSITION, light_position);    glEnable(GL_LIGHT1);    glClearColor(1.0f,1.0f,1.0f,0.0f);    glMatrixMode(GL_PROJECTION);    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);    glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);    glMatrixMode(GL_MODELVIEW);    glLoadIdentity() ;}class Vector3 { public: GLfloat x, y, z; void Normalize();};void Vector3::Normalize(){   GLfloat magnitude = sqrtf(x*x + y*y + z*z);   x /= magnitude;   y /= magnitude;   z /= magnitude;}Vector3 crossProduct(Vector3 S1, Vector3 S2) {    Vector3 S3;    S3.x = S1.y*S2.z - S1.z*S2.y;    S3.y = S1.z*S2.x - S1.x*S2.z;    S3.z = S1.x*S2.y - S1.y*S2.x;    return S3;}Vector3 SubtractVectors(Vector3 M1, Vector3 M2) {    Vector3 M3;    M3.x = M1.x - M2.x;    M3.y = M1.y - M2.y;    M3.z = M1.z - M2.z;    return M3;}Vector3 GetNormalFace(Vector3 p1, Vector3 p2, Vector3 p3){      Vector3 side1 = SubtractVectors(p2,p1);      Vector3 side2 = SubtractVectors(p3,p1);      Vector3 normal = crossProduct(side1, side2);      normal.Normalize();      return normal;}static void display(void) {    one = "1";    two = "2";    three = "3";    four = "4";    five = "5";    six = "6";    seven = "7";    eight = "8";    nine = "9";    ten = "t";    eleven = "e";    twelve = "w";    size = 0.5f;    RP1[0] = 0.0f;    RP1[1] = size;    RP1[2] = size*G_RATIO;    //size = 1.0f;    RP2[0] = 0.0f;    RP2[1] = -size;    RP2[2] = size*G_RATIO;    //size = 0.7f;    RP3[0] = 0.0f;    RP3[1] = -size;    RP3[2] = -size*G_RATIO;    //size = 0.3f;    RP4[0] = 0.0f;    RP4[1] = size;    RP4[2] = -size*G_RATIO;    //size = 0.1f;    RP5[0] = size;    RP5[1] = size*G_RATIO;    RP5[2] = 0.0f;    //size = 0.5f;    RP6[0] = -size;    RP6[1] = size*G_RATIO;    RP6[2] = 0.0f;    //size = 0.8f;    RP7[0] = -size;    RP7[1] = -size*G_RATIO;    RP7[2] = 0.0f;    //size = 0.2f;    RP8[0] = size;    RP8[1] = -size*G_RATIO;    RP8[2] = 0.0f;    //size = 1.2f;    RP9[0] = size*G_RATIO;    RP9[1] = 0.0f;    RP9[2] = size;    //size = 0.5f;    RP10[0] = -size*G_RATIO;    RP10[1] = 0.0f;    RP10[2] = size;    //size = 0.9f;    RP11[0] = -size*G_RATIO;    RP11[1] = 0.0f;    RP11[2] = -size;    //size = 0.4f;    RP12[0] = size*G_RATIO;    RP12[1] = 0.0f;    RP12[2] = -size;    Vector3 PP1;    Vector3 PP2;    Vector3 PP3;    Vector3 Normal;    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    glLoadIdentity();    glTranslatef(0.0f,0.0f,-5.0f);    glRotatef(ry,1.0f,0.0f,0.0f);    glRotatef(rx,0.0f,1.0f,0.0f);    glRotatef(rz,0.0f,0.0f,1.0f);    glBegin(GL_TRIANGLES);    PP1.x = P1[0];    PP1.y = P1[1];    PP1.z = P1[2];    PP2.x = P4[0];    PP2.y = P4[1];    PP2.z = P4[2];    PP3.x = P7[0];    PP3.y = P7[1];    PP3.z = P7[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);			// Set Top Point Of Triangle To Red    glVertex3fv( P1);			// First Point Of The Triangle    glColor4fv(green);				// Set Left Point Of Triangle To Green    glVertex3fv(P4);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P7);    PP1.x = P1[0];    PP1.y = P1[1];    PP1.z = P1[2];    PP2.x = P4[0];    PP2.y = P4[1];    PP2.z = P4[2];    PP3.x = P8[0];    PP3.y = P8[1];    PP3.z = P8[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);			// Set Top Point Of Triangle To Red    glVertex3fv( P1);			// First Point Of The Triangle    glColor4fv(green);				// Set Left Point Of Triangle To Green    glVertex3fv(P4);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( P8);     PP1.x = P1[0];    PP1.y = P1[1];    PP1.z = P1[2];    PP2.x = P11[0];    PP2.y = P11[1];    PP2.z = P11[2];    PP3.x = P12[0];    PP3.y = P12[1];    PP3.z = P12[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);			// Set Top Point Of Triangle To Red    glVertex3fv( P1);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P11);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( P12);    PP1.x = P9[0];    PP1.y = P9[1];    PP1.z = P9[2];    PP2.x = P4[0];    PP2.y = P4[1];    PP2.z = P4[2];    PP3.x = P10[0];    PP3.y = P10[1];    PP3.z = P10[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);			// Set Top Point Of Triangle To Red    glVertex3fv( P4);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P9);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( P10);    PP1.x = P9[0];    PP1.y = P9[1];    PP1.z = P9[2];    PP2.x = P4[0];    PP2.y = P4[1];    PP2.z = P4[2];    PP3.x = P7[0];    PP3.y = P7[1];    PP3.z = P7[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P4);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P9);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( P7);    PP1.x = P11[0];    PP1.y = P11[1];    PP1.z = P11[2];    PP2.x = P8[0];    PP2.y = P8[1];    PP2.z = P8[2];    PP3.x = P1[0];    PP3.y = P1[1];    PP3.z = P1[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P1);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P11);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P8);    PP1.x = P1[0];    PP1.y = P1[1];    PP1.z = P1[2];    PP2.x = P12[0];    PP2.y = P12[1];    PP2.z = P12[2];    PP3.x = P7[0];    PP3.y = P7[1];    PP3.z = P7[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P1);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P12);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P7);    PP1.x = P1[0];    PP1.y = P1[1];    PP1.z = P1[2];    PP2.x = P4[0];    PP2.y = P4[1];    PP2.z = P4[2];    PP3.x = P7[0];    PP3.y = P7[1];    PP3.z = P7[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P4);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P10);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P8);    PP1.x = P10[0];    PP1.y = P10[1];    PP1.z = P10[2];    PP2.x = P5[0];    PP2.y = P5[1];    PP2.z = P5[2];    PP3.x = P8[0];    PP3.y = P8[1];    PP3.z = P8[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P8);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P5);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P10);    PP1.x = P11[0];    PP1.y = P11[1];    PP1.z = P11[2];    PP2.x = P5[0];    PP2.y = P5[1];    PP2.z = P5[2];    PP3.x = P8[0];    PP3.y = P8[1];    PP3.z = P8[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P8);			// First Point Of The Triangle    glColor4fv(green);				// Set Left Point Of Triangle To Green    glVertex3fv(P11);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P5);    PP1.x = P12[0];    PP1.y = P12[1];    PP1.z = P12[2];    PP2.x = P6[0];    PP2.y = P6[1];    PP2.z = P6[2];    PP3.x = P7[0];    PP3.y = P7[1];    PP3.z = P7[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P7);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P12);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P6);    PP1.x = P9[0];    PP1.y = P9[1];    PP1.z = P9[2];    PP2.x = P6[0];    PP2.y = P6[1];    PP2.z = P6[2];    PP3.x = P7[0];    PP3.y = P7[1];    PP3.z = P7[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);			// Set Top Point Of Triangle To Red    glVertex3fv( P7);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P9);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P6);    PP1.x = P12[0];    PP1.y = P12[1];    PP1.z = P12[2];    PP2.x = P2[0];    PP2.y = P2[1];    PP2.z = P2[2];    PP3.x = P11[0];    PP3.y = P11[1];    PP3.z = P11[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);			// Set Top Point Of Triangle To Red    glVertex3fv( P12);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P11);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P2);    PP1.x = P12[0];    PP1.y = P12[1];    PP1.z = P12[2];    PP2.x = P2[0];    PP2.y = P2[1];    PP2.z = P2[2];    PP3.x = P6[0];    PP3.y = P6[1];    PP3.z = P6[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P12);			// First Point Of The Triangle    glColor4fv(green);				// Set Left Point Of Triangle To Green    glVertex3fv(P2);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P6);    PP1.x = P10[0];    PP1.y = P10[1];    PP1.z = P10[2];    PP2.x = P3[0];    PP2.y = P3[1];    PP2.z = P3[2];    PP3.x = P9[0];    PP3.y = P9[1];    PP3.z = P9[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P9);			// First Point Of The Triangle    glColor4fv(green);				// Set Left Point Of Triangle To Green    glVertex3fv(P10);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P3);    PP1.x = P11[0];    PP1.y = P11[1];    PP1.z = P11[2];    PP2.x = P2[0];    PP2.y = P2[1];    PP2.z = P2[2];    PP3.x = P5[0];    PP3.y = P5[1];    PP3.z = P5[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P11);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P5);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P2);    PP1.x = P10[0];    PP1.y = P10[1];    PP1.z = P10[2];    PP2.x = P3[0];    PP2.y = P3[1];    PP2.z = P3[2];    PP3.x = P5[0];    PP3.y = P5[1];    PP3.z = P5[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);			// Set Top Point Of Triangle To Red    glVertex3fv( P5);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P10);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P3);    PP1.x = P1[0];    PP1.y = P1[1];    PP1.z = P1[2];    PP2.x = P4[0];    PP2.y = P4[1];    PP2.z = P4[2];    PP3.x = P7[0];    PP3.y = P7[1];    PP3.z = P7[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P5);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P2);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P3);    PP1.x = P9[0];    PP1.y = P9[1];    PP1.z = P9[2];    PP2.x = P6[0];    PP2.y = P6[1];    PP2.z = P6[2];    PP3.x = P3[0];    PP3.y = P3[1];    PP3.z = P3[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P9);			// First Point Of The Triangle    glColor4fv(green);				// Set Left Point Of Triangle To Green    glVertex3fv(P6);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P3);    PP1.x = P2[0];    PP1.y = P2[1];    PP1.z = P2[2];    PP2.x = P6[0];    PP2.y = P6[1];    PP2.z = P6[2];    PP3.x = P3[0];    PP3.y = P3[1];    PP3.z = P3[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P2);			// First Point Of The Triangle    glColor4fv(green);				// Set Left Point Of Triangle To Green    glVertex3fv(P6);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P3);    // here the new one begines    glColor4fv(red);			// Set Top Point Of Triangle To Red    glVertex3fv( RP1);			// First Point Of The Triangle    glColor4fv(org);				// Set Left Point Of Triangle To Green    glVertex3fv(RP4);			// Second Point Of The Triangle    glColor4fv(yellow);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP7);    glColor4fv(red);			// Set Top Point Of Triangle To Red    glVertex3fv( RP1);			// First Point Of The Triangle    glColor4fv(org);				// Set Left Point Of Triangle To Green    glVertex3fv(RP4);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( RP8);    glColor4fv(red);			// Set Top Point Of Triangle To Red    glVertex3fv( RP1);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP11);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( RP12);    glColor4fv(red);			// Set Top Point Of Triangle To Red    glVertex3fv( RP4);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP9);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( RP10);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP4);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP9);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( RP7);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP1);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP11);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP8);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP1);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP12);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP7);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP4);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP10);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP8);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP8);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP5);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP10);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP8);			// First Point Of The Triangle    glColor4fv(org);				// Set Left Point Of Triangle To Green    glVertex3fv(RP11);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP5);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP7);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP12);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP6);    glColor4fv(red);			// Set Top Point Of Triangle To Red    glVertex3fv( RP7);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP9);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP6);    glColor4fv(red);			// Set Top Point Of Triangle To Red    glVertex3fv( RP12);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP11);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP2);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP12);			// First Point Of The Triangle    glColor4fv(org);				// Set Left Point Of Triangle To Green    glVertex3fv(RP2);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP6);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP9);			// First Point Of The Triangle    glColor4fv(org);				// Set Left Point Of Triangle To Green    glVertex3fv(RP10);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP3);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP11);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP5);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP2);    glColor4fv(red);			// Set Top Point Of Triangle To Red    glVertex3fv( RP5);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP10);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP3);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP5);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP2);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP3);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP9);			// First Point Of The Triangle    glColor4fv(org);				// Set Left Point Of Triangle To Green    glVertex3fv(RP6);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP3);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP2);			// First Point Of The Triangle    glColor4fv(org);				// Set Left Point Of Triangle To Green    glVertex3fv(RP6);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP3);    glEnd();    glColor4f(0.0f,0.0f,0.0f,1.0f);    glRasterPos3fv(P1);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *one);    glRasterPos3fv(P2);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *two);    glRasterPos3fv(P3);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *three);    glRasterPos3fv(P4);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *four);    glRasterPos3fv(P5);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *five);    glRasterPos3fv(P6);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *six);    glRasterPos3fv(P7);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *seven);    glRasterPos3fv(P8);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *eight);    glRasterPos3fv(P9);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *nine);    glRasterPos3fv(P10);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *ten);    glRasterPos3fv(P11);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *eleven);    glRasterPos3fv(P12);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *twelve);    glRasterPos3fv(RP1);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *one);    glRasterPos3fv(RP2);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *two);    glRasterPos3fv(RP3);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *three);    glRasterPos3fv(RP4);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *four);    glRasterPos3fv(RP5);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *five);    glRasterPos3fv(RP6);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *six);    glRasterPos3fv(RP7);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *seven);    glRasterPos3fv(RP8);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *eight);    glRasterPos3fv(RP9);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *nine);    glRasterPos3fv(RP10);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *ten);    glRasterPos3fv(RP11);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *eleven);    glRasterPos3fv(RP12);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *twelve);    glutSwapBuffers();}static void key(unsigned char key, int x, int y) {    switch (key) {           case 'd':           rx +=3.0f;           break;           case 'a':           rx -=3.0f;           break;           case 'w':           ry +=3.0f;           break;           case 's':           ry -=3.0f;           break;           case 'z':           rz +=3.0f;           break;           case 'x':           rz -=3.0f;           break;    }    glutPostRedisplay();}static void idle(void) {    glutPostRedisplay();}int main(int argc, char *argv[]) {    glutInit(&argc, argv);    glutInitWindowSize(640,480);    glutInitWindowPosition(10,10);    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);    glutCreateWindow("GLUT Shapes");    glutReshapeFunc(resize);    glutDisplayFunc(display);    glutKeyboardFunc(key);    glutIdleFunc(idle);    glutMainLoop();    return 1;}

##### Share on other sites
You forgot to do this:

glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);

Also check that every face is specified in the same winding order or you'll get both correctly illuminated polygons and black ones(wrong illuminated polygons);

##### Share on other sites
Additionally, you don't set any normals after the "// here the new one begines" line. Thus you'll use the same normal for all subsequent triangles.

I also can't see where you're setting the material or enabling GL_COLOR_MATERIAL and using glColorMaterial(...). Without one of those lighting won't work. I'd suggest using glColorMaterial or otherwise you'd have to set a new material for every vertex.

One last thing: "It doesn't work" isn't quite helpful. It would be better to explain what doesn't work (i.e. what you get in contrast to what you expect) or post some screenshot. Without that it is quite hard to find out what actually doesn't work.

##### Share on other sites
ok so both Deliverance and Lord evil are both right about what happen. Some of the Faces are being shaded solid black as i rotate while others are perfectly shaded (ya finely something is shaded). and as well like lord evil pointed out there is no martial so when you can see whats shaded it's just gray. I'm not quite sure what Deliverance was talking about though. i understand the problem he foretold because i can see but i don't understand what he is talking about when he explains how to fix it. o and if it's of any relevance i don't understand why this problem is being caused either just something about winding order. i best guess is that he means when declaring the normals it should happen in the same order as you declare the vertices.

//my updated code, enable GL_COLOR_MATRIAL, GL_DEPTH thingy and GL_LIGHTING

 #ifdef __APPLE__#include <GLUT/glut.h>#else#include <windows.h>#endif#include <stdlib.h>#include <GL/glut.h>#include <GL/gl.h>#include <GL/glu.h>#include <stdlib.h>#include <stdio.h>#include <cmath>const GLfloat G_RATIO = (1 - sqrt(5))/2;GLfloat	rx;GLfloat	ry;GLfloat	rz;GLfloat size;int i;int j;int k;const GLfloat P1[] =    {0.0f, 1.0f, G_RATIO};const GLfloat P2[] =	{0.0f,-1.0f, G_RATIO};const GLfloat P3[] =	{ 0.0f,-1.0f, -G_RATIO};const GLfloat P4[] =	{0.0f, 1.0f, -G_RATIO};const GLfloat P5[] =	{1.0f,G_RATIO, 0.0f};const GLfloat P6[] =	{ -1.0f,G_RATIO, 0.0f};const GLfloat P7[] =	{ -1.0f, -G_RATIO, 0.0f};const GLfloat P8[] =	{1.0f,-G_RATIO, 0.0f};const GLfloat P9[] =	{ G_RATIO,0.0f, 1.0f};const GLfloat P10[] =	{ -G_RATIO, 0.0f, 1.0f};const GLfloat P11[] =	{-G_RATIO,0.0f, - 1.0f};const GLfloat P12[] =	{ G_RATIO,0.0f, -1.0f};const GLfloat purple[] =	{ 1.0f,0.0f,1.0f,0.4f};const GLfloat green[] =	{ 0.0f,1.0f,0.0f,0.4f};const GLfloat blue[] =	{ 0.0f,0.0f,1.0f,0.4f};//const GLfloat red[] = {1.0f,0.0f,0.0f,1.0f};//const GLfloat org[] = {1.0f,1.0f,0.0f,1.0f};//const GLfloat yellow[] = {1.0f,0.0f,1.0f,1.0f};const GLfloat red[] = { 1.0f,0.0f,1.0f,0.4f};const GLfloat org[] = { 0.0f,1.0f,0.0f,0.4f};const GLfloat yellow[] = { 0.0f,0.0f,1.0f,0.4f};const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat high_shininess[] = { 100.0f }; GLfloat RP1[3]; GLfloat RP2[3]; GLfloat RP3[3]; GLfloat RP4[3]; GLfloat RP5[3]; GLfloat RP6[3]; GLfloat RP7[3]; GLfloat RP8[3]; GLfloat RP9[3]; GLfloat RP10[3]; GLfloat RP11[3]; GLfloat RP12[3];char *one;char *two;char *three;char *four;char *five;char *six;char *seven;char *eight;char *nine;char *ten;char *eleven;char *twelve;static void resize(int width, int height){    const float ar = (float) width / (float) height;    glDisable(GL_CULL_FACE);    glEnable(GL_BLEND);    glViewport(0, 0, width, height);    glEnable(GL_LIGHTING);    glEnable(GL_DEPTH_TEST);    glEnable(GL_COLOR_MATERIAL);    glShadeModel(GL_SMOOTH);    glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);    glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);    glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);    glLightfv(GL_LIGHT1, GL_POSITION, light_position);    glEnable(GL_LIGHT1);    glClearColor(1.0f,1.0f,1.0f,0.0f);    glMatrixMode(GL_PROJECTION);    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);    glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);    glMatrixMode(GL_MODELVIEW);    glLoadIdentity() ;}class Vector3 { public: GLfloat x, y, z; void Normalize();};void Vector3::Normalize(){   GLfloat magnitude = sqrtf(x*x + y*y + z*z);   x /= magnitude;   y /= magnitude;   z /= magnitude;}Vector3 crossProduct(Vector3 S1, Vector3 S2) {    Vector3 S3;    S3.x = S1.y*S2.z - S1.z*S2.y;    S3.y = S1.z*S2.x - S1.x*S2.z;    S3.z = S1.x*S2.y - S1.y*S2.x;    return S3;}Vector3 SubtractVectors(Vector3 M1, Vector3 M2) {    Vector3 M3;    M3.x = M1.x - M2.x;    M3.y = M1.y - M2.y;    M3.z = M1.z - M2.z;    return M3;}Vector3 GetNormalFace(Vector3 p1, Vector3 p2, Vector3 p3){      Vector3 side1 = SubtractVectors(p2,p1);      Vector3 side2 = SubtractVectors(p3,p1);      Vector3 normal = crossProduct(side1, side2);      normal.Normalize();      return normal;}static void display(void) {    one = "1";    two = "2";    three = "3";    four = "4";    five = "5";    six = "6";    seven = "7";    eight = "8";    nine = "9";    ten = "t";    eleven = "e";    twelve = "w";    size = 0.5f;    RP1[0] = 0.0f;    RP1[1] = size;    RP1[2] = size*G_RATIO;    //size = 1.0f;    RP2[0] = 0.0f;    RP2[1] = -size;    RP2[2] = size*G_RATIO;    //size = 0.7f;    RP3[0] = 0.0f;    RP3[1] = -size;    RP3[2] = -size*G_RATIO;    //size = 0.3f;    RP4[0] = 0.0f;    RP4[1] = size;    RP4[2] = -size*G_RATIO;    //size = 0.1f;    RP5[0] = size;    RP5[1] = size*G_RATIO;    RP5[2] = 0.0f;    //size = 0.5f;    RP6[0] = -size;    RP6[1] = size*G_RATIO;    RP6[2] = 0.0f;    //size = 0.8f;    RP7[0] = -size;    RP7[1] = -size*G_RATIO;    RP7[2] = 0.0f;    //size = 0.2f;    RP8[0] = size;    RP8[1] = -size*G_RATIO;    RP8[2] = 0.0f;    //size = 1.2f;    RP9[0] = size*G_RATIO;    RP9[1] = 0.0f;    RP9[2] = size;    //size = 0.5f;    RP10[0] = -size*G_RATIO;    RP10[1] = 0.0f;    RP10[2] = size;    //size = 0.9f;    RP11[0] = -size*G_RATIO;    RP11[1] = 0.0f;    RP11[2] = -size;    //size = 0.4f;    RP12[0] = size*G_RATIO;    RP12[1] = 0.0f;    RP12[2] = -size;    Vector3 PP1;    Vector3 PP2;    Vector3 PP3;    Vector3 Normal;    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    glLoadIdentity();    glTranslatef(0.0f,0.0f,-5.0f);    glRotatef(ry,1.0f,0.0f,0.0f);    glRotatef(rx,0.0f,1.0f,0.0f);    glRotatef(rz,0.0f,0.0f,1.0f);    glBegin(GL_TRIANGLES);    PP1.x = P1[0];    PP1.y = P1[1];    PP1.z = P1[2];    PP2.x = P4[0];    PP2.y = P4[1];    PP2.z = P4[2];    PP3.x = P7[0];    PP3.y = P7[1];    PP3.z = P7[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);			// Set Top Point Of Triangle To Red    glVertex3fv( P1);			// First Point Of The Triangle    glColor4fv(green);				// Set Left Point Of Triangle To Green    glVertex3fv(P4);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P7);    PP1.x = P1[0];    PP1.y = P1[1];    PP1.z = P1[2];    PP2.x = P4[0];    PP2.y = P4[1];    PP2.z = P4[2];    PP3.x = P8[0];    PP3.y = P8[1];    PP3.z = P8[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);			// Set Top Point Of Triangle To Red    glVertex3fv( P1);			// First Point Of The Triangle    glColor4fv(green);				// Set Left Point Of Triangle To Green    glVertex3fv(P4);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( P8);     PP1.x = P1[0];    PP1.y = P1[1];    PP1.z = P1[2];    PP2.x = P11[0];    PP2.y = P11[1];    PP2.z = P11[2];    PP3.x = P12[0];    PP3.y = P12[1];    PP3.z = P12[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);			// Set Top Point Of Triangle To Red    glVertex3fv( P1);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P11);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( P12);    PP1.x = P9[0];    PP1.y = P9[1];    PP1.z = P9[2];    PP2.x = P4[0];    PP2.y = P4[1];    PP2.z = P4[2];    PP3.x = P10[0];    PP3.y = P10[1];    PP3.z = P10[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);			// Set Top Point Of Triangle To Red    glVertex3fv( P4);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P9);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( P10);    PP1.x = P9[0];    PP1.y = P9[1];    PP1.z = P9[2];    PP2.x = P4[0];    PP2.y = P4[1];    PP2.z = P4[2];    PP3.x = P7[0];    PP3.y = P7[1];    PP3.z = P7[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P4);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P9);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( P7);    PP1.x = P11[0];    PP1.y = P11[1];    PP1.z = P11[2];    PP2.x = P8[0];    PP2.y = P8[1];    PP2.z = P8[2];    PP3.x = P1[0];    PP3.y = P1[1];    PP3.z = P1[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P1);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P11);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P8);    PP1.x = P1[0];    PP1.y = P1[1];    PP1.z = P1[2];    PP2.x = P12[0];    PP2.y = P12[1];    PP2.z = P12[2];    PP3.x = P7[0];    PP3.y = P7[1];    PP3.z = P7[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P1);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P12);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P7);    PP1.x = P1[0];    PP1.y = P1[1];    PP1.z = P1[2];    PP2.x = P4[0];    PP2.y = P4[1];    PP2.z = P4[2];    PP3.x = P7[0];    PP3.y = P7[1];    PP3.z = P7[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P4);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P10);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P8);    PP1.x = P10[0];    PP1.y = P10[1];    PP1.z = P10[2];    PP2.x = P5[0];    PP2.y = P5[1];    PP2.z = P5[2];    PP3.x = P8[0];    PP3.y = P8[1];    PP3.z = P8[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P8);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P5);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P10);    PP1.x = P11[0];    PP1.y = P11[1];    PP1.z = P11[2];    PP2.x = P5[0];    PP2.y = P5[1];    PP2.z = P5[2];    PP3.x = P8[0];    PP3.y = P8[1];    PP3.z = P8[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P8);			// First Point Of The Triangle    glColor4fv(green);				// Set Left Point Of Triangle To Green    glVertex3fv(P11);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P5);    PP1.x = P12[0];    PP1.y = P12[1];    PP1.z = P12[2];    PP2.x = P6[0];    PP2.y = P6[1];    PP2.z = P6[2];    PP3.x = P7[0];    PP3.y = P7[1];    PP3.z = P7[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P7);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P12);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P6);    PP1.x = P9[0];    PP1.y = P9[1];    PP1.z = P9[2];    PP2.x = P6[0];    PP2.y = P6[1];    PP2.z = P6[2];    PP3.x = P7[0];    PP3.y = P7[1];    PP3.z = P7[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);			// Set Top Point Of Triangle To Red    glVertex3fv( P7);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P9);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P6);    PP1.x = P12[0];    PP1.y = P12[1];    PP1.z = P12[2];    PP2.x = P2[0];    PP2.y = P2[1];    PP2.z = P2[2];    PP3.x = P11[0];    PP3.y = P11[1];    PP3.z = P11[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);			// Set Top Point Of Triangle To Red    glVertex3fv( P12);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P11);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P2);    PP1.x = P12[0];    PP1.y = P12[1];    PP1.z = P12[2];    PP2.x = P2[0];    PP2.y = P2[1];    PP2.z = P2[2];    PP3.x = P6[0];    PP3.y = P6[1];    PP3.z = P6[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P12);			// First Point Of The Triangle    glColor4fv(green);				// Set Left Point Of Triangle To Green    glVertex3fv(P2);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P6);    PP1.x = P10[0];    PP1.y = P10[1];    PP1.z = P10[2];    PP2.x = P3[0];    PP2.y = P3[1];    PP2.z = P3[2];    PP3.x = P9[0];    PP3.y = P9[1];    PP3.z = P9[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P9);			// First Point Of The Triangle    glColor4fv(green);				// Set Left Point Of Triangle To Green    glVertex3fv(P10);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P3);    PP1.x = P11[0];    PP1.y = P11[1];    PP1.z = P11[2];    PP2.x = P2[0];    PP2.y = P2[1];    PP2.z = P2[2];    PP3.x = P5[0];    PP3.y = P5[1];    PP3.z = P5[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P11);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P5);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P2);    PP1.x = P10[0];    PP1.y = P10[1];    PP1.z = P10[2];    PP2.x = P3[0];    PP2.y = P3[1];    PP2.z = P3[2];    PP3.x = P5[0];    PP3.y = P5[1];    PP3.z = P5[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);			// Set Top Point Of Triangle To Red    glVertex3fv( P5);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P10);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P3);    PP1.x = P1[0];    PP1.y = P1[1];    PP1.z = P1[2];    PP2.x = P4[0];    PP2.y = P4[1];    PP2.z = P4[2];    PP3.x = P7[0];    PP3.y = P7[1];    PP3.z = P7[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P5);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of Triangle To Green    glVertex3fv(P2);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P3);    PP1.x = P9[0];    PP1.y = P9[1];    PP1.z = P9[2];    PP2.x = P6[0];    PP2.y = P6[1];    PP2.z = P6[2];    PP3.x = P3[0];    PP3.y = P3[1];    PP3.z = P3[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P9);			// First Point Of The Triangle    glColor4fv(green);				// Set Left Point Of Triangle To Green    glVertex3fv(P6);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P3);    PP1.x = P2[0];    PP1.y = P2[1];    PP1.z = P2[2];    PP2.x = P6[0];    PP2.y = P6[1];    PP2.z = P6[2];    PP3.x = P3[0];    PP3.y = P3[1];    PP3.z = P3[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);				// Set Top Point Of Triangle To Red    glVertex3fv( P2);			// First Point Of The Triangle    glColor4fv(green);				// Set Left Point Of Triangle To Green    glVertex3fv(P6);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( P3);    // here the new one begines    glColor4fv(red);			// Set Top Point Of Triangle To Red    glVertex3fv( RP1);			// First Point Of The Triangle    glColor4fv(org);				// Set Left Point Of Triangle To Green    glVertex3fv(RP4);			// Second Point Of The Triangle    glColor4fv(yellow);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP7);    glColor4fv(red);			// Set Top Point Of Triangle To Red    glVertex3fv( RP1);			// First Point Of The Triangle    glColor4fv(org);				// Set Left Point Of Triangle To Green    glVertex3fv(RP4);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( RP8);    glColor4fv(red);			// Set Top Point Of Triangle To Red    glVertex3fv( RP1);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP11);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( RP12);    glColor4fv(red);			// Set Top Point Of Triangle To Red    glVertex3fv( RP4);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP9);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( RP10);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP4);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP9);			// Second Point Of The Triangle    glColor4fv(purple);			// Set Right Point Of Triangle To Blue    glVertex3fv( RP7);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP1);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP11);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP8);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP1);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP12);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP7);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP4);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP10);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP8);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP8);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP5);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP10);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP8);			// First Point Of The Triangle    glColor4fv(org);				// Set Left Point Of Triangle To Green    glVertex3fv(RP11);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP5);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP7);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP12);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP6);    glColor4fv(red);			// Set Top Point Of Triangle To Red    glVertex3fv( RP7);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP9);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP6);    glColor4fv(red);			// Set Top Point Of Triangle To Red    glVertex3fv( RP12);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP11);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP2);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP12);			// First Point Of The Triangle    glColor4fv(org);				// Set Left Point Of Triangle To Green    glVertex3fv(RP2);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP6);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP9);			// First Point Of The Triangle    glColor4fv(org);				// Set Left Point Of Triangle To Green    glVertex3fv(RP10);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP3);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP11);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP5);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP2);    glColor4fv(red);			// Set Top Point Of Triangle To Red    glVertex3fv( RP5);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP10);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP3);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP5);			// First Point Of The Triangle    glColor4fv(org);					// Set Left Point Of Triangle To Green    glVertex3fv(RP2);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP3);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP9);			// First Point Of The Triangle    glColor4fv(org);				// Set Left Point Of Triangle To Green    glVertex3fv(RP6);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP3);    glColor4fv(red);				// Set Top Point Of Triangle To Red    glVertex3fv( RP2);			// First Point Of The Triangle    glColor4fv(org);				// Set Left Point Of Triangle To Green    glVertex3fv(RP6);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle To Blue    glVertex3fv( RP3);    glEnd();    glColor4f(0.0f,0.0f,0.0f,1.0f);    glRasterPos3fv(P1);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *one);    glRasterPos3fv(P2);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *two);    glRasterPos3fv(P3);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *three);    glRasterPos3fv(P4);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *four);    glRasterPos3fv(P5);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *five);    glRasterPos3fv(P6);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *six);    glRasterPos3fv(P7);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *seven);    glRasterPos3fv(P8);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *eight);    glRasterPos3fv(P9);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *nine);    glRasterPos3fv(P10);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *ten);    glRasterPos3fv(P11);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *eleven);    glRasterPos3fv(P12);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *twelve);    glRasterPos3fv(RP1);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *one);    glRasterPos3fv(RP2);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *two);    glRasterPos3fv(RP3);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *three);    glRasterPos3fv(RP4);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *four);    glRasterPos3fv(RP5);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *five);    glRasterPos3fv(RP6);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *six);    glRasterPos3fv(RP7);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *seven);    glRasterPos3fv(RP8);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *eight);    glRasterPos3fv(RP9);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *nine);    glRasterPos3fv(RP10);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *ten);    glRasterPos3fv(RP11);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *eleven);    glRasterPos3fv(RP12);    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *twelve);    glutSwapBuffers();}static void key(unsigned char key, int x, int y) {    switch (key) {           case 'd':           rx +=3.0f;           break;           case 'a':           rx -=3.0f;           break;           case 'w':           ry +=3.0f;           break;           case 's':           ry -=3.0f;           break;           case 'z':           rz +=3.0f;           break;           case 'x':           rz -=3.0f;           break;    }    glutPostRedisplay();}static void idle(void) {    glutPostRedisplay();}int main(int argc, char *argv[]) {    glutInit(&argc, argv);    glutInitWindowSize(640,480);    glutInitWindowPosition(10,10);    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);    glutCreateWindow("GLUT Shapes");    glutReshapeFunc(resize);    glutDisplayFunc(display);    glutKeyboardFunc(key);    glutIdleFunc(idle);    glutMainLoop();    return 1;}

##### Share on other sites
O and could you explian (or give link to site) how to both declare for each vertex and declare the Martial once with glColorMaterial.

##### Share on other sites
o and when GL_DEPTH_TEST is enabled there is no alpha blending, and another thing please ignore the vertexes after "// the new one begins here". if anyone who is helpful (i.e. Lord_Evil, Deliverance, Nanoha. i.e. not someone like me) D would like me to take that out for the duration you are helping me then i will do that.

##### Share on other sites
ok so i understand winding order and why it causes this problom but isn't there a way to make it so that both sides display the same no matter what. any way i tryed this but the winding issue is still there

    glFrontFace(GL_CW);    PP1.x = P9[0];    PP1.y = P9[1];    PP1.z = P9[2];    PP2.x = P6[0];    PP2.y = P6[1];    PP2.z = P6[2];    PP3.x = P7[0];    PP3.y = P7[1];    PP3.z = P7[2];    Normal = GetNormalFace(PP1, PP2, PP3);    glNormal3f(Normal.x,Normal.y,Normal.z);    glColor4fv(blue);			// Set Top Point Of Triangle To Red    glVertex3fv( P7);			// First Point Of The Triangle    glColor4fv(green);					// Set Left Point Of     glVertex3fv(P9);			// Second Point Of The Triangle    glColor4fv(purple);				// Set Right Point Of Triangle     glVertex3fv( P6);    glFrontFace(GL_CCW);

##### Share on other sites
Winding influences normals generation and backface culling.

Disabling backface culling to make OpenGL render triangles with a different winding is easy: glDisable(GL_CULL_FACE);

Additionally, the direction of the calculated normals depends on winding.

Let the 3 vertices be P1(0,0,0), P2(1,0,0) and P3(0,1,0) which form a triangle in the yz-plane (without transformation it would be parallel to the view plane).

Now depending on the order in which you pass those to the method you get different normals:

N1 = GetNormalFace(P1,P2,P3) = (0,0,1) //counter clockwise winding, normal points towards the camera -> face is lit

N2 = GetNormalFace(P1,P3,P2) = (0,0,-1) //clockwise winding, normal points away from the camera -> face is not lit

However, you could activate two-sided lighting:
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.0); //0.0f would turn tow-sided lighting off, everything else turns it on

Note that disabling backface culling and enabling two-sided lighting might result noticable performance degradation.

##### Share on other sites
ok so i took out the glFrontFace(GL_CW) and GL_CCW function calls and enabled two faced lighting but an odd thing happed, the lit faces reversed. so triangle (P7,P4,P1) was dark but now is light and triangle (P9,P4,P1) is now dark but before was light.

##### Share on other sites
there is also a wired thing that happens when the depth test is enabled and martial coloring are enabled, some triangles will be transparent and others will be solid, o and the solid ones are always colored never black. how ever this is not a very big deal as i will not be using depth test on final product.

##### Share on other sites
Well, I'd suggest not to use two-sided lighting but to fix your polygon winding. That will be easier to do.

However, with two-sided lighting the polygons will be rendered twice and I suspect the backface is rendered over the front face thus inverting the lighting.
Did you have depth test enabled?
Which depth function did you use?

As for the transparency:
Blending (i.e. transparency) does generally depend on the order in which triangles are drawn (there are some order-independent approaches, but I guess they'd be complicated for now). Thus, if depth testing is enabled and you render a polygon at greater depth than another which you rendered before it might be rejected by the depth test.

Example:

Consider a green and a red polygon which cover the same pixel and have alpha of 0.5 but the green one farther away from the camera.

If you render the green polygon first and then the red one, you'll get a blend of green and red.

However, if you render the red one first and the green one second, you'll just get a red pixel (depending on your blend equation and settings for the background color). The reason is that by default depth test rejects incoming fragments which have equal or greater depth than is already stored for that pixel. Thus the green fragment will be rejected and never be blended with the red one.

##### Share on other sites
ok so im satisfied with what i have now for the most part except i want to be able to render the text in longer strings. right now i can only display one charter at a time.

##### Share on other sites
here is an example of how i want the text to work: http://www.opengl.org/resources/features/fontsurvey/sooft/images/fig1-1.gif

here is how mine looks:
http://i598.photobucket.com/albums/tt62/ishkabible_pic/Untitled-1.png

see how theres can have multiple charters per string... well mine cant thats why 10 is t, 11 is e, 12 is w. i would like to know how to do this

##### Share on other sites

This topic is 2783 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628710
• Total Posts
2984325

• 23
• 11
• 9
• 13
• 14