[Clean] Fixed formatting for good.

This commit is contained in:
Rtch90 2012-04-07 15:03:03 +01:00
parent 8834fcc762
commit 48a056984d
5 changed files with 78 additions and 78 deletions

BIN
Bin/LibD

Binary file not shown.

View File

@ -12,10 +12,10 @@ public:
bool Create(int width, int height, int bpp, bool fullscreen); bool Create(int width, int height, int bpp, bool fullscreen);
void Destroy(bool); void Destroy(bool);
void ProcessEvents(void); void ProcessEvents(void);
void AttachGame(Game* game) { _game = game; } void AttachGame(Game* game) { _game = game; }
bool IsRunning(void) { return _isRunning; } bool IsRunning(void) { return _isRunning; }
void SwapBuffers(void) { SwapBuffers(_hdc); } void SwapBuffers(void) { SwapBuffers(_hdc); }
static LRESULT CALLBACK StaticWndProc(HWND wnd, UINT msg, WPARAP wParam, LPARAM lParam); static LRESULT CALLBACK StaticWndProc(HWND wnd, UINT msg, WPARAP wParam, LPARAM lParam);
LRESULT CALLBACK WndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK WndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam);
@ -27,15 +27,15 @@ private:
Game* GetAttachedGame(void) { return _game; } Game* GetAttachedGame(void) { return _game; }
// A pointer to the application. // A pointer to the application.
Game* _game; Game* _game;
bool _isRunning; bool _isRunning;
bool _isFullScreen; bool _isFullScreen;
float _lastTime; float _lastTime;
HWND _hwnd; // Window handle. HWND _hwnd; // Window handle.
HGLRC _hglrc; // Rendering context. HGLRC _hglrc; // Rendering context.
HDC _hdc; // Device context. HDC _hdc; // Device context.
RECT _windowRect; // Window bound. RECT _windowRect; // Window bound.
HINSTANCE _hinstance; // Application instance. HINSTANCE _hinstance; // Application instance.
WNDCLASSEX _windowClass; WNDCLASSEX _windowClass;
} }

View File

@ -27,7 +27,7 @@ void Game::Prepare(float dt) {
const float SPEED = 15.0f; const float SPEED = 15.0f;
_rotationAngle += SPEED*dt; _rotationAngle += SPEED*dt;
if(_rotationAngle > 360.0f) { if(_rotationAngle > 360.0f) {
_rotationAngle -= 360.0f; _rotationAngle -= 360.0f;
} }
} }

View File

@ -11,7 +11,7 @@
using std::string; using std::string;
//typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display* dpy, GLXFBConfig config, //typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display* dpy, GLXFBConfig config,
// GLXContext share_context, bool direct, const int* attrib_list); // GLXContext share_context, bool direct, const int* attrib_list);
unsigned int GetTickCount(void) { unsigned int GetTickCount(void) {
struct timeval t; struct timeval t;
@ -23,18 +23,18 @@ unsigned int GetTickCount(void) {
} }
LGLXWindow::LGLXWindow(void) : LGLXWindow::LGLXWindow(void) :
_game(NULL), _game(NULL),
_isRunning(true), _isRunning(true),
_lastTime(0), _lastTime(0),
_display(NULL), _display(NULL),
_xWindow(0), _xWindow(0),
_glContext(0), _glContext(0),
_screenID(0), _screenID(0),
_isFullscreen(false), _isFullscreen(false),
_width(0), _width(0),
_height(0), _height(0),
_bpp(0), _bpp(0),
_GL3Supported(false) {} _GL3Supported(false) {}
LGLXWindow::~LGLXWindow(void) { LGLXWindow::~LGLXWindow(void) {
@ -57,61 +57,61 @@ bool LGLXWindow::Create(int width, int height, int bpp, bool fullscreen) {
XF86VidModeModeInfo **modes; XF86VidModeModeInfo **modes;
if(!XF86VidModeGetAllModeLines(_display, _screenID, &modeNum, &modes)) { if(!XF86VidModeGetAllModeLines(_display, _screenID, &modeNum, &modes)) {
std::cerr << "Could not query the video modes." << std::endl; std::cerr << "Could not query the video modes." << std::endl;
return false; return false;
} }
_XF86DeskMode = *modes[0]; _XF86DeskMode = *modes[0];
int bestMode = -1; int bestMode = -1;
for(int i = 0; i < modeNum; i++) { for(int i = 0; i < modeNum; i++) {
if((modes[i]->hdisplay == width) && (modes[i]->vdisplay == height)) { if((modes[i]->hdisplay == width) && (modes[i]->vdisplay == height)) {
bestMode = i; bestMode = i;
} }
} }
if(bestMode == -1) { if(bestMode == -1) {
std::cerr << "Could not find a suitable graphics mode." << std::endl; std::cerr << "Could not find a suitable graphics mode." << std::endl;
return false; return false;
} }
int doubleBufferedAttribList[] = { int doubleBufferedAttribList[] = {
GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RGBA, GLX_DOUBLEBUFFER,
GLX_RED_SIZE, 4, GLX_RED_SIZE, 4,
GLX_GREEN_SIZE, 4, GLX_GREEN_SIZE, 4,
GLX_BLUE_SIZE, 4, GLX_BLUE_SIZE, 4,
GLX_DEPTH_SIZE, 16, GLX_DEPTH_SIZE, 16,
None None
}; };
XVisualInfo* vi = NULL; XVisualInfo* vi = NULL;
// Attempt to create a double buffered window. // Attempt to create a double buffered window.
vi = glXChooseVisual(_display, _screenID, doubleBufferedAttribList); vi = glXChooseVisual(_display, _screenID, doubleBufferedAttribList);
if(!vi) { if(!vi) {
std::cerr << "Could not create a double buffere window.. Sux.." <<std::endl; std::cerr << "Could not create a double buffere window.. Sux.." <<std::endl;
} }
// Time to create a GL 2.1 context. // Time to create a GL 2.1 context.
GLXContext gl2Context = glXCreateContext(_display, vi, 0, GL_TRUE); GLXContext gl2Context = glXCreateContext(_display, vi, 0, GL_TRUE);
if(!gl2Context) { if(!gl2Context) {
std::cerr << "Could Not create a GL 2.1 context, check your darn graphics drivers" << std::endl; std::cerr << "Could Not create a GL 2.1 context, check your darn graphics drivers" << std::endl;
return false; return false;
} }
// Get a pointer to the GL 3.0 context creation. // Get a pointer to the GL 3.0 context creation.
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs
= (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddress((GLubyte*)"glXCreateContextAttribsARB"); = (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddress((GLubyte*)"glXCreateContextAttribsARB");
if(glXCreateContextAttribs == NULL) { if(glXCreateContextAttribs == NULL) {
std::cerr << "OpenGL 3.0 is not supported, falling back to 2.1" << std::endl; std::cerr << "OpenGL 3.0 is not supported, falling back to 2.1" << std::endl;
_glContext = gl2Context; _glContext = gl2Context;
_GL3Supported = false; _GL3Supported = false;
} else { } else {
// We create a GL 3.0 context.. // We create a GL 3.0 context..
int attribs[] = { int attribs[] = {
GLX_CONTEXT_MAJOR_VERSION_ARB, 3, // We want a 3.0 context. GLX_CONTEXT_MAJOR_VERSION_ARB, 3, // We want a 3.0 context.
GLX_CONTEXT_MINOR_VERSION_ARB, 0, GLX_CONTEXT_MINOR_VERSION_ARB, 0,
0 // Zero indicates the end of the array. 0 // Zero indicates the end of the array.
}; };
_glContext = glXCreateContextAttribs(_display, framebufferConfig, 0, true, &attribs[0]); _glContext = glXCreateContextAttribs(_display, framebufferConfig, 0, true, &attribs[0]);
@ -121,10 +121,10 @@ bool LGLXWindow::Create(int width, int height, int bpp, bool fullscreen) {
} }
Colormap cmap = XCreateColormap(_display, RootWindow(_display, vi->screen), vi->visual, AllocNone); Colormap cmap = XCreateColormap(_display, RootWindow(_display, vi->screen), vi->visual, AllocNone);
_XSetAttr.colormap = cmap; _XSetAttr.colormap = cmap;
_XSetAttr.border_pixel = 0; _XSetAttr.border_pixel = 0;
_XSetAttr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | _XSetAttr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
StructureNotifyMask; StructureNotifyMask;
_XSetAttr.override_redirect = False; _XSetAttr.override_redirect = False;
//unsigned long windowAttributes = CWBorderPixel | CWColormap | CWEventMask; //unsigned long windowAttributes = CWBorderPixel | CWColormap | CWEventMask;
@ -138,8 +138,8 @@ bool LGLXWindow::Create(int width, int height, int bpp, bool fullscreen) {
} }
_xWindow = XCreateWindow(_display, RootWindow(_display, vi->screen), _xWindow = XCreateWindow(_display, RootWindow(_display, vi->screen),
0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap | CWEventMask, &_XSetAttr); CWBorderPixel | CWColormap | CWEventMask, &_XSetAttr);
string title = "LibD"; string title = "LibD";
if(fullscreen) { if(fullscreen) {
@ -147,7 +147,7 @@ bool LGLXWindow::Create(int width, int height, int bpp, bool fullscreen) {
XMapRaised(_display, _xWindow); XMapRaised(_display, _xWindow);
XGrabKeyboard(_display, _xWindow, True, GrabModeAsync, GrabModeAsync, CurrentTime); XGrabKeyboard(_display, _xWindow, True, GrabModeAsync, GrabModeAsync, CurrentTime);
XGrabPointer(_display, _xWindow, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, XGrabPointer(_display, _xWindow, True, ButtonPressMask, GrabModeAsync, GrabModeAsync,
_xWindow, None, CurrentTime); _xWindow, None, CurrentTime);
} else { } else {
Atom wmDelete = XInternAtom(_display, "WM_DELETE_WINDOW", True); Atom wmDelete = XInternAtom(_display, "WM_DELETE_WINDOW", True);
XSetWMProtocols(_display, _xWindow, &wmDelete, 1); XSetWMProtocols(_display, _xWindow, &wmDelete, 1);
@ -159,17 +159,17 @@ bool LGLXWindow::Create(int width, int height, int bpp, bool fullscreen) {
glXMakeCurrent(_display, _xWindow, _glContext); glXMakeCurrent(_display, _xWindow, _glContext);
int posX = 0; int posX = 0;
int posY = 0; int posY = 0;
Window winDummy; Window winDummy;
unsigned int borderDummy; unsigned int borderDummy;
_width = (unsigned) width; _width = (unsigned) width;
_height = (unsigned) height; _height = (unsigned) height;
_bpp = (unsigned) bpp; _bpp = (unsigned) bpp;
XGetGeometry(_display, _xWindow, &winDummy, &posX, &posY, XGetGeometry(_display, _xWindow, &winDummy, &posX, &posY,
&_width, &_height, &borderDummy, &_bpp); &_width, &_height, &borderDummy, &_bpp);
// Init the time. // Init the time.
_lastTime = GetTickCount(); _lastTime = GetTickCount();
@ -202,17 +202,17 @@ void LGLXWindow::ProcessEvents(void) {
break; break;
case ConfigureNotify: case ConfigureNotify:
{ {
int width = event.xconfigure.width; int width = event.xconfigure.width;
int height = event.xconfigure.height; int height = event.xconfigure.height;
GetAttachedGame()->OnResize(width, height); GetAttachedGame()->OnResize(width, height);
} }
break; break;
case KeyPress: case KeyPress:
{ {
if(XLookupKeysym(&event.xkey, 0) == XK_Escape) { if(XLookupKeysym(&event.xkey, 0) == XK_Escape) {
_isRunning = false; _isRunning = false;
} }
// Register the key press with keyboard interface. // Register the key press with keyboard interface.
} }
break; break;
case KeyRelease: case KeyRelease:

View File

@ -18,10 +18,10 @@ int WINAPI winMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine,
int main(int argc, char** argv) { int main(int argc, char** argv) {
#endif #endif
// Get our window settings. // Get our window settings.
const int windowWidth = 800; const int windowWidth = 800;
const int windowHeight = 600; const int windowHeight = 600;
const int windowBPP = 16; const int windowBPP = 16;
const int windowFullscreen = false; const int windowFullscreen = false;
#ifdef _WIN32_ #ifdef _WIN32_
// This is our window. // This is our window.
@ -41,29 +41,29 @@ int main(int argc, char** argv) {
#ifdef _WIN32_ #ifdef _WIN32_
MessageBox(NULL, "Unable to create the OpenGL Window", "An error occured", MB_ICONERROR | MB_OK); MessageBox(NULL, "Unable to create the OpenGL Window", "An error occured", MB_ICONERROR | MB_OK);
#endif #endif
programWindow.Destroy(); // Reset the display and exit. programWindow.Destroy(); // Reset the display and exit.
return 1; return 1;
} }
if(!game.Init()) { // Initialize our game. if(!game.Init()) { // Initialize our game.
#ifdef _WIN32_ #ifdef _WIN32_
MessageBox(NULL, "Could not initialize the application", "An error occured", MB_ICONERROR | MB_OK); MessageBox(NULL, "Could not initialize the application", "An error occured", MB_ICONERROR | MB_OK);
#endif #endif
programWindow.Destroy(); // Reset the display and exit. programWindow.Destroy(); // Reset the display and exit.
return 1; return 1;
} }
// This is the main loop, we render frames until IsRunning returns false. // This is the main loop, we render frames until IsRunning returns false.
while(programWindow.IsRunning()) { while(programWindow.IsRunning()) {
programWindow.ProcessEvents(); // Process any window events. programWindow.ProcessEvents(); // Process any window events.
// We get the time that passed since the last frame. // We get the time that passed since the last frame.
float elapsedTime = programWindow.GetElapsedSeconds(); float elapsedTime = programWindow.GetElapsedSeconds();
game.Prepare(elapsedTime); // Do any pre-rendering logic. game.Prepare(elapsedTime); // Do any pre-rendering logic.
game.Render(); // Render the scene. game.Render(); // Render the scene.
programWindow.SwapBuffers(); programWindow.SwapBuffers();
} }
game.Shutdown(); // Free any resouces. game.Shutdown(); // Free any resouces.
programWindow.Destroy(); // Destroy the program window. programWindow.Destroy(); // Destroy the program window.
return 0; return 0;
} }