-
Notifications
You must be signed in to change notification settings - Fork 0
/
asyle.cpp
116 lines (104 loc) · 3.49 KB
/
asyle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "texturemanager.h"
#include "skybox.h"
TextureManager* texturemanager = TextureManager::getTextureManager();
Skybox* skybox;
SDL_Surface* screen;
int gwidth=800;
int gheight=600;
// SDL destroys the current opengl context upon resizing T_T
// wtf is this
void cleanup()
{
delete skybox;
skybox=0;
texturemanager->cleanup();
}
void init()
{
glClearColor(0.5,0.5,0.5,1.0);
glClearDepth(1.0f);
glViewport(0,0,gwidth,gheight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(50,gwidth/gheight,1.0,500.0);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glShadeModel( GL_SMOOTH );
/* Culling. */
glCullFace( GL_BACK );
glFrontFace( GL_CCW );
glEnable( GL_CULL_FACE );
glEnable(GL_TEXTURE_2D);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
char textures[6][24] =
{
"miramar_ft.tga",
"miramar_dn.tga",
"miramar_bk.tga",
"miramar_lf.tga",
"miramar_rt.tga",
"miramar_up.tga"
};
skybox=new Skybox("miramar_ft.tga", "miramar_bk.tga",
"miramar_up.tga", "miramar_dn.tga",
"miramar_lf.tga", "miramar_rt.tga", "Skybox");
//glEnable(GL_LIGHTING);
//glEnable(GL_LIGHT0);
//float col[]={1.0,1.0,1.0,1.0};
//glLightfv(GL_LIGHT0,GL_DIFFUSE,col);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
skybox->draw();
//float pos[]={-1.0,1.0,-2.0,1.0};
//glLightfv(GL_LIGHT0,GL_POSITION,pos);
//glTranslatef(0.0,-30.0,-100.0);
//glCallList(cube); //and display it
}
int main(int argc,char** argv)
{
SDL_Init(SDL_INIT_EVERYTHING);
screen=SDL_SetVideoMode(gwidth,gheight,32,SDL_SWSURFACE|SDL_OPENGL|SDL_RESIZABLE);
bool running=true;
Uint32 start;
SDL_Event event;
init();
while(running)
{
start=SDL_GetTicks();
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
printf("quittin\n");
running=false;
break;
case SDL_VIDEORESIZE:
gwidth=event.resize.w;
gheight=event.resize.h;
cleanup();
SDL_FreeSurface(screen);
screen=SDL_SetVideoMode(gwidth,gheight,32,SDL_SWSURFACE|SDL_OPENGL|SDL_RESIZABLE);
init();
break;
}
}
display();
SDL_GL_SwapBuffers();
SDL_Delay(100);
}
cleanup();
SDL_FreeSurface(screen);
SDL_Quit();
return 0;
}