#include #include #include #include "texture.h" // Define a constant for the value of PI #define GL_PI 3.1415f GLuint texture1; GLuint texture2; static GLfloat ambientLight[] = { 0.3f, 0.3f, 0.3f, 1.0f }; static GLfloat diffuseLight[] = { 0.7f, 0.7f, 0.7f, 1.0f }; static GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; static GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f }; static float rotY = 0.0; // Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // >> Modellezo programresz glBindTexture(GL_TEXTURE_2D, texture1); glPushMatrix(); glTranslatef(-10.0, 0.0, 0.0); glRotatef(rotY, 0, 1, 0); glColor3f(1.0, 1.0, 1.0); glutSolidTeapot(5.0); glPopMatrix(); glBindTexture(GL_TEXTURE_2D, texture2); glPushMatrix(); glTranslatef(10.0, 0.0, 0.0); glRotatef(360.0 - rotY, 0, 1, 0); glColor3f(1.0, 1.0, 1.0); glutSolidTeapot(5.0); glPopMatrix(); // << Modellezo programresz // Flush drawing commands glutSwapBuffers(); } // This function does any needed initialization on the rendering // context. void SetupRC() { // Black background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight); // Setup and enable light 0 glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); glLightfv(GL_LIGHT0, GL_SPECULAR, specular); glEnable(GL_LIGHT0); // Enable Material color tracking glEnable(GL_COLOR_MATERIAL); // Front material ambient and diffuse colors track glColor glColorMaterial(GL_FRONT, GL_AMBIENT); texture1 = TextureLoad("land.bmp", GL_FALSE, GL_LINEAR, GL_LINEAR, GL_REPEAT); texture2 = TextureLoad("pot.bmp", GL_FALSE, GL_LINEAR, GL_LINEAR, GL_CLAMP); glEnable(GL_TEXTURE_2D); } void SpecialKeys(int key, int x, int y) { // ... int state; /* printf("Funkciobillentyu lenyomva, kodja %d, pozicio (%d,%d). ", key, x, y); state = glutGetModifiers(); if(state & GLUT_ACTIVE_SHIFT) printf("SHIFT lenyomva. "); if(state & GLUT_ACTIVE_CTRL) printf("CTRL lenyomva. "); if(state & GLUT_ACTIVE_ALT) printf("ALT lenyomva. "); printf("\n"); fflush(stdout); // Refresh the Window glutPostRedisplay(); */ } void Keyboard(unsigned char key, int x, int y) { // ... int state; /* printf("Billentyu lenyomva, kodja %c, pozicio (%d,%d). ", key, x, y); state = glutGetModifiers(); if(state & GLUT_ACTIVE_SHIFT) printf("SHIFT lenyomva. "); if(state & GLUT_ACTIVE_CTRL) printf("CTRL lenyomva. "); if(state & GLUT_ACTIVE_ALT) printf("ALT lenyomva. "); printf("\n"); fflush(stdout); glutPostRedisplay(); */ } void Timer(int value) { // printf("Timer esemeny (%d)\n", value); rotY += 5.0; if (rotY>= 355.0) { rotY = 0.0; } glutPostRedisplay(); glutTimerFunc(50, Timer, value + 1); } void Idle() { glutPostRedisplay(); } void ChangeSizeOrtho(int w, int h) { GLfloat nRange = 25.0f; // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); // Reset projection matrix stack glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Establish clipping volume (left, right, bottom, top, near, far) if (w <= h) glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange); else glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange); // Reset Model view matrix stack glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void ChangeSizePerspective(GLsizei w, GLsizei h) { GLfloat fAspect; // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); fAspect = (GLfloat)w/(GLfloat)h; // Reset coordinate system glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Produce the perspective projection gluPerspective(60.0f, // fovy fAspect, // aspect 10.0, // zNear 100.0 // zFar ); gluLookAt(0.0, 0.0, 50.0, // eye 0.0, 0.0, 0.0, // center 0.0, 1.0, 0.0 // up ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc, char* argv[]) { // >> Inicializalas glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("Texturazott teaskannak"); // << Inicializalas // >> Callback fuggvenyek glutReshapeFunc(ChangeSizeOrtho); // Parhuzamos vetites glutDisplayFunc(RenderScene); glutTimerFunc(1000, Timer, 1); // 1 mp mulva meghivodik a Timer() fuggveny // << Callback fuggvenyek SetupRC(); glutMainLoop(); return 0; }