Linux x86-64 build of everything but the client, FARDive, and libpq. For libvitaboy Renderer, this is made possible with the new libgldemo.

This commit is contained in:
Fatbag 2012-07-02 12:14:12 -05:00
parent 9b5b1758c2
commit 90c703188b
23 changed files with 789 additions and 399 deletions

View file

@ -3,10 +3,19 @@
cmake_minimum_required(VERSION 2.6)
enable_language(ASM)
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "gcc")
set(CMAKE_ASM_COMPILER "gcc")
project(Niotso)
# Installation directory
set(CMAKE_INSTALL_PREFIX "c:/Program Files (x86)/Maxis/The Sims Online/Niotso" CACHE FILEPATH "Installation directory")
if(WIN32)
set(CMAKE_INSTALL_PREFIX "c:/Program Files (x86)/Maxis/The Sims Online/Niotso" CACHE FILEPATH "Installation directory")
else()
set(CMAKE_INSTALL_PREFIX "/usr/bin" CACHE FILEPATH "Installation directory")
endif()
# Build type
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
@ -15,17 +24,31 @@ else()
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build configurations: Release Debug")
endif()
if(WIN32)
set(64BIT 0)
else()
set(64BIT 1)
endif()
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
# Base options
set(CFLAGS "-Wall -Wextra -Wabi -pedantic -m32 -mmmx -msse -msse2 -msse3 -mfpmath=both -msahf -malign-double -mpc32 -fvisibility=hidden")
set(LDFLAGS "-m32")
set(RCFLAGS "-F pe-i386")
set(ASMFLAGS "-O3 -F win32")
set(CFLAGS "-Wall -Wextra -Wabi -pedantic -mmmx -msse -msse2 -msse3 -fvisibility=hidden")
set(LDFLAGS "")
set(RCFLAGS "")
set(CFLAGS_LANG_C "-ansi")
set(CFLAGS_LANG_CPP "-fvisibility-inlines-hidden -fno-exceptions -fno-rtti -fno-threadsafe-statics")
if(64BIT)
set(CFLAGS "-m64 ${CFLAGS}")
set(LDFLAGS "-m64 ${LDFLAGS}")
set(RCFLAGS "${RCFLAGS} -F pe-x86-64")
else()
set(CFLAGS "-m32 ${CFLAGS}")
set(LDFLAGS "-m32 ${LDFLAGS}")
set(RCFLAGS "${RCFLAGS} -F pe-i386")
endif()
####
## [Profiles]
@ -39,11 +62,11 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
endif()
# Size
set(CFLAGS_SIZE "${CFLAGS} -Os -g0 -fomit-frame-pointer -ffast-math -fmerge-all-constants -funsafe-loop-optimizations -fmerge-all-constants -fsched-pressure -mstringop-strategy=rep_byte")
set(CFLAGS_SIZE "${CFLAGS} -Os -g0 -fomit-frame-pointer -mfpmath=both -msahf -malign-double -mpc32 -ffast-math -fmerge-all-constants -funsafe-loop-optimizations -fmerge-all-constants -fsched-pressure -mstringop-strategy=rep_byte")
set(LDFLAGS_SIZE "${LDFLAGS} -s -fwhole-program")
# Speed
set(CFLAGS_SPEED "${CFLAGS} -O3 -g0 -fomit-frame-pointer -ffast-math -fmerge-all-constants -funsafe-loop-optimizations -fmerge-all-constants -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -fgcse-sm -fgcse-las -fsched-spec-load -fsched-spec-load-dangerous -fsched-stalled-insns=0 -fsched-stalled-insns-dep -fsched2-use-superblocks -fipa-pta -fipa-matrix-reorg -ftree-loop-linear -floop-interchange -floop-strip-mine -floop-block -fgraphite-identity -floop-parallelize-all -ftree-loop-distribution -ftree-loop-im -ftree-loop-ivcanon -fivopts -fvect-cost-model -fvariable-expansion-in-unroller -fbranch-target-load-optimize -maccumulate-outgoing-args -flto")
set(CFLAGS_SPEED "${CFLAGS} -O3 -g0 -fomit-frame-pointer -mfpmath=both -msahf -malign-double -mpc32 -ffast-math -fmerge-all-constants -funsafe-loop-optimizations -fmerge-all-constants -fsched-pressure -fmodulo-sched -fmodulo-sched-allow-regmoves -fgcse-sm -fgcse-las -fsched-spec-load -fsched-spec-load-dangerous -fsched-stalled-insns=0 -fsched-stalled-insns-dep -fsched2-use-superblocks -fipa-pta -fipa-matrix-reorg -ftree-loop-linear -floop-interchange -floop-strip-mine -floop-block -fgraphite-identity -floop-parallelize-all -ftree-loop-distribution -ftree-loop-im -ftree-loop-ivcanon -fivopts -fvect-cost-model -fvariable-expansion-in-unroller -fbranch-target-load-optimize -maccumulate-outgoing-args -flto")
set(LDFLAGS_SPEED "${LDFLAGS} -s -fwhole-program -flto")
else()
# Debug
@ -57,23 +80,30 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_C_FLAGS "${CFLAGS_LANG_C} ${CFLAGS_SIZE}")
set(CMAKE_CXX_FLAGS "${CFLAGS_LANG_CPP} ${CFLAGS_SIZE}")
set(CMAKE_SHARED_LINKER_FLAGS "${LDFLAGS} ${LDFLAGS_SIZE}")
if(64BIT)
set(CMAKE_SHARED_LIBRARY_C_FLAGS "-fpic")
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-fpic")
set(CMAKE_SHARED_LIBRARY_ASM_FLAGS "-fpic")
else()
set(CMAKE_SHARED_LIBRARY_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "")
set(CMAKE_SHARED_LIBRARY_ASM_FLAGS "")
endif()
set(CMAKE_SHARED_LINKER_FLAGS "-shared ${LDFLAGS} ${LDFLAGS_SIZE}")
set(CMAKE_EXE_LINKER_FLAGS "${LDFLAGS} ${LDFLAGS_SIZE}")
set(CMAKE_RC_FLAGS "${RCFLAGS}")
endif()
set(CMAKE_ASM_FLAGS "${CFLAGS}")
enable_language(ASM)
set(CMAKE_ASM_COMPILER "gcc")
set(CMAKE_ASM_FLAGS "${CFLAGS}")
if(WIN32)
set(DIST_NAME "windows" CACHE STRING "Output folder name for the _dist folder (no start or end slash)")
elseif(APPLE)
set(DIST_NAME "mac" CACHE STRING "Output folder name for the _dist folder (no start or end slash)")
elseif(UNIX)
set(DIST_NAME "linux" CACHE STRING "Output folder name for the _dist folder (no start or end slash)")
else()
set(DIST_NAME "unknown" CACHE STRING "Output folder name for the _dist folder (no start or end slash)")
endif()
if(WIN32)
set(DIST_NAME "windows" CACHE STRING "Output folder name for the _dist folder (no start or end slash)")
elseif(APPLE)
set(DIST_NAME "mac" CACHE STRING "Output folder name for the _dist folder (no start or end slash)")
elseif(UNIX)
set(DIST_NAME "linux" CACHE STRING "Output folder name for the _dist folder (no start or end slash)")
else()
set(DIST_NAME "unknown" CACHE STRING "Output folder name for the _dist folder (no start or end slash)")
endif()
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/_dist/${DIST_NAME}") (-flto means our archive files should not be redistributed)
@ -83,4 +113,4 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/_dist/${DIST_NAME}")
add_subdirectory(Client)
add_subdirectory(Libraries)
add_subdirectory(Server)
add_subdirectory(Tools)
add_subdirectory(Tools)

View file

@ -1,4 +1,13 @@
if(WIN32)
set(GLDEMO_EXE WIN32)
set(GLDEMO_LIBS mingw32 libgldemo_static opengl32 glu32)
else()
set(GLDEMO_EXE "")
set(GLDEMO_LIBS libgldemo_static Xxf86vm rt Xext X11 GL GLU)
endif()
add_subdirectory(FileHandler)
add_subdirectory(freetype)
add_subdirectory(libgldemo)
add_subdirectory(libpq)
add_subdirectory(libvitaboy)
add_subdirectory(libvitaboy)

View file

@ -1,6 +1,14 @@
cmake_minimum_required(VERSION 2.6)
project(FileHandler)
set(FILEHANDLER_SERIES 0)
set(FILEHANDLER_MAJOR 0)
set(FILEHANDLER_MINOR 0)
if(64BIT)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic")
endif()
add_subdirectory(far)
add_subdirectory(iff)
add_subdirectory(libexpat)
@ -11,10 +19,6 @@ add_subdirectory(utk)
add_subdirectory(xa)
add_subdirectory(zlib)
set(FILEHANDLER_SERIES 0)
set(FILEHANDLER_MAJOR 0)
set(FILEHANDLER_MINOR 0)
set(FILEHANDLER_SOURCES
Audio.cpp
File.cpp
@ -46,4 +50,5 @@ set_target_properties(FileHandler_shared PROPERTIES
PREFIX ""
IMPORT_PREFIX ""
CLEAN_DIRECT_OUTPUT 1)
target_link_libraries(FileHandler_shared kernel32 far_static iff_static jpegturbo_static libmpg123_static libpng_static zlib_static)
target_link_libraries(FileHandler_shared far_static iff_static jpegturbo_static libmpg123_static libpng_static zlib_static m)

View file

@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <limits.h>
#ifndef read_uint32be
#define read_int32be(x) (signed)(((x)[0]<<(8*3)) | ((x)[1]<<(8*2)) | ((x)[2]<<(8*1)) | ((x)[3]<<(8*0)))
@ -361,4 +362,4 @@ void iff_delete(IFFFile * IFFFileInfo);
}
#endif
#endif
#endif

View file

@ -82,7 +82,7 @@ int utk_read_header(utkheader_t * UTKHeader, const uint8_t * Buffer, size_t File
return 1;
}
int utk_decode(const uint8_t *__restrict InBuffer, uint8_t *__restrict OutBuffer, unsigned Frames){
int utk_decode(const uint8_t *__restrict InBuffer, uint8_t *__restrict OutBuffer, size_t Frames){
utkparams_t p;
p.InData = InBuffer;
SetUTKParameters(&p);
@ -336,4 +336,4 @@ static void PredictionFilter(const float *__restrict ImpulseTrain, float *__rest
Residual[i] = x;
}
}
}

View file

@ -50,10 +50,10 @@ typedef struct {
extern "C" {
#endif
int utk_read_header(utkheader_t * UTKHeader, const uint8_t * Buffer, unsigned FileSize);
int utk_decode(const uint8_t *__restrict InBuffer, uint8_t *__restrict OutBuffer, unsigned Frames);
int utk_read_header(utkheader_t * UTKHeader, const uint8_t * Buffer, size_t FileSize);
int utk_decode(const uint8_t *__restrict InBuffer, uint8_t *__restrict OutBuffer, size_t Frames);
void UTKGenerateTables(void);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -51,7 +51,7 @@ int main(int argc, char *argv[]){
"\n"
"Report bugs to <X-Fi6@phppoll.org>.\n"
"utkdecode is maintained by the Niotso project.\n"
"Home page: <http://www.niotso.org/>");
"Home page: <http://www.niotso.org/>\n");
return 0;
}
@ -167,4 +167,4 @@ int main(int argc, char *argv[]){
}
return 0;
}
}

View file

@ -19,6 +19,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <limits.h>
#include "read_xa.h"
#define HINIBBLE(byte) ((byte) >> 4)
@ -29,7 +30,7 @@
#define read_uint16(x) (unsigned)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)))
#endif
unsigned xa_compressed_size(unsigned Frames, unsigned Channels)
size_t xa_compressed_size(size_t Frames, size_t Channels)
{
/* This function calculates the size of compressed XA data with known frames and channels, as such:
** Channels * (ceil(Frames/2) + ceil(Frames/28))
@ -103,7 +104,7 @@ static const int16_t XATable[] =
0, -1, -3, -4
};
int xa_decode(const uint8_t *__restrict InBuffer, uint8_t *__restrict OutBuffer, unsigned Frames, unsigned Channels)
int xa_decode(const uint8_t *__restrict InBuffer, uint8_t *__restrict OutBuffer, size_t Frames, size_t Channels)
{
channel_t Channel[8];
memset(Channel, 0, sizeof(Channel));
@ -143,4 +144,4 @@ int xa_decode(const uint8_t *__restrict InBuffer, uint8_t *__restrict OutBuffer,
if(!--Frames) return 1;
}
}
}
}

View file

@ -28,18 +28,18 @@ typedef struct
uint16_t nBlockAlign;
uint16_t wBitsPerSample;
unsigned Frames;
unsigned XADataSize;
size_t Frames;
size_t XADataSize;
} xaheader_t;
#ifdef __cplusplus
extern "C" {
#endif
unsigned xa_compressed_size(unsigned Frames, unsigned Channels);
int xa_read_header(xaheader_t * XAHeader, const uint8_t * Buffer, unsigned FileSize);
int xa_decode(const uint8_t *__restrict InBuffer, uint8_t *__restrict OutBuffer, unsigned Frames, unsigned Channels);
size_t xa_compressed_size(size_t Frames, size_t Channels);
int xa_read_header(xaheader_t * XAHeader, const uint8_t * Buffer, size_t FileSize);
int xa_decode(const uint8_t *__restrict InBuffer, uint8_t *__restrict OutBuffer, size_t Frames, size_t Channels);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -49,7 +49,7 @@ int main(int argc, char *argv[]){
"\n"
"Report bugs to <X-Fi6@phppoll.org>.\n"
"xadecode is maintained by the Niotso project.\n"
"Home page: <http://www.niotso.org/>");
"Home page: <http://www.niotso.org/>\n");
return 0;
}
@ -163,4 +163,4 @@ int main(int argc, char *argv[]){
}
return 0;
}
}

View file

@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 2.6)
project(libgldemo)
if(WIN32)
set(LIBGLDEMO_SOURCES wgl.c)
else()
set(LIBGLDEMO_SOURCES glx.c)
add_definitions(-D_POSIX_C_SOURCE=200112)
endif()
add_library(libgldemo_static STATIC ${LIBGLDEMO_SOURCES})
set_target_properties(libgldemo_static PROPERTIES
OUTPUT_NAME "gldemo"
CLEAN_DIRECT_OUTPUT 1)

234
Libraries/libgldemo/glx.c Normal file
View file

@ -0,0 +1,234 @@
/*
libgldemo - General-purpose OpenGL demo backend
glx.c - Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "libgldemo.h"
static Display *display = NULL;
static int screen = 0;
static Window window = 0;
static GLXContext hrc = 0;
static uint8_t keys[256] = {0};
static uint8_t f11_pressed = 0;
static uint16_t WndWidth, WndHeight;
static uint16_t ResWidth, ResHeight;
static int fullscreen = 0;
void KillGLWindow()
{
if(hrc){
glXMakeCurrent(display, None, NULL);
glXDestroyContext(display, hrc);
hrc = 0;
}
if(window){
XDestroyWindow(display, window);
window = 0;
}
}
static int CreateGLWindow(const char *__restrict title, uint16_t width, uint16_t height)
{
int attlist[] = {
GLX_RGBA,
GLX_RED_SIZE, 4,
GLX_GREEN_SIZE, 4,
GLX_BLUE_SIZE, 4,
GLX_DEPTH_SIZE, 16,
GLX_DOUBLEBUFFER,
None
};
XVisualInfo *visualinfo;
Colormap cmap;
Atom wmDelete;
XSetWindowAttributes attr;
int (APIENTRY *glXSwapIntervalSGIptr)(int);
visualinfo = glXChooseVisual(display, screen, attlist);
if(visualinfo == NULL){
KillGLWindow();
DemoErrorBox("Can't find a suitable pixel format.");
return 0;
}
/* create a color map */
cmap = XCreateColormap(display, RootWindow(display, visualinfo->screen), visualinfo->visual, AllocNone);
attr.colormap = cmap;
attr.border_pixel = 0;
hrc = glXCreateContext(display, visualinfo, NULL, GL_TRUE);
if(hrc == NULL){
KillGLWindow();
DemoErrorBox("Failed to create an OpenGL rendering context.");
return 0;
}
attr.event_mask = KeyPressMask | KeyReleaseMask | StructureNotifyMask;
if(fullscreen){
attr.override_redirect = True;
width = ResWidth;
height = ResHeight;
XWarpPointer(display, None, window, 0, 0, 0, 0, 0, 0);
}else{
attr.override_redirect = False;
}
if(!(window = XCreateWindow(display, XRootWindow(display, visualinfo->screen),
(ResWidth - width)>>1,
(ResHeight - height)>>1,
width,
height,
0, visualinfo->depth, InputOutput, visualinfo->visual,
CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &attr)
)){
KillGLWindow();
DemoErrorBox("Window creation error.");
return 0;
}
WndWidth = width;
WndHeight = height;
XSetStandardProperties(display, window, title, title, None, NULL, 0, NULL);
XMapRaised(display, window);
XGrabKeyboard(display, window, True, GrabModeAsync, GrabModeAsync, CurrentTime);
wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True);
XSetWMProtocols(display, window, &wmDelete, 1);
/* connect the glx-context to the window */
glXMakeCurrent(display, window, hrc);
XFlush(display);
if(!Demo.InitGL()){
KillGLWindow();
DemoErrorBox("Initialization failed.");
return 0;
}
if(!Demo.ResizeScene(width&&height ? width : 1, width&&height ? height : 1)){
KillGLWindow();
DemoErrorBox("Scene resize failed.");
return 0;
}
glXSwapIntervalSGIptr = (int (APIENTRY *)(int)) glXGetProcAddressARB((const GLubyte *) "glXSwapIntervalSGI");
if(glXSwapIntervalSGIptr) glXSwapIntervalSGIptr(1);
return 1;
}
int main()
{
int dotclock;
XF86VidModeModeLine modeline;
struct timespec time1;
display = XOpenDisplay(0);
if(display == NULL){
KillGLWindow();
DemoErrorBox("Failed to obtain the X11 display context.");
return 0;
}
XkbSetDetectableAutoRepeat(display, True, 0);
screen = XDefaultScreen(display);
XF86VidModeGetModeLine(display, screen, &dotclock, &modeline);
ResWidth = modeline.hdisplay;
ResHeight = modeline.vdisplay;
if(Demo.Startup && !Demo.Startup())
return -1;
if(!CreateGLWindow(Demo.Title, Demo.Width, Demo.Height))
return -1;
clock_gettime(CLOCK_REALTIME, &time1);
while(1){
struct timespec time2;
float TimeDelta;
while(XPending(display)){
XEvent event;
XNextEvent(display, &event);
switch(event.type){
case ConfigureNotify:
if(((unsigned)event.xconfigure.width != WndWidth) ||
((unsigned)event.xconfigure.height != WndHeight)){
WndWidth = event.xconfigure.width;
WndHeight = event.xconfigure.height;
Demo.ResizeScene(event.xconfigure.width, event.xconfigure.height);
}
break;
case KeyPress: {
KeySym key = XLookupKeysym(&event.xkey, 0);
if(key <= 255)
keys[(key + 'A' - 'a') & 255] = 1;
else if(key == XK_Left) keys[KEY_LEFT] = 1;
else if(key == XK_Up) keys[KEY_UP] = 1;
else if(key == XK_Right) keys[KEY_RIGHT] = 1;
else if(key == XK_Down) keys[KEY_DOWN] = 1;
else{
if(key == XK_Escape){
KillGLWindow();
XCloseDisplay(display);
return (!Demo.Shutdown || Demo.Shutdown()) ? 0 : -1;
}
if(key == XK_F11 && !f11_pressed){
KillGLWindow();
fullscreen = !fullscreen;
CreateGLWindow(Demo.Title, Demo.Width, Demo.Height);
f11_pressed = 1;
}
}
break;
}
case KeyRelease: {
KeySym key = XLookupKeysym(&event.xkey, 0);
if(key <= 255)
keys[(key + 'A' - 'a') & 255] = 0;
else if(key == XK_Left) keys[KEY_LEFT] = 0;
else if(key == XK_Up) keys[KEY_UP] = 0;
else if(key == XK_Right) keys[KEY_RIGHT] = 0;
else if(key == XK_Down) keys[KEY_DOWN] = 0;
else if(key == XK_F11) f11_pressed = 0;
break;
}
case ClientMessage:
if (XGetAtomName(display, event.xclient.message_type)[0] == 'W'){
KillGLWindow();
XCloseDisplay(display);
return (!Demo.Shutdown || Demo.Shutdown()) ? 0 : -1;
}
}
}
/* Find the timedelta */
clock_gettime(CLOCK_REALTIME, &time2);
TimeDelta = (float)(time2.tv_sec - time1.tv_sec) + ((float)(time2.tv_nsec - time1.tv_nsec)) * 1e-9;
if(TimeDelta < 0) TimeDelta = 0; /* Safe-guard in case of system delay */
time1 = time2;
/* Draw */
Demo.DrawScene(TimeDelta, keys);
glXSwapBuffers(display, window);
}
}

View file

@ -0,0 +1,68 @@
/*
libgldemo - General-purpose OpenGL demo backend
libgldemo.h - Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
typedef struct {
const char *__restrict Title;
uint16_t Width, Height;
int (* Startup)(void);
int (* Shutdown)(void);
int (* InitGL)(void);
int (* ResizeScene)(uint16_t width, uint16_t height);
int (* DrawScene)(float TimeDelta, uint8_t keys[256]);
} DemoConfig;
#ifdef __cplusplus
extern "C" {
#endif
extern const DemoConfig Demo;
#ifdef __cplusplus
}
#endif
#ifdef _WIN32
#include <windows.h>
#define DemoMessageBox(x) MessageBox(NULL, x, NULL, MB_OK)
#define DemoErrorBox(x) MessageBox(NULL, x, NULL, MB_OK | MB_ICONERROR)
#define KEY_LEFT VK_LEFT
#define KEY_UP VK_UP
#define KEY_RIGHT VK_RIGHT
#define KEY_DOWN VK_DOWN
#else
#define POSIX_C_SOURCE 199309L
#include <stdio.h>
#include <time.h>
#include <GL/glx.h>
#include <X11/extensions/xf86vmode.h>
#include <X11/XKBlib.h>
#include <X11/keysym.h>
#define DemoMessageBox(x) fprintf(stdout, "%s\n", x)
#define DemoErrorBox(x) fprintf(stderr, "%s\n", x)
#define KEY_LEFT 0x25
#define KEY_UP 0x26
#define KEY_RIGHT 0x27
#define KEY_DOWN 0x28
#endif

282
Libraries/libgldemo/wgl.c Normal file
View file

@ -0,0 +1,282 @@
/*
libgldemo - General-purpose OpenGL demo backend
wgl.c - Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "libgldemo.h"
static HWND hWnd = NULL;
static HDC hDC = NULL;
static HGLRC hRC = NULL;
static HINSTANCE hInst;
static uint8_t keys[256] = {0};
static uint16_t ResWidth, ResHeight, ResDepth;
static int fullscreen = 0;
static float FramePeriod;
static void KillGLWindow()
{
if(fullscreen){
ShowCursor(1);
}
if(hRC){
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hRC);
hRC = NULL;
}
if(hDC){
ReleaseDC(hWnd, hDC);
hDC = NULL;
}
if(hWnd){
DestroyWindow(hWnd);
hWnd = NULL;
}
UnregisterClass("OpenGL", hInst);
}
static int CreateGLWindow(const char *__restrict title, uint16_t width, uint16_t height)
{
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), 1, /* Size and version */
PFD_DRAW_TO_WINDOW | /* dwFlags */
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA, /* iPixelType */
0, /* cColorBits */
0, 0, 0, 0, 0, 0, 0, 0, /* R,G,B,A bits */
0, 0, 0, 0, 0, /* Accumulation buffer bits */
16, /* cDepthBits */
0, /* cStencilBits */
0, /* cAuxBuffers */
PFD_MAIN_PLANE, /* iLayerType */
0, /* Reserved */
0, 0, 0 /* Masks */
};
DEVMODE dm;
DWORD dwStyle, dwExStyle;
RECT WindowRect;
int PixelFormat;
BOOL (WINAPI *wglSwapIntervalEXT)(int);
int (WINAPI *wglGetSwapIntervalEXT)(void);
if(fullscreen){
width = dm.dmPelsWidth;
height = dm.dmPelsHeight;
dwExStyle = WS_EX_APPWINDOW | WS_EX_TOPMOST;
dwStyle = WS_POPUP;
ShowCursor(0);
}else{
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle = WS_OVERLAPPEDWINDOW;
WindowRect.left = 0;
WindowRect.right = width;
WindowRect.top = 0;
WindowRect.bottom = height;
AdjustWindowRectEx(&WindowRect, dwStyle, 0, dwExStyle);
width = WindowRect.right - WindowRect.left;
height = WindowRect.bottom - WindowRect.top;
}
if(!(hWnd = CreateWindowEx(dwExStyle, "OpenGL",
title,
dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
(ResWidth - width)>>1,
(ResHeight - height)>>1,
width,
height,
NULL, NULL, hInst, NULL))
){
KillGLWindow();
DemoErrorBox("Window creation error.");
return 0;
}
hDC = GetDC(hWnd);
if(!hDC){
KillGLWindow();
DemoErrorBox("Failed to create an OpenGL device context.");
return 0;
}
PixelFormat = ChoosePixelFormat(hDC, &pfd);
if(!PixelFormat){
KillGLWindow();
DemoErrorBox("Can't find a suitable PixelFormat.");
return 0;
}
if(!SetPixelFormat(hDC, PixelFormat, &pfd)){
KillGLWindow();
DemoErrorBox("Can't set the PixelFormat.");
return 0;
}
hRC = wglCreateContext(hDC);
if(!hRC){
KillGLWindow();
DemoErrorBox("Failed to create an OpenGL rendering context.");
return 0;
}
if(!wglMakeCurrent(hDC, hRC)){
KillGLWindow();
DemoErrorBox("Failed to activate the OpenGL device context.");
return 0;
}
ShowWindow(hWnd, SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
if(!Demo.InitGL()){
KillGLWindow();
DemoErrorBox("Initialization failed.");
return 0;
}
if(!Demo.ResizeScene(width&&height ? width : 1, width&&height ? height : 1)){
KillGLWindow();
DemoErrorBox("Scene resize failed.");
return 0;
}
wglSwapIntervalEXT = (BOOL (WINAPI *)(int)) wglGetProcAddress("wglSwapIntervalEXT");
if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
wglGetSwapIntervalEXT = (int (WINAPI *)(void)) wglGetProcAddress("wglGetSwapIntervalEXT");
if(wglGetSwapIntervalEXT) wglGetSwapIntervalEXT(); /* Seems necessary on some cards */
return 1;
}
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_KEYDOWN:
if(wParam == VK_ESCAPE){
PostQuitMessage(0);
}else if(wParam == VK_F11 && !keys[VK_F11]){
KillGLWindow();
fullscreen = !fullscreen;
if(!CreateGLWindow(Demo.Title, Demo.Width, Demo.Height))
PostQuitMessage(0);
}
case WM_KEYUP:
keys[wParam] = (uMsg == WM_KEYDOWN);
return 0;
case WM_DEVMODECHANGE: {
DEVMODE dm;
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
ResWidth = dm.dmPelsWidth;
ResHeight = dm.dmPelsHeight;
ResDepth = dm.dmBitsPerPel;
FramePeriod = 1.0f/dm.dmDisplayFrequency;
}
case WM_SIZE:
Demo.ResizeScene(LOWORD(lParam), HIWORD(lParam));
return 0;
case WM_CLOSE:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wc = {
CS_HREDRAW | CS_VREDRAW | CS_OWNDC, /* style */
(WNDPROC) WndProc, /* lpfnWndProc */
0, /* cbClsExtra */
0, /* cbWndExtra */
NULL, /* hInstance */
NULL, /* hIcon */
NULL, /* hCursor */
NULL, /* hbrBackground */
NULL, /* lpszMenuName */
"OpenGL" /* lpszClassName */
};
DEVMODE dm;
LARGE_INTEGER ClockFreq, PreviousTime;
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
wc.hInstance = hInst = hInstance;
wc.hIcon = (HICON) LoadImage(NULL, IDI_WINLOGO, IMAGE_ICON, 0, 0, LR_SHARED);
wc.hCursor = (HCURSOR) LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED | LR_DEFAULTSIZE);
hInstance = GetModuleHandle(NULL);
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
ResWidth = dm.dmPelsWidth;
ResHeight = dm.dmPelsHeight;
ResDepth = dm.dmBitsPerPel;
FramePeriod = 1.0f/dm.dmDisplayFrequency;
QueryPerformanceFrequency(&ClockFreq);
if(!RegisterClass(&wc)){
MessageBox(NULL, "Failed to register the window class.", NULL, MB_OK | MB_ICONERROR);
return 0;
}
if(Demo.Startup && !Demo.Startup())
return -1;
if(!CreateGLWindow(Demo.Title, Demo.Width, Demo.Height))
return -1;
QueryPerformanceCounter(&PreviousTime);
while(1){
MSG msg;
LARGE_INTEGER CurrentTime;
float TimeDelta;
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessage(&msg);
if(msg.message == WM_QUIT){
KillGLWindow();
return (!Demo.Shutdown || Demo.Shutdown()) ? 0 : -1;
}
}
/* Find the timedelta */
QueryPerformanceCounter(&CurrentTime);
TimeDelta = (float)(CurrentTime.QuadPart-PreviousTime.QuadPart)/ClockFreq.QuadPart;
if(TimeDelta < 0) TimeDelta = 0; /* Safe-guard in case of system delay */
PreviousTime = CurrentTime;
/* Draw */
Demo.DrawScene(TimeDelta, keys);
SwapBuffers(hDC);
/* Sleep for the remainder of the frame */
QueryPerformanceCounter(&CurrentTime);
TimeDelta = (float)(CurrentTime.QuadPart-PreviousTime.QuadPart)/ClockFreq.QuadPart;
TimeDelta = (FramePeriod - TimeDelta) * 1000;
if(TimeDelta > 1) Sleep((unsigned) TimeDelta);
}
}

View file

@ -19,8 +19,11 @@ set(LIBVITABOY_SOURCES
)
if(WIN32)
set(LIBVITABOY_SOURCES ${LIBVITABOY_SOURCES} resource.rc)
else()
add_definitions(-Dstricmp=strcasecmp)
endif()
include_directories(${CMAKE_SOURCE_DIR}/Libraries/libgldemo)
include_directories(${CMAKE_SOURCE_DIR}/Libraries/FileHandler)
#### Static library (uncomment to build)
@ -31,6 +34,7 @@ include_directories(${CMAKE_SOURCE_DIR}/Libraries/FileHandler)
add_library(libvitaboy_shared SHARED ${LIBVITABOY_SOURCES})
set_target_properties(libvitaboy_shared PROPERTIES
COMPILE_FLAGS "-fvisibility=default"
OUTPUT_NAME "vitaboy${LIBVITABOY_SERIES}"
VERSION ${LIBVITABOY_SERIES}.${LIBVITABOY_MAJOR}.${LIBVITABOY_MINOR}
SOVERSION ${LIBVITABOY_SERIES}
@ -42,5 +46,5 @@ set_target_properties(libvitaboy_shared PROPERTIES
add_executable(vbparse vbparse.cpp)
target_link_libraries(vbparse libvitaboy_shared FileHandler_shared)
add_executable(Renderer Renderer.cpp)
target_link_libraries(Renderer libvitaboy_shared FileHandler_shared opengl32 glu32 winmm)
add_executable(Renderer ${GLDEMO_EXE} Renderer.cpp)
target_link_libraries(Renderer libvitaboy_shared ${GLDEMO_LIBS} FileHandler_shared m)

View file

@ -47,22 +47,11 @@
*/
#include <math.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glext.h>
#include <FileHandler.hpp>
#include <libgldemo.h>
#include "libvitaboy.hpp"
HDC hDC=NULL;
HGLRC hRC=NULL;
HWND hWnd=NULL;
HINSTANCE hInstance;
bool keys[256] = {0};
bool active=true;
bool fullscreen=false;
float zoom = -10;
static float zoom = -10;
struct BasicVertex_t {
float x, y, z;
};
@ -70,34 +59,29 @@ struct CharacterPlacement_t {
BasicVertex_t Translation;
BasicVertex_t Rotation;
};
CharacterPlacement_t Character = {{0,-3,0}, {0,0,0}};
static CharacterPlacement_t Character = {{0,-3,0}, {0,0,0}};
Skeleton_t Skeleton;
static Skeleton_t Skeleton;
const unsigned TextureCount = 3;
unsigned texture[3];
static const unsigned TextureCount = 3;
static unsigned texture[3];
enum { Texture_Body, Texture_Head, Texture_Hand };
const char* const TexturePaths[] = {"body.jpg", "head.jpg", "hand.jpg"};
static const char* const TexturePaths[] = {"body.jpg", "head.jpg", "hand.jpg"};
const unsigned MeshCount = 4;
Mesh_t Meshes[4];
static const unsigned MeshCount = 4;
static Mesh_t Meshes[4];
enum { Mesh_Body, Mesh_Head, Mesh_LHand, Mesh_RHand };
const char* const MeshPaths[] = {"body.mesh", "head.mesh", "lhand.mesh", "rhand.mesh" };
const unsigned Mesh_UseTexture[] = { Texture_Body, Texture_Head, Texture_Hand, Texture_Hand };
const char* const MeshActivate[] = {NULL, "HEAD", "L_HAND", "R_HAND"};
static const char* const MeshPaths[] = {"body.mesh", "head.mesh", "lhand.mesh", "rhand.mesh" };
static const unsigned Mesh_UseTexture[] = { Texture_Body, Texture_Head, Texture_Hand, Texture_Hand };
static const char* const MeshActivate[] = {NULL, "HEAD", "L_HAND", "R_HAND"};
Animation_t Animation;
float AnimationTime = 0;
static Animation_t Animation;
static float AnimationTime = 0;
bool ShowMesh = true;
bool ShowSkeleton = true;
static bool ShowMesh = true;
static bool ShowSkeleton = true;
LARGE_INTEGER ClockFreq, PreviousTime;
float FramePeriod;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void DisplayFileError(const char * Filename){
static void DisplayFileError(const char * Filename){
const char * Message;
switch(File::Error){
case FERR_NOT_FOUND:
@ -121,10 +105,10 @@ void DisplayFileError(const char * Filename){
char Buffer[1024];
sprintf(Buffer, Message, Filename);
MessageBox(hWnd, Buffer, NULL, MB_OK | MB_ICONERROR);
DemoErrorBox(Buffer);
}
bool LoadTextures()
static int LoadTextures()
{
glGenTextures(3, texture);
for(int i=0; i<3; i++){
@ -144,26 +128,10 @@ bool LoadTextures()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
return true;
return 1;
}
void ResizeScene(GLsizei width, GLsizei height)
{
if(height==0) height++;
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
bool InitGL()
static int InitGL()
{
if(!LoadTextures())
return false;
@ -177,10 +145,25 @@ bool InitGL()
glDisable(GL_BLEND);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
return true;
return 1;
}
void TransformVertices(Bone_t& Bone)
static int ResizeScene(uint16_t width, uint16_t height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
return 1;
}
static void TransformVertices(Bone_t& Bone)
{
glTranslatef(Bone.Translation.x, Bone.Translation.y, Bone.Translation.z);
float Matrix[16];
@ -240,7 +223,7 @@ void TransformVertices(Bone_t& Bone)
}
}
void BlendVertices()
static void BlendVertices()
{
for(unsigned i=0; i<MeshCount; i++){
Mesh_t& Mesh = Meshes[i];
@ -261,7 +244,7 @@ void BlendVertices()
}
}
void DrawMeshes()
static void DrawMeshes()
{
glPointSize(2.0);
glColor3f(1.0, 1.0, 1.0);
@ -287,7 +270,7 @@ void DrawMeshes()
glDisable(GL_TEXTURE_2D);
}
void AdvanceFrame(Skeleton_t& Skeleton, Animation_t& Animation, float TimeDelta)
static void AdvanceFrame(Skeleton_t& Skeleton, Animation_t& Animation, float TimeDelta)
{
float Duration = (float)Animation.Motions[0].FrameCount/30;
AnimationTime += TimeDelta;
@ -340,7 +323,7 @@ void AdvanceFrame(Skeleton_t& Skeleton, Animation_t& Animation, float TimeDelta)
}
}
void DrawBonesSkeleton(Bone_t& Bone)
static void DrawBonesSkeleton(Bone_t& Bone)
{
glPointSize(5.0);
glTranslatef(Bone.Translation.x, Bone.Translation.y, Bone.Translation.z);
@ -367,29 +350,22 @@ void DrawBonesSkeleton(Bone_t& Bone)
}
}
void DrawSkeleton()
static void DrawSkeleton()
{
glPushMatrix();
DrawBonesSkeleton(Skeleton.Bones[0]);
glPopMatrix();
}
int DrawGLScene()
static int DrawScene(float TimeDelta, uint8_t keys[256])
{
//Obtain the current time
LARGE_INTEGER CurrentTime;
QueryPerformanceCounter(&CurrentTime);
float TimeDelta = (float)(CurrentTime.QuadPart-PreviousTime.QuadPart)/ClockFreq.QuadPart;
if(TimeDelta < 0) TimeDelta = 0; //Safe-guard in case of system delay
PreviousTime = CurrentTime;
//Handle user interaction
if(keys['A']) /*{if(zoom <=-1.0f) zoom+=0.05f; }*/ zoom+=3*TimeDelta;
if(keys['S']) /*{if(zoom >=-10.0f) zoom-=0.05f; }*/ zoom-=3*TimeDelta;
if(keys[VK_UP]){ if((Character.Rotation.x-=60*TimeDelta) <=-360) Character.Rotation.x+=360; }
if(keys[VK_DOWN]){ if((Character.Rotation.x+=60*TimeDelta) >=360) Character.Rotation.x-=360; }
if(keys[VK_LEFT]){ if((Character.Rotation.y-=60*TimeDelta) <=-360) Character.Rotation.y+=360; }
if(keys[VK_RIGHT]){ if((Character.Rotation.y+=60*TimeDelta) >=360) Character.Rotation.y-=360; }
if(keys[KEY_UP]){ if((Character.Rotation.x-=60*TimeDelta) <=-360) Character.Rotation.x+=360; }
if(keys[KEY_DOWN]){ if((Character.Rotation.x+=60*TimeDelta) >=360) Character.Rotation.x-=360; }
if(keys[KEY_LEFT]){ if((Character.Rotation.y-=60*TimeDelta) <=-360) Character.Rotation.y+=360; }
if(keys[KEY_RIGHT]){ if((Character.Rotation.y+=60*TimeDelta) >=360) Character.Rotation.y-=360; }
if(keys['X']){ if((Character.Rotation.z-=60*TimeDelta) <=-360) Character.Rotation.z+=360; }
if(keys['Z']){ if((Character.Rotation.z+=60*TimeDelta) >=360) Character.Rotation.z-=360; }
if(keys['K']){ Character.Translation.y-=3*TimeDelta; }
@ -421,224 +397,7 @@ int DrawGLScene()
return true;
}
void KillGLWindow()
{
if(fullscreen){
ChangeDisplaySettings(NULL, 0); //Reset to the desktop resolution
ShowCursor(true);
}
if(hRC){
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hRC);
hRC = NULL;
}
if(hDC){
ReleaseDC(hWnd,hDC);
hDC = NULL;
}
if(hWnd){
DestroyWindow(hWnd);
hWnd = NULL;
}
UnregisterClass("OpenGL", hInstance);
hInstance = NULL;
}
BOOL CreateGLWindow(const char * title, int width, int height, int bits, bool fullscreenflag)
{
fullscreen = fullscreenflag;
hInstance = GetModuleHandle(NULL);
WNDCLASS wc = {
CS_HREDRAW | CS_VREDRAW | CS_OWNDC, //style
(WNDPROC) WndProc, //lpfnWndProc
0, //cbClsExtra
0, //cbWndExtra
hInstance, //hInstance
(HICON) LoadImage(NULL, IDI_WINLOGO, IMAGE_ICON, 0, 0, LR_SHARED), //hIcon
(HCURSOR) LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED | LR_DEFAULTSIZE), //hCursor
NULL, //hbrBackground
NULL, //lpszMenuName
"OpenGL" //lpszClassName
};
if(!RegisterClass(&wc)){
MessageBox(NULL, "Failed to registrer the window class.", NULL, MB_OK | MB_ICONERROR);
return false;
}
DWORD dwStyle, dwExStyle;
if(fullscreen){
DEVMODE dmScreenSettings;
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dmScreenSettings);
width = dmScreenSettings.dmPelsWidth;
height = dmScreenSettings.dmPelsHeight;
bits = dmScreenSettings.dmBitsPerPel;
dwExStyle = WS_EX_APPWINDOW | WS_EX_TOPMOST;
dwStyle = WS_POPUP;
ShowCursor(false);
}else{
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle = WS_OVERLAPPEDWINDOW;
}
RECT WindowRect;
WindowRect.left = 0;
WindowRect.right = width;
WindowRect.top = 0;
WindowRect.bottom = height;
AdjustWindowRectEx(&WindowRect, dwStyle, false, dwExStyle);
// Create The Window
if(!(hWnd = CreateWindowEx(dwExStyle, "OpenGL",
title,
dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
0, 0,
WindowRect.right-WindowRect.left,
WindowRect.bottom-WindowRect.top,
NULL, NULL, hInstance, NULL))
){
KillGLWindow();
MessageBox(NULL, "Window creation error.", NULL, MB_OK | MB_ICONERROR);
return false;
}
const PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), 1, //Size and version
PFD_DRAW_TO_WINDOW | //dwFlags
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA, //iPixelType
bits, //cColorBits
0, 0, 0, 0, 0, 0, 0, 0, //R,G,B,A bits
0, 0, 0, 0, 0, //Accumulation buffer bits
16, //cDepthBits
0, //cStencilBits
0, //cAuxBuffers
PFD_MAIN_PLANE, //iLayerType
0, //Reserved
0, 0, 0 //Masks
};
hDC = GetDC(hWnd);
if(!hDC){
KillGLWindow();
MessageBox(NULL, "Failed to create an OpenGL device context.", NULL, MB_OK | MB_ICONERROR);
return false;
}
int PixelFormat = ChoosePixelFormat(hDC, &pfd);
if(!PixelFormat){
KillGLWindow();
MessageBox(NULL, "Can't find a suitable PixelFormat.", NULL, MB_OK | MB_ICONERROR);
return false;
}
if(!SetPixelFormat(hDC, PixelFormat, &pfd)){
KillGLWindow();
MessageBox(NULL, "Can't set the PixelFormat.", NULL, MB_OK | MB_ICONERROR);
return false;
}
hRC = wglCreateContext(hDC);
if(!hRC){
KillGLWindow();
MessageBox(NULL, "Failed to create an OpenGL rendering context.", NULL, MB_OK | MB_ICONERROR);
return false;
}
if(!wglMakeCurrent(hDC, hRC)){
KillGLWindow();
MessageBox(NULL, "Failed to activate the OpenGL device context.", NULL, MB_OK | MB_ICONERROR);
return false;
}
ShowWindow(hWnd, SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
ResizeScene(width, height);
if(!InitGL()){
KillGLWindow();
MessageBox(NULL, "Initialization failed.", NULL, MB_OK | MB_ICONERROR);
return false;
}
BOOL (WINAPI *wglSwapIntervalEXT)(int) = (BOOL (WINAPI *)(int)) wglGetProcAddress("wglSwapIntervalEXT");
if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
int (WINAPI *wglGetSwapIntervalEXT)(void) = (int (WINAPI *)(void)) wglGetProcAddress("wglGetSwapIntervalEXT");
if(wglGetSwapIntervalEXT) wglGetSwapIntervalEXT(); //Seems necessary on some cards
QueryPerformanceFrequency(&ClockFreq);
QueryPerformanceCounter(&PreviousTime);
return true;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_KEYDOWN: {
if(wParam == VK_ESCAPE){
PostQuitMessage(0);
}else if(wParam == VK_F11 && !keys[VK_F11]){
KillGLWindow();
fullscreen = !fullscreen;
if(!CreateGLWindow("libvitaboy - Renderer",640,480,24,fullscreen)){
PostQuitMessage(0);
}
}
keys[wParam] = true;
} return 0;
case WM_KEYUP: {
keys[wParam] = false;
} return 0;
case WM_ACTIVATE: {
// LoWord Can Be WA_INACTIVE, WA_ACTIVE, WA_CLICKACTIVE,
// The High-Order Word Specifies The Minimized State Of The Window Being Activated Or Deactivated.
// A NonZero Value Indicates The Window Is Minimized.
if ((LOWORD(wParam) != WA_INACTIVE) && !((BOOL)HIWORD(wParam)))
active = true;
else
active = false;
} return 0;
case WM_SIZE: {
ResizeScene(LOWORD(lParam),HIWORD(lParam));
} return 0;
case WM_SYSCOMMAND: {
switch (wParam) {
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
} break;
case WM_DEVMODECHANGE: {
DEVMODE dm;
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
FramePeriod = 1.0f/dm.dmDisplayFrequency;
} return 0;
case WM_CLOSE: {
PostQuitMessage(0);
} return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
bool Read(const char * Filename, uint8_t ** InData){
static bool Read(const char * Filename, uint8_t ** InData){
*InData = File::ReadFile(Filename);
if(*InData != NULL){
VBFile.set(*InData, File::FileSize);
@ -649,7 +408,7 @@ bool Read(const char * Filename, uint8_t ** InData){
return false;
}
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
static int Startup()
{
uint8_t * InData;
@ -671,36 +430,17 @@ int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
free(InData);
AdvanceFrame(Skeleton, Animation, 0);
if(!CreateGLWindow("libvitaboy - Renderer",640,480,16,fullscreen)){
return 0;
}
DEVMODE dm;
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
FramePeriod = 1.0f/dm.dmDisplayFrequency;
bool quit = false;
MSG msg;
while(true){
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessage(&msg);
if(msg.message == WM_QUIT)
quit = true;
}
if(quit) break;
DrawGLScene();
SwapBuffers(hDC);
LARGE_INTEGER RenderTime;
QueryPerformanceCounter(&RenderTime);
float SleepDuration = (FramePeriod - (float)(RenderTime.QuadPart-PreviousTime.QuadPart)/ClockFreq.QuadPart) * 1000;
if(SleepDuration > 1) Sleep((unsigned) SleepDuration);
}
//Shutdown
KillGLWindow();
return (msg.wParam);
return 1;
}
extern "C" {
const DemoConfig Demo = {
"libvitaboy - Renderer", //Title
640,480, //Width, Height
Startup, //Startup
NULL, //Shutdown
InitGL, //InitGL
ResizeScene, //ResizeScene
DrawScene //DrawScene
};
}

View file

@ -78,4 +78,4 @@ void FindQuaternionMatrix(float * Matrix, Rotation_t * Quaternion){
Matrix[13] = 0.0f;
Matrix[14] = 0.0f;
Matrix[15] = 1.0f;
}
}

View file

@ -17,6 +17,7 @@
*/
#include <stdio.h>
#include <strings.h>
#include <FileHandler.hpp>
#include "libvitaboy.hpp"
@ -155,4 +156,4 @@ int main(int argc, char *argv[]){
}
return 0;
}
}

View file

@ -12,9 +12,7 @@ if(WIN32)
windows/Dialog/AddToArchive.cpp
windows/Dialog/NewArchive.cpp
)
set(FARDIVE_LINK ole32 uxtheme)
include_directories(${CMAKE_SOURCE_DIR}/Libraries/FileHandler/libpng)
add_executable(FARDive WIN32 ${FARDIVE_SOURCES})
endif()
include_directories(${CMAKE_SOURCE_DIR}/Libraries/FileHandler/libpng)
target_link_libraries(FARDive ${FARDIVE_LINK} FileHandler_shared)
target_link_libraries(FARDive ole32 uxtheme FileHandler_shared)
endif()

View file

@ -12,4 +12,4 @@ set(IFF2HTML_SOURCES
include_directories(${CMAKE_SOURCE_DIR}/Libraries/FileHandler)
add_executable(iff2html ${IFF2HTML_SOURCES})
target_link_libraries(iff2html iff_static libpng_static zlib_static)
target_link_libraries(iff2html iff_static libpng_static zlib_static m)

View file

@ -41,10 +41,10 @@ static void printsize(FILE * hFile, size_t FileSize){
fprintf(hFile, "%.1f kB (", (float)FileSize/1024);
while((temp/=1000) != 0)
position *= 1000;
fprintf(hFile, "%u", FileSize/position);
fprintf(hFile, "%u", (unsigned) FileSize/position);
FileSize -= (FileSize/position)*position;
while((position/=1000) != 0){
fprintf(hFile, ",%.3u", FileSize/position);
fprintf(hFile, ",%.3u", (unsigned) FileSize/position);
FileSize -= (FileSize/position)*position;
}
fprintf(hFile, " bytes)");
@ -322,7 +322,7 @@ int main(int argc, char *argv[]){
fprintf(hFile, "<table class=\"center centerall\">\n");
fprintf(hFile, "<tr><th>Image</th></tr>\n");
fprintf(hFile, "<tr><td><img src=\"%s_%u_%.4x.png\" width=\"%u\" height=\"%u\" alt=\"\" /></td></tr>\n",
bmp ? "bmp" : "fbmp", c+1, ChunkData->ChunkID, Width, Height);
bmp ? "bmp" : "fbmp", c+1, ChunkData->ChunkID, (unsigned) Width, (unsigned) Height);
fprintf(hFile, "</table>\n");
success++;
}
@ -708,4 +708,4 @@ int main(int argc, char *argv[]){
printf("Wrote contents to '%s'.\n", OutFile);
return 0;
}
}

View file

@ -78,7 +78,7 @@ void MD5Update(ctx, buf, len)
/* Handle any leading odd-sized chunks */
if (t) {
unsigned char *p = (unsigned char *) ctx->in + t;
unsigned char *p = (unsigned char *) ctx->in.c + t;
t = 64 - t;
if (len < t) {
@ -86,24 +86,24 @@ void MD5Update(ctx, buf, len)
return;
}
memcpy(p, buf, t);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
byteReverse(ctx->in.c, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in.c);
buf += t;
len -= t;
}
/* Process data in 64-byte chunks */
while (len >= 64) {
memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
memcpy(ctx->in.c, buf, 64);
byteReverse(ctx->in.c, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in.c);
buf += 64;
len -= 64;
}
/* Handle any remaining bytes of data. */
memcpy(ctx->in, buf, len);
memcpy(ctx->in.c, buf, len);
}
/*
@ -121,7 +121,7 @@ void MD5Final(digest, ctx)
/* Set the first char of padding to 0x80. This is safe since there is
always at least one byte free */
p = ctx->in + count;
p = ctx->in.c + count;
*p++ = 0x80;
/* Bytes of padding needed to make 64 bytes */
@ -131,22 +131,22 @@ void MD5Final(digest, ctx)
if (count < 8) {
/* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
byteReverse(ctx->in.c, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in.c);
/* Now fill the next block with 56 bytes */
memset(ctx->in, 0, 56);
memset(ctx->in.c, 0, 56);
} else {
/* Pad block to 56 bytes */
memset(p, 0, count - 8);
}
byteReverse(ctx->in, 14);
byteReverse(ctx->in.c, 14);
/* Append length in bits and transform */
((uint32 *) ctx->in)[14] = ctx->bits[0];
((uint32 *) ctx->in)[15] = ctx->bits[1];
ctx->in.i[14] = ctx->bits[0];
ctx->in.i[15] = ctx->bits[1];
MD5Transform(ctx->buf, (uint32 *) ctx->in);
MD5Transform(ctx->buf, (uint32 *) ctx->in.c);
byteReverse((unsigned char *) ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */

View file

@ -34,7 +34,10 @@ typedef unsigned long uint32;
struct MD5Context {
uint32 buf[4];
uint32 bits[2];
unsigned char in[64];
union {
unsigned char c[64];
uint32 i[16];
} in;
};
extern void MD5Init();