void Decepticon :: DrawBody() { if (anti_aliasing) { glEnable (GL_LINE_SMOOTH); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE); glLineWidth (1.5); } // if statement GLfloat mat_ambient[] = {0.0, 0.0, 1.0, 1.0}; GLfloat mat_diffuse[] = {0.0, 0.0, 0.8, 1.0}; glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glBegin(display_mode); // bottom left edge CalculateNormal(10, 10, -2.5, -2.5, 0, -2.5); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(-35, 0, 20); glVertex3f(-37.5, 0, 17.5); glVertex3f(-45, 10, 17.5); glVertex3f(-42.5, 10, 20); glEnd(); glBegin(display_mode); // bottom right edge CalculateNormal(2.5, 0, -2.5, 5, 10, -2.5); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(35, 0, 20); glVertex3f(37.5, 0, 17.5); glVertex3f(45, 10, 17.5); glVertex3f(42.5, 10, 20); glEnd(); glBegin(display_mode); // left edge CalculateNormal(-2.5, 40, -2.5, -2.5, 0, -2.5); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(-42.5, 10, 20); glVertex3f(-45, 10, 17.5); glVertex3f(-45, 50, 17.5); glVertex3f(-42.5, 47.5, 20); glEnd(); glBegin(display_mode); // right edge CalculateNormal(2.5, 0, -2.5, 2.5, 40, -2.5); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(42.5, 10, 20); glVertex3f(45, 10, 17.5); glVertex3f(45, 50, 17.5); glVertex3f(42.5, 47.5, 20); glEnd(); glBegin(display_mode); // top left edge CalculateNormal(30, 2.5, -2.5, 27.5, 2.5, -2.5); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(-42.5, 47.5, 20); glVertex3f(-45, 50, 17.5); glVertex3f(-15, 50, 17.5); glVertex3f(-15, 47.5, 20); glEnd(); glBegin(display_mode); // top right edge CalculateNormal(2.5, 2.5, -2.5, -27.5, 2.5, -2.5); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(42.5, 47.5, 20); glVertex3f(45, 50, 17.5); glVertex3f(15, 50, 17.5); glVertex3f(15, 47.5, 20); glEnd(); glBegin(display_mode); // left inner wall glNormal3f(0, 0, 1); glVertex3f(-15, 50, 15); glVertex3f(-15, 50, 17.5); glVertex3f(-15, 47.5, 20); glVertex3f(-15, 45, 20); glVertex3f(-15, 45, 17.5); glEnd(); glBegin(display_mode); // right inner wall glNormal3f(0, 0, 1); glVertex3f(15, 50, 15); glVertex3f(15, 50, 17.5); glVertex3f(15, 47.5, 20); glVertex3f(15, 45, 20); glVertex3f(15, 45, 17.5); glEnd(); glBegin(display_mode); // middle flat wall glNormal3f(0, 1, 0); glVertex3f(-15, 45, 17.5); glVertex3f(-15, 45, 20); glVertex3f(15, 45, 20); glVertex3f(15, 45, 17.5); glEnd(); glBegin(display_mode); // middle slanted edge CalculateNormal(30, 5, -2.5, 0, 5, -2.5); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(-15, 45, 17.5); glVertex3f(-15, 50, 15); glVertex3f(15, 50, 15); glVertex3f(15, 45, 17.5); glEnd(); glBegin(display_mode); // bottom edge CalculateNormal(-2.5, 0, -2.5, 72.5, 0, -2.5); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(-35, 0, 20); glVertex3f(-37.5, 0, 17.5); glVertex3f(37.5, 0, 17.5); glVertex3f(35, 0, 20); glEnd(); glBegin(display_mode); // back face glNormal3f(0, 0, -1); glVertex3f(-37.5, 0, -17.5); glVertex3f(-45, 10, -17.5); glVertex3f(-45, 50, -17.5); glVertex3f(45, 50, -17.5); glVertex3f(45, 10, -17.5); glVertex3f(37.5, 0, -17.5); glEnd(); glBegin(display_mode); // front bevelled left face glNormal3f(0, 0, 1); glVertex3f(-35, 0, 20); glVertex3f(-42.5, 10, 20); glVertex3f(-42.5, 47.5, 20); glVertex3f(-30, 40, 20); glVertex3f(-30, 15, 20); glVertex3f(-27.5, 12.5, 20); glEnd(); glBegin(display_mode); // front bevelled left edge glNormal3f(1, 0, 0); glVertex3f(-30, 40, 20); glVertex3f(-30, 15, 20); glVertex3f(-30, 15, 17.5); glVertex3f(-30, 40, 17.5); glEnd(); glBegin(display_mode); // front bevelled right face glNormal3f(0, 0, 1); glVertex3f(35, 0, 20); glVertex3f(42.5, 10, 20); glVertex3f(42.5, 47.5, 20); glVertex3f(30, 40, 20); glVertex3f(30, 15, 20); glVertex3f(27.5, 12.5, 20); glEnd(); glBegin(display_mode); // front bevelled right edge glNormal3f(-1, 0, 0); glVertex3f(30, 40, 20); glVertex3f(30, 15, 20); glVertex3f(30, 15, 17.5); glVertex3f(30, 40, 17.5); glEnd(); glBegin(display_mode); // front bevelled bottom face glNormal3f(0, 0, 1); glVertex3f(-35, 0, 20); glVertex3f(-27.5, 12.5, 20); glVertex3f(27.5, 12.5, 20); glVertex3f(35, 0, 20); glEnd(); glBegin(display_mode); // front bevelled bottom edge glNormal3f(0, 1, 0); glVertex3f(-27.5, 12.5, 20); glVertex3f(27.5, 12.5, 20); glVertex3f(27.5, 12.5, 17.5); glVertex3f(-27.5, 12.5, 17.5); glEnd(); glBegin(display_mode); // front bevelled bottom left edge CalculateNormal(-2.5, 2.5, -2.5, -2.5, 2.5, 0); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(-27.5, 12.5, 20); glVertex3f(-30, 15, 20); glVertex3f(-30, 15, 17.5); glVertex3f(-27.5, 12.5, 17.5); glEnd(); glBegin(display_mode); // front bevelled bottom right edge CalculateNormal(2.5, 2.5, 0, 2.5, 2.5, -2.5); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(27.5, 12.5, 20); glVertex3f(30, 15, 20); glVertex3f(30, 15, 17.5); glVertex3f(27.5, 12.5, 17.5); glEnd(); glBegin(display_mode); // front bevelled top left face glNormal3f(0, 0, 1); glVertex3f(-30, 40, 20); glVertex3f(-42.5, 47.5, 20); glVertex3f(-15, 47.5, 20); glVertex3f(-15, 40, 20); glEnd(); glBegin(display_mode); // front bevelled top right face glNormal3f(0, 0, 1); glVertex3f(30, 40, 20); glVertex3f(42.5, 47.5, 20); glVertex3f(15, 47.5, 20); glVertex3f(15, 40, 20); glEnd(); glBegin(display_mode); // front bevelled top middle face glNormal3f(0, 0, 1); glVertex3f(-15, 45, 20); glVertex3f(-15, 40, 20); glVertex3f(15, 40, 20); glVertex3f(15, 45, 20); glEnd(); glBegin(display_mode); // front bevelled top edge glNormal3f(0, 1, 0); glVertex3f(-30, 40, 20); glVertex3f(30, 40, 20); glVertex3f(30, 40, 17.5); glVertex3f(-30, 40, 17.5); glEnd(); glBegin(display_mode); // bottom face glNormal3f(0, -1, 0); glVertex3f(-37.5, 0, 17.5); glVertex3f(-37.5, 0, -17.5); glVertex3f(37.5, 0, -17.5); glVertex3f(37.5, 0, 17.5); glEnd(); glBegin(display_mode); // bottom left face CalculateNormal(-7.5, 10, 35, -7.5, 10, 0); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(-37.5, 0, 17.5); glVertex3f(-45, 10, 17.5); glVertex3f(-45, 10, -17.5); glVertex3f(-37.5, 0, -17.5); glEnd(); glBegin(display_mode); // bottom right face CalculateNormal(7.5, 10, 0, 7.5, 10, 35); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(37.5, 0, 17.5); glVertex3f(45, 10, 17.5); glVertex3f(45, 10, -17.5); glVertex3f(37.5, 0, -17.5); glEnd(); glBegin(display_mode); // left face glNormal3f(-1, 0, 0); glVertex3f(-45, 10, 17.5); glVertex3f(-45, 50, 17.5); glVertex3f(-45, 50, -17.5); glVertex3f(-45, 10, -17.5); glEnd(); glBegin(display_mode); // right face glNormal3f(1, 0, 0); glVertex3f(45, 10, 17.5); glVertex3f(45, 50, 17.5); glVertex3f(45, 50, -17.5); glVertex3f(45, 10, -17.5); glEnd(); glBegin(display_mode); // top face glNormal3f(0, 1, 0); glVertex3f(-45, 50, 17.5); glVertex3f(-15, 50, 17.5); glVertex3f(-15, 50, 15); glVertex3f(15, 50, 15); glVertex3f(15, 50, 17.5); glVertex3f(45, 50, 17.5); glVertex3f(45, 50, -17.5); glVertex3f(-45, 50, -17.5); glEnd(); mat_ambient[0] = 1.0; mat_ambient[1] = 1.0; mat_ambient[2] = 0.0; mat_diffuse[0] = 0.8; mat_diffuse[1] = 0.8; mat_diffuse[2] = 0.0; glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glBegin(display_mode); // left upper stripe face glNormal3f(0, 0, 1); glVertex3f(-42.5, 35, 21); glVertex3f(-42.5, 31, 21); glVertex3f(-32.5, 31, 21); glVertex3f(-32.5, 35, 21); glEnd(); glBegin(display_mode); // right upper stripe face glNormal3f(0, 0, 1); glVertex3f(42.5, 35, 21); glVertex3f(42.5, 31, 21); glVertex3f(32.5, 31, 21); glVertex3f(32.5, 35, 21); glEnd(); glBegin(display_mode); // left lower stripe face glNormal3f(0, 0, 1); glVertex3f(-42.5, 29, 21); glVertex3f(-42.5, 25, 21); glVertex3f(-32.5, 25, 21); glVertex3f(-32.5, 29, 21); glEnd(); glBegin(display_mode); // right lower stripe face glNormal3f(0, 0, 1); glVertex3f(42.5, 29, 21); glVertex3f(42.5, 25, 21); glVertex3f(32.5, 25, 21); glVertex3f(32.5, 29, 21); glEnd(); glBegin(display_mode); // left upper stripe left rise glNormal3f(-1, 0, 0); glVertex3f(-42.5, 35, 21); glVertex3f(-42.5, 31, 21); glVertex3f(-42.5, 31, 20); glVertex3f(-42.5, 35, 20); glEnd(); glBegin(display_mode); // right upper stripe right rise glNormal3f(1, 0, 0); glVertex3f(42.5, 35, 21); glVertex3f(42.5, 31, 21); glVertex3f(42.5, 31, 20); glVertex3f(42.5, 35, 20); glEnd(); glBegin(display_mode); // left upper stripe upper rise glNormal3f(0, 1, 0); glVertex3f(-42.5, 35, 21); glVertex3f(-32.5, 35, 21); glVertex3f(-32.5, 35, 20); glVertex3f(-42.5, 35, 20); glEnd(); glBegin(display_mode); // right upper stripe upper rise glNormal3f(0, 1, 0); glVertex3f(42.5, 35, 21); glVertex3f(32.5, 35, 21); glVertex3f(32.5, 35, 20); glVertex3f(42.5, 35, 20); glEnd(); glBegin(display_mode); // left upper stripe right rise glNormal3f(1, 0, 0); glVertex3f(-32.5, 35, 21); glVertex3f(-32.5, 31, 21); glVertex3f(-32.5, 31, 20); glVertex3f(-32.5, 35, 20); glEnd(); glBegin(display_mode); // right upper stripe left rise glNormal3f(-1, 0, 0); glVertex3f(32.5, 35, 21); glVertex3f(32.5, 31, 21); glVertex3f(32.5, 31, 20); glVertex3f(32.5, 35, 20); glEnd(); glBegin(display_mode); // left upper stripe lower rise glNormal3f(0, -1, 0); glVertex3f(-42.5, 31, 21); glVertex3f(-32.5, 31, 21); glVertex3f(-32.5, 31, 20); glVertex3f(-42.5, 31, 20); glEnd(); glBegin(display_mode); // right upper stripe lower rise glNormal3f(0, -1, 0); glVertex3f(42.5, 31, 21); glVertex3f(32.5, 31, 21); glVertex3f(32.5, 31, 20); glVertex3f(42.5, 31, 20); glEnd(); glBegin(display_mode); // left lower stripe left rise glNormal3f(-1, 0, 0); glVertex3f(-42.5, 29, 21); glVertex3f(-42.5, 25, 21); glVertex3f(-42.5, 25, 20); glVertex3f(-42.5, 29, 20); glEnd(); glBegin(display_mode); // right lower stripe right rise glNormal3f(1, 0, 0); glVertex3f(42.5, 29, 21); glVertex3f(42.5, 25, 21); glVertex3f(42.5, 25, 20); glVertex3f(42.5, 29, 20); glEnd(); glBegin(display_mode); // left lower stripe upper rise glNormal3f(0, 1, 0); glVertex3f(-42.5, 29, 21); glVertex3f(-32.5, 29, 21); glVertex3f(-32.5, 29, 20); glVertex3f(-42.5, 29, 20); glEnd(); glBegin(display_mode); // right lower stripe upper rise glNormal3f(0, 1, 0); glVertex3f(42.5, 29, 21); glVertex3f(32.5, 29, 21); glVertex3f(32.5, 29, 20); glVertex3f(42.5, 29, 20); glEnd(); glBegin(display_mode); // left lower stripe right rise glNormal3f(1, 0, 0); glVertex3f(-32.5, 29, 21); glVertex3f(-32.5, 25, 21); glVertex3f(-32.5, 25, 20); glVertex3f(-32.5, 29, 21); glEnd(); glBegin(display_mode); // right lower stripe left rise glNormal3f(-1, 0, 0); glVertex3f(32.5, 29, 21); glVertex3f(32.5, 25, 21); glVertex3f(32.5, 25, 20); glVertex3f(32.5, 29, 21); glEnd(); glBegin(display_mode); // left lower stripe lower rise glNormal3f(0, -1, 0); glVertex3f(-42.5, 25, 21); glVertex3f(-32.5, 25, 21); glVertex3f(-32.5, 25, 20); glVertex3f(-42.5, 25, 20); glEnd(); glBegin(display_mode); // right lower stripe lower rise glNormal3f(0, 0, -1); glVertex3f(42.5, 25, 21); glVertex3f(32.5, 25, 21); glVertex3f(32.5, 25, 20); glVertex3f(42.5, 25, 20); glEnd(); mat_ambient[0] = 0.0; mat_ambient[1] = 0.0; mat_ambient[2] = 0.8; mat_diffuse[0] = 0.0; mat_diffuse[1] = 0.0; mat_diffuse[2] = 0.5; glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glBegin(display_mode); // back brace back left face glNormal3f(0, 0, -1); glVertex3f(-45, 20, -15); glVertex3f(-50, 25, -15); glVertex3f(-50, 50, -15); glVertex3f(-45, 50, -15); glEnd(); glBegin(display_mode); // back brace back right face glNormal3f(0, 0, -1); glVertex3f(45, 20, -15); glVertex3f(50, 25, -15); glVertex3f(50, 50, -15); glVertex3f(45, 50, -15); glEnd(); glBegin(display_mode); // back brace back top face glNormal3f(0, 0, -1); glVertex3f(-50, 50, -15); glVertex3f(-45, 55, -15); glVertex3f(45, 55, -15); glVertex3f(50, 50, -15); glEnd(); glBegin(display_mode); // back brace front left face glNormal3f(0, 0, 1); glVertex3f(-45, 20, -5); glVertex3f(-50, 25, -5); glVertex3f(-50, 50, -5); glVertex3f(-45, 50, -5); glEnd(); glBegin(display_mode); // back brace front right face glNormal3f(0, 0, 1); glVertex3f(45, 20, -5); glVertex3f(50, 25, -5); glVertex3f(50, 50, -5); glVertex3f(45, 50, -5); glEnd(); glBegin(display_mode); // back brace front top face glNormal3f(0, 0, 1); glVertex3f(-50, 50, -5); glVertex3f(-45, 55, -5); glVertex3f(45, 55, -5); glVertex3f(50, 50, -5); glEnd(); glBegin(display_mode); // front brace back left face glNormal3f(0, 0, -1); glVertex3f(-45, 20, 5); glVertex3f(-50, 25, 5); glVertex3f(-50, 50, 5); glVertex3f(-45, 50, 5); glEnd(); glBegin(display_mode); // front brace back right face glNormal3f(0, 0, -1); glVertex3f(45, 20, 5); glVertex3f(50, 25, 5); glVertex3f(50, 50, 5); glVertex3f(45, 50, 5); glEnd(); glBegin(display_mode); // front brace back top face glNormal3f(0, 0, 1); glVertex3f(-50, 50, 15); glVertex3f(-45, 55, 15); glVertex3f(45, 55, 15); glVertex3f(50, 50, 15); glEnd(); glBegin(display_mode); // front brace back left face glNormal3f(0, 0, 1); glVertex3f(-45, 20, 15); glVertex3f(-50, 25, 15); glVertex3f(-50, 50, 15); glVertex3f(-45, 50, 15); glEnd(); glBegin(display_mode); // front brace back right face glNormal3f(0, 0, 1); glVertex3f(45, 20, 15); glVertex3f(50, 25, 15); glVertex3f(50, 50, 15); glVertex3f(45, 50, 15); glEnd(); glBegin(display_mode); // front brace back top face glNormal3f(0, 0, 1); glVertex3f(-50, 50, 15); glVertex3f(-45, 55, 15); glVertex3f(45, 55, 15); glVertex3f(50, 50, 15); glEnd(); glBegin(display_mode); // back brace lower left edge CalculateNormal(-5, 5, 0, -5, 5, -10); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(-45, 20, -5); glVertex3f(-50, 25, -5); glVertex3f(-50, 25, -15); glVertex3f(-45, 20, -15); glEnd(); glBegin(display_mode); // front brace lower left edge CalculateNormal(-5, 5, 10, -5, 5, 0); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(-45, 20, 5); glVertex3f(-50, 25, 5); glVertex3f(-50, 25, 15); glVertex3f(-45, 20, 15); glEnd(); glBegin(display_mode); // back brace lower right edge CalculateNormal(5, 5, -10, 5, 5, 0); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(45, 20, -5); glVertex3f(50, 25, -5); glVertex3f(50, 25, -15); glVertex3f(45, 20, -15); glEnd(); glBegin(display_mode); // front brace lower right edge CalculateNormal(5, 5, 0, 5, 5, 10); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(45, 20, 5); glVertex3f(50, 25, 5); glVertex3f(50, 25, 15); glVertex3f(45, 20, 15); glEnd(); glBegin(display_mode); // back brace left edge glNormal3f(-1, 0, 0); glVertex3f(-50, 25, -5); glVertex3f(-50, 50, -5); glVertex3f(-50, 50, -15); glVertex3f(-50, 25, -15); glEnd(); glBegin(display_mode); // front brace left edge glNormal3f(-1, 0, 0); glVertex3f(-50, 25, 5); glVertex3f(-50, 50, 5); glVertex3f(-50, 50, 15); glVertex3f(-50, 25, 15); glEnd(); glBegin(display_mode); // back brace right edge glNormal3f(1, 0, 0); glVertex3f(50, 25, -5); glVertex3f(50, 50, -5); glVertex3f(50, 50, -15); glVertex3f(50, 25, -15); glEnd(); glBegin(display_mode); // front brace right edge glNormal3f(1, 0, 0); glVertex3f(50, 25, 5); glVertex3f(50, 50, 5); glVertex3f(50, 50, 15); glVertex3f(50, 25, 15); glEnd(); glBegin(display_mode); // back brace top left edge CalculateNormal(5, 5, 0, 5, 5, -10); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(-50, 50, -5); glVertex3f(-45, 55, -5); glVertex3f(-45, 55, -15); glVertex3f(-50, 50, -15); glEnd(); glBegin(display_mode); // back brace top right edge CalculateNormal(-5, 5, -10, -5, 5, 0); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(50, 50, -5); glVertex3f(45, 55, -5); glVertex3f(45, 55, -15); glVertex3f(50, 50, -15); glEnd(); glBegin(display_mode); // front brace top left edge CalculateNormal(5, 5, 10, 5, 5, 0); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(-50, 50, 5); glVertex3f(-45, 55, 5); glVertex3f(-45, 55, 15); glVertex3f(-50, 50, 15); glEnd(); glBegin(display_mode); // front brace top right edge CalculateNormal(5, 5, 0, -5, 5, 10); glNormal3f(normal_vector[0], normal_vector[1], normal_vector[2]); glVertex3f(50, 50, 5); glVertex3f(45, 55, 5); glVertex3f(45, 55, 15); glVertex3f(50, 50, 15); glEnd(); glBegin(display_mode); // back brace top edge glNormal3f(0, 1, 0); glVertex3f(-45, 55, -5); glVertex3f(45, 55, -5); glVertex3f(45, 55, -15); glVertex3f(-45, 55, -15); glEnd(); glBegin(display_mode); // front brace top edge glNormal3f(0, 1, 0); glVertex3f(-45, 55, 5); glVertex3f(45, 55, 5); glVertex3f(45, 55, 15); glVertex3f(-45, 55, 15); glEnd(); mat_ambient[0] = 1.0; mat_ambient[1] = 1.0; mat_ambient[2] = 1.0; mat_diffuse[0] = 1.0; mat_diffuse[1] = 1.0; mat_diffuse[2] = 1.0; glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glBegin(display_mode); // gun-mount front face glNormal3f(0, 0, 1); glVertex3f(22, 55, 12.5); glVertex3f(22, 60, 12.5); glVertex3f(32, 60, 12.5); glVertex3f(32, 55, 12.5); glEnd(); glBegin(display_mode); // gun-mount back face glNormal3f(0, 0, -1); glVertex3f(22, 55, 7.5); glVertex3f(22, 60, 7.5); glVertex3f(32, 60, 7.5); glVertex3f(32, 55, 7.5); glEnd(); glBegin(display_mode); // gun-mount left face glNormal3f(-1, 0, 0); glVertex3f(22, 55, 12.5); glVertex3f(22, 60, 12.5); glVertex3f(22, 60, 7.5); glVertex3f(22, 55, 7.5); glEnd(); glBegin(display_mode); // gun-mount right face glNormal3f(1, 0, 0); glVertex3f(32, 55, 12.5); glVertex3f(32, 60, 12.5); glVertex3f(32, 60, 7.5); glVertex3f(32, 55, 7.5); glEnd(); glBegin(display_mode); // gun-mount top face glNormal3f(0, 1, 0); glVertex3f(22, 60, 12.5); glVertex3f(22, 60, 7.5); glVertex3f(32, 60, 7.5); glVertex3f(32, 60, 12.5); glEnd(); mat_ambient[0] = 0.0; mat_ambient[1] = 0.0; mat_ambient[2] = 1.0; mat_diffuse[0] = 0.0; mat_diffuse[1] = 0.0; mat_diffuse[2] = 0.8; glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); if (display_mode == GL_LINE_LOOP) { glPushMatrix(); glTranslatef(-30, 67.5, -32.5); glRotatef(90, 1, 0, 0); TaperedWireCylinder(0, 12.5, 0, 20); TaperedWireCylinder(15, 12.5, 12.5, 20); glTranslatef(0, 15, 0); TaperedWireCylinder(0, 12.5, 9.5, 20); TaperedWireCylinder(3, 9.5, 9.5, 20); glTranslatef(0, 3, 0); TaperedWireCylinder(0, 9.5, 12.5, 20); TaperedWireCylinder(30, 12.5, 12.5, 20); glTranslatef(0, 30, 0); TaperedWireCylinder(0, 12.5, 9.5, 20); TaperedWireCylinder(2, 9.5, 9.5, 20); glTranslatef(0, 2, 0); TaperedWireCylinder(0, 9.5, 12.5, 20); TaperedWireCylinder(4, 12.5, 12.5, 20); glTranslatef(0, 4, 0); TaperedWireCylinder(0, 12.5, 9.5, 20); TaperedWireCylinder(5, 9.5, 9.5, 20); glTranslatef(0, 5, 0); TaperedWireCylinder(0, 9.5, 12.5, 20); TaperedWireCylinder(4, 12.5, 12.5, 20); glTranslatef(0, 4, 0); TaperedWireCylinder(0, 12.5, 9.5, 20); TaperedWireCylinder(2, 9.5, 9.5, 20); glTranslatef(0, 2, 0); TaperedWireCylinder(0, 9.5, 12.5, 20); glPushMatrix(); glTranslatef(0, 5, 0); mat_ambient[0] = 1.0; mat_ambient[1] = 0.0; mat_ambient[2] = 0.0; mat_diffuse[0] = 0.8; mat_diffuse[1] = 0.0; mat_diffuse[2] = 0.0; glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); TaperedWireCylinder(5, 12.5, 12.5, 20); mat_ambient[0] = 0.0; mat_ambient[1] = 0.0; mat_ambient[2] = 1.0; mat_diffuse[0] = 0.0; mat_diffuse[1] = 0.0; mat_diffuse[2] = 1.0; glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glPopMatrix(); TaperedWireCylinder(15, 12.5, 12.5, 20); glTranslatef(0, 15, 0); TaperedWireCylinder(0, 12.5, 9.5, 20); glTranslatef(0, -2, 0); TaperedWireCylinder(0, 9.5, 0, 20); TaperedWireCylinder(2, 9.5, 9.5, 20); glPopMatrix(); } // if statement else if (display_mode == GL_POLYGON) { glPushMatrix(); glTranslatef(-30, 67.5, -32.5); glRotatef(90, 1, 0, 0); TaperedCylinder(0, 12.5, 0, 20); TaperedCylinder(15, 12.5, 12.5, 20); glTranslatef(0, 15, 0); TaperedCylinder(0, 12.5, 9.5, 20); TaperedCylinder(3, 9.5, 9.5, 20); glTranslatef(0, 3, 0); TaperedCylinder(0, 9.5, 12.5, 20); TaperedCylinder(30, 12.5, 12.5, 20); glTranslatef(0, 30, 0); TaperedCylinder(0, 12.5, 9.5, 20); TaperedCylinder(2, 9.5, 9.5, 20); glTranslatef(0, 2, 0); TaperedCylinder(0, 9.5, 12.5, 20); TaperedCylinder(4, 12.5, 12.5, 20); glTranslatef(0, 4, 0); TaperedCylinder(0, 12.5, 9.5, 20); TaperedCylinder(5, 9.5, 9.5, 20); glTranslatef(0, 5, 0); TaperedCylinder(0, 9.5, 12.5, 20); TaperedCylinder(4, 12.5, 12.5, 20); glTranslatef(0, 4, 0); TaperedCylinder(0, 12.5, 9.5, 20); TaperedCylinder(2, 9.5, 9.5, 20); glTranslatef(0, 2, 0); TaperedCylinder(0, 9.5, 12.5, 20); glPushMatrix(); glTranslatef(0, 5, 0); mat_ambient[0] = 1.0; mat_ambient[1] = 0.0; mat_ambient[2] = 0.0; mat_diffuse[0] = 0.8; mat_diffuse[1] = 0.0; mat_diffuse[2] = 0.0; glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); TaperedCylinder(5, 12.6, 12.6, 20); mat_ambient[0] = 0.0; mat_ambient[1] = 0.0; mat_ambient[2] = 1.0; mat_diffuse[0] = 0.0; mat_diffuse[1] = 0.0; mat_diffuse[2] = 1.0; glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glPopMatrix(); TaperedCylinder(15, 12.5, 12.5, 20); glTranslatef(0, 15, 0); TaperedCylinder(0, 12.5, 9.5, 20); glTranslatef(0, -2, 0); TaperedCylinder(0, 9.5, 0, 20); TaperedCylinder(2, 9.5, 9.5, 20); glPopMatrix(); } // else statement } // DrawBody
void InternalEdgeDemo::clientMoveAndDisplay() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); float dt = getDeltaTimeMicroseconds() * 0.000001f; if (m_animatedMesh) { static float offset=0.f; offset+=0.01f; // setVertexPositions(waveheight,offset); #if 0 ///not currently supported, we need to update the btInternalTriangleInfoMap int i; int j; btVector3 aabbMin(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT); btVector3 aabbMax(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT); for ( i=NUM_VERTS_X/2-3;i<NUM_VERTS_X/2+2;i++) { for (j=NUM_VERTS_X/2-3;j<NUM_VERTS_Y/2+2;j++) { aabbMax.setMax(gVertices[i+j*NUM_VERTS_X]); aabbMin.setMin(gVertices[i+j*NUM_VERTS_X]); gVertices[i+j*NUM_VERTS_X].setValue((i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE, 0.f, //waveheight*sinf((float)i+offset)*cosf((float)j+offset), (j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE); aabbMin.setMin(gVertices[i+j*NUM_VERTS_X]); aabbMax.setMax(gVertices[i+j*NUM_VERTS_X]); } } trimeshShape->partialRefitTree(aabbMin,aabbMax); #else btVector3 aabbMin,aabbMax; trimeshShape->getMeshInterface()->calculateAabbBruteForce(aabbMin,aabbMax); trimeshShape->refitTree(aabbMin,aabbMax); #endif //for debugging: clear all contact points involving mesh proxy. Note: this is a slow/unoptimized operation. //m_dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(staticBody->getBroadphaseHandle(),getDynamicsWorld()->getDispatcher()); } m_dynamicsWorld->stepSimulation(dt); ///enable one of the following to debug (render debug lines each frame) //m_dynamicsWorld->stepSimulation(1./800.,0); //m_dynamicsWorld->stepSimulation(1./60.,100,1./800.); //m_dynamicsWorld->stepSimulation(1./60.,0); int lineWidth=450; int xStart = m_glutScreenWidth - lineWidth; int yStart = 20; if((getDebugMode() & btIDebugDraw::DBG_DrawText)!=0) { setOrthographicProjection(); glDisable(GL_LIGHTING); glColor3f(0, 0, 0); char buf[124]; glRasterPos3f(xStart, yStart, 0); if (enable) { sprintf(buf,"InternalEdgeUtility enabled"); } else { sprintf(buf,"InternalEdgeUtility disabled"); } GLDebugDrawString(xStart,20,buf); yStart+=20; glRasterPos3f(xStart, yStart, 0); sprintf(buf,"Press 'n' to toggle InternalEdgeUtility"); yStart+=20; GLDebugDrawString(xStart,yStart,buf); glRasterPos3f(xStart, yStart, 0); resetPerspectiveProjection(); glEnable(GL_LIGHTING); } renderme(); //optional but useful: debug drawing m_dynamicsWorld->debugDrawWorld(); glFlush(); swapBuffers(); }
void DoPostprocess() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_DEPTH_TEST); glDisable(GL_BLEND); glDisable(GL_LIGHTING); // So, to do proper tone mapping of HDR to LDR we need to know the average luminance // of the scene. We do this by rendering the scene's luminance to a smaller texture, // generating mipmaps for it, and grabbing the luminance at the smallest mipmap level glViewport(0,0,128,128); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, luminanceFb); glEnable(GL_TEXTURE_RECTANGLE_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, tex); State::UseProgram(postprocessLuminance); postprocessLuminance->set_fboTex(0); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0); glTexCoord2f(width, 0.0); glVertex2f(1.0, 0.0); glTexCoord2f(0.0,height); glVertex2f(0.0, 1.0); glTexCoord2f(width, height); glVertex2f(1.0, 1.0); glEnd(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glDisable(GL_TEXTURE_RECTANGLE_ARB); glBindTexture(GL_TEXTURE_2D, luminanceTex); glEnable(GL_TEXTURE_2D); glGenerateMipmapEXT(GL_TEXTURE_2D); float avgLum[4]; glGetTexImage(GL_TEXTURE_2D, 7, GL_RGB, GL_FLOAT, avgLum); //printf("%f -> ", avgLum[0]); avgLum[0] = std::max(float(exp(avgLum[0])), 0.03f); //printf("%f\n", avgLum[0]); // see reinhard algo const float midGrey = 1.03f - 2.0f/(2.0f+log10(avgLum[0] + 1.0f)); glDisable(GL_TEXTURE_2D); glViewport(0,0,width>>1,height>>1); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, halfsizeFb); glEnable(GL_TEXTURE_RECTANGLE_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, tex); State::UseProgram(postprocessBloom1Downsample); postprocessBloom1Downsample->set_avgLum(avgLum[0]); postprocessBloom1Downsample->set_middleGrey(midGrey); postprocessBloom1Downsample->set_fboTex(0); glBegin(GL_TRIANGLE_STRIP); glVertex2f(0.0, 0.0); glVertex2f(1.0, 0.0); glVertex2f(0.0, 1.0); glVertex2f(1.0, 1.0); glEnd(); glViewport(0,0,width>>2,height>>2); State::UseProgram(postprocessBloom2Downsample); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bloomFb1); glEnable(GL_TEXTURE_RECTANGLE_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, halfsizeTex); glBegin(GL_TRIANGLE_STRIP); glVertex2f(0.0, 0.0); glVertex2f(1.0, 0.0); glVertex2f(0.0, 1.0); glVertex2f(1.0, 1.0); glEnd(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bloomFb2); glEnable(GL_TEXTURE_RECTANGLE_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, bloomTex1); State::UseProgram(postprocessBloom3VBlur); postprocessBloom3VBlur->set_fboTex(0); glBegin(GL_TRIANGLE_STRIP); glVertex2f(0.0, 0.0); glVertex2f(1.0, 0.0); glVertex2f(0.0, 1.0); glVertex2f(1.0, 1.0); glEnd(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, bloomFb1); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, bloomTex2); State::UseProgram(postprocessBloom4HBlur); postprocessBloom4HBlur->set_fboTex(0); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0); glTexCoord2f(1.0, 0.0); glVertex2f(1.0, 0.0); glTexCoord2f(0.0,1.0); glVertex2f(0.0, 1.0); glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0); glEnd(); glViewport(0,0,width,height); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glEnable(GL_TEXTURE_RECTANGLE_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, tex); glActiveTexture(GL_TEXTURE1); glEnable(GL_TEXTURE_RECTANGLE_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, bloomTex1); State::UseProgram(postprocessCompose); postprocessCompose->set_fboTex(0); postprocessCompose->set_bloomTex(1); postprocessCompose->set_avgLum(avgLum[0]); //printf("Mid grey %f\n", midGrey); postprocessCompose->set_middleGrey(midGrey); glBegin(GL_TRIANGLE_STRIP); glVertex2f(0.0, 0.0); glVertex2f(1.0, 0.0); glVertex2f(0.0, 1.0); glVertex2f(1.0, 1.0); glEnd(); State::UseProgram(0); #if 0 glViewport(0,0,width,height); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glEnable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_RECTANGLE_ARB); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); glColor3f(1.0,1.0,1.0); glBindTexture(GL_TEXTURE_2D, luminanceTex); State::UseProgram(0); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0); glTexCoord2f(1.0, 0.0); glVertex2f(1.0, 0.0); glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 1.0); glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0); glEnd(); glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); glDisable(GL_TEXTURE_2D); #endif glEnable(GL_DEPTH_TEST); glDisable(GL_TEXTURE_RECTANGLE_ARB); glActiveTexture(GL_TEXTURE0); glDisable(GL_TEXTURE_RECTANGLE_ARB); glError(); }
int main(int argc, char *argv[]) { int c; int i; GLfloat mat_specular[] = { 0.7, 0.7, 0.7, 1.0 }; GLfloat mat_shininess[] = { 40.0 }; GLfloat light_position[] = { 4.5, 0.0, 4.5, 0.0 }; glutInit(&argc, argv); num_disks = MAX_DISKS; while((c = getopt(argc, argv, "n:s:m:")) != -1) { switch (c) { case 'n': num_disks = atoi(optarg); if (num_disks < 1 || num_disks > MAX_DISKS) { num_disks = MAX_DISKS; } break; case 's': spinning = atoi(optarg) ? 1 : 0; break; case 'm': motion = atoi(optarg) ? 1 : 0; break; default: break; } } glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutCreateWindow("Hanoi"); glutDisplayFunc(display); glutVisibilityFunc(visible); glMatrixMode(GL_PROJECTION); gluPerspective(40.0, 1.0, 0.1, 10.0); glMatrixMode(GL_MODELVIEW); gluLookAt(0, 5.5, 3.5, 0, 0, 0, 0, 0, 1); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); #ifndef TOOSLOW glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glEnable(GL_COLOR_MATERIAL); #endif #ifndef TOOSLOW glShadeModel(GL_SMOOTH); #endif glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); #ifndef TOOSLOW glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); #endif glDepthFunc(GL_LEQUAL); glClearColor(0.3, 0.3, 0.3, 0.0); #ifndef TOOSLOW glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); #endif glPolygonMode(GL_FRONT, GL_FILL); glutCreateMenu(menu); glutAddMenuEntry("Toggle motion", 2); glutAddMenuEntry("Toggle spinning", 3); glutAddMenuEntry("Quit", 666); glutAttachMenu(GLUT_RIGHT_BUTTON); #if defined(GL_POLYGON_OFFSET_EXT) if (glutExtensionSupported("GL_EXT_polygon_offset")) { glPolygonOffsetEXT(0.5, 0.0); glEnable(GL_POLYGON_OFFSET_EXT); } #endif poledlist(DL_POLE); floordlist(DL_FLOOR); disks_on_poles[0].num_disks = num_disks; for (i=0; i<num_disks; i++) { diskdlist(DL_DISK+i, 0.3 + i*0.1); disks_on_poles[0].disks[num_disks-i-1] = i; disk_offset[i][Z] = 0.2*(num_disks-i-1); } /* * start hanoi instruction engine */ { int engine_args[2]; extern void engine(int *); int p[2]; prctl(PR_SETEXITSIG, SIGTERM); if (-1 == pipe(p)) { perror("can't pipe"); exit(1); } engine_args[0] = num_disks; engine_args[1] = p[1]; engine_fd = p[0]; engine_pid = sproc((void(*)(void *))engine, PR_SALL, (void *)engine_args); if (engine_pid == -1) { perror("can't sproc"); exit(1); } } glutMainLoop(); /*NOTREACHED*/ return 0; /* ANSI C requires main to return int. */ }
void Renderer::drawCube(Texture **textures) { OpenGLTexture *texture0 = static_cast<OpenGLTexture *>(textures[0]); // Size of the cube float t = 256.0f; // Used fragment of the textures float s = texture0->width / (float) texture0->internalWidth; glEnable(GL_TEXTURE_2D); glDepthMask(GL_FALSE); glBindTexture(GL_TEXTURE_2D, static_cast<OpenGLTexture *>(textures[4])->id); glBegin(GL_TRIANGLE_STRIP); // X- glTexCoord2f(0, s); glVertex3f(-t,-t, t); glTexCoord2f(s, s); glVertex3f(-t,-t,-t); glTexCoord2f(0, 0); glVertex3f(-t, t, t); glTexCoord2f(s, 0); glVertex3f(-t, t,-t); glEnd(); glBindTexture(GL_TEXTURE_2D, static_cast<OpenGLTexture *>(textures[3])->id); glBegin(GL_TRIANGLE_STRIP); // X+ glTexCoord2f(0, s); glVertex3f( t,-t,-t); glTexCoord2f(s, s); glVertex3f( t,-t, t); glTexCoord2f(0, 0); glVertex3f( t, t,-t); glTexCoord2f(s, 0); glVertex3f( t, t, t); glEnd(); glBindTexture(GL_TEXTURE_2D, static_cast<OpenGLTexture *>(textures[1])->id); glBegin(GL_TRIANGLE_STRIP); // Y- glTexCoord2f(0, s); glVertex3f( t,-t,-t); glTexCoord2f(s, s); glVertex3f(-t,-t,-t); glTexCoord2f(0, 0); glVertex3f( t,-t, t); glTexCoord2f(s, 0); glVertex3f(-t,-t, t); glEnd(); glBindTexture(GL_TEXTURE_2D, static_cast<OpenGLTexture *>(textures[5])->id); glBegin(GL_TRIANGLE_STRIP); // Y+ glTexCoord2f(0, s); glVertex3f( t, t, t); glTexCoord2f(s, s); glVertex3f(-t, t, t); glTexCoord2f(0, 0); glVertex3f( t, t,-t); glTexCoord2f(s, 0); glVertex3f(-t, t,-t); glEnd(); glBindTexture(GL_TEXTURE_2D, static_cast<OpenGLTexture *>(textures[0])->id); glBegin(GL_TRIANGLE_STRIP); // Z- glTexCoord2f(0, s); glVertex3f(-t,-t,-t); glTexCoord2f(s, s); glVertex3f( t,-t,-t); glTexCoord2f(0, 0); glVertex3f(-t, t,-t); glTexCoord2f(s, 0); glVertex3f( t, t,-t); glEnd(); glBindTexture(GL_TEXTURE_2D, static_cast<OpenGLTexture *>(textures[2])->id); glBegin(GL_TRIANGLE_STRIP); // Z+ glTexCoord2f(0, s); glVertex3f( t,-t, t); glTexCoord2f(s, s); glVertex3f(-t,-t, t); glTexCoord2f(0, 0); glVertex3f( t, t, t); glTexCoord2f(s, 0); glVertex3f(-t, t, t); glEnd(); glDepthMask(GL_TRUE); }
//------------------------------------------- void ofxAssimpModelLoader::draw(ofPolyRenderMode renderType) { if(scene == NULL) { return; } ofPushStyle(); if(!ofGetGLProgrammableRenderer()){ #ifndef TARGET_OPENGLES glPushAttrib(GL_ALL_ATTRIB_BITS); glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); glPolygonMode(GL_FRONT_AND_BACK, ofGetGLPolyMode(renderType)); #endif glEnable(GL_NORMALIZE); } ofPushMatrix(); ofMultMatrix(modelMatrix); for(unsigned int i=0; i<modelMeshes.size(); i++) { ofxAssimpMeshHelper & mesh = modelMeshes[i]; ofPushMatrix(); ofMultMatrix(mesh.matrix); if(bUsingTextures){ if(mesh.hasTexture()) { ofTexture * tex = mesh.getTexturePtr(); if(tex->isAllocated()) { tex->bind(); } } } if(bUsingMaterials){ mesh.material.begin(); } if(mesh.twoSided) { glEnable(GL_CULL_FACE); } else { glDisable(GL_CULL_FACE); } ofEnableBlendMode(mesh.blendMode); #ifndef TARGET_OPENGLES mesh.vbo.drawElements(GL_TRIANGLES,mesh.indices.size()); #else switch(renderType){ case OF_MESH_FILL: mesh.vbo.drawElements(GL_TRIANGLES,mesh.indices.size()); break; case OF_MESH_WIREFRAME: mesh.vbo.drawElements(GL_LINES,mesh.indices.size()); break; case OF_MESH_POINTS: mesh.vbo.drawElements(GL_POINTS,mesh.indices.size()); break; } #endif if(bUsingTextures){ if(mesh.hasTexture()) { ofTexture * tex = mesh.getTexturePtr(); if(tex->isAllocated()) { tex->unbind(); } } } if(bUsingMaterials){ mesh.material.end(); } ofPopMatrix(); } ofPopMatrix(); if(!ofGetGLProgrammableRenderer()){ #ifndef TARGET_OPENGLES glPopClientAttrib(); glPopAttrib(); #endif } ofPopStyle(); }
/* This is called twice from space_graph.c -> graph_main_area_draw() * Unselected then selected F-Curves are drawn so that they do not occlude each other. */ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid *grid, short sel) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; /* build list of curves to draw */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE); filter |= ((sel) ? (ANIMFILTER_SEL) : (ANIMFILTER_UNSEL)); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* for each curve: * draw curve, then handle-lines, and finally vertices in this order so that * the data will be layered correctly */ for (ale = anim_data.first; ale; ale = ale->next) { FCurve *fcu = (FCurve *)ale->key_data; FModifier *fcm = find_active_fmodifier(&fcu->modifiers); AnimData *adt = ANIM_nla_mapping_get(ac, ale); /* map keyframes for drawing if scaled F-Curve */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0); /* draw curve: * - curve line may be result of one or more destructive modifiers or just the raw data, * so we need to check which method should be used * - controls from active modifier take precedence over keyframes * (XXX! editing tools need to take this into account!) */ /* 1) draw curve line */ { /* set color/drawing style for curve itself */ if ( ((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) || (fcu->flag & FCURVE_PROTECTED) ) { /* protected curves (non editable) are drawn with dotted lines */ setlinestyle(2); } if ( ((fcu->grp) && (fcu->grp->flag & AGRP_MUTED)) || (fcu->flag & FCURVE_MUTED) ) { /* muted curves are drawn in a grayish hue */ // XXX should we have some variations? UI_ThemeColorShade(TH_HEADER, 50); } else { /* set whatever color the curve has set * - unselected curves draw less opaque to help distinguish the selected ones */ glColor4f(fcu->color[0], fcu->color[1], fcu->color[2], fcurve_display_alpha(fcu)); } /* draw active F-Curve thicker than the rest to make it stand out */ if (fcu->flag & FCURVE_ACTIVE) { glLineWidth(2.0); } /* anti-aliased lines for less jagged appearance */ if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); /* draw F-Curve */ if ((fcu->modifiers.first) || (fcu->flag & FCURVE_INT_VALUES)) { /* draw a curve affected by modifiers or only allowed to have integer values * by sampling it at various small-intervals over the visible region */ draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid); } else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) { /* just draw curve based on defined data (i.e. no modifiers) */ if (fcu->bezt) draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d); else if (fcu->fpt) draw_fcurve_curve_samples(ac, ale->id, fcu, &ar->v2d); } /* restore settings */ setlinestyle(0); glLineWidth(1.0); if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) glDisable(GL_LINE_SMOOTH); glDisable(GL_BLEND); } /* 2) draw handles and vertices as appropriate based on active * - if the option to only show controls if the F-Curve is selected is enabled, we must obey this */ if (!(sipo->flag & SIPO_SELCUVERTSONLY) || (fcu->flag & FCURVE_SELECTED)) { if (fcurve_are_keyframes_usable(fcu) == 0) { /* only draw controls if this is the active modifier */ if ((fcu->flag & FCURVE_ACTIVE) && (fcm)) { switch (fcm->type) { case FMODIFIER_TYPE_ENVELOPE: /* envelope */ draw_fcurve_modifier_controls_envelope(fcm, &ar->v2d); break; } } } else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) { /* apply unit mapping */ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, fcu, 0); if (fcu->bezt) { int do_handles = draw_fcurve_handles_check(sipo, fcu); if (do_handles) { /* only draw handles/vertices on keyframes */ glEnable(GL_BLEND); draw_fcurve_handles(sipo, fcu); glDisable(GL_BLEND); } draw_fcurve_vertices(sipo, ar, fcu, do_handles, (sipo->flag & SIPO_SELVHANDLESONLY)); } else { /* samples: only draw two indicators at either end as indicators */ draw_fcurve_samples(sipo, ar, fcu); } /* unapply unit mapping */ ANIM_unit_mapping_apply_fcurve(ac->scene, ale->id, fcu, ANIM_UNITCONV_RESTORE); } } /* undo mapping of keyframes for drawing if scaled F-Curve */ if (adt) ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0); } /* free list of curves */ BLI_freelistN(&anim_data); }
static void time_draw_cache(SpaceTime *stime, Object *ob) { PTCacheID *pid; ListBase pidlist; SpaceTimeCache *stc = stime->caches.first; float yoffs = 0.f; if (!(stime->cache_display & TIME_CACHE_DISPLAY) || (!ob)) return; BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0); /* iterate over pointcaches on the active object, * add spacetimecache and vertex array for each */ for (pid = pidlist.first; pid; pid = pid->next) { float col[4], *fp; int i, sta = pid->cache->startframe, end = pid->cache->endframe; int len = (end - sta + 1) * 4; switch (pid->type) { case PTCACHE_TYPE_SOFTBODY: if (!(stime->cache_display & TIME_CACHE_SOFTBODY)) continue; break; case PTCACHE_TYPE_PARTICLES: if (!(stime->cache_display & TIME_CACHE_PARTICLES)) continue; break; case PTCACHE_TYPE_CLOTH: if (!(stime->cache_display & TIME_CACHE_CLOTH)) continue; break; case PTCACHE_TYPE_SMOKE_DOMAIN: case PTCACHE_TYPE_SMOKE_HIGHRES: if (!(stime->cache_display & TIME_CACHE_SMOKE)) continue; break; case PTCACHE_TYPE_DYNAMICPAINT: if (!(stime->cache_display & TIME_CACHE_DYNAMICPAINT)) continue; break; } if (pid->cache->cached_frames == NULL) continue; /* make sure we have stc with correct array length */ if (stc == NULL || MEM_allocN_len(stc->array) != len * 2 * sizeof(float)) { if (stc) { MEM_freeN(stc->array); } else { stc = MEM_callocN(sizeof(SpaceTimeCache), "spacetimecache"); BLI_addtail(&stime->caches, stc); } stc->array = MEM_callocN(len * 2 * sizeof(float), "SpaceTimeCache array"); } /* fill the vertex array with a quad for each cached frame */ for (i = sta, fp = stc->array; i <= end; i++) { if (pid->cache->cached_frames[i - sta]) { fp[0] = (float)i - 0.5f; fp[1] = 0.0; fp += 2; fp[0] = (float)i - 0.5f; fp[1] = 1.0; fp += 2; fp[0] = (float)i + 0.5f; fp[1] = 1.0; fp += 2; fp[0] = (float)i + 0.5f; fp[1] = 0.0; fp += 2; } } glPushMatrix(); glTranslatef(0.0, (float)V2D_SCROLL_HEIGHT + yoffs, 0.0); glScalef(1.0, CACHE_DRAW_HEIGHT, 0.0); switch (pid->type) { case PTCACHE_TYPE_SOFTBODY: col[0] = 1.0; col[1] = 0.4; col[2] = 0.02; col[3] = 0.1; break; case PTCACHE_TYPE_PARTICLES: col[0] = 1.0; col[1] = 0.1; col[2] = 0.02; col[3] = 0.1; break; case PTCACHE_TYPE_CLOTH: col[0] = 0.1; col[1] = 0.1; col[2] = 0.75; col[3] = 0.1; break; case PTCACHE_TYPE_SMOKE_DOMAIN: case PTCACHE_TYPE_SMOKE_HIGHRES: col[0] = 0.2; col[1] = 0.2; col[2] = 0.2; col[3] = 0.1; break; case PTCACHE_TYPE_DYNAMICPAINT: col[0] = 1.0; col[1] = 0.1; col[2] = 0.75; col[3] = 0.1; break; default: BLI_assert(0); col[0] = 1.0; col[1] = 0.0; col[2] = 1.0; col[3] = 0.1; } glColor4fv(col); glEnable(GL_BLEND); glRectf((float)sta, 0.0, (float)end, 1.0); col[3] = 0.4f; if (pid->cache->flag & PTCACHE_BAKED) { col[0] -= 0.4f; col[1] -= 0.4f; col[2] -= 0.4f; } else if (pid->cache->flag & PTCACHE_OUTDATED) { col[0] += 0.4f; col[1] += 0.4f; col[2] += 0.4f; } glColor4fv(col); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, stc->array); glDrawArrays(GL_QUADS, 0, (fp - stc->array) / 2); glDisableClientState(GL_VERTEX_ARRAY); glDisable(GL_BLEND); glPopMatrix(); yoffs += CACHE_DRAW_HEIGHT; stc = stc->next; } BLI_freelistN(&pidlist); /* free excessive caches */ while (stc) { SpaceTimeCache *tmp = stc->next; BLI_remlink(&stime->caches, stc); MEM_freeN(stc->array); MEM_freeN(stc); stc = tmp; } }
void init(void) { glClearColor(0.0, 0.0, 0.0, 0.0); glOrtho (-50, 50, -50, 50, -50 , 50); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); }
void EDA_3D_CANVAS::create_and_render_shadow_buffer( GLuint *aDst_gl_texture, GLuint aTexture_size, bool aDraw_body, int aBlurPasses ) { glDisable( GL_TEXTURE_2D ); glViewport( 0, 0, aTexture_size, aTexture_size); glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Render body and shapes if( aDraw_body && m_glLists[GL_ID_BODY] ) glCallList( m_glLists[GL_ID_BODY] ); if( m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] ) glCallList( m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] ); // Create and Initialize the float depth buffer float *depthbufferFloat = (float*) malloc( aTexture_size * aTexture_size * sizeof(float) ); for( unsigned int i = 0; i < (aTexture_size * aTexture_size); i++ ) depthbufferFloat[i] = 1.0f; glPixelStorei( GL_PACK_ALIGNMENT, 4 ); glPixelStorei( GL_UNPACK_ALIGNMENT, 4 ); glReadBuffer( GL_BACK_LEFT ); glReadPixels( 0, 0, aTexture_size, aTexture_size, GL_DEPTH_COMPONENT, GL_FLOAT, depthbufferFloat ); CheckGLError( __FILE__, __LINE__ ); glEnable( GL_TEXTURE_2D ); glGenTextures( 1, aDst_gl_texture ); glBindTexture( GL_TEXTURE_2D, *aDst_gl_texture ); CIMAGE imgDepthBuffer( aTexture_size, aTexture_size ); CIMAGE imgDepthBufferAux( aTexture_size, aTexture_size ); imgDepthBuffer.SetPixelsFromNormalizedFloat( depthbufferFloat ); free( depthbufferFloat ); // Debug texture image //wxString filename; //filename.Printf( "imgDepthBuffer_%04d", *aDst_gl_texture ); //imgDepthBuffer.SaveAsPNG( filename ); while( aBlurPasses > 0 ) { aBlurPasses--; imgDepthBufferAux.EfxFilter( &imgDepthBuffer, FILTER_GAUSSIAN_BLUR ); imgDepthBuffer.EfxFilter( &imgDepthBufferAux, FILTER_GAUSSIAN_BLUR ); } // Debug texture image //filename.Printf( "imgDepthBuffer_blur%04d", *aDst_gl_texture ); //imgDepthBuffer.SaveAsPNG( filename ); unsigned char *depthbufferRGBA = (unsigned char*) malloc( aTexture_size * aTexture_size * 4 ); unsigned char *pPixels = imgDepthBuffer.GetBuffer(); // Convert it to a RGBA buffer for( unsigned int i = 0; i < (aTexture_size * aTexture_size); i++ ) { depthbufferRGBA[i * 4 + 0] = 0; depthbufferRGBA[i * 4 + 1] = 0; depthbufferRGBA[i * 4 + 2] = 0; depthbufferRGBA[i * 4 + 3] = 255 - pPixels[i]; // Store in alpha channel the inversion of the image } glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, aTexture_size, aTexture_size, 0, GL_RGBA, GL_UNSIGNED_BYTE, depthbufferRGBA ); free( depthbufferRGBA ); CheckGLError( __FILE__, __LINE__ ); }
void EDA_3D_CANVAS::Redraw() { // SwapBuffer requires the window to be shown before calling if( !IsShownOnScreen() ) return; wxString err_messages; WX_STRING_REPORTER errorReporter( &err_messages ); STATUS_TEXT_REPORTER activityReporter( Parent(), 0 ); // Display build time at the end of build unsigned strtime = GetRunningMicroSecs(); SetCurrent( *m_glRC ); // Set the OpenGL viewport according to the client size of this canvas. // This is done here rather than in a wxSizeEvent handler because our // OpenGL rendering context (and thus viewport setting) is used with // multiple canvases: If we updated the viewport in the wxSizeEvent // handler, changing the size of one canvas causes a viewport setting that // is wrong when next another canvas is repainted. wxSize size = GetClientSize(); InitGL(); if( isRealisticMode() && isEnabled( FL_RENDER_SHADOWS ) ) { generateFakeShadowsTextures( &errorReporter, &activityReporter ); } // *MUST* be called *after* SetCurrent( ): glViewport( 0, 0, size.x, size.y ); // clear color and depth buffers glClearColor( 0.95, 0.95, 1.0, 1.0 ); glClearStencil( 0 ); glClearDepth( 1.0 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); glShadeModel( GL_SMOOTH ); // Draw background glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glDisable( GL_LIGHTING ); glDisable( GL_COLOR_MATERIAL ); glDisable( GL_DEPTH_TEST ); glDisable( GL_TEXTURE_2D ); // Draw the background ( rectangle with color gradient) glBegin( GL_QUADS ); SetGLColor( GetPrm3DVisu().m_BgColor_Top, 1.0 ); glVertex2f( -1.0, 1.0 ); // Top left corner SetGLColor( GetPrm3DVisu().m_BgColor, 1.0 ); glVertex2f( -1.0,-1.0 ); // bottom left corner glVertex2f( 1.0,-1.0 ); // bottom right corner SetGLColor( GetPrm3DVisu().m_BgColor_Top, 1.0 ); glVertex2f( 1.0, 1.0 ); // top right corner glEnd(); glEnable( GL_DEPTH_TEST ); // set viewing projection glMatrixMode( GL_PROJECTION ); glLoadIdentity(); #define MAX_VIEW_ANGLE 160.0 / 45.0 if( GetPrm3DVisu().m_Zoom > MAX_VIEW_ANGLE ) GetPrm3DVisu().m_Zoom = MAX_VIEW_ANGLE; if( Parent()->ModeIsOrtho() ) { // OrthoReductionFactor is chosen to provide roughly the same size as // Perspective View const double orthoReductionFactor = 400 / GetPrm3DVisu().m_Zoom; // Initialize Projection Matrix for Ortographic View glOrtho( -size.x / orthoReductionFactor, size.x / orthoReductionFactor, -size.y / orthoReductionFactor, size.y / orthoReductionFactor, 1, 100 ); } else { // Ratio width / height of the window display double ratio_HV = (double) size.x / size.y; // Initialize Projection Matrix for Perspective View gluPerspective( 45.0f * GetPrm3DVisu().m_Zoom, ratio_HV, 1, 100 ); } // position viewer glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0.0f, 0.0f, -(m_ZBottom + m_ZTop) / 2.0f ); // Setup light sources: SetLights(); CheckGLError( __FILE__, __LINE__ ); glMatrixMode( GL_MODELVIEW ); // position viewer // transformations GLfloat mat[4][4]; // Translate motion first, so rotations don't mess up the orientation... glTranslatef( m_draw3dOffset.x, m_draw3dOffset.y, 0.0F ); build_rotmatrix( mat, GetPrm3DVisu().m_Quat ); glMultMatrixf( &mat[0][0] ); glRotatef( GetPrm3DVisu().m_Rot[0], 1.0, 0.0, 0.0 ); glRotatef( GetPrm3DVisu().m_Rot[1], 0.0, 1.0, 0.0 ); glRotatef( GetPrm3DVisu().m_Rot[2], 0.0, 0.0, 1.0 ); if( ! m_glLists[GL_ID_BOARD] || ! m_glLists[GL_ID_TECH_LAYERS] ) CreateDrawGL_List( &errorReporter, &activityReporter ); if( isEnabled( FL_AXIS ) && m_glLists[GL_ID_AXIS] ) glCallList( m_glLists[GL_ID_AXIS] ); // move the board in order to draw it with its center at 0,0 3D coordinates glTranslatef( -GetPrm3DVisu().m_BoardPos.x * GetPrm3DVisu().m_BiuTo3Dunits, -GetPrm3DVisu().m_BoardPos.y * GetPrm3DVisu().m_BiuTo3Dunits, 0.0f ); if( isEnabled( FL_MODULE ) ) { if( ! m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] ) CreateDrawGL_List( &errorReporter, &activityReporter ); } glEnable( GL_LIGHTING ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); if( isRealisticMode() && isEnabled( FL_RENDER_TEXTURES ) ) glEnable( GL_TEXTURE_2D ); else glDisable( GL_TEXTURE_2D ); // Set material for the board glEnable( GL_COLOR_MATERIAL ); SetOpenGlDefaultMaterial(); //glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, FALSE ); // Board Body GLint shininess_value = 32; glMateriali( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value ); if( isEnabled( FL_SHOW_BOARD_BODY ) ) { if( m_glLists[GL_ID_BODY] ) { glCallList( m_glLists[GL_ID_BODY] ); } } // Board // specify material parameters for the lighting model. shininess_value = 52; glMateriali( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value ); glm::vec4 specular( GetPrm3DVisu().m_CopperColor.m_Red * 0.20f, GetPrm3DVisu().m_CopperColor.m_Green * 0.20f, GetPrm3DVisu().m_CopperColor.m_Blue * 0.20f, 1.0f ); glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.x ); if( m_glLists[GL_ID_BOARD] ) { glCallList( m_glLists[GL_ID_BOARD] ); } // Tech layers shininess_value = 32; glMateriali( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value ); glm::vec4 specularTech( 0.0f, 0.0f, 0.0f, 1.0f ); glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specularTech.x ); if( m_glLists[GL_ID_TECH_LAYERS] ) { glCallList( m_glLists[GL_ID_TECH_LAYERS] ); } if( isEnabled( FL_COMMENTS ) || isEnabled( FL_ECO ) ) { if( ! m_glLists[GL_ID_AUX_LAYERS] ) CreateDrawGL_List( &errorReporter, &activityReporter ); glCallList( m_glLists[GL_ID_AUX_LAYERS] ); } //glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, TRUE ); // Draw Component Shadow if( isEnabled( FL_MODULE ) && isRealisticMode() && isEnabled( FL_RENDER_SHADOWS ) ) { glEnable( GL_CULL_FACE ); glDisable( GL_DEPTH_TEST ); glEnable( GL_COLOR_MATERIAL ) ; SetOpenGlDefaultMaterial(); glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); glEnable( GL_TEXTURE_2D ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); if( m_glLists[GL_ID_SHADOW_FRONT] ) { glBindTexture( GL_TEXTURE_2D, m_text_fake_shadow_front ); glCallList( m_glLists[GL_ID_SHADOW_FRONT] ); } if( m_glLists[GL_ID_SHADOW_BACK] ) { glBindTexture( GL_TEXTURE_2D, m_text_fake_shadow_back ); glCallList( m_glLists[GL_ID_SHADOW_BACK] ); } glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); glEnable( GL_DEPTH_TEST ); glDisable( GL_TEXTURE_2D ); glDisable( GL_CULL_FACE ); } glEnable( GL_COLOR_MATERIAL ); SetOpenGlDefaultMaterial(); glDisable( GL_BLEND ); // Draw Solid Shapes if( isEnabled( FL_MODULE ) ) { if( ! m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] ) CreateDrawGL_List( &errorReporter, &activityReporter ); glCallList( m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] ); } glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); // Grid uses transparency: draw it after all objects if( isEnabled( FL_GRID ) ) { if( ! m_glLists[GL_ID_GRID] ) CreateDrawGL_List( &errorReporter, &activityReporter ); glCallList( m_glLists[GL_ID_GRID] ); } // Draw Board Shadow if( isRealisticMode() && isEnabled( FL_RENDER_SHADOWS ) ) { if( m_glLists[GL_ID_SHADOW_BOARD] ) { glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glColor4f( 1.0, 1.0, 1.0, 0.75f ); glEnable( GL_CULL_FACE ); glDisable( GL_COLOR_MATERIAL ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_text_fake_shadow_board ); glCallList( m_glLists[GL_ID_SHADOW_BOARD] ); glDisable( GL_CULL_FACE ); glDisable( GL_TEXTURE_2D ); } } // This list must be drawn last, because it contains the // transparent gl objects, which should be drawn after all // non transparent objects if( isEnabled( FL_MODULE ) && m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] ) { glEnable( GL_COLOR_MATERIAL ); SetOpenGlDefaultMaterial(); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glCallList( m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] ); } // Debug bounding boxes /* glDisable( GL_BLEND ); glDisable( GL_COLOR_MATERIAL ); glDisable( GL_LIGHTING ); glColor4f( 1.0f, 0.0f, 1.0f, 1.0f ); m_fastAABBox_Shadow.GLdebug(); glColor4f( 0.0f, 1.0f, 1.0f, 1.0f ); m_boardAABBox.GLdebug(); */ SwapBuffers(); // Show calculation time if some activity was reported if( activityReporter.HasMessage() ) { // Calculation time in seconds double calculation_time = (double)( GetRunningMicroSecs() - strtime) / 1e6; activityReporter.Report( wxString::Format( _( "Build time %.3f s" ), calculation_time ) ); } else activityReporter.Report( wxEmptyString ); if( !err_messages.IsEmpty() ) wxLogMessage( err_messages ); }
void GlPolyQuad::draw(float, Camera *) { assert(polyQuadEdges.size() % 2 == 0 && polyQuadEdges.size() > 2 && polyQuadEdgesColors.size() == (polyQuadEdges.size() / 2)); vector<Coord> vertexArray; vector<float> texCoordsArray; vector<Vector<float, 4> >colorsArray; vector<unsigned short> quadIndices; vector<unsigned short> outlineIndices; unsigned int nbSubdivisionsPerSegment = 1; unsigned int nbVertices = polyQuadEdges.size(); vector<Coord> *vertices = &polyQuadEdges; GlShaderProgram *currentShader = GlShaderProgram::getCurrentActiveShader(); if (currentShader != NULL && currentShader->getName() == "fisheye") { nbSubdivisionsPerSegment = 20; vertices = &vertexArray; nbVertices = ((polyQuadEdges.size() / 2) - 1) * nbSubdivisionsPerSegment * 2; vertexArray.reserve(nbVertices); } texCoordsArray.reserve(nbVertices * 2); colorsArray.reserve(nbVertices); quadIndices.reserve(nbVertices); outlineIndices.resize(nbVertices); for (size_t i = 0 ; i < (polyQuadEdges.size() / 2) - 1 ; ++i) { Vector<float, 4> startColor; Vector<float, 4> endColor; startColor[0] = polyQuadEdgesColors[i].getRGL(); startColor[1] = polyQuadEdgesColors[i].getGGL(); startColor[2] = polyQuadEdgesColors[i].getBGL(); startColor[3] = polyQuadEdgesColors[i].getAGL(); endColor[0] = polyQuadEdgesColors[i+1].getRGL(); endColor[1] = polyQuadEdgesColors[i+1].getGGL(); endColor[2] = polyQuadEdgesColors[i+1].getBGL(); endColor[3] = polyQuadEdgesColors[i+1].getAGL(); if (nbSubdivisionsPerSegment == 1) { texCoordsArray.push_back(static_cast<GLfloat>(i)); texCoordsArray.push_back(0.0f); texCoordsArray.push_back(static_cast<GLfloat>(i)); texCoordsArray.push_back(1.0f); colorsArray.push_back(startColor); colorsArray.push_back(startColor); quadIndices.push_back(2*i); quadIndices.push_back(2*i+1); outlineIndices[i] = 2*i; outlineIndices[nbVertices - (i+1)] = 2*i+1; } else { for (unsigned int j = 0 ; j < nbSubdivisionsPerSegment ; ++j) { unsigned int n = i * nbSubdivisionsPerSegment + j; Coord v1 = polyQuadEdges[2*i] + (j / static_cast<float>(nbSubdivisionsPerSegment - 1)) * (polyQuadEdges[2*(i+1)] - polyQuadEdges[2*i]); Coord v2 = polyQuadEdges[2*i+1] + (j / static_cast<float>(nbSubdivisionsPerSegment - 1)) * (polyQuadEdges[2*(i+1)+1] - polyQuadEdges[2*i+1]); vertexArray.push_back(v1); vertexArray.push_back(v2); float texCoordFactor = ((polyQuadEdges[2*i].dist(polyQuadEdges[2*i+2])) / (nbSubdivisionsPerSegment - 1)) / (polyQuadEdges[2*i].dist(polyQuadEdges[2*i+1])); texCoordsArray.push_back(static_cast<GLfloat>(i) + static_cast<GLfloat>(j) * texCoordFactor); texCoordsArray.push_back(0.0f); texCoordsArray.push_back(static_cast<GLfloat>(i) + static_cast<GLfloat>(j) * texCoordFactor); texCoordsArray.push_back(1.0f); Vector<float, 4> color = startColor + (j / static_cast<float>(nbSubdivisionsPerSegment - 1)) * (endColor - startColor); colorsArray.push_back(color); colorsArray.push_back(color); quadIndices.push_back(2*n); quadIndices.push_back(2*n+1); outlineIndices[n] = 2*n; outlineIndices[nbVertices - (n+1)] = 2*n+1; } } if (nbSubdivisionsPerSegment == 1 && i == (polyQuadEdges.size() / 2) - 2) { quadIndices.push_back(2*(i+1)); quadIndices.push_back(2*(i+1)+1); outlineIndices[i+1] = 2*(i+1); outlineIndices[nbVertices - (i+2)] = 2*(i+1)+1; texCoordsArray.push_back(static_cast<GLfloat>(i+1)); texCoordsArray.push_back(0.0f); texCoordsArray.push_back(static_cast<GLfloat>(i+1)); texCoordsArray.push_back(1.0f); colorsArray.push_back(endColor); colorsArray.push_back(endColor); } } outlineIndices.push_back(0); if (textureName != "") { GlTextureManager::getInst().activateTexture(textureName); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); } glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(3, GL_FLOAT, 3 * sizeof(float), &((*vertices)[0][0])); glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(float), &texCoordsArray[0]); glColorPointer(4, GL_FLOAT, 4 * sizeof(float), &colorsArray[0][0]); if (nbSubdivisionsPerSegment > 1) { glDrawElements(GL_QUAD_STRIP, vertexArray.size(), GL_UNSIGNED_SHORT, &quadIndices[0]); } else { glDrawElements(GL_QUAD_STRIP, polyQuadEdges.size(), GL_UNSIGNED_SHORT, &quadIndices[0]); } glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); if (textureName != "") { GlTextureManager::getInst().desactivateTexture(); } if (outlined) { glLineWidth(outlineWidth); setMaterial(outlineColor); if (nbSubdivisionsPerSegment > 1) { glDrawElements(GL_LINE_LOOP, vertexArray.size(), GL_UNSIGNED_SHORT, &outlineIndices[0]); } else { glDrawElements(GL_LINE_LOOP, polyQuadEdges.size(), GL_UNSIGNED_SHORT, &outlineIndices[0]); } if (outlineWidth != 1) { glLineWidth(1); } } glDisableClientState(GL_VERTEX_ARRAY); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); }
static int display_manufacture_handler(window_info *win) { Uint8 str[80]; int i; //dirty hack for opacity //if manufacture_win is opaque then recipe_win should be and viceversa if (recipes_shown) win->opaque=windows_list.window[recipe_win].opaque; else windows_list.window[recipe_win].opaque=win->opaque; glColor3f(0.77f,0.57f,0.39f); glEnable(GL_TEXTURE_2D); glColor3f(1.0f,1.0f,1.0f); //ok, now let's draw the objects... for(i=35;i>=0;i--){ if(manufacture_list[i].quantity > 0) { int x_start,y_start; //get the x and y x_start=SLOT_SIZE*(i%12)+1; y_start=SLOT_SIZE*(i/12); draw_item(manufacture_list[i].image_id,x_start,y_start,SLOT_SIZE); safe_snprintf((char *)str, sizeof(str), "%i",manufacture_list[i].quantity); draw_string_small_shadowed(x_start, (i&1)?(y_start+17):(y_start+7), (unsigned char*)str, 1,1.0f,1.0f,1.0f, 0.0f, 0.0f, 0.0f); } } //ok, now let's draw the mixed objects draw_production_pipe(2,manufacture_menu_y_len-37, -1); //now, draw the inventory text, if any. if (last_items_string_id != inventory_item_string_id) { put_small_text_in_box((unsigned char*)inventory_item_string, strlen(inventory_item_string), win->len_x-8, items_string); last_items_string_id = inventory_item_string_id; } draw_string_small(4,manufacture_menu_y_len-85,(unsigned char *)items_string,4); // Render the grid *after* the images. It seems impossible to code // it such that images are rendered exactly within the boxes on all // cards glDisable(GL_TEXTURE_2D); glColor3f(0.77f,0.57f,0.39f); //draw the grid rendergrid(12,3,0,0,SLOT_SIZE,SLOT_SIZE); //Draw the bottom grid - NOT NEEDED, DONE IN draw_production_pipe //rendergrid(NUM_MIX_SLOTS,1,0, manufacture_menu_y_len-37, SLOT_SIZE, SLOT_SIZE); //Draw recipe control buttons draw_recipe_controls(); glEnable(GL_TEXTURE_2D); #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE return 1; }
void YuiSwapBuffers(void) { int buf_width, buf_height; int error; pthread_mutex_lock(&g_mtxGlLock); if( g_Display == EGL_NO_DISPLAY ) { pthread_mutex_unlock(&g_mtxGlLock); return; } if( eglMakeCurrent(g_Display,g_Surface,g_Surface,g_Context) == EGL_FALSE ) { printf( "eglMakeCurrent fail %04x",eglGetError()); pthread_mutex_unlock(&g_mtxGlLock); return; } glClearColor( 0.0f,0.0f,0.0f,1.0f); glClear(GL_COLOR_BUFFER_BIT); if( g_FrameBuffer == 0 ) { glEnable(GL_TEXTURE_2D); glGenTextures(1,&g_FrameBuffer); glBindTexture(GL_TEXTURE_2D, g_FrameBuffer); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); error = glGetError(); if( error != GL_NO_ERROR ) { printf("gl error %d", error ); return; } }else{ glBindTexture(GL_TEXTURE_2D, g_FrameBuffer); } VIDCore->GetGlSize(&buf_width, &buf_height); glTexSubImage2D(GL_TEXTURE_2D, 0,0,0,buf_width,buf_height,GL_RGBA,GL_UNSIGNED_BYTE,dispbuffer); if( g_VertexBuffer == 0 ) { glGenBuffers(1, &g_VertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, g_VertexBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),vertices,GL_STATIC_DRAW); error = glGetError(); if( error != GL_NO_ERROR ) { printf("gl error %d", error ); return; } }else{ glBindBuffer(GL_ARRAY_BUFFER, g_VertexBuffer); } if( buf_width != g_buf_width || buf_height != g_buf_height ) { vertices[6]=vertices[10]=(float)buf_width/1024.f; vertices[11]=vertices[15]=(float)buf_height/1024.f; glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),vertices,GL_STATIC_DRAW); glVertexPointer(2, GL_FLOAT, sizeof(float)*4, 0); glTexCoordPointer(2, GL_FLOAT, sizeof(float)*4, (void*)(sizeof(float)*2)); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); g_buf_width = buf_width; g_buf_height = buf_height; } glDrawArrays(GL_TRIANGLE_FAN, 0, 4); eglSwapBuffers(g_Display,g_Surface); pthread_mutex_unlock(&g_mtxGlLock); }
void myInit(void) { /* glGetIntegerv(GL_MAX_CLIP_PLANES, nest); printf("GL_MAX_CLIP_PLANES are %d \n", nest[0]); */ /*%%%%%%%% Initialize Positional Light and Ambient Light %%%%%%%%*/ #if 0 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); #endif #if 0 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmb); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiff); glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpec); glEnable(GL_LIGHT0); #endif /*** Initial light position is declared in the display function ***/ glLightfv(GL_LIGHT1, GL_AMBIENT, light1Amb); glLightfv(GL_LIGHT1, GL_DIFFUSE, light1Diff); glLightfv(GL_LIGHT1, GL_SPECULAR, light1Spec); glEnable(GL_LIGHT1); glEnable(GL_LIGHTING); /* glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.7);*/ /* glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.04);*/ /* use 0.04 w/ 24 bit color */ glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.07); /* try 0.07 w/ 24 bit color */ /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ /*########### Initialize Fog ##################*/ /* { GLfloat fog_color[] = {0.5, 0.5, 0.5, 1.0}; GLfloat fog_start[] = {0.0, 0.0, 1.0, 20.0}; glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_LINEAR); glFogfv(GL_FOG_COLOR, fog_color); glFogf(GL_FOG_DENSITY, 0.35); glFogfv(GL_FOG_START, fog_start); glHint(GL_FOG_HINT, GL_FASTEST); } */ /*##########################################*/ /*....Shadow Matrices For Floor, Left Wall, Back Wall, and Right Wall......*/ /* For light0 */ myShadowMatrix(groundPlane, lightPos, shadowMat_ground); myShadowMatrix(leftPlane, lightPos, shadowMat_left); myShadowMatrix(columnPlane, lightPos, shadowMat_column); myShadowMatrix(backPlane, lightPos, shadowMat_back); myShadowMatrix(rightPlane, lightPos, shadowMat_right); /* For light1 */ myShadowMatrix(groundPlane, light1Pos, shadowMat1_ground); myShadowMatrix(leftPlane, light1Pos, shadowMat1_left); myShadowMatrix(backPlane, light1Pos, shadowMat1_back); myShadowMatrix(rightPlane, light1Pos, shadowMat1_right); /*.......................................................................*/ /*sssssssssssssssss Make Satellite Body and Shadow ssssssssssssssssssssssss*/ glNewList(satellite1, GL_COMPILE); glPushMatrix(); drawSatellite(satellite_diffuse, satellite_ambient, satellite_specular, satellite_shiny); glPopMatrix(); glEndList(); glNewList(satellite2, GL_COMPILE); glPushMatrix(); drawSatellite(shadow_diffuse, shadow_ambient, shadow_specular, shadow_shiny); glPopMatrix(); glEndList(); /*sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss*/ /*ppppppppppppppppppppppppppp Make Solar Panels and Shadows pppppppppppppppppp*/ glNewList(panel1, GL_COMPILE); glPushMatrix(); drawPanels(panel_color, panel_ambient); glPopMatrix(); glEndList(); glNewList(panel2, GL_COMPILE); glPushMatrix(); drawPanels(shadow_diffuse, shadow_ambient); glPopMatrix(); glEndList(); /*pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp*/ /*========= Make Floor ==============*/ glNewList(ground, GL_COMPILE); glPushMatrix(); glPushAttrib(GL_LIGHTING_BIT); glMaterialfv(GL_FRONT, GL_DIFFUSE, floor_color); glMaterialfv(GL_FRONT, GL_AMBIENT, shadow_ambient); glTranslatef(0.0, -1.5, -5.0); glRotatef(-90.0, 1, 0, 0); glScalef(5.0, 5.0, 1.0); drawGround(); /* draw ground */ glPopAttrib(); glPopMatrix(); glEndList(); /*==================================*/ /*@@@@@@@@@@ Make Lamp Post and Lamp @@@@@@@@@@@@*/ glNewList(21, GL_COMPILE); glPushMatrix(); glPushAttrib(GL_LIGHTING_BIT); glMaterialfv(GL_FRONT, GL_AMBIENT, lamp_post_specular); glTranslatef(0.0, -0.1, -5.0); glScalef(0.07, 1.45, 0.07); drawCube(lamp_post_diffuse, lamp_post_ambient); /* draw lamp post */ glPopAttrib(); glPopMatrix(); glPushMatrix(); glTranslatef(0.0, -1.45, -5.0); glScalef(0.3, 0.05, 0.3); drawCube(wall_color, cube_ambient); /* draw lamp post base */ glPopMatrix(); glEndList(); glNewList(22, GL_COMPILE); glPushMatrix(); glPushAttrib(GL_LIGHTING_BIT); glMaterialfv(GL_FRONT, GL_AMBIENT, lamp_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, lamp_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, lamp_specular); glTranslatef(0.0, 1.6, -5.0); glutSolidSphere(0.3, 20.0, 20.0); /* draw lamp */ glPopAttrib(); glPopMatrix(); glEndList(); /*** Lamp post base shadow ***/ glNewList(501, GL_COMPILE); glPushMatrix(); glPushAttrib(GL_LIGHTING_BIT); glMaterialfv(GL_FRONT, GL_AMBIENT, shadow_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, shadow_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, shadow_specular); glMaterialfv(GL_FRONT, GL_SHININESS, shadow_shiny); glTranslatef(0.0, -1.49, -5.0); glRotatef(-90.0, 1.0, 0.0, 0.0); glScalef(0.7, 0.7, 1.0); drawOct(); glPopAttrib(); glPopMatrix(); glEndList(); /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ /*||||||||||| Make Left Wall |||||||||||||*/ glNewList(left_wall, GL_COMPILE); glPushMatrix(); glPushAttrib(GL_LIGHTING_BIT); glMaterialfv(GL_FRONT, GL_DIFFUSE, wall_color); glMaterialfv(GL_FRONT, GL_AMBIENT, wall_ambient); glTranslatef(0.0, -1.5, 0.0); glTranslatef(0.0, 1.2, 0.0); glTranslatef(0.0, 0.0, -5.0); glTranslatef(-5.0, 0.0, 0.0); glRotatef(90.0, 0, 1, 0); glScalef(4.5, 1.2, 1.0); glNormal3f (0.0, 0.0, 1.0); drawGround(); /* draw left wall */ glPopAttrib(); glPopMatrix(); glEndList(); /*||||||||||||||||||||||||||||||||||||||||*/ /*\\\\\\\\\\\\\ Make Right Wall \\\\\\\\\\\\\\\\\\\*/ glNewList(right_wall, GL_COMPILE); glPushMatrix(); glPushAttrib(GL_LIGHTING_BIT); glMaterialfv(GL_FRONT, GL_DIFFUSE, wall_color); glMaterialfv(GL_FRONT, GL_AMBIENT, wall_ambient); glTranslatef(0.0, -1.5, 0.0); glTranslatef(0.0, 1.2, 0.0); glTranslatef(0.0, 0.0, -5.0); glTranslatef(5.0, 0.0, 0.0); glRotatef(270.0, 0, 1, 0); glScalef(4.5, 1.2, 1.0); glNormal3f (0.0, 0.0, 1.0); drawGround(); /* draw right wall */ glPopAttrib(); glPopMatrix(); glEndList(); /*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/ /*[[[[[[[[[[[ Build Columns ]]]]]]]]]]]*/ glPushMatrix(); glNewList(1, GL_COMPILE); glPushMatrix(); glScalef(0.4, 1.4, 0.4); drawCube(column_color, column_ambient); /* draw column1 */ glPopMatrix(); glEndList(); glNewList(2, GL_COMPILE); glPushMatrix(); glTranslatef(0.0, -1.45, 0.0); glScalef(0.5, 0.1, 0.5); drawCube(wall_color, cube_ambient); /* draw base */ glPopMatrix(); glPushMatrix(); glTranslatef(0.0, 1.45, 0.0); glScalef(0.5, 0.1, 0.5); drawCube(wall_color, cube_ambient); /* draw top */ glPopMatrix(); glEndList(); glPopMatrix(); glNewList(column, GL_COMPILE); glPushMatrix(); glCallList(1); glCallList(2); glPopMatrix(); glEndList(); /***** Place columns at front of scene. *****/ glNewList(4, GL_COMPILE); glPushMatrix(); glTranslatef(-5.0, 0.0, -0.5); glCallList(column); glPopMatrix(); glEndList(); glNewList(5, GL_COMPILE); glPushMatrix(); glTranslatef(-1.75, 0.0, -0.5); glCallList(column); glPopMatrix(); glEndList(); glNewList(6, GL_COMPILE); glPushMatrix(); glTranslatef(1.75, 0.0, -0.5); glCallList(column); glPopMatrix(); glEndList(); glNewList(17, GL_COMPILE); glPushMatrix(); glTranslatef(5.0, 0.0, -0.5); glCallList(column); glPopMatrix(); glEndList(); /*** Get the modelview matrix once ***/ glPushMatrix(); glRotatef(-mvr_d, mvr_x, mvr_y, mvr_z); glTranslatef(-mvt_x, -mvt_y, -mvt_z); glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *) four_columnsXform); glPopMatrix(); glNewList(four_columns, GL_COMPILE); glPushMatrix(); glCallList(4); glCallList(5); glCallList(6); glCallList(17); glPopMatrix(); glEndList(); /***** Make two columns for sides of scene *****/ glNewList(two_columns, GL_COMPILE); glPushMatrix(); glRotatef(90.0, 0.0, 1.0, 0.0); glTranslatef(5.0, 0.0, -5.0); glPushMatrix(); glTranslatef(0.0, 0.0, -0.3); glCallList(column); glPopMatrix(); glPushMatrix(); glTranslatef(0.0, 0.0, 10.3); glCallList(column); glPopMatrix(); glPopMatrix(); glEndList(); /*[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]*/ /* .......................Make shadows .........................*/ glPushMatrix(); glNewList(8, GL_COMPILE); glPushMatrix(); glScalef(0.4, 1.4, 0.4); drawCube(shadow_diffuse, shadow_ambient); /* draw column1 */ glPopMatrix(); glEndList(); glNewList(9, GL_COMPILE); glPushMatrix(); glTranslatef(0.0, -1.45, 0.0); glScalef(0.5, 0.1, 0.5); drawCube(shadow_diffuse, shadow_ambient); /* draw base. */ glPopMatrix(); glPushMatrix(); glTranslatef(0.0, 1.45, 0.0); glScalef(0.5, 0.1, 0.5); drawCube(shadow_diffuse, shadow_ambient); /* draw top. */ glPopMatrix(); glEndList(); glPopMatrix(); glNewList(10, GL_COMPILE); glPushMatrix(); glCallList(8); glCallList(9); glPopMatrix(); glEndList(); glNewList(11, GL_COMPILE); glPushMatrix(); glTranslatef(-5.0, 0.0, -0.5); glCallList(10); glPopMatrix(); glEndList(); glNewList(12, GL_COMPILE); glPushMatrix(); glTranslatef(-1.75, 0.0, -0.5); glCallList(10); glPopMatrix(); glEndList(); glNewList(13, GL_COMPILE); glPushMatrix(); glTranslatef(1.75, 0.0, -0.5 ); glCallList(10); glPopMatrix(); glEndList(); glNewList(14, GL_COMPILE); glPushMatrix(); glTranslatef(5.0, 0.0, -0.5 ); glCallList(10); glPopMatrix(); glEndList(); glNewList(15, GL_COMPILE); glPushMatrix(); glCallList(11); glCallList(12); glCallList(13); glCallList(14); glPopMatrix(); glEndList(); glNewList(100, GL_COMPILE); glPushMatrix(); glMultMatrixf((const GLfloat *) shadowMat_ground); glTranslatef(-mvt_x, -mvt_y, -mvt_z); /* correct for modelview matrix */ glRotatef(-mvr_d, mvr_x, mvr_y, mvr_z); glMultMatrixf((const GLfloat *) four_columnsXform); glCallList(15); glPopMatrix(); glEndList(); glNewList(101, GL_COMPILE); glPushMatrix(); glMultMatrixf((const GLfloat *) shadowMat_left); glTranslatef(-mvt_x, -mvt_y, -mvt_z); /* correct for modelview matrix */ glRotatef(-mvr_d, mvr_x, mvr_y, mvr_z); glMultMatrixf((const GLfloat *) four_columnsXform); glCallList(15); glPopMatrix(); glEndList(); glNewList(102, GL_COMPILE); glPushMatrix(); glMultMatrixf((const GLfloat *) shadowMat_back); glRotatef(-mvr_d, mvr_x, mvr_y, mvr_z); glTranslatef(-mvt_x, -mvt_y, -mvt_z); /* correct for modelview matrix */ glMultMatrixf((const GLfloat *) four_columnsXform); glCallList(15); glPopMatrix(); glEndList(); glNewList(103, GL_COMPILE); glPushMatrix(); glMultMatrixf((const GLfloat *) shadowMat_right); glRotatef(-mvr_d, mvr_x, mvr_y, mvr_z); glTranslatef(-mvt_x, -mvt_y, -mvt_z); /* correct for modelview matrix */ glMultMatrixf((const GLfloat *) four_columnsXform); glCallList(15); glPopMatrix(); glEndList(); /* ......................................................*/ }
void OutdoorLightStats::setupLighting() { GLfloat la[4]; GLfloat ld[4]; GLfloat lp[4]; la[3] = 1.0f; ld[3] = 1.0f; lp[3] = 0.0f; // directional lights plz la[0] = la[1] = la[2] = 0.0f; if (dayIntensity > 0) { ld[0] = dayColor.x * dayIntensity; ld[1] = dayColor.y * dayIntensity; ld[2] = dayColor.z * dayIntensity; lp[0] = dayDir.x; lp[1] = dayDir.z; lp[2] = -dayDir.y; glLightfv(GL_LIGHT0, GL_AMBIENT, la); glLightfv(GL_LIGHT0, GL_DIFFUSE, ld); glLightfv(GL_LIGHT0, GL_POSITION,lp); glEnable(GL_LIGHT0); } else glDisable(GL_LIGHT0); if (nightIntensity > 0) { ld[0] = nightColor.x * nightIntensity; ld[1] = nightColor.y * nightIntensity; ld[2] = nightColor.z * nightIntensity; lp[0] = nightDir.x; lp[1] = nightDir.z; lp[2] = -nightDir.y; glLightfv(GL_LIGHT1, GL_AMBIENT, la); glLightfv(GL_LIGHT1, GL_DIFFUSE, ld); glLightfv(GL_LIGHT1, GL_POSITION,lp); glEnable(GL_LIGHT1); } else glDisable(GL_LIGHT1); // light 2 will be ambient -> max. 3 lights for outdoors... la[0] = ambientColor.x * ambientIntensity; la[1] = ambientColor.y * ambientIntensity; la[2] = ambientColor.z * ambientIntensity; /* ld[0] = ld[1] = ld[2] = 0.0f; lp[0] = lp[1] = lp[2] = 0.0f; glLightfv(GL_LIGHT2, GL_AMBIENT, la); glLightfv(GL_LIGHT2, GL_DIFFUSE, ld); glLightfv(GL_LIGHT2, GL_POSITION,lp); glEnable(GL_LIGHT2); */ glDisable(GL_LIGHT2); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, la); // not using the rest glDisable(GL_LIGHT3); glDisable(GL_LIGHT4); glDisable(GL_LIGHT5); glDisable(GL_LIGHT6); glDisable(GL_LIGHT7); // should really loop to GL_MAX_LIGHTS lol }
void SetupRC() { glEnable(GL_DEPTH_TEST); // Hidden surface removal glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); }
static void Init (void) { static const char *fragShaderText = "uniform vec3 lightPos;\n" "uniform vec4 diffuse;\n" "uniform vec4 specular;\n" "varying vec3 normal;\n" "void main () {\n" " // Compute dot product of light direction and normal vector\n" " float dotProd = max (dot (lightPos, normalize (normal)), 0.0);\n" " // Compute diffuse and specular contributions\n" #if 1 " gl_FragColor = diffuse * dotProd + specular * pow (dotProd, 20.0);\n" #elif 1 /* test IF/ELSE/ENDIF */ " if (normal.y > 0.0) { \n" " gl_FragColor = diffuse * dotProd + specular * pow (dotProd, 20.0);\n" " } \n" " else { \n" " if (normal.x < 0.0) { \n" " gl_FragColor = vec4(1, 0, 0, 0); \n" " } \n" " else { \n" " gl_FragColor = vec4(1, 1, 0, 0); \n" " } \n" " } \n" #elif 1 /* test LOOP */ " while (1) { \n" " if (normal.y >= 0.0) { \n" " gl_FragColor = vec4(1, 0, 0, 0); \n" " break; \n" " } else { \n" " gl_FragColor = diffuse * dotProd + specular * pow (dotProd, 20.0);\n" " break; \n" " } \n" " } \n" #endif "}\n" ; static const char *vertShaderText = "varying vec3 normal;\n" "void main () {\n" " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" " normal = gl_NormalMatrix * gl_Normal;\n" "}\n" ; if (!glutExtensionSupported ("GL_ARB_fragment_shader")) { printf ("Sorry, this demo requires GL_ARB_fragment_shader\n"); exit(1); } if (!glutExtensionSupported ("GL_ARB_shader_objects")) { printf ("Sorry, this demo requires GL_ARB_shader_objects\n"); exit(1); } if (!glutExtensionSupported ("GL_ARB_shading_language_100")) { printf ("Sorry, this demo requires GL_ARB_shading_language_100\n"); exit(1); } if (!glutExtensionSupported ("GL_ARB_vertex_shader")) { printf ("Sorry, this demo requires GL_ARB_vertex_shader\n"); exit(1); } glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) GETPROCADDRESS ("glCreateShaderObjectARB"); glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) GETPROCADDRESS ("glShaderSourceARB"); glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) GETPROCADDRESS ("glCompileShaderARB"); glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) GETPROCADDRESS ("glCreateProgramObjectARB"); glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) GETPROCADDRESS ("glAttachObjectARB"); glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) GETPROCADDRESS ("glLinkProgramARB"); glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) GETPROCADDRESS ("glUseProgramObjectARB"); glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) GETPROCADDRESS ("glGetUniformLocationARB"); glUniform3fvARB = (PFNGLUNIFORM3FVARBPROC) GETPROCADDRESS ("glUniform3fvARB"); glUniform4fvARB = (PFNGLUNIFORM3FVARBPROC) GETPROCADDRESS ("glUniform4fvARB"); fragShader = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB); glShaderSourceARB (fragShader, 1, &fragShaderText, NULL); glCompileShaderARB (fragShader); vertShader = glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB); glShaderSourceARB (vertShader, 1, &vertShaderText, NULL); glCompileShaderARB (vertShader); program = glCreateProgramObjectARB (); glAttachObjectARB (program, fragShader); glAttachObjectARB (program, vertShader); glLinkProgramARB (program); glUseProgramObjectARB (program); uLightPos = glGetUniformLocationARB (program, "lightPos"); uDiffuse = glGetUniformLocationARB (program, "diffuse"); uSpecular = glGetUniformLocationARB (program, "specular"); glUniform4fvARB (uDiffuse, 1, diffuse); glUniform4fvARB (uSpecular, 1, specular); glClearColor (0.3f, 0.3f, 0.3f, 0.0f); glEnable (GL_DEPTH_TEST); glEnable (GL_LIGHT0); glEnable (GL_LIGHTING); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, specular); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 20.0f); printf ("GL_RENDERER = %s\n", (const char *) glGetString (GL_RENDERER)); printf ("Press p to toggle between per-pixel and per-vertex lighting\n"); }
void ActivateTexture( struct Texture * t ) { glEnable( t->type ); glActiveTextureARB( GL_TEXTURE0_ARB + t->slot ); glBindTexture(t->type, t->texture ); }
void testApp::draw() { ofSetColor(255,255); // camera1.draw(0, 0); ofRectangle rgbdRect(0, 0, 1280, 720); cam.applyRotation = cam.applyTranslation = showRGBD && rgbdRect.inside(mouseX, mouseY); if(showRGBD){ ofSetColor(0); ofRect(rgbdRect); ofSetColor(255); cam.begin(rgbdRect); glEnable(GL_DEPTH); renderer1.drawWireFrame(); ofPushMatrix(); // ofMultMatrix(calibrationMatrix); // ofVec3f axis; // float angle; // rotation.getRotate(angle, axis); // ofRotate(-angle, axis.x,axis.y,axis.z); // ofTranslate(-translation); ofMultMatrix(getMatrix()); renderer2.drawWireFrame(); ofPopMatrix(); glDisable(GL_DEPTH); cam.end(); } else{ // front.getColorImage().draw(0,0); //back.getRawIRImage().draw(640, 480); depthImage1Rect = ofRectangle(0,0,640,480); depthImage2Rect = ofRectangle(640,0,640,480); if(depthImage1.isAllocated()) depthImage1.draw(0, 0); if(depthImage2.isAllocated()) depthImage2.draw(640, 0); if(inThreshold){ ofSetColor(255,200,10); } else{ ofSetColor(255); } contourFinder.draw(); ofPushMatrix(); ofTranslate(640, 0); backContourFinder.draw(); ofPopMatrix(); ofSetColor(255); ofPushStyle(); // for(int i = 0; i < 4; i++){ // ofSetColor( markerColors[i] ); // ofCircle(depthImage1Rect.getTopLeft() + cam1Calib[i], 5); // ofCircle(depthImage2Rect.getTopLeft() + cam2Calib[i], 5); // // } //draw cross hires ofSetLineWidth(3); ofSetColor(255, 100, 100, 150); ofLine(320, 0, 320, 480); ofLine(640+320, 0, 640+320, 480); ofLine(0, 240, 640*2, 240); ofPopStyle(); } ofDrawBitmapString("framerate " + ofToString(ofGetFrameRate()) + "\n" + "area depth: " + ofToString(areaDepth,1) + "\n"+ "time in thresdhold: " + ofToString(ofGetElapsedTimef() - thresholdEnteredTime,1), 10, 500); gui.draw(); // camera2.draw(0, 0); // camera.drawPhoto(0, 0, 432, 288); /* if(camera.isLiveReady()) { stringstream status; status << camera.getWidth() << "x" << camera.getHeight() << " @ " << (int) ofGetFrameRate() << " app-fps " << " / " << (int) camera.getFrameRate() << " cam-fps"; ofDrawBitmapString(status.str(), 10, 20); } */ if(pix.isAllocated()){ // pix.draw(0,0); } }
/* left hand part */ void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar) { ListBase anim_data = {NULL, NULL}; bAnimListElem *ale; int filter; View2D *v2d = &ar->v2d; float y = 0.0f, height; size_t items; int i = 0; /* build list of channels to draw */ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS); items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* Update max-extent of channels here (taking into account scrollers): * - this is done to allow the channel list to be scrollable, but must be done here * to avoid regenerating the list again and/or also because channels list is drawn first * - offset of ACHANNEL_HEIGHT*2 is added to the height of the channels, as first is for * start of list offset, and the second is as a correction for the scrollers. */ height = (float)((items * ACHANNEL_STEP) + (ACHANNEL_HEIGHT * 2)); UI_view2d_totRect_set(v2d, ar->winx, height); /* loop through channels, and set up drawing depending on their type */ { /* first pass: just the standard GL-drawing for backdrop + text */ y = (float)ACHANNEL_FIRST; for (ale = anim_data.first, i = 0; ale; ale = ale->next, i++) { const float yminc = (float)(y - ACHANNEL_HEIGHT_HALF); const float ymaxc = (float)(y + ACHANNEL_HEIGHT_HALF); /* check if visible */ if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) || IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) ) { /* draw all channels using standard channel-drawing API */ ANIM_channel_draw(ac, ale, yminc, ymaxc); } /* adjust y-position for next one */ y -= ACHANNEL_STEP; } } { /* second pass: widgets */ uiBlock *block = uiBeginBlock(C, ar, __func__, UI_EMBOSS); size_t channel_index = 0; y = (float)ACHANNEL_FIRST; /* set blending again, as may not be set in previous step */ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); for (ale = anim_data.first, i = 0; ale; ale = ale->next, i++) { const float yminc = (float)(y - ACHANNEL_HEIGHT_HALF); const float ymaxc = (float)(y + ACHANNEL_HEIGHT_HALF); /* check if visible */ if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) || IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) ) { /* draw all channels using standard channel-drawing API */ ANIM_channel_draw_widgets(C, ac, ale, block, yminc, ymaxc, channel_index); } /* adjust y-position for next one */ y -= ACHANNEL_STEP; channel_index++; } uiEndBlock(C, block); uiDrawBlock(C, block); glDisable(GL_BLEND); } /* free tempolary channels */ BLI_freelistN(&anim_data); }
void GLText::draw() { glEnable(GL_TEXTURE_2D); double pos=0; color.use(); sf::Texture texture(font->getTexture(size)); sf::Vector2u texsize=texture.getSize(); sf::Texture::bind(&texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); int min_back=0; for (unsigned int i=0; i<message.size(); ++i) { sf::Glyph glyph=font->getGlyph(message[i],size,false); if (i==0) min_back=glyph.bounds.top; if (min_back>glyph.bounds.top) min_back=glyph.bounds.top; } GLPoint poz=position; poz.x-=origin.x; poz.y-=origin.y; poz.z-=origin.z; for (unsigned int i=0; i<message.size(); ++i) { sf::Glyph glyph=font->getGlyph(message[i],size,false); if (message[i]==' ') glyph.bounds.width=size/4; glBegin(GL_POLYGON); glTexCoord2d(glyph.textureRect.left/double(texsize.x),glyph.textureRect.top/double(texsize.y)); GLPoint help(pos,glyph.bounds.top-min_back,0); rotate3d(help,rotation.x,rotation.y,rotation.z); help.x*=scale.x; help.y*=scale.y; help.z*=scale.z; help.x+=poz.x; help.y+=poz.y; help.z+=poz.z; help.use(); glTexCoord2d((glyph.textureRect.left+glyph.textureRect.width)/double(texsize.x),glyph.textureRect.top/double(texsize.y)); help=GLPoint(pos+glyph.bounds.width,glyph.bounds.top-min_back); rotate3d(help,rotation.x,rotation.y,rotation.z); help.x*=scale.x; help.y*=scale.y; help.z*=scale.z; help.x+=poz.x; help.y+=poz.y; help.z+=poz.z; help.use(); glTexCoord2d((glyph.textureRect.left+glyph.textureRect.width)/double(texsize.x),(glyph.textureRect.top+glyph.textureRect.height)/double(texsize.y)); help=GLPoint(pos+glyph.bounds.width,glyph.bounds.top-min_back+glyph.bounds.height); rotate3d(help,rotation.x,rotation.y,rotation.z); help.x*=scale.x; help.y*=scale.y; help.z*=scale.z; help.x+=poz.x; help.y+=poz.y; help.z+=poz.z; help.use(); glTexCoord2d(glyph.textureRect.left/double(texsize.x),(glyph.textureRect.top+glyph.textureRect.height)/double(texsize.y)); help=GLPoint(pos,glyph.bounds.top+glyph.bounds.height-min_back); rotate3d(help,rotation.x,rotation.y,rotation.z); help.x*=scale.x; help.y*=scale.y; help.z*=scale.z; help.x+=poz.x; help.y+=poz.y; help.z+=poz.z; help.use(); glEnd(); pos+=glyph.bounds.width; } sf::Texture::bind(NULL); glDisable(GL_TEXTURE_2D); }
void RenderScene() { g_globalCam.Update(); // Clear Depth and color buffers // glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Enabled texturing and depth testing // glEnable(GL_TEXTURE_2D); // Enable Texturing glEnable(GL_DEPTH_TEST); // Enable Depth tests glDepthFunc(GL_LEQUAL); // LESSEQUAL depth test glEnable( GL_CULL_FACE ); glCullFace( GL_BACK ); glFrontFace( GL_CCW ); // Do a depth only pass // int rtColor = (g_bMSAA) ? g_msaaColor : DEFAULT_HANDLE; int rtDepth = (g_bMSAA) ? g_msaaDepth : DEFAULT_HANDLE; g_pTexInterface->BindRenderTarget(&rtColor, 1, rtDepth); glColorMask(0, 0, 0, 0); if(g_bMSAA) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); RenderGeometry( ); int def = DEFAULT_HANDLE; glColorMask(1, 1, 1, 1); // Render the gbuffer to non-msaa targets // RenderSceneGBuffer(); RenderLightBuffer(); rtColor = (g_bMSAA) ? g_msaaColor : DEFAULT_HANDLE; rtDepth = (g_bMSAA) ? g_msaaDepth : DEFAULT_HANDLE; g_pTexInterface->BindRenderTarget(&rtColor, 1, rtDepth); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); rtColor = (g_bMSAA) ? g_normalDepthColor : g_lightBuffer; vec2 viewDims = {(float)GetScreenWidth(), (float)GetScreenHeight()}; g_pShaderInterface->BindShader( g_compositeShader ); g_pShaderInterface->SetFloat( "g_viewDims", viewDims, 2 ); g_pShaderInterface->SetStateMatrix( "g_matWorldViewProj", MATRIX_MODELVIEW | MATRIX_PROJECTION ); g_pShaderInterface->SetTexture( "g_lightBuffer", rtColor ); g_pShaderInterface->SetTexture("g_diffuseTexture", g_groundTexture); int textured = 1; g_pShaderInterface->SetInt( "g_bIsTextured", &textured, 0 ); glDepthFunc(GL_LEQUAL); RenderGeometry(); g_pShaderInterface->UnbindShader(); if(g_bMSAA) { g_pTexInterface->BindTexture(g_lightBuffer); RenderTexturedFullscreenQuad(); // Rebind default backbuffer // g_pTexInterface->ResolveMSAATarget(g_resolveTexture); g_pTexInterface->BindRenderTarget(&def, 1, DEFAULT_HANDLE); glDisable(GL_DEPTH_TEST); g_pTexInterface->BindTexture(g_resolveTexture); // resolve tex RenderTexturedFullscreenQuad(); } g_pTexInterface->EvictTextures(); #ifdef RENDER_DEBUG glDepthFunc(GL_ALWAYS); renderDebug(); glDepthFunc(GL_LEQUAL); #endif glFlush(); }
void Light::Enable() { glEnable(GL_LIGHT1); }
/* Handler for window-repaint event. Call back when the window first appears and whenever the window needs to be re-painted. */ void display() { glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer with current clearing color // Define shapes enclosed within a pair of glBegin and glEnd glBegin(GL_QUADS); glColor3f(0.7f, 0.7f, 0.7f); glVertex2f(0.0f, 1.0f); glColor3f(0.5f, 0.5f, 0.5f); glVertex2f(0.0f, 0.0f); glColor3f(0.7f, 0.7f, 0.7f); glVertex2f(1.0f, 0.0f); glColor3f(0.5f, 0.5f, 0.5f); glVertex2f(1.0f, 1.0f); glEnd(); for(float i = 0.0; i < 1.0; i += 0.05){ glBegin(GL_LINES); glColor3f(0.3f, 0.3f, 0.3f); glVertex2f(0.0f, i); glVertex2f(1.0f, i); glEnd(); } for(float i = 0.0; i < 1.0; i += 0.05){ glBegin(GL_LINES); glColor3f(0.3f, 0.3f, 0.3f); glVertex2f(i, 0.0f); glVertex2f(i, 1.0f); glEnd(); } /*****************************************************************************/ /* AFISARE TRIUNGHIURI */ glBegin(GL_TRIANGLES); for(unsigned int i = 0; i < Tris.size(); i ++){ setRandomColor(); glVertex2f(Tris.at(i).at(0).getX(), Tris.at(i).at(0).getY()); glVertex2f(Tris.at(i).at(1).getX(), Tris.at(i).at(1).getY()); glVertex2f(Tris.at(i).at(2).getX(), Tris.at(i).at(2).getY()); } glEnd(); /*****************************************************************************/ /* AFISARE LINII concav concav = blue convex convex = red concav convex = yellow */ glEnable(GL_LINE_SMOOTH); glColor3dv(black); //glLineWidth(1.0); glBegin(GL_LINE_STRIP); for (unsigned int i = 0; i < Points.size(); i++){ if (i == (Points.size() - 1)){ if ((getPointType(i) == CONVEX) && (getPointType(0) == CONVEX)){ glColor3dv(red); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(0).getX(), Points.at(0).getY()); } else if ((getPointType(i) == CONCAVE) && (getPointType(0) == CONCAVE)){ glColor3dv(blue); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(0).getX(), Points.at(0).getY()); } else{ glColor3dv(yellow); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(0).getX(), Points.at(0).getY()); } } else{ if ((getPointType(i) == CONVEX) && (getPointType(i + 1) == CONVEX)){ glColor3dv(red); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(i + 1).getX(), Points.at(i + 1).getY()); } else if ((getPointType(i) == CONCAVE) && (getPointType(i + 1) == CONCAVE)){ glColor3dv(blue); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(i + 1).getX(), Points.at(i + 1).getY()); } else{ glColor3dv(yellow); glVertex2f(Points.at(i).getX(), Points.at(i).getY()); glVertex2f(Points.at(i + 1).getX(), Points.at(i + 1).getY()); } } } glEnd(); /*****************************************************************************/ /* AFISARE PUNCTE convex = green concav = black */ glColor3dv(v); glPointSize(4.0); glBegin(GL_POINTS); for (unsigned int i = 0; i < Points.size(); i++){ if (getPointType(i) == CONVEX){ glColor3dv(green); glVertex2d(Points.at(i).getX(), Points.at(i).getY()); } else{ glColor3dv(black); glVertex2d(Points.at(i).getX(), Points.at(i).getY()); } } glEnd(); //glLineWidth(1.0); glFlush(); // Render now }
int main(int argc, char **argv) { int width = 320, height = 240; int i; char *name; glutInitWindowSize(width, height); glutInit(&argc, argv); /* process commmand line args */ for (i = 1; i < argc; ++i) { if (!strcmp("-db", argv[i])) { useDB = !useDB; } else { usage(); } } /* choose visual */ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); name = "MOTH - by Bob Doyle"; glutCreateWindow(name); glutKeyboardFunc(keyboard); myInit(); /* initialize objects in scene */ glutDisplayFunc(display); glutVisibilityFunc(visible); glutCreateMenu(menu_select); glutAddMenuEntry("Start motion", 1); glutAddMenuEntry("Stop motion", 2); glutAddMenuEntry("Quit", 5); glutAddMenuEntry("Drink Ed's beer", 5); glutAttachMenu(GLUT_RIGHT_BUTTON); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-.9, .9, -.9, .9, 1.0, 35.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); #if 0 glTranslatef(0.0, 0.0, mvt_zi); #endif glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); /* double your fun */ glShadeModel(GL_SMOOTH); glDepthFunc(GL_LESS); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); myInit(); /* initialize objects in scene */ glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
void SDLGLWindow::enableDebugLogging() { glEnable(GL_DEBUG_OUTPUT); glDebugMessageCallback(gl_debug_callback, nullptr); }
void display(void) { glPushMatrix(); /* Make sure the matrix stack is cleared at the end of this function. */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); /*@@@@@@ Rotation and Translation of Entire Scene @@@@@*/ if(mvt_x < 0 && mvt_y < 0){ glTranslatef(mvt_x ,mvt_y ,mvt_z ); mvt_x = mvt_x - Tx; mvt_y = mvt_y - Ty; mvt_z = mvt_z - Tz; glRotatef(mvr_d, mvr_x, mvr_y, mvr_z); mvr_d = mvr_d - Rx; } else{ glTranslatef(0.0, 0.0 ,mvt_z); } /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ glPushMatrix(); glLightfv(GL_LIGHT1, GL_POSITION, light1Pos); glPopMatrix(); /*______________________ Draw Floor _______________________*/ glPushMatrix(); glCallList(ground); glPopMatrix(); /*_________________________________________________________*/ /*@@@@@@@@@ Draw Lamp Post amd Lamp @@@@@@@@@@*/ glPushMatrix(); glCallList(21); glPopMatrix(); glPushMatrix(); glCallList(22); glPopMatrix(); glPushMatrix(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glCallList(501); glDisable(GL_BLEND); glPopMatrix(); /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ /*||||||||||||||||||| Draw Left Wall ||||||||||||||||||*/ glCallList(left_wall); /*|||||||||||||||||||||||||||||||||||||||||||||||||||||*/ /*\\\\\\\\\\\\\\\\ Draw Right Wall \\\\\\\\\\\\\\*/ glCallList(right_wall); /*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/ /*[[[[[[[[[[[[[[[[[[[ Draw Columns ]]]]]]]]]]]]]]]]]]]*/ /***** Place columns at front of scene. *****/ glCallList(four_columns); /***** Place columns at back of scene. *****/ glPushMatrix(); glTranslatef(0.0, 0.0, -9.0); glCallList(four_columns); glPopMatrix(); /***** Place columns at centers of left and right walls. *****/ glCallList(two_columns); /*[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]*/ /*....................... Draw Column Shadows ....................*/ /*glDepthMask(GL_FALSE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ /* shadows on floor */ /* glPushMatrix(); glCallList(100); glPopMatrix();*/ /* shdows on left wall */ /* glPushMatrix(); glCallList(101); glPopMatrix();*/ /* shdows on back wall */ /* glPushMatrix(); glCallList(102); glPopMatrix();*/ /* shdows on right wall */ /* glPushMatrix(); glCallList(103); glPopMatrix();*/ /*glDepthMask(GL_TRUE); glDisable(GL_BLEND);*/ /*................................................................*/ /************************* CUBE ***********************/ glMaterialf(GL_FRONT, GL_SHININESS, 99.0); glMaterialfv(GL_FRONT, GL_SPECULAR, cube_specular); glPushMatrix(); glTranslatef(0.0, 0.0, -5.0); glRotatef((360.0 / (30 * 2)) * tick, 0, 1, 0); glPushMatrix(); glTranslatef(0.0, 0.2, 2.0); /* glTranslatef(0.0, 0.2, 0.0); */ /* glScalef(0.3, 0.3, 0.3); */ glRotatef((360.0 / (30 * 1)) * tick, 1, 0, 0); glRotatef((360.0 / (30 * 2)) * tick, 0, 1, 0); glRotatef((360.0 / (30 * 4)) * tick, 0, 0, 1); glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *) cubeXform); /* drawSatellite(satellite_diffuse, satellite_ambient, satellite_specular, satellite_shiny); */ glCallList(satellite1); glCallList(panel1); /* drawPanels(panel_color, panel_ambient); */ glPopMatrix(); glPopMatrix(); glMaterialf(GL_FRONT, GL_SHININESS, 0.0); glMaterialfv(GL_FRONT, GL_SPECULAR, shadow_specular); /****************************************************/ /*................... CUBE SHADOWS .............................*/ /*glDepthMask(GL_FALSE);*/ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPushMatrix(); glMultMatrixf((const GLfloat *) shadowMat1_ground); glRotatef(-mvr_d, mvr_x, mvr_y, mvr_z); glTranslatef(-mvt_x, -mvt_y, -mvt_z); /* correct for modelview matrix */ glMultMatrixf((const GLfloat *) cubeXform); /* drawSatellite(shadow_diffuse, shadow_ambient, shadow_specular, shadow_shiny); */ /* draw ground shadow */ glCallList(satellite2); glTranslatef(0.0, -.040, 0.0); glCallList(panel2); /* drawPanels(shadow_diffuse, shadow_ambient); */ glPopMatrix(); /* Shadow left wall only if cube is in front of left wall. */ if((tick*6) >= 220 && (tick*6) <= 320) { glPushMatrix(); glMultMatrixf((const GLfloat *) shadowMat1_left); glRotatef(-mvr_d, mvr_x, mvr_y, mvr_z); glTranslatef(-mvt_x, -mvt_y, -mvt_z); /* correct for modelview matrix */ glMultMatrixf((const GLfloat *) cubeXform); drawSatellite(shadow_diffuse, shadow_ambient, shadow_specular, shadow_shiny); /* draw left shadow */ drawPanels(shadow_diffuse, shadow_ambient); glPopMatrix(); } /* Shadow back wall only if cube is in front of back wall. */ if((tick*6) >= 125 && (tick*6) <= 330) { glPushMatrix(); glMultMatrixf((const GLfloat *) shadowMat1_back); glRotatef(-mvr_d, mvr_x, mvr_y, mvr_z); glTranslatef(-mvt_x, -mvt_y, -mvt_z); /* correct for modelview matrix */ glMultMatrixf((const GLfloat *) cubeXform); drawSatellite(shadow_diffuse, shadow_ambient, shadow_specular, shadow_shiny); /* draw back wall shadow */ drawPanels(shadow_diffuse, shadow_ambient); glPopMatrix(); } /* Shadow right wall only if cube is in front of right wall. */ if((tick*6) >= 40 && (tick*6) <= 145) { glPushMatrix(); glMultMatrixf((const GLfloat *) shadowMat1_right); glRotatef(-mvr_d, mvr_x, mvr_y, mvr_z); glTranslatef(-mvt_x, -mvt_y, -mvt_z); /* correct for modelview matrix */ glMultMatrixf((const GLfloat *) cubeXform); drawSatellite(shadow_diffuse, shadow_ambient, shadow_specular, shadow_shiny); /* draw right wall shadow */ drawPanels(shadow_diffuse, shadow_ambient); glPopMatrix(); } /*glDepthMask(GL_TRUE);*/ glDisable(GL_BLEND); /*.........................................................*/ glutSwapBuffers(); checkErrors(); glPopMatrix(); /* Clear the matrix stack */ }
void RenderWorld::init() { const EGLint attribs[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_DEPTH_SIZE, 16, EGL_NONE }; EGLint format; EGLint numConfigs; EGLConfig config; mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(mDisplay, 0, 0); eglChooseConfig(mDisplay, attribs, &config, 1, &numConfigs); eglGetConfigAttrib(mDisplay, config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(mAndroidApp->window, 0, 0, format); mSurface = eglCreateWindowSurface(mDisplay, config, mAndroidApp->window, NULL); EGLint c_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; mContext = eglCreateContext(mDisplay, config, 0, c_attribs); if (eglMakeCurrent(mDisplay, mSurface, mSurface, mContext) == EGL_FALSE) throw Exception("eglMakeCurrent failed"); eglQuerySurface(mDisplay, mSurface, EGL_WIDTH, &mWidth); eglQuerySurface(mDisplay, mSurface, EGL_HEIGHT, &mHeight); mView = Matrix::createLookAt(Vector3::ONE*25, Vector3::ZERO, Vector3::UNIT_Y); mProj = Matrix::createPerspectiveFOV(Math::PI/3.0f, (float)mWidth/(float)mHeight, 1.0f, 1000.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); shared_ptr<ResourceLoader> vloader(new VertexShaderLoader); shared_ptr<ResourceLoader> ploader(new PixelShaderLoader); shared_ptr<ResourceLoader> mloader(new MeshLoader); shared_ptr<ResourceLoader> tloader(new TextureLoader); shared_ptr<ResourceLoader> mtloader(new MaterialLoader); shared_ptr<ResourceLoader> skloader(new SkinLoader); ResourceManager& rman = Engine::getPtr()->getResourceManager(); rman.addLoader(vloader); rman.addLoader(ploader); rman.addLoader(mloader); rman.addLoader(tloader); rman.addLoader(mtloader); rman.addLoader(skloader); VertexShader* vshader = rman.get<VertexShader>("test.vs"); PixelShader* pshader = rman.get<PixelShader>("test.fs"); mProgram = new Program; mProgram->attach(*vshader); mProgram->attach(*pshader); mProgram->link(); }
bool CRenderSystemGL::ResetRenderSystem(int width, int height, bool fullScreen, float refreshRate) { m_width = width; m_height = height; glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); CalculateMaxTexturesize(); glViewport(0, 0, width, height); glScissor(0, 0, width, height); glEnable(GL_TEXTURE_2D); glEnable(GL_SCISSOR_TEST); //ati doesn't init the texture matrix correctly //so we have to do it ourselves glMatrixMode(GL_TEXTURE); glLoadIdentity(); if (glewIsSupported("GL_ARB_multitexture")) { //clear error flags ResetGLErrors(); GLint maxtex; glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &maxtex); //some sanity checks GLenum error = glGetError(); if (error != GL_NO_ERROR) { CLog::Log(LOGERROR, "ResetRenderSystem() GL_MAX_TEXTURE_IMAGE_UNITS_ARB returned error %i", (int)error); maxtex = 3; } else if (maxtex < 1 || maxtex > 32) { CLog::Log(LOGERROR, "ResetRenderSystem() GL_MAX_TEXTURE_IMAGE_UNITS_ARB returned invalid value %i", (int)maxtex); maxtex = 3; } //reset texture matrix for all textures for (GLint i = 0; i < maxtex; i++) { glActiveTextureARB(GL_TEXTURE0 + i); glLoadIdentity(); } glActiveTextureARB(GL_TEXTURE0); } glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, width-1, height-1, 0.0f, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_BLEND); // Turn Blending On glDisable(GL_DEPTH_TEST); return true; }