Last active
September 15, 2015 22:52
-
-
Save bitbrain/67dcd6dedca131cc8f52 to your computer and use it in GitHub Desktop.
Leider gehen materials nicht..
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* OpenGL module | |
* Assessment 4 | |
* | |
* author: Miguel Gonzalez <[email protected]> | |
*/ | |
#include <GL/glut.h> | |
GLint CAM_POS[] = { 3.0, 3.0, 3.0 }; | |
GLfloat mat[4]; | |
GLfloat AMBIENT_COLOR[] = {0.6f, 0.0f, 1.2f, 1.0f}; | |
GLfloat LIGHT_POS[] = { 1.0, 0.0, 0.0 }; | |
GLfloat LIGHT_COLOR[] = {0.0f, 0.0f, 0.0f, 0.0f}; | |
int t = 0; | |
void brassMaterial() | |
{ | |
double shine = 0.21794872; | |
mat[0] = 0.329412; | |
mat[1] = 0.223529; | |
mat[2] = 0.027451; | |
mat[3] = 1.0; | |
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat); | |
mat[0] = 0.780392; | |
mat[1] = 0.568627; | |
mat[2] = 0.113725; | |
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat); | |
mat[0] = 0.992157; | |
mat[1] = 0.941176; | |
mat[2] = 0.807843; | |
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat); | |
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shine * 128.0); | |
} | |
void redPlasticMaterial() | |
{ | |
double shine = .25; | |
mat[0] = 0.0; | |
mat[1] = 0.0; | |
mat[2] = 0.0; | |
mat[3] = 0.5; | |
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat); | |
mat[0] = 0.5; | |
mat[1] = 0.0; | |
mat[2] = 0.0; | |
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat); | |
mat[0] = 0.7; | |
mat[1] = 0.6; | |
mat[2] = 0.6; | |
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat); | |
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shine * 128.0); | |
} | |
void ambientLight() { | |
glLightfv(GL_LIGHT0, GL_AMBIENT, AMBIENT_COLOR); | |
} | |
void pointLight() { | |
glLightfv(GL_LIGHT0, GL_SPECULAR, LIGHT_COLOR); | |
glLightfv(GL_LIGHT0, GL_POSITION, LIGHT_POS); | |
} | |
void display() | |
{ | |
glClearColor(0.2f, 0.0f, 0.1f, 1.0f); | |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
glMatrixMode(GL_MODELVIEW); | |
glLoadIdentity(); | |
gluLookAt(CAM_POS[0], CAM_POS[1], CAM_POS[2], 0.0, 0.0, 0.0, 0.0, 0.4, 0.0); | |
glTranslatef(0.0, 0.0, 0.0); | |
glEnable(GL_LIGHT0); | |
ambientLight(); | |
pointLight(); | |
glPushMatrix(); | |
glEnable(GL_COLOR_MATERIAL); | |
brassMaterial(); | |
glRotatef(0.8f * t, 1, 1, 1); | |
glutSolidCone(1.0f, 2.0f, 256.0f, 256.0f); | |
glDisable(GL_COLOR_MATERIAL); | |
glPopMatrix(); | |
glTranslatef(0.0f, 0.0f, -3.0f); | |
glPushMatrix(); | |
glEnable(GL_COLOR_MATERIAL); | |
glRotatef(-0.8f * t, 0, 1, 1); | |
redPlasticMaterial(); | |
glutSolidCone(1.0f, 2.0f, 256.0f, 256.0f); | |
glDisable(GL_COLOR_MATERIAL); | |
glPopMatrix(); | |
glDisable(GL_LIGHT0); | |
glFlush(); | |
glutSwapBuffers(); | |
t++; | |
} | |
void reshape(GLsizei w, GLsizei h) | |
{ | |
glViewport (0, 0, (GLsizei) w, (GLsizei) h); | |
glMatrixMode (GL_PROJECTION); | |
glLoadIdentity(); | |
gluPerspective(50.0,(GLfloat)w/(GLfloat)h,1.0,20.0); | |
glMatrixMode(GL_MODELVIEW); | |
glLoadIdentity(); | |
} | |
void refresh(int te) | |
{ | |
glutPostRedisplay(); | |
glutTimerFunc( 10, refresh, 1); | |
} | |
int main(int argc, char** argv) { | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); | |
glutInitWindowSize(800, 600); | |
glutInitWindowPosition(100, 100); | |
glutCreateWindow("OpenGL - Assessment 3"); | |
glEnable(GL_LIGHTING); | |
glEnable(GL_DEPTH_TEST); | |
glutReshapeFunc(reshape); | |
glutDisplayFunc(display); | |
glutTimerFunc( 10, refresh, 1); | |
glutMainLoop(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment