-- Changed to use SDL rather than GLX/WIN32.

This commit is contained in:
Rtch90 2011-10-22 17:35:26 +01:00
parent 87527a2226
commit 96b2b3ff65
14 changed files with 215 additions and 91 deletions

14
Bin/Debug.log Normal file
View File

@ -0,0 +1,14 @@
Log Started: Sat Oct 22 17:32:56 2011
-----Debug Initialized-----
-----Engine Initialization Complete-----
-----Logic-----
-----Cleaning Up------
Window destroyed!
Log Closed: Sat Oct 22 17:32:59 2011

BIN
Unuk-QT/Debug.o Normal file

Binary file not shown.

BIN
Unuk-QT/Entity.o Normal file

Binary file not shown.

BIN
Unuk-QT/Game.o Normal file

Binary file not shown.

BIN
Unuk-QT/ImageLoader.o Normal file

Binary file not shown.

View File

@ -1,6 +1,6 @@
############################################################################# #############################################################################
# Makefile for building: Unuk-QT # Makefile for building: Unuk-QT
# Generated by qmake (2.01a) (Qt 4.7.3) on: Sun Oct 16 16:15:29 2011 # Generated by qmake (2.01a) (Qt 4.7.3) on: Sat Oct 22 17:32:53 2011
# Project: Unuk-QT.pro # Project: Unuk-QT.pro
# Template: app # Template: app
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro # Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
@ -16,7 +16,7 @@ CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I.
LINK = g++ LINK = g++
LFLAGS = LFLAGS =
LIBS = $(SUBLIBS) -L/usr/lib -lGL -lSDL -lQtGui -lQtCore -lpthread LIBS = $(SUBLIBS) -L/usr/lib -lGL -lSDL -lGLU -lQtGui -lQtCore -lpthread
AR = ar cqs AR = ar cqs
RANLIB = RANLIB =
QMAKE = /usr/bin/qmake-qt4 QMAKE = /usr/bin/qmake-qt4
@ -46,7 +46,6 @@ OBJECTS_DIR = ./
SOURCES = ../src/libUnuk/Vec2.cpp \ SOURCES = ../src/libUnuk/Vec2.cpp \
../src/libUnuk/Sprite.cpp \ ../src/libUnuk/Sprite.cpp \
../src/libUnuk/ImageLoader.cpp \ ../src/libUnuk/ImageLoader.cpp \
../src/libUnuk/GlxWindow.cpp \
../src/libUnuk/Debug.cpp \ ../src/libUnuk/Debug.cpp \
../src/Unuk/Player.cpp \ ../src/Unuk/Player.cpp \
../src/Unuk/main.cpp \ ../src/Unuk/main.cpp \
@ -55,7 +54,6 @@ SOURCES = ../src/libUnuk/Vec2.cpp \
OBJECTS = Vec2.o \ OBJECTS = Vec2.o \
Sprite.o \ Sprite.o \
ImageLoader.o \ ImageLoader.o \
GlxWindow.o \
Debug.o \ Debug.o \
Player.o \ Player.o \
main.o \ main.o \
@ -160,7 +158,7 @@ qmake: FORCE
dist: dist:
@$(CHK_DIR_EXISTS) .tmp/Unuk-QT1.0.0 || $(MKDIR) .tmp/Unuk-QT1.0.0 @$(CHK_DIR_EXISTS) .tmp/Unuk-QT1.0.0 || $(MKDIR) .tmp/Unuk-QT1.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Vec2.h ../src/libUnuk/ImageLoader.h ../src/libUnuk/GlxWindow.h ../src/libUnuk/Sprite.h ../src/libUnuk/Debug.h ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/Unuk/Game.h ../src/Unuk/Player.h ../src/libUnuk/KeyboardInterface.h ../src/libUnuk/XKeyboardInterface.h ../src/libUnuk/Static.h ../src/libUnuk/UnukWindow.h ../src/libUnuk/Geometry.h ../src/libUnuk/Entity.h ../src/libUnuk/EntityType.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Vec2.cpp ../src/libUnuk/Sprite.cpp ../src/libUnuk/ImageLoader.cpp ../src/libUnuk/GlxWindow.cpp ../src/libUnuk/Debug.cpp ../src/Unuk/Player.cpp ../src/Unuk/main.cpp ../src/Unuk/Game.cpp ../src/libUnuk/Entity.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0 $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Vec2.h ../src/libUnuk/ImageLoader.h ../src/libUnuk/Sprite.h ../src/libUnuk/Debug.h ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/Unuk/Game.h ../src/Unuk/Player.h ../src/libUnuk/KeyboardInterface.h ../src/libUnuk/XKeyboardInterface.h ../src/libUnuk/Static.h ../src/libUnuk/UnukWindow.h ../src/libUnuk/Geometry.h ../src/libUnuk/Entity.h ../src/libUnuk/EntityType.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Vec2.cpp ../src/libUnuk/Sprite.cpp ../src/libUnuk/ImageLoader.cpp ../src/libUnuk/Debug.cpp ../src/Unuk/Player.cpp ../src/Unuk/main.cpp ../src/Unuk/Game.cpp ../src/libUnuk/Entity.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0
clean:compiler_clean clean:compiler_clean
@ -214,30 +212,17 @@ ImageLoader.o: ../src/libUnuk/ImageLoader.cpp ../src/libUnuk/ImageLoader.h \
../src/libUnuk/Debug.h ../src/libUnuk/Debug.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o ImageLoader.o ../src/libUnuk/ImageLoader.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o ImageLoader.o ../src/libUnuk/ImageLoader.cpp
GlxWindow.o: ../src/libUnuk/GlxWindow.cpp ../src/Unuk/Game.h \
../src/Unuk/Player.h \
../src/libUnuk/Sprite.h \
../src/libUnuk/ImageLoader.h \
../src/libUnuk/GlxWindow.h \
../src/Libs/glxext.h \
../src/libUnuk/XKeyboardInterface.h \
../src/libUnuk/KeyboardInterface.h \
../src/libUnuk/Debug.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o GlxWindow.o ../src/libUnuk/GlxWindow.cpp
Debug.o: ../src/libUnuk/Debug.cpp ../src/libUnuk/Debug.h Debug.o: ../src/libUnuk/Debug.cpp ../src/libUnuk/Debug.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Debug.o ../src/libUnuk/Debug.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Debug.o ../src/libUnuk/Debug.cpp
Player.o: ../src/Unuk/Player.cpp ../src/libUnuk/Sprite.h \ Player.o: ../src/Unuk/Player.cpp ../src/libUnuk/Sprite.h \
../src/libUnuk/ImageLoader.h \ ../src/libUnuk/ImageLoader.h \
../src/libUnuk/Debug.h \ ../src/libUnuk/Debug.h \
../src/libUnuk/KeyboardInterface.h \
../src/Unuk/Player.h ../src/Unuk/Player.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Player.o ../src/Unuk/Player.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Player.o ../src/Unuk/Player.cpp
main.o: ../src/Unuk/main.cpp ../src/libUnuk/Win32Window.h \ main.o: ../src/Unuk/main.cpp ../src/Unuk/Game.h \
../src/libUnuk/GlxWindow.h \
../src/Libs/glxext.h \
../src/Unuk/Game.h \
../src/Unuk/Player.h \ ../src/Unuk/Player.h \
../src/libUnuk/Sprite.h \ ../src/libUnuk/Sprite.h \
../src/libUnuk/ImageLoader.h \ ../src/libUnuk/ImageLoader.h \

BIN
Unuk-QT/Player.o Normal file

Binary file not shown.

BIN
Unuk-QT/Sprite.o Normal file

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,6 @@
LIBS += -lGL -lSDL LIBS += -lGL \
-lSDL \
-lGLU
RESOURCES += RESOURCES +=
OTHER_FILES += ../src/libUnuk/Vec2.o \ OTHER_FILES += ../src/libUnuk/Vec2.o \
../src/libUnuk/ImageLoader.o \ ../src/libUnuk/ImageLoader.o \
@ -7,7 +9,6 @@ OTHER_FILES += ../src/libUnuk/Vec2.o \
../src/libUnuk/Debug.o ../src/libUnuk/Debug.o
HEADERS += ../src/libUnuk/Vec2.h \ HEADERS += ../src/libUnuk/Vec2.h \
../src/libUnuk/ImageLoader.h \ ../src/libUnuk/ImageLoader.h \
../src/libUnuk/GlxWindow.h \
../src/libUnuk/Sprite.h \ ../src/libUnuk/Sprite.h \
../src/libUnuk/Debug.h \ ../src/libUnuk/Debug.h \
../src/Libs/wglext.h \ ../src/Libs/wglext.h \
@ -24,7 +25,6 @@ HEADERS += ../src/libUnuk/Vec2.h \
SOURCES += ../src/libUnuk/Vec2.cpp \ SOURCES += ../src/libUnuk/Vec2.cpp \
../src/libUnuk/Sprite.cpp \ ../src/libUnuk/Sprite.cpp \
../src/libUnuk/ImageLoader.cpp \ ../src/libUnuk/ImageLoader.cpp \
../src/libUnuk/GlxWindow.cpp \
../src/libUnuk/Debug.cpp \ ../src/libUnuk/Debug.cpp \
../src/Unuk/Player.cpp \ ../src/Unuk/Player.cpp \
../src/Unuk/main.cpp \ ../src/Unuk/main.cpp \

BIN
Unuk-QT/Vec2.o Normal file

Binary file not shown.

BIN
Unuk-QT/main.o Normal file

Binary file not shown.

View File

@ -1,5 +1,6 @@
#ifndef _GAME_H_ #ifndef _GAME_H_
#define _GAME_H_ #define _GAME_H_
#include "SDL/SDL.h"
#include "Player.h" #include "Player.h"
class Game { class Game {

View File

@ -1,92 +1,216 @@
#define WIN32_LEAN_AND_MEAN #ifdef __unix__
#define WIN32_EXTRA_LEAN #include <sys/time.h>
#define GLX_GLXEXT_LEGACY // Defined so we use our own glxext.h, rather than the system one.
#ifdef WIN32
#include <windows.h>
#include "../libUnuk/Win32Window.h"
#else
#include "../libUnuk/GlxWindow.h"
#endif #endif
#include <SDL/SDL.h> #include <stdio.h>
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "SDL/SDL.h"
#include "Game.h" #include "Game.h"
#include "../libUnuk/Debug.h" #include "../libUnuk/Debug.h"
#ifdef WIN32 // Screen width, height, and bit depth.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow) { const int SCREEN_WIDTH = 640;
#else const int SCREEN_HEIGHT = 480;
int main(/*int argc, char** argv*/) { const int SCREEN_BPP = 16;
#endif
// Define our SDL surface.
SDL_Surface *surface;
void Quit(int returnCode) {
Debug::logger->message("-----Cleaning Up------");
// Clean up the window.
SDL_Quit();
Debug::logger->message("Window destroyed!");
Debug::closeLog();
// And exit appropriately.
exit(returnCode);
}
// Reset our viewport after a window resize.
int ResizeWindow(int width, int height) {
// Height and width ration.
GLfloat ratio;
// Prevent devide by zero.
if(height == 0)
height = 1;
ratio = (GLfloat )width / (GLfloat)height;
// Setup our viewport.
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
// Change to the projection matrix and set our viewing volume.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Set our perspective.
gluPerspective(45.0f, ratio, 0.1f, 100.0f);
// Change to the MODELVIEW.
glMatrixMode(GL_MODELVIEW);
// Reset The View.
glLoadIdentity();
return 1;
}
void ProcessEvents(SDL_keysym *keysym) {
switch(keysym->sym) {
case SDLK_ESCAPE:
// Quit if we detect 'esc' key.
Quit(0);
break;
case SDLK_F1:
// Fullscreen.
SDL_WM_ToggleFullScreen(surface);
break;
default:
break;
}
return;
}
int InitGL(void) {
// Enable smooth shading.
glShadeModel(GL_SMOOTH);
// Set the background black.
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// Depth buffer setup.
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
// Nice Perspective Calculations.
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
return 1;
}
unsigned int GetTickCount() {
struct timeval t;
gettimeofday(&t, NULL);
unsigned long secs = t.tv_sec * 1000;
secs += (t.tv_usec / 1000);
return secs;
}
float GetElapsedSeconds(void) {
unsigned int lastTime = 0;
unsigned int currentTime = GetTickCount();
unsigned int diff = currentTime - lastTime;
lastTime = currentTime;
return float(diff) / 1000.0f;
}
int main() {
// Initialize our Debug log. // Initialize our Debug log.
Debug::openLog(true); Debug::openLog(true);
Debug::logger->message("-----Debug Initialized-----"); Debug::logger->message("-----Debug Initialized-----");
// Set our window settings.
const int windowWidth = 800;
const int windowHeight = 600;
const int windowBPP = 16;
const int windowFullscreen = false;
#ifdef WIN32 int videoFlags;
// This is our window. bool done = false;
Win32Window programWindow(hInstance); SDL_Event event;
#else const SDL_VideoInfo *videoInfo;
GlxWindow programWindow;
#endif
// Set SDL up so we can use it for input and crap.
SDL_Init(SDL_INIT_EVERYTHING);
// The Game code.
Game game; Game game;
// Attach the game to our window. // Initialize SDL.
programWindow.AttachGame(&game); if(SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError());
// Attempt to create the window. Quit(1);
if(!programWindow.Create(windowWidth, windowHeight, windowBPP, windowFullscreen)) {
// If it fails to be created...
#ifdef WIN32
MessageBox(NULL, "Unable to create the OpenGL window.", "Error", MB_ICONERROR | MB_OK);
#endif
// Reset the display and exit.
programWindow.Destroy();
return 1;
} }
// Make sure our game is initialized. // Fetch the video info.
if(!game.Init()) { videoInfo = SDL_GetVideoInfo();
#ifdef WIN32
MessageBox(Null, "Could not initialize the application", "Error", MB_ICONERROR | MB_OK); // Set the window caption.
#endif SDL_WM_SetCaption("Unuk", NULL);
// Reset the display and exit.
programWindow.Destroy(); if(!videoInfo) {
return 1; fprintf( stderr, "Video query failed: %s\n", SDL_GetError());
Quit(1);
} }
// Pass some flags to SDL_SetVideoMode.
videoFlags = SDL_OPENGL;
videoFlags |= SDL_GL_DOUBLEBUFFER;
videoFlags |= SDL_HWPALETTE;
videoFlags |= SDL_RESIZABLE;
// Can the surface be stored in memory?
if(videoInfo->hw_available)
videoFlags |= SDL_HWSURFACE;
else
videoFlags |= SDL_SWSURFACE;
// Can we perform blitting on the GPU?
if(videoInfo->blit_hw)
videoFlags |= SDL_HWACCEL;
// Set up the OpenGL double buffer.
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
// Get an SDL surface.
surface = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, videoFlags);
// Is there an SDL surface?
if(!surface) {
fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError());
Quit(1);
}
// Initialize OpenGL.
InitGL();
// Resize the initial window.
ResizeWindow(SCREEN_WIDTH, SCREEN_HEIGHT);
Debug::logger->message("\n\n-----Engine Initialization Complete-----"); Debug::logger->message("\n\n-----Engine Initialization Complete-----");
Debug::logger->message("\n\n-----Logic-----"); Debug::logger->message("\n\n-----Logic-----");
// Main loop: We render frames untill IsRunning returns false.
while(programWindow.IsRunning()) {
// Process the window events.
programWindow.ProcessEvents();
// Get the time that passed since the last frame. while(!done) {
float elapsedTime = programWindow.GetElapsedSeconds(); // Time to poll events.
while(SDL_PollEvent(&event)) {
//Perform any logic before rendering. switch(event.type) {
case SDL_VIDEORESIZE:
// Handle resize events.
surface = SDL_SetVideoMode(event.resize.w, event.resize.h, 16, videoFlags);
if(!surface) {
fprintf(stderr, "Could not get a surface after resize: %s\n", SDL_GetError());
Quit(1);
}
ResizeWindow(event.resize.w, event.resize.h);
break;
case SDL_KEYDOWN:
// handle keydown events.
ProcessEvents(&event.key.keysym);
break;
case SDL_QUIT:
// Handle quit events.
done = true;
break;
default:
break;
}
}
// Render the scene.
float elapsedTime = GetElapsedSeconds();
//game.ProcessEvents();
game.Prepare(elapsedTime); game.Prepare(elapsedTime);
// Let us now render the scene.
game.Render(); game.Render();
SDL_GL_SwapBuffers();
programWindow.SwapBuffers();
} }
// Free any recources used.
game.Shutdown(); game.Shutdown();
// Destroy the window. // Clean ourselves up and exit.
programWindow.Destroy(); Quit(0);
// Sucess!!!11one!one1! // We should never get here.
return 0; return(0);
} }