#endif
#include "Game.h"
-#include "IL/il.h"
-#include "IL/ilu.h"
-#include "IL/ilut.h"
+
+#ifndef USE_DEVIL
+# ifdef WIN32
+# define USE_DEVIL
+# endif
+#endif
+
+#if USE_DEVIL
+ #include "IL/il.h"
+ #include "IL/ilu.h"
+ #include "IL/ilut.h"
+#else
+ // just use libpng and libjpg directly; it's lighter-weight and easier
+ // to manage the dependencies on Linux...
+ #include "png.h"
+ static bool load_image(const char * fname, TGAImageRec & tex);
+ static bool load_png(const char * fname, TGAImageRec & tex);
+ static bool load_jpg(const char * fname, TGAImageRec & tex);
+#endif
// ADDED GWC
#ifdef _MSC_VER
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glAlphaFunc( GL_GREATER, 0.5f);
+#if USE_DEVIL
if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION ||
ilutGetInteger(ILUT_VERSION_NUM) < ILUT_VERSION)
ilEnable(IL_ORIGIN_SET);
ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
+#endif
GLint width = kContextWidth;
GLint height = kContextHeight;
// game.Dispose();
+#if USE_DEVIL
ilShutDown();
+#endif
#if USE_SDL
SDL_Quit();
return false;
}
+ #if USE_DEVIL
ILstring f = strdup(ConvertFileName(fname));
if (!f)
{
}
*/
free(f);
+ #else
+ res = load_image(fname, tex);
+ if (!res) STUBBED("load_image() failed!");
+ #endif
return res;
}
void ScreenShot(const char * fname)
{
+ #if USE_DEVIL
ILstring f = strdup(fname);
if (!f)
{
ilDeleteImages(1, &iid);
free(f);
+ #else
+ STUBBED("Non-DevIL screenshot");
+ #endif
}
+#if !USE_DEVIL
+static bool load_image(const char *file_name, TGAImageRec &tex)
+{
+ char *ptr = strrchr(file_name, '.');
+ if (ptr)
+ {
+ if (stricmp(ptr+1, "png") == 0)
+ return load_png(file_name, tex);
+ else if (stricmp(ptr+1, "jpg") == 0)
+ return load_jpg(file_name, tex);
+ }
+
+ STUBBED("Unsupported image type");
+ return false;
+}
+
+static bool load_jpg(const char *file_name, TGAImageRec &tex)
+{
+ // !!! FIXME: write this.
+ STUBBED("load_jpg");
+ return false;
+}
+
+/* stolen from public domain example.c code in libpng distribution. */
+static bool load_png(const char *file_name, TGAImageRec &tex)
+{
+ bool hasalpha = false;
+ png_structp png_ptr = NULL;
+ png_infop info_ptr = NULL;
+ png_uint_32 width, height;
+ int bit_depth, color_type, interlace_type;
+ png_byte **rows = NULL;
+ bool retval = false;
+ png_byte **row_pointers = NULL;
+ FILE *fp = fopen(file_name, "rb");
+
+ if (fp == NULL)
+ return(NULL);
+
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+ if (png_ptr == NULL)
+ goto png_done;
+
+ info_ptr = png_create_info_struct(png_ptr);
+ if (info_ptr == NULL)
+ goto png_done;
+
+ if (setjmp(png_jmpbuf(png_ptr)))
+ goto png_done;
+
+ png_init_io(png_ptr, fp);
+ png_read_png(png_ptr, info_ptr,
+ PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING,
+ png_voidp_NULL);
+ png_get_IHDR(png_ptr, info_ptr, &width, &height,
+ &bit_depth, &color_type, &interlace_type, NULL, NULL);
+
+ if (bit_depth != 8) // transform SHOULD handle this...
+ goto png_done;
+
+ if (color_type & PNG_COLOR_MASK_PALETTE) // !!! FIXME?
+ goto png_done;
+
+ if ((color_type & PNG_COLOR_MASK_COLOR) == 0) // !!! FIXME?
+ goto png_done;
+
+ hasalpha = ((color_type & PNG_COLOR_MASK_ALPHA) != 0);
+ row_pointers = png_get_rows(png_ptr, info_ptr);
+ if (!row_pointers)
+ goto png_done;
+
+ retval = malloc(width * height * 4);
+ if (!retval)
+ goto png_done;
+
+ if (!hasalpha)
+ {
+ png_byte *dst = tex.data;
+ for (int i = height-1; i >= 0; i--)
+ {
+ png_byte *src = row_pointers[i];
+ for (int j = 0; j < width; j++)
+ {
+ dst[0] = src[0];
+ dst[1] = src[1];
+ dst[2] = src[2];
+ dst[3] = 0xFF;
+ src += 3;
+ dst += 4;
+ }
+ }
+ }
+
+ else
+ {
+ png_byte *dst = tex.data;
+ int pitch = width * 4;
+ for (int i = height-1; i >= 0; i--, dst += pitch)
+ memcpy(dst, row_pointers[i], pitch);
+ }
+
+ tex.sizeX = width;
+ tex.sizeY = height;
+ tex.bpp = 32;
+ retval = true;
+
+png_done:
+ png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
+ fclose(fp);
+ return (retval);
+}
+#endif
+
macosx := false
+use_devil := false
BINDIR := bin
RUNDIR := run
SRCDIR := Source
SDLDIR := SDL12
+LIBPNGDIR := libpng-1.2.8
+ZLIBDIR := zlib-1.2.3
EXE := $(RUNDIR)/lugaru-bin
-Dstricmp=strcasecmp \
INCLUDES := \
- -I./SDL12/include \
+ -I$(SRCDIR) \
+ -I$(SDLDIR)/include \
-I./OpenGL/ \
-I./OpenGL/GL \
- -I$(SRCDIR) \
- -I$(SRCDIR)/devil/include \
+
+ifeq ($(strip $(use_devil)),true)
+ DEFINES += -DUSE_DEVIL=1
+ INCLUDES += -I$(SRCDIR)/devil/include
+else
+ DEFINES += -DZ_PREFIX=1
+ INCLUDES += -I$(ZLIBDIR) -I$(LIBPNGDIR)
+endif
CFLAGS := -g -c $(OPT) $(INCLUDES) $(DEFINES) -fsigned-char
CFLAGS += -w
else
CFLAGS += -DPLATFORM_LINUX=1
#CFLAGS += -msse -mmmx
- LDFLAGS := ./libSDL-1.2.so.0 -lGL -lGLU ./libfmod.so ./libIL.so.1 ./libILU.so.1 ./libILUT.so.1
+ LDFLAGS := ./libSDL-1.2.so.0 -lGL -lGLU ./libfmod.so
+
+ ifeq ($(strip $(use_devil)),true)
+ LDFLAGS += ./libIL.so.1 ./libILU.so.1 ./libILUT.so.1
+ endif
endif
CXXFLAGS := $(CFLAGS)
WinInput.cpp \
OpenGL_Windows.cpp \
+SRCS := $(foreach f,$(SRCS),$(SRCDIR)/$(f))
+
+
+IMGSRCS := \
+ png.c \
+ pngerror.c \
+ pnggccrd.c \
+ pngget.c \
+ pngmem.c \
+ pngpread.c \
+ pngread.c \
+ pngrio.c \
+ pngrtran.c \
+ pngrutil.c \
+ pngset.c \
+ pngtrans.c \
+ pngvcrd.c \
+ pngwio.c \
+ pngwrite.c \
+ pngwtran.c \
+ pngwutil.c \
+
+IMGSRCS := $(foreach f,$(IMGSRCS),$(LIBPNGDIR)/$(f))
+
+
+ZLIBSRCS = \
+ adler32.c \
+ compress.c \
+ crc32.c \
+ deflate.c \
+ gzio.c \
+ infback.c \
+ inffast.c \
+ inflate.c \
+ inftrees.c \
+ trees.c \
+ uncompr.c \
+ zutil.c \
+
+ZLIBSRCS := $(foreach f,$(ZLIBSRCS),$(ZLIBDIR)/$(f))
+
+
+ifneq ($(strip $(use_devil)),true)
+ SRCS += $(IMGSRCS) $(ZLIBSRCS)
+endif
OBJS := $(SRCS:.CC=.o)
OBJS := $(OBJS:.cc=.o)
OBJS := $(OBJS:.c=.o)
OBJS := $(OBJS:.m=.o)
OBJS := $(foreach f,$(OBJS),$(BINDIR)/$(f))
-SRCS := $(foreach f,$(SRCS),$(SRCDIR)/$(f))
.PHONY: clean all
all : $(EXE)
-$(BINDIR)/%.o : $(SRCDIR)/%.cpp
+$(BINDIR)/%.o : %.cpp
$(CXX) -o $@ $(CXXFLAGS) $<
-$(BINDIR)/%.o : $(SRCDIR)/%.CC
+$(BINDIR)/%.o : %.CC
$(CXX) -o $@ $(CXXFLAGS) $<
-$(BINDIR)/%.o : $(SRCDIR)/%.cc
+$(BINDIR)/%.o : %.cc
$(CXX) -o $@ $(CXXFLAGS) $<
-$(BINDIR)/%.o : $(SRCDIR)/%.m
+$(BINDIR)/%.o : %.m
$(CC) -o $@ $(CFLAGS) $<
-$(BINDIR)/%.o : $(SRCDIR)/%.c
+$(BINDIR)/%.o : %.c
$(CC) -o $@ $(CFLAGS) $<
$(EXE) : $(OBJS) $(APPOBJS)
$(LD) -o $@ $(APPLDFLAGS) $(LDFLAGS) $(OBJS) $(APPOBJS)
clean:
- rm -rf $(BINDIR)/*.o
- rm -rf $(BINDIR)/logger/*.o
- rm -rf $(EXE)
+ rm -f $(BINDIR)/*.o
+ rm -f $(BINDIR)/$(SRCDIR)/*.o
+ rm -f $(BINDIR)/$(SRCDIR)/logger/*.o
+ rm -f $(BINDIR)/$(LIBPNGDIR)/*.o
+ rm -f $(BINDIR)/$(ZLIBDIR)/*.o
+ rm -f $(EXE)
# end of makefile ...