rendered paste body#ifndef __GLassEngine__
#define __GLassEngine__
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL.h>
#include <SDL_image.h>
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"sdl.lib")
#pragma comment(lib,"sdl_image.lib")
#define GLassOPENGL SDL_OPENGL
#define GLassFULLSC SDL_FULLSCREEN
const int RUN_CALLBACK_FUNCTION = 1;
class GLassApp
{
private:
int TheApp;
bool rf;
bool ef;
bool lf;
bool of;
int (*eventloop) (SDL_Event ev);
void (*renderfunction) (void);
void (*logicfunction) (void);
void (*objcallback) (GLassApp *app);
public:
GLassApp(int w, int h, Uint32 flags)
{
rf = false;
ef = false;
lf = false;
of = false;
int error;
SDL_Surface* drawContext;
error = SDL_Init(SDL_INIT_EVERYTHING);
// Create a double-buffered draw context
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
// Use 32-bit color: 8 bits of red, green, blue, and alpha.
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
//flags = SDL_OPENGL;// | SDL_FULLSCREEN;
drawContext = SDL_SetVideoMode(640, 480, 0, flags);
TheApp = 0;
glOrtho(-1, 1, -1, 1, -1, 1);
}
~GLassApp()
{
SDL_Quit();
}
void EventL()
{
SDL_Event event;
while(SDL_PollEvent(&event))
{ /* Loop until there are no events left on the queue */
if(ef)
{
TheApp = eventloop(event);
}
switch(event.type)
{ /* Process the appropiate event type */
case SDL_USEREVENT:
if(event.user.code==RUN_CALLBACK_FUNCTION)
{
if(of) { objcallback(this); }
}
break;
case SDL_KEYDOWN: /* Handle a KEYDOWN event */
printf("Oh! Key press\n");
break;
case SDL_MOUSEMOTION:
break;
case SDL_QUIT:
TheApp = 1;
break;
default: /* Report an unhandled event */
//printf("I don't know what this event is!\n");
break;
}
}
}
void DrawL()
{
glClear(GL_COLOR_BUFFER_BIT);
if(rf)
{
renderfunction();
}
SDL_GL_SwapBuffers();
}
void LogicL()
{
if(lf)
{
logicfunction();
}
}
void Run()
{
while(!TheApp)
{
EventL();
LogicL();
DrawL();
}
}
void AddEventLoop(int (*event) (SDL_Event ev))
{
(eventloop) = (*event);
ef = true;
}
void AddRenderLoop(void (*renderfunc) (void))
{
(renderfunction) = (*renderfunc);
rf = true;
}
void AddLogicLoop(void (*logicfunc) (void))
{
(logicfunction) = (*logicfunc);
lf = true;
}
void AddObject(void (*obj) (GLassApp *app))
{
(objcallback) = (*obj);
of = true;
}
};
#endif