[Fix] Initialized some uninitialized variables.

[Fix] Changed Allanis' bounding box class to use SDL surfaces.
[Add] Initial Qt Creator support in Windows.
This commit is contained in:
Tamir Atias 2012-04-12 18:01:06 +03:00
parent 1a2ba29855
commit 06e13c3c33
8 changed files with 42 additions and 330 deletions

View File

@ -1,13 +1,15 @@
CONFIG -= qt CONFIG -= qt
LIBS += -lGL \ LIBS += -lGL \
-lSDL \ -lSDL \
-lSDL_ttf \
-lSDL_image \ -lSDL_image \
-lSDL_gfx \
-ltinyxml \ -ltinyxml \
-lGLU \ -lGLU \
-lz \ -lz \
-ltinyxml -ltinyxml
win32: {
LIBS -= -lGL -lGLU
LIBS += -lkernel32 -luser32 -lgdi32 -lopengl32 -lglu32
}
HEADERS += ../src/Actor/Player.h \ HEADERS += ../src/Actor/Player.h \
../src/Collision/AABB.h \ ../src/Collision/AABB.h \
../src/Global/Constants.h \ ../src/Global/Constants.h \
@ -17,7 +19,6 @@ HEADERS += ../src/Actor/Player.h \
../src/Level/Level.h \ ../src/Level/Level.h \
../src/Level/Layer.h \ ../src/Level/Layer.h \
../src/Level/Tileset.h \ ../src/Level/Tileset.h \
../src/Main/LGLXWindow.h \
../src/Main/GLWindow.h \ ../src/Main/GLWindow.h \
../src/Main/Game.h \ ../src/Main/Game.h \
../src/Math/Timer.h \ ../src/Math/Timer.h \
@ -52,7 +53,6 @@ SOURCES += ../src/Actor/Player.cpp \
../src/Level/Tileset.cpp \ ../src/Level/Tileset.cpp \
../src/Level/Level.cpp \ ../src/Level/Level.cpp \
../src/Level/Layer.cpp \ ../src/Level/Layer.cpp \
../src/Main/LGLXWindow.cpp \
../src/Main/GLWindow.cpp \ ../src/Main/GLWindow.cpp \
../src/Main/Game.cpp \ ../src/Main/Game.cpp \
../src/Main/main.cpp \ ../src/Main/main.cpp \

View File

@ -6,11 +6,13 @@ Player::Player(void) {
_allowCollision = true; _allowCollision = true;
_notColliding = false; _notColliding = false;
_blueCollision = false; _blueCollision = false;
_player = new Sprite();
_player->LoadSprite("../Data/Img/Player.png");
// Loading of sprites and collision details. // Loading of sprites and collision details.
// This should be directed to a collision sheet. // This should be directed to a collision sheet.
//_collisionBound = new AABB(); _collisionBound = new AABB();
//_collisionBound->CreateAABBFromSprite("../Data/Img/Player"); _collisionBound->CreateAABBFromSprite("../Data/Img/Player");
//_environmentCollisionBound = new AABB(); //_environmentCollisionBound = new AABB();
//_environmentCollisionBound->SetMin(_collisionBound->GetMin().x, _collisionBound->GetMax().y - 50.0f); //_environmentCollisionBound->SetMin(_collisionBound->GetMin().x, _collisionBound->GetMax().y - 50.0f);
@ -23,9 +25,6 @@ Player::~Player(void) {
} }
void Player::Update(void) { void Player::Update(void) {
if(!_player) {
_player->LoadSprite("../Data/Img/Player.png");
}
// Position and collision bound with the player. // Position and collision bound with the player.
//_collisionBound->SetPositionOffset(_player->GetX(), _player->GetY()); //_collisionBound->SetPositionOffset(_player->GetX(), _player->GetY());
//_environmentCollisionBound->SetPositionOffset(_player->GetX, _player->GetY()); //_environmentCollisionBound->SetPositionOffset(_player->GetX, _player->GetY());

View File

@ -1,6 +1,6 @@
#include <SDL/SDL_image.h>
#include "AABB.h" #include "AABB.h"
typedef Uint32 DWORD; typedef Uint32 DWORD;
AABB::AABB(void) { AABB::AABB(void) {
@ -21,8 +21,10 @@ AABB::AABB(Vec2 &min, Vec2 &max) {
} }
AABB::~AABB(void) { AABB::~AABB(void) {
if(_sprite) if(_sprite) {
delete _sprite; SDL_FreeSurface(_sprite);
_sprite = NULL;
}
} }
void AABB::SetRelativePosition(float x, float y) { void AABB::SetRelativePosition(float x, float y) {
@ -53,22 +55,24 @@ bool AABB::InCollision(AABB* otherAABB) {
void AABB::CreateAABBFromSprite(const char* filename) { void AABB::CreateAABBFromSprite(const char* filename) {
std::string tempName(filename); std::string tempName(filename);
tempName += ".png"; tempName += ".png";
_sprite = new Sprite(); _sprite = IMG_Load(filename);
_sprite->LoadSprite(tempName); if(!_sprite) {
return;
}
// I have no methods here, hopefully KonoM will have it // I have no methods here, hopefully KonoM will have it
// implemented real soon... // implemented real soon...
//float spriteWidth = _sprite->GetWidth(); //float spriteWidth = _sprite->w;
//float spriteHeight = _sprite->GetHeight(); //float spriteHeight = _sprite->h;
// Find the min, look through until we find a first instance of a white color. // Find the min, look through until we find a first instance of a white color.
bool found = false; bool found = false;
int color = 0; int color = 0;
DWORD* pixels = (DWORD*)screen->pixels; DWORD* pixels = (DWORD*)_sprite->pixels;
for(int width = 0; width < _sprite->GetWidth(); width++) { for(int width = 0; width < _sprite->w; width++) {
for(int height = 0; height < _sprite->GetHeight(); height++) { for(int height = 0; height < _sprite->h; height++) {
// FUCKING PAIN IN THE ASS MOTHERFUCKER!!!! // FUCKING PAIN IN THE ASS MOTHERFUCKER!!!!
DWORD offset = height * screen->pitch + width; DWORD offset = height * screen->pitch + width;
// if(((DWORD)pixels[offset]) != 0 && !found) { // if(((DWORD)pixels[offset]) != 0 && !found) {
@ -76,17 +80,17 @@ void AABB::CreateAABBFromSprite(const char* filename) {
// found = true; // found = true;
// color = ((DWORD)pixels[offset]); // color = ((DWORD)pixels[offset]);
// // Break out of these god forsaken loops. // // Break out of these god forsaken loops.
// width = _sprite->GetWidth(); // width = _sprite->w;
// height = _sprite->GetHeight(); // height = _sprite->h;
// } // }
} }
} }
// Let's try to find the max.x now.. // Let's try to find the max.x now..
_max.x = (float)_sprite->GetWidth(); _max.x = (float)_sprite->w;
found = false; found = false;
for(int width = (int)_min.x; width < _sprite->GetWidth(); width++) { for(int width = (int)_min.x; width < _sprite->w; width++) {
DWORD offset = _min.y * screen->pitch + width; DWORD offset = (DWORD)_min.y * screen->pitch + width;
// if(((DWORD)pixels[offset] != color && !found)) { // if(((DWORD)pixels[offset] != color && !found)) {
// found = true; // found = true;
// _max.x = (float)width; // _max.x = (float)width;
@ -94,10 +98,10 @@ void AABB::CreateAABBFromSprite(const char* filename) {
} }
// Now for the max.y // Now for the max.y
_max.y = (float)_sprite->GetHeight(); _max.y = (float)_sprite->h;
found = false; found = false;
for(int height = (int)_min.y; height < _sprite->GetWidth(); height++) { for(int height = (int)_min.y; height < _sprite->w; height++) {
DWORD offset = (DWORD)(height * screen->pitch + _min.x); DWORD offset = height * screen->pitch + (DWORD)_min.x;
// if(((DWORD)pixels[offset]) != color && !found) { // if(((DWORD)pixels[offset]) != color && !found) {
// found = true; // found = true;
// _max.y = (float)height; // _max.y = (float)height;

View File

@ -2,7 +2,6 @@
#include <string> #include <string>
#include "../Math/Vec2.h" #include "../Math/Vec2.h"
#include "../Sprite/Sprite.h"
#include "../Global/Globals.h" #include "../Global/Globals.h"
/* /*
@ -13,6 +12,8 @@
* against other bounding box's. * against other bounding box's.
*/ */
struct SDL_Surface;
class AABB { class AABB {
public: public:
AABB(void); AABB(void);
@ -39,5 +40,5 @@ private:
Vec2 _staticMin; Vec2 _staticMin;
Vec2 _staticMax; Vec2 _staticMax;
Sprite* _sprite; SDL_Surface* _sprite;
}; };

View File

@ -35,7 +35,7 @@ bool Game::Init(void) {
glAlphaFunc(GL_GREATER, 0.1f); glAlphaFunc(GL_GREATER, 0.1f);
_level->Load("../Data/Map/Ugly.tmx"); _level->Load("../Data/Map/Ugly.tmx");
_player->Update();
// Return success. // Return success.
return true; return true;
} }

View File

@ -1,242 +0,0 @@
#include <iostream>
#include <string>
#ifdef __unix__
#include <sys/time.h>
#endif
#include "../System/Debug.h"
#include "LGLXWindow.h"
#include "Game.h"
using std::string;
//typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display* dpy, GLXFBConfig config,
// GLXContext share_context, bool direct, const int* attrib_list);
unsigned int GetTickCount(void) {
struct timeval t;
gettimeofday(&t, NULL);
unsigned long secs = t.tv_sec * 1000;
secs += (t.tv_usec / 1000);
return secs;
}
LGLXWindow::LGLXWindow(void) :
_game(NULL),
_isRunning(true),
_lastTime(0),
_display(NULL),
_xWindow(0),
_glContext(0),
_screenID(0),
_isFullscreen(false),
_width(0),
_height(0),
_bpp(0),
_GL3Supported(false)
{ CreateInput(); }
LGLXWindow::~LGLXWindow(void) {
}
bool LGLXWindow::Create(int width, int height, int bpp, bool fullscreen) {
// Open the default display.
_display = XOpenDisplay(0);
if(!_display) {
Debug::logger->message("Could not open the display.");
return false;
}
// Get the default screen ID.
_screenID = DefaultScreen(_display);
int n = 0, modeNum = 0;
// Get a frambuffer config useing the default attributes.
GLXFBConfig framebufferConfig = (*glXChooseFBConfig(_display, DefaultScreen(_display), 0, &n));
XF86VidModeModeInfo **modes;
if(!XF86VidModeGetAllModeLines(_display, _screenID, &modeNum, &modes)) {
Debug::logger->message("Could not query the video modes.");
return false;
}
_XF86DeskMode = *modes[0];
int bestMode = -1;
for(int i = 0; i < modeNum; i++) {
if((modes[i]->hdisplay == width) && (modes[i]->vdisplay == height)) {
bestMode = i;
}
}
if(bestMode == -1) {
Debug::logger->message("Could not find a suitable graphics mode.");
return false;
}
int doubleBufferedAttribList[] = {
GLX_RGBA, GLX_DOUBLEBUFFER,
GLX_RED_SIZE, 4,
GLX_GREEN_SIZE, 4,
GLX_BLUE_SIZE, 4,
GLX_DEPTH_SIZE, 16,
None
};
XVisualInfo* vi = NULL;
// Attempt to create a double buffered window.
vi = glXChooseVisual(_display, _screenID, doubleBufferedAttribList);
if(!vi) {
Debug::logger->message("Could not create a double buffere window.. Sux..");
}
// Time to create a GL 2.1 context.
GLXContext gl2Context = glXCreateContext(_display, vi, 0, GL_TRUE);
if(!gl2Context) {
Debug::logger->message("Could Not create a GL 2.1 context, check your darn graphics drivers");
return false;
}
// Get a pointer to the GL 3.0 context creation.
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs
= (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddress((GLubyte*)"glXCreateContextAttribsARB");
if(glXCreateContextAttribs == NULL) {
Debug::logger->message("OpenGL 3.0 is not supported, falling back to 2.1");
_glContext = gl2Context;
_GL3Supported = false;
} else {
// We create a GL 3.0 context..
int attribs[] = {
GLX_CONTEXT_MAJOR_VERSION_ARB, 3, // We want a 3.0 context.
GLX_CONTEXT_MINOR_VERSION_ARB, 0,
0 // Zero indicates the end of the array.
};
_glContext = glXCreateContextAttribs(_display, framebufferConfig, 0, true, &attribs[0]);
// We can destroy thr GL 2.0 context once the 3.0 one has been checked.
glXDestroyContext(_display, gl2Context);
_GL3Supported = true;
}
Colormap cmap = XCreateColormap(_display, RootWindow(_display, vi->screen), vi->visual, AllocNone);
_XSetAttr.colormap = cmap;
_XSetAttr.border_pixel = 0;
_XSetAttr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
StructureNotifyMask;
_XSetAttr.override_redirect = False;
//unsigned long windowAttributes = CWBorderPixel | CWColormap | CWEventMask;
if(fullscreen) {
//windowAttributes = CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect;
XF86VidModeSwitchToMode(_display, _screenID, modes[bestMode]);
XF86VidModeSetViewPort(_display, _screenID, 0, 0);
_XSetAttr.override_redirect = True;
}
_xWindow = XCreateWindow(_display, RootWindow(_display, vi->screen),
0, 0, width, height, 0, vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap | CWEventMask, &_XSetAttr);
string title = "LibD";
if(fullscreen) {
XWarpPointer(_display, None, _xWindow, 0, 0, 0, 0, 0, 0);
XMapRaised(_display, _xWindow);
XGrabKeyboard(_display, _xWindow, True, GrabModeAsync, GrabModeAsync, CurrentTime);
XGrabPointer(_display, _xWindow, True, ButtonPressMask, GrabModeAsync, GrabModeAsync,
_xWindow, None, CurrentTime);
} else {
Atom wmDelete = XInternAtom(_display, "WM_DELETE_WINDOW", True);
XSetWMProtocols(_display, _xWindow, &wmDelete, 1);
XSetStandardProperties(_display, _xWindow, title.c_str(), None, 0, NULL, 0, NULL);
XMapRaised(_display, _xWindow);
}
XFree(modes);
glXMakeCurrent(_display, _xWindow, _glContext);
int posX = 0;
int posY = 0;
Window winDummy;
unsigned int borderDummy;
_width = (unsigned) width;
_height = (unsigned) height;
_bpp = (unsigned) bpp;
XGetGeometry(_display, _xWindow, &winDummy, &posX, &posY,
&_width, &_height, &borderDummy, &_bpp);
// Init the time.
_lastTime = GetTickCount();
return true;
}
void LGLXWindow::Destroy(void) {
if(_glContext) {
glXMakeCurrent(_display, None, NULL);
glXDestroyContext(_display, _glContext);
_glContext = NULL;
}
if(_isFullscreen) {
XF86VidModeSwitchToMode(_display, _screenID, &_XF86DeskMode);
XF86VidModeSetViewPort(_display, _screenID, 0, 0);
}
DestroyInput();
XCloseDisplay(_display);
}
void LGLXWindow::ProcessEvents(void) {
XEvent event;
while(XPending(_display) > 0) {
XNextEvent(_display, &event);
switch(event.type) {
case Expose:
if(event.xexpose.count != 0)
break;
break;
case ConfigureNotify:
{
int width = event.xconfigure.width;
int height = event.xconfigure.height;
GetAttachedGame()->OnResize(width, height);
}
break;
case KeyPress:
{
if(XLookupKeysym(&event.xkey, 0) == XK_Escape) {
_isRunning = false;
}
UpdateInput();
// Register the key press with keyboard interface.
}
break;
case KeyRelease:
{
// Code here NAW!
}
break;
case ClientMessage:
if(string(XGetAtomName(_display, event.xclient.message_type)) == string("WM_PROTOCOLS")) {
_isRunning = false;
}
break;
default:
break;
}
}
}
float LGLXWindow::GetElapsedSeconds(void) {
unsigned int currentTime = GetTickCount();
unsigned int diff = currentTime - _lastTime;
_lastTime = currentTime;
return float(diff) / 1000.0f;
}

View File

@ -1,58 +0,0 @@
#pragma once
#define GLX_GLXEXT_LEGACY // Use our local glxext.h rather than the system one.
#include <GL/glx.h>
#include "../glx/glxext.h"
#include "../IO/Input.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/xf86vmode.h>
#include <X11/keysym.h>
#include <ctime>
class Game;
class LGLXWindow {
public:
LGLXWindow(void);
virtual ~LGLXWindow(void);
bool Create(int width, int hight, int bpp, bool fullscreen);
void Destroy(void);
void ProcessEvents(void);
void AttachGame(Game* game) { _game = game; }
bool IsRunning(void) { return _isRunning; }
void SwapBuffers(void) { glXSwapBuffers(_display, _xWindow); }
float GetElapsedSeconds(void);
private:
// A pointer to our game thingy..
Game* _game;
// Check to see if the window is still running FFS.
bool _isRunning;
keyboard_t keyboard;
Game* GetAttachedGame(void) { return _game; }
unsigned int _lastTime;
Display* _display;
Window _xWindow;
GLXContext _glContext;
XF86VidModeModeInfo _XF86DeskMode;
XSetWindowAttributes _XSetAttr;
int _screenID;
bool _isFullscreen;
unsigned int _width;
unsigned int _height;
unsigned int _bpp;
bool _GL3Supported;
// I think that's about all I need for now.. FOR NOW!!!
};

View File

@ -3,6 +3,14 @@
#include <iostream> #include <iostream>
using namespace std; using namespace std;
#ifndef GL_BGR_EXT
#define GL_BGR_EXT 0x80E0
#endif
#ifndef GL_BGRA_EXT
#define GL_BGRA_EXT 0x80E1
#endif
ResourceManager<Texture> textureManager; ResourceManager<Texture> textureManager;
static GLuint boundTexture = 0; static GLuint boundTexture = 0;