-- Changed to use SDL rather than GLX/WIN32.
This commit is contained in:
parent
87527a2226
commit
96b2b3ff65
14
Bin/Debug.log
Normal file
14
Bin/Debug.log
Normal 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
BIN
Unuk-QT/Debug.o
Normal file
Binary file not shown.
BIN
Unuk-QT/Entity.o
Normal file
BIN
Unuk-QT/Entity.o
Normal file
Binary file not shown.
BIN
Unuk-QT/Game.o
Normal file
BIN
Unuk-QT/Game.o
Normal file
Binary file not shown.
BIN
Unuk-QT/ImageLoader.o
Normal file
BIN
Unuk-QT/ImageLoader.o
Normal file
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
#############################################################################
|
||||
# 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
|
||||
# Template: app
|
||||
# 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.
|
||||
LINK = g++
|
||||
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
|
||||
RANLIB =
|
||||
QMAKE = /usr/bin/qmake-qt4
|
||||
@ -46,7 +46,6 @@ OBJECTS_DIR = ./
|
||||
SOURCES = ../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 \
|
||||
@ -55,7 +54,6 @@ SOURCES = ../src/libUnuk/Vec2.cpp \
|
||||
OBJECTS = Vec2.o \
|
||||
Sprite.o \
|
||||
ImageLoader.o \
|
||||
GlxWindow.o \
|
||||
Debug.o \
|
||||
Player.o \
|
||||
main.o \
|
||||
@ -160,7 +158,7 @@ qmake: FORCE
|
||||
|
||||
dist:
|
||||
@$(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
|
||||
@ -214,30 +212,17 @@ ImageLoader.o: ../src/libUnuk/ImageLoader.cpp ../src/libUnuk/ImageLoader.h \
|
||||
../src/libUnuk/Debug.h
|
||||
$(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
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Debug.o ../src/libUnuk/Debug.cpp
|
||||
|
||||
Player.o: ../src/Unuk/Player.cpp ../src/libUnuk/Sprite.h \
|
||||
../src/libUnuk/ImageLoader.h \
|
||||
../src/libUnuk/Debug.h \
|
||||
../src/libUnuk/KeyboardInterface.h \
|
||||
../src/Unuk/Player.h
|
||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Player.o ../src/Unuk/Player.cpp
|
||||
|
||||
main.o: ../src/Unuk/main.cpp ../src/libUnuk/Win32Window.h \
|
||||
../src/libUnuk/GlxWindow.h \
|
||||
../src/Libs/glxext.h \
|
||||
../src/Unuk/Game.h \
|
||||
main.o: ../src/Unuk/main.cpp ../src/Unuk/Game.h \
|
||||
../src/Unuk/Player.h \
|
||||
../src/libUnuk/Sprite.h \
|
||||
../src/libUnuk/ImageLoader.h \
|
||||
|
BIN
Unuk-QT/Player.o
Normal file
BIN
Unuk-QT/Player.o
Normal file
Binary file not shown.
BIN
Unuk-QT/Sprite.o
Normal file
BIN
Unuk-QT/Sprite.o
Normal file
Binary file not shown.
BIN
Unuk-QT/Unuk-QT
BIN
Unuk-QT/Unuk-QT
Binary file not shown.
@ -1,4 +1,6 @@
|
||||
LIBS += -lGL -lSDL
|
||||
LIBS += -lGL \
|
||||
-lSDL \
|
||||
-lGLU
|
||||
RESOURCES +=
|
||||
OTHER_FILES += ../src/libUnuk/Vec2.o \
|
||||
../src/libUnuk/ImageLoader.o \
|
||||
@ -7,7 +9,6 @@ OTHER_FILES += ../src/libUnuk/Vec2.o \
|
||||
../src/libUnuk/Debug.o
|
||||
HEADERS += ../src/libUnuk/Vec2.h \
|
||||
../src/libUnuk/ImageLoader.h \
|
||||
../src/libUnuk/GlxWindow.h \
|
||||
../src/libUnuk/Sprite.h \
|
||||
../src/libUnuk/Debug.h \
|
||||
../src/Libs/wglext.h \
|
||||
@ -24,7 +25,6 @@ HEADERS += ../src/libUnuk/Vec2.h \
|
||||
SOURCES += ../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 \
|
||||
|
BIN
Unuk-QT/Vec2.o
Normal file
BIN
Unuk-QT/Vec2.o
Normal file
Binary file not shown.
BIN
Unuk-QT/main.o
Normal file
BIN
Unuk-QT/main.o
Normal file
Binary file not shown.
@ -1,5 +1,6 @@
|
||||
#ifndef _GAME_H_
|
||||
#define _GAME_H_
|
||||
#include "SDL/SDL.h"
|
||||
#include "Player.h"
|
||||
|
||||
class Game {
|
||||
|
@ -1,92 +1,216 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_EXTRA_LEAN
|
||||
#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"
|
||||
#ifdef __unix__
|
||||
#include <sys/time.h>
|
||||
#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 "../libUnuk/Debug.h"
|
||||
|
||||
#ifdef WIN32
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow) {
|
||||
#else
|
||||
int main(/*int argc, char** argv*/) {
|
||||
#endif
|
||||
// Screen width, height, and bit depth.
|
||||
const int SCREEN_WIDTH = 640;
|
||||
const int SCREEN_HEIGHT = 480;
|
||||
const int SCREEN_BPP = 16;
|
||||
|
||||
// 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.
|
||||
Debug::openLog(true);
|
||||
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
|
||||
// This is our window.
|
||||
Win32Window programWindow(hInstance);
|
||||
#else
|
||||
GlxWindow programWindow;
|
||||
#endif
|
||||
|
||||
// Set SDL up so we can use it for input and crap.
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
|
||||
// The Game code.
|
||||
int videoFlags;
|
||||
bool done = false;
|
||||
SDL_Event event;
|
||||
const SDL_VideoInfo *videoInfo;
|
||||
Game game;
|
||||
|
||||
// Attach the game to our window.
|
||||
programWindow.AttachGame(&game);
|
||||
|
||||
// Attempt to create the window.
|
||||
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;
|
||||
// Initialize SDL.
|
||||
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError());
|
||||
Quit(1);
|
||||
}
|
||||
|
||||
// Make sure our game is initialized.
|
||||
if(!game.Init()) {
|
||||
#ifdef WIN32
|
||||
MessageBox(Null, "Could not initialize the application", "Error", MB_ICONERROR | MB_OK);
|
||||
#endif
|
||||
// Reset the display and exit.
|
||||
programWindow.Destroy();
|
||||
return 1;
|
||||
// Fetch the video info.
|
||||
videoInfo = SDL_GetVideoInfo();
|
||||
|
||||
// Set the window caption.
|
||||
SDL_WM_SetCaption("Unuk", NULL);
|
||||
|
||||
if(!videoInfo) {
|
||||
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-----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.
|
||||
float elapsedTime = programWindow.GetElapsedSeconds();
|
||||
|
||||
//Perform any logic before rendering.
|
||||
game.Prepare(elapsedTime);
|
||||
// Let us now render the scene.
|
||||
game.Render();
|
||||
|
||||
programWindow.SwapBuffers();
|
||||
while(!done) {
|
||||
// Time to poll events.
|
||||
while(SDL_PollEvent(&event)) {
|
||||
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.Render();
|
||||
SDL_GL_SwapBuffers();
|
||||
}
|
||||
|
||||
// Free any recources used.
|
||||
game.Shutdown();
|
||||
// Destroy the window.
|
||||
programWindow.Destroy();
|
||||
// Clean ourselves up and exit.
|
||||
Quit(0);
|
||||
|
||||
// Sucess!!!11one!one1!
|
||||
return 0;
|
||||
// We should never get here.
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user