Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define GLUT_DISABLE_ATEXIT_HACK
- #include "GLee.h"
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <ctime>
- #include "Targa.h"
- int screenWidth = 600;
- int screenHeight = 600;
- int fps = 60;
- GLdouble cameraPos[] = {0.0, 0.0, 25.0};
- double baserotation = 180.0;
- double rotation = 0.0;
- GLfloat lightAmb[] = {0.1, 0.1, 0.1, 1.0};
- GLfloat lightDif[] = {0.7, 0.7, 0.7, 1.0};
- GLfloat lightPos[] = {0, 0, 800, 1.0};
- GLfloat lightSpec[] = {1, 1, 1, 1};
- GLuint tex;
- void init(){
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_POINT_SMOOTH);
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_TEXTURE_CUBE_MAP_ARB);
- glEnable(GL_TEXTURE_GEN_S);
- glEnable(GL_TEXTURE_GEN_T);
- glEnable(GL_TEXTURE_GEN_R);
- glGenTextures(1, &tex);
- glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_REPEAT);
- glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
- glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
- glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
- glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, tex);
- LoadTGAMipmap("textures/right.tga", GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB);
- LoadTGAMipmap("textures/left.tga", GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB);
- LoadTGAMipmap("textures/top.tga", GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB);
- LoadTGAMipmap("textures/bottom.tga", GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB);
- LoadTGAMipmap("textures/near.tga", GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB);
- LoadTGAMipmap("textures/far.tga", GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
- }
- void display() {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glLoadIdentity ();
- gluLookAt(cameraPos[0], cameraPos[1], cameraPos[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glRotatef(baserotation, 0, 1, 0);
- glRotatef(rotation, 0, 1, 0);
- glMatrixMode(GL_MODELVIEW);
- glutSolidSphere(3, 30, 30);
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glRotatef(rotation, 0, 1, 0);
- glMatrixMode(GL_MODELVIEW);
- glutSolidSphere(3, 30, 30);
- glutSolidSphere(200, 50, 50);
- glFlush ();
- glutPostRedisplay();
- glutSwapBuffers();
- }
- void reshape(int w, int h) {
- glViewport(0, 0, (GLsizei) w, (GLsizei) h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45.0, (GLfloat)w / (GLfloat)h, 1.5, 300.0);
- glMatrixMode(GL_MODELVIEW);
- }
- void keyboard(unsigned char key, int x, int y){
- switch(key){
- case 27 :
- case 'q':
- exit(0);
- break;
- }
- }
- void timerfunc(int p){
- rotation += 0.3;
- glutPostRedisplay();
- glutTimerFunc(1000/fps, &timerfunc, 0);
- }
- void menu(int value) {
- switch(value) {
- case 0:
- exit(0);
- break;
- }
- }
- int main(int argc, char *argv[]) {
- srand(time(NULL));
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(screenWidth, screenHeight);
- glutCreateWindow(argv[0]);
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutKeyboardFunc(keyboard);
- glutTimerFunc(1000/fps, &timerfunc, 0);
- glutCreateMenu(menu);
- glutAddMenuEntry("Wyjscie", 0);
- glutAttachMenu(GLUT_RIGHT_BUTTON);
- init();
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement