currently works for images (SDL and GDI+ loaders) and sound samples.legacy
@@ -405,16 +405,18 @@ dnl Can we build neercs? | |||
AM_CONDITIONAL(BUILD_NEERCS, test "${ac_cv_my_have_caca}" != "no") | |||
dnl Extra libraries we may need | |||
dnl Extra libraries we may need | |||
AC_SUBST(MATH_LIBS) | |||
AC_SUBST(PAM_LIBS) | |||
AC_SUBST(UTIL_LIBS) | |||
dnl How to use the Lol Engine inside this tree | |||
LOL_CFLAGS="$LOL_CFLAGS -I \$(top_srcdir)/src" | |||
dnl How to use the Lol Engine inside this tree | |||
LOL_CFLAGS="$LOL_CFLAGS -I\$(top_srcdir)/src" | |||
LOL_CFLAGS="$LOL_CFLAGS -DLOL_SOURCE_SUBDIR=\\\"\$(subdir)\\\"" | |||
LOL_CFLAGS="$LOL_CFLAGS $SDL_CFLAGS $GL_CFLAGS $EGL_CFLAGS $LIBPNG_CFLAGS" | |||
LOL_LIBS="$LOL_LIBS $SDL_LIBS $GL_LIBS $EGL_LIBS $LIBPNG_LIBS $D3D_LIBS" | |||
dnl Extra flags | |||
AC_SUBST(LOL_CFLAGS) | |||
AC_SUBST(LOL_LIBS) | |||
@@ -22,6 +22,7 @@ liblol_a_SOURCES = \ | |||
lol/math/vector.h lol/math/half.h lol/math/real.h lol/math/remez.h \ | |||
lol/math/math.h \ | |||
lol/math/geometry.h \ | |||
lol/sys/init.h \ | |||
lol/image/color.h \ | |||
\ | |||
generated/location.hh generated/position.hh generated/stack.hh \ | |||
@@ -72,6 +73,8 @@ liblol_a_SOURCES = \ | |||
\ | |||
mesh/mesh.cpp mesh/mesh.h \ | |||
\ | |||
sys/init.cpp \ | |||
\ | |||
image/image.cpp image/image.h image/image-private.h \ | |||
image/codec/gdiplus-image.cpp \ | |||
image/codec/ios-image.cpp \ | |||
@@ -88,6 +88,8 @@ static inline int isnan(float f) | |||
#include <lol/math/vector.h> | |||
#include <lol/math/geometry.h> | |||
#include <lol/sys/init.h> | |||
#include <lol/image/color.h> | |||
#include "numeric.h" | |||
@@ -1,7 +1,7 @@ | |||
// | |||
// Lol Engine | |||
// | |||
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> | |||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
@@ -62,13 +62,14 @@ bool GdiPlusImageData::Open(char const *path) | |||
return false; | |||
} | |||
String fullpath = String(System::GetDataDir()) + String(path); | |||
size_t len; | |||
len = mbstowcs(NULL, path, 0); | |||
len = mbstowcs(NULL, &fullpath[0], 0); | |||
wchar_t *wpath = new wchar_t[len + 1]; | |||
if (mbstowcs(wpath, path, len + 1) == (size_t)-1) | |||
if (mbstowcs(wpath, &fullpath[0], len + 1) == (size_t)-1) | |||
{ | |||
#if !LOL_RELEASE | |||
Log::Error("invalid image name %s\n", path); | |||
Log::Error("invalid image name %s\n", &fullpath[0]); | |||
#endif | |||
delete[] wpath; | |||
return false; | |||
@@ -76,19 +77,18 @@ bool GdiPlusImageData::Open(char const *path) | |||
bitmap = NULL; | |||
status = Gdiplus::Ok; | |||
for (wchar_t const *wname = wpath; *wname; wname++) | |||
bitmap = Gdiplus::Bitmap::FromFile(wpath, 0); | |||
if (bitmap) | |||
{ | |||
bitmap = Gdiplus::Bitmap::FromFile(wname, 0); | |||
if (bitmap) | |||
status = bitmap->GetLastStatus(); | |||
if (status != Gdiplus::Ok) | |||
{ | |||
status = bitmap->GetLastStatus(); | |||
if (status == Gdiplus::Ok) | |||
break; | |||
#if !LOL_RELEASE | |||
if (status != Gdiplus::InvalidParameter) | |||
Log::Error("error %d loading %s\n", status, path); | |||
#endif | |||
delete bitmap; | |||
bitmap = NULL; | |||
} | |||
} | |||
@@ -1,7 +1,7 @@ | |||
// | |||
// Lol Engine | |||
// | |||
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> | |||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
@@ -48,7 +48,7 @@ public: | |||
static SDL_Surface *Create32BppSurface(ivec2 size); | |||
private: | |||
SDL_Surface *img; | |||
SDL_Surface *m_img; | |||
}; | |||
/* | |||
@@ -57,43 +57,41 @@ private: | |||
bool SdlImageData::Open(char const *path) | |||
{ | |||
for (char const *name = path; *name; name++) | |||
if ((img = IMG_Load(name))) | |||
break; | |||
if (!img) | |||
String fullpath = String(System::GetDataDir()) + String(path); | |||
m_img = IMG_Load(&fullpath[0]); | |||
if (!m_img) | |||
{ | |||
#if !LOL_RELEASE | |||
Log::Error("could not load %s\n", path); | |||
Log::Error("could not load %s\n", &fullpath[0]); | |||
#endif | |||
return false; | |||
} | |||
size = ivec2(img->w, img->h); | |||
size = ivec2(m_img->w, m_img->h); | |||
if (img->format->BytesPerPixel != 4) | |||
if (m_img->format->BytesPerPixel != 4) | |||
{ | |||
SDL_Surface *tmp = Create32BppSurface(size); | |||
SDL_BlitSurface(img, NULL, tmp, NULL); | |||
SDL_FreeSurface(img); | |||
img = tmp; | |||
SDL_BlitSurface(m_img, NULL, tmp, NULL); | |||
SDL_FreeSurface(m_img); | |||
m_img = tmp; | |||
} | |||
format = img->format->Amask ? Image::FORMAT_RGBA : Image::FORMAT_RGB; | |||
format = m_img->format->Amask ? Image::FORMAT_RGBA : Image::FORMAT_RGB; | |||
return true; | |||
} | |||
bool SdlImageData::Close() | |||
{ | |||
SDL_FreeSurface(img); | |||
SDL_FreeSurface(m_img); | |||
return true; | |||
} | |||
void * SdlImageData::GetData() const | |||
{ | |||
return img->pixels; | |||
return m_img->pixels; | |||
} | |||
SDL_Surface *SdlImageData::Create32BppSurface(ivec2 size) | |||
@@ -0,0 +1,46 @@ | |||
// | |||
// Lol Engine | |||
// | |||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
// http://www.wtfpl.net/ for more details. | |||
// | |||
// | |||
// Various system helper functions | |||
// ------------------------------- | |||
// | |||
#if !defined __LOL_SYS_INIT_H__ | |||
#define __LOL_SYS_INIT_H__ | |||
#include <stdint.h> | |||
namespace lol | |||
{ | |||
namespace System | |||
{ | |||
extern void Init(Array<char const *> &args); | |||
extern void SetDataDir(char const *dir); | |||
extern char const *GetDataDir(); | |||
static inline void Init(int argc, char *argv[]) | |||
{ | |||
Array<char const *> args; | |||
for (int i = 0; i < argc; i++) | |||
args << argv[i]; | |||
Init(args); | |||
} | |||
} /* namespace System */ | |||
} /* namespace lol */ | |||
#endif // __LOL_SYS_INIT_H__ | |||
@@ -63,11 +63,12 @@ Sample::Sample(char const *path) | |||
sprintf(data->name, "<sample> %s", path); | |||
#if defined USE_SDL_MIXER | |||
data->chunk = Mix_LoadWAV(path); | |||
String fullpath = String(System::GetDataDir()) + String(path); | |||
data->chunk = Mix_LoadWAV(&fullpath[0]); | |||
if (!data->chunk) | |||
{ | |||
#if !LOL_RELEASE | |||
Log::Error("could not load %s\n", path); | |||
Log::Error("could not load %s\n", &fullpath[0]); | |||
#endif | |||
SDL_Quit(); | |||
exit(1); | |||
@@ -0,0 +1,66 @@ | |||
// | |||
// Lol Engine | |||
// | |||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
// http://www.wtfpl.net/ for more details. | |||
// | |||
#if defined HAVE_CONFIG_H | |||
# include "config.h" | |||
#endif | |||
#include "core.h" | |||
namespace lol | |||
{ | |||
namespace System | |||
{ | |||
void Init(Array<char const *> &args) | |||
{ | |||
/* Try to guess the data directory from the executable location. */ | |||
if (args.Count() > 0) | |||
{ | |||
#if defined _WIN32 | |||
# define SEPARATOR '\\' | |||
#else | |||
# define SEPARATOR '/' | |||
#endif | |||
char const *last_slash = strrchr(args[0], SEPARATOR); | |||
if (last_slash) | |||
{ | |||
String dir; | |||
dir.Resize(last_slash - args[0] + 1); | |||
memcpy(&dir[0], args[0], last_slash - args[0] + 1); | |||
SetDataDir(&dir[0]); | |||
} | |||
} | |||
} | |||
/* | |||
* Data directory handling | |||
*/ | |||
String data_dir = ""; | |||
void SetDataDir(char const *dir) | |||
{ | |||
data_dir = dir; | |||
} | |||
char const *GetDataDir() | |||
{ | |||
return &data_dir[0]; | |||
} | |||
} /* namespace System */ | |||
} /* namespace lol */ | |||
@@ -2,7 +2,7 @@ | |||
// BtPhysTest | |||
// | |||
// Copyright: (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||
// (c) 2012 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2012-2013 Sam Hocevar <sam@hocevar.net> | |||
// | |||
#if defined HAVE_CONFIG_H | |||
@@ -475,6 +475,8 @@ BtPhysTest::~BtPhysTest() | |||
int main(int argc, char **argv) | |||
{ | |||
System::Init(argc, argv); | |||
Application app("BtPhysTest", ivec2(1280, 720), 60.0f); | |||
#if defined _MSC_VER && !defined _XBOX | |||
@@ -1,7 +1,7 @@ | |||
// | |||
// Lol Engine - Triangle tutorial | |||
// | |||
// Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net> | |||
// Copyright: (c) 2012-2013 Sam Hocevar <sam@hocevar.net> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
@@ -74,6 +74,8 @@ private: | |||
int main(int argc, char **argv) | |||
{ | |||
System::Init(argc, argv); | |||
Application app("Tutorial 1: Triangle", ivec2(640, 480), 60.0f); | |||
#if defined _MSC_VER && !defined _XBOX | |||
@@ -135,6 +135,8 @@ private: | |||
int main(int argc, char **argv) | |||
{ | |||
System::Init(argc, argv); | |||
Application app("Tutorial 2: Cube", ivec2(640, 480), 60.0f); | |||
#if defined _MSC_VER && !defined _XBOX | |||
@@ -1,7 +1,7 @@ | |||
// | |||
// Lol Engine - Noise tutorial | |||
// | |||
// Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net> | |||
// Copyright: (c) 2012-2013 Sam Hocevar <sam@hocevar.net> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
@@ -85,6 +85,8 @@ private: | |||
int main(int argc, char **argv) | |||
{ | |||
System::Init(argc, argv); | |||
Application app("Tutorial 3: Noise", ivec2(1280, 720), 60.0f); | |||
#if defined _MSC_VER && !defined _XBOX | |||
@@ -1,7 +1,7 @@ | |||
// | |||
// Lol Engine - Graphing tutorial | |||
// | |||
// Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net> | |||
// Copyright: (c) 2012-2013 Sam Hocevar <sam@hocevar.net> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
@@ -115,6 +115,8 @@ private: | |||
int main(int argc, char **argv) | |||
{ | |||
System::Init(argc, argv); | |||
Application app("Tutorial 4: Texture", ivec2(640, 480), 60.0f); | |||
new TextureDemo(); | |||
@@ -29,13 +29,12 @@ public: | |||
m_gears.Push(EasyMesh(), mat4(1.0f), 180.0f / 18); | |||
m_gears.Push(EasyMesh(), mat4(1.0f), 180.0f / 18); | |||
m_gears[0].m1.Compile("[sc#00f ab 8 1 8 ty -.25]\ | |||
[sc#f9f scb#f9f acg 12 10 5 5 20 20 5 5 0.1 0 s .1 .1 .1 ty -.1 csgu]\ | |||
[sc#fff scb#000 acg 12 10 10 10 20 20 5 5 0.1 0 s .05 .05 .05 tx -1.5 ty .3 csgu]\ | |||
[sc#00f ab 5 3 9 tx 2.5 csgs]\ | |||
[[ sc#fff ab 3 1.4 2 tx -2 tz -2 \ | |||
[sc#fff ab 2.1 .7 1.1 ty .5 tx -1.4 tz -1.4 csgs] mz] csgu] \ | |||
"); | |||
m_gears[0].m1.Compile("[sc#00f ab 8 1 8 ty -.25]" | |||
"[sc#f9f scb#f9f acg 12 10 5 5 20 20 5 5 0.1 0 s .1 .1 .1 ty -.1 csgu]" | |||
"[sc#fff scb#000 acg 12 10 10 10 20 20 5 5 0.1 0 s .05 .05 .05 tx -1.5 ty .3 csgu]" | |||
"[sc#00f ab 5 3 9 tx 2.5 csgs]" | |||
"[[ sc#fff ab 3 1.4 2 tx -2 tz -2 " | |||
"[sc#fff ab 2.1 .7 1.1 ty .5 tx -1.4 tz -1.4 csgs] mz] csgu]"); | |||
//m_gears[0].m1.Compile("[sc#f9f scb#f9f acg 12 10 5 5 20 20 5 5 0.1 0 s .1 .1 .1 [sc#00f ab 3 1 2 ty .25 tx 1 csgs]]"); | |||
m_gears[1].m1.Compile("sc#ff9 scb#ff9 acg 54 10 95 95 90 90 -5 -5 0.1 0 s .1 .1 .1"); | |||
//m_gears[2].m1.Compile("sc#9ff scb#9ff acg 18 10 5 5 30 30 5 5 0.1 0 s .1 .1 .1 [sc#00f scb#00f ab 2 2 2 tx 1.5]"); | |||
@@ -121,6 +120,8 @@ private: | |||
int main(int argc, char **argv) | |||
{ | |||
System::Init(argc, argv); | |||
Application app("Tutorial 5: EasyMesh", ivec2(960, 600), 60.0f); | |||
new EasyMeshTutorial(); | |||
app.Run(); | |||
@@ -1,7 +1,7 @@ | |||
// | |||
// Lol Engine - Framebuffer Object tutorial | |||
// | |||
// Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net> | |||
// Copyright: (c) 2012-2013 Sam Hocevar <sam@hocevar.net> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
@@ -138,6 +138,8 @@ private: | |||
int main(int argc, char **argv) | |||
{ | |||
System::Init(argc, argv); | |||
Application app("Tutorial 08: Framebuffer Object", ivec2(640, 480), 60.0f); | |||
#if defined _MSC_VER && !defined _XBOX | |||
@@ -553,6 +553,7 @@ int main(int argc, char **argv) | |||
{ | |||
ivec2 window_size(640, 480); | |||
System::Init(argc, argv); | |||
Application app("Tutorial 3: Fractal", window_size, 60.0f); | |||
#if defined _MSC_VER && !defined _XBOX | |||