Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This example program is created by thecplusplusuy for demonstration purposes. It's a simple skybox:
- //http://www.youtube.com/user/thecplusplusguy
- //Free source, modify if you want, LGPL licence (I guess), I would be happy, if you would not delete the link
- //so other people can see the tutorial
- //this file is main.cpp, the entry point of the program, and we load the model here, and use the 3D camera and the skybox in here.
- //You need the objloader.h and objloader.cpp file for that (earlier I uploaded the source, so I don't again), and you need an object (test10.obj) which you load (obviously you could use just simple primitives (triangle, quad) for that too, but object are looks better), you also need the 6 texture with R5G6R5 format: front.bmp, right.bmp, left.bmp, top.bmp, bottom.bmp, back.bmp.
- //the objloader.h and objloader.cpp header file is not uploaded, it haven't changed, download the earlier one.
- #include "functions.h"
- #include "objloader.h"
- float angle=0.0;
- int cube;
- objloader obj;
- bool mousein=false;
- void init()
- {
- glClearColor(0.5,0.5,0.5,1.0);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45,640.0/480.0,1.0,500.0);
- glMatrixMode(GL_MODELVIEW);
- glEnable(GL_DEPTH_TEST);
- cube=obj.load("test10.obj");
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- float col[]={1.0,1.0,1.0,1.0};
- glLightfv(GL_LIGHT0,GL_DIFFUSE,col);
- initskybox();
- }
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- Control(0.2,0.2,mousein); //calculate the position, and rotate the camera
- drawSkybox(50.0); //Draw the skybox here, so we apply the rotation, but we do not apply the translation to it.
- UpdateCamera(); //move the camera to the new location
- float pos[]={-1.0,1.0,-2.0,1.0};
- glLightfv(GL_LIGHT0,GL_POSITION,pos);
- glCallList(cube);
- }
- int main()
- {
- SDL_Init(SDL_INIT_EVERYTHING);
- SDL_Surface* screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE|SDL_OPENGL);
- bool running=true;
- Uint32 start;
- SDL_Event event;
- init();
- while(running)
- {
- start=SDL_GetTicks();
- while(SDL_PollEvent(&event))
- {
- switch(event.type)
- {
- case SDL_QUIT:
- running=false;
- break;
- case SDL_MOUSEBUTTONDOWN:
- mousein=true;
- SDL_ShowCursor(SDL_DISABLE);
- break;
- case SDL_KEYDOWN:
- if(event.key.keysym.sym==SDLK_p)
- {
- mousein=false;
- SDL_ShowCursor(SDL_ENABLE);
- break;
- }
- if(event.key.keysym.sym==SDLK_ESCAPE)
- {
- running=false;
- break;
- }
- }
- }
- display();
- SDL_GL_SwapBuffers();
- angle+=0.5;
- if(angle>360)
- angle-=360;
- if(1000/30>(SDL_GetTicks()-start))
- SDL_Delay(1000/30-(SDL_GetTicks()-start));
- }
- SDL_Quit();
- killskybox();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment