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
|
class SCREEN
{
public:
SCREEN(char * T = "VMAP SCENE", bool FULL = false, int S_w = 800, int S_h = 600, int S_bpp = 16);
void InitVMAP(void);
void Draw(void);
private:
/* WINDOW PROPERTIES */
int SCREEN_w;
int SCREEN_h;
int SCREEN_bpp;
char * TITLE;
bool MainLoop;
Uint8 * Keys;
Uint32 Vflags;
int FpsT;
SDL_Surface * Screen;
SDL_Event E;
void ReshapeGL(void);
};
void SCREEN::InitVMAP(void)
{
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
cerr << "Unable to open SDL: " << SDL_GetError() << endl;
exit(1);
}
atexit(SDL_Quit);
FpsT = SDL_GetTicks();
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if(!(Screen = SDL_SetVideoMode(SCREEN_w, SCREEN_h, SCREEN_bpp, Vflags)))
{
cerr << "Unable to set Videomode: " << SDL_GetError() << endl;
exit(1);
}
atexit(SDL_Quit);
SDL_FillRect(Screen, NULL, SDL_MapRGBA(Screen->format, 0, 0, 0, 0));
ReshapeGL();
SDL_WM_SetCaption(TITLE, NULL);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
return;
}
void SCREEN::Draw(void)
{
while(!SDL_PollEvent(& E) || E.type != 2)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glBegin(GL_TRIANGLES);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, 0.0f);
glEnd();
SDL_GL_SwapBuffers();
}
return;
} |
Partager