Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux compatibility. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

MACHINE= $(shell uname -s)

ifeq ($(MACHINE),Darwin)
CXXFLAGS = \
-O2 \
-I/System/Library/Frameworks/GLUT.framework/Headers \
Expand All @@ -24,8 +28,29 @@ RESOURCES = \
resources/*.png \
resources/*.vert \
resources/world.xml

else
LIBS = \
`sdl-config --cflags` \
-I/usr/include \
-lGLU \
-lGL \
-lGLEW \
-lglut \
-lSDL \
-lSDL_image \
-lSDL_mixer \
-ltinyxml

endif

ifeq ($(MACHINE),Darwin)
all : obj/Polly-B-Gone.app
else
all : obj/polly-b-gone
endif

ifeq ($(MACHINE),Darwin)

obj/main.out : \
obj/ball.o \
Expand Down Expand Up @@ -66,6 +91,48 @@ obj/main.out : \
obj/worlds.o \
src/SDLMain.m

else

obj/main.out : \
obj/ball.o \
obj/block.o \
obj/escalator.o \
obj/fan.o \
obj/lighting.o \
obj/material.o \
obj/model.o \
obj/physics/constraint.o \
obj/physics/force.o \
obj/physics/particle.o \
obj/physics/rotation.o \
obj/physics/shape.o \
obj/physics/transform.o \
obj/physics/translation.o \
obj/physics/vector.o \
obj/player.o \
obj/portal.o \
obj/ramp.o \
obj/resource.o \
obj/room.o \
obj/room_force.o \
obj/room_object.o \
obj/rotating.o \
obj/seesaw.o \
obj/shader.o \
obj/simulation.o \
obj/sound.o \
obj/switch.o \
obj/texture.o \
obj/trail.o \
obj/transforming.o \
obj/translating.o \
obj/tube.o \
obj/wall.o \
obj/world.o \
obj/worlds.o

endif

obj/physics/particle_test.out : \
obj/physics/force.o \
obj/physics/particle.o \
Expand All @@ -79,6 +146,8 @@ obj/physics/shape_test.out : \
obj/physics/vector_test.out : \
obj/physics/vector.o

ifeq ($(MACHINE),Darwin)

obj/Polly-B-Gone.app : obj/main.out $(RESOURCES) resources/Info.plist Makefile
rm -rf $@
mkdir -p $@/Contents/MacOS
Expand All @@ -94,8 +163,17 @@ obj/Polly-B-Gone.app : obj/main.out $(RESOURCES) resources/Info.plist Makefile
find $@/Contents/Frameworks -name Headers | xargs rm -r
# ln -sf ../../../../resources/world.xml $@/Contents/Resources/world.xml

else
obj/polly-b-gone : obj/main.out
mv obj/main.out polly-b-gone
endif

obj/%.out : obj/%.o
ifeq ($(MACHINE),Darwin)
$(CXX) $(LDFLAGS) -o $@ $^
else
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
endif

obj/%.o : src/%.cpp
mkdir -p $(@D)
Expand Down
6 changes: 5 additions & 1 deletion src/lighting.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
#ifndef MBOSTOCK_LIGHTING_H
#define MBOSTOCK_LIGHTING_H

#include <OpenGL/gl.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif

namespace mbostock {

Expand Down
33 changes: 30 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
// -*- C++ -*-

#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#endif
#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include <TinyXML/tinyxml.h>
#ifdef __APPLE__
#include <TinyXML/tinyxml.h>
#else
#include <tinyxml.h>
#endif

#include "room.h"
#include "shader.h"
Expand Down Expand Up @@ -116,19 +126,31 @@ static void toggleFullScreen() {
static void handleKeyDown(SDL_Event* event) {
switch (event->key.keysym.sym) {
case SDLK_LEFT: {
#ifdef __APPLE__
if (event->key.keysym.mod & KMOD_META) {
#else
if (event->key.keysym.mod & KMOD_CTRL) {
#endif
world->previousRoom();
}
break;
}
case SDLK_DOWN: {
#ifdef __APPLE__
if (event->key.keysym.mod & KMOD_META) {
#else
if (event->key.keysym.mod & KMOD_CTRL) {
#endif
world->resetPlayer();
}
break;
}
case SDLK_RIGHT: {
#ifdef __APPLE__
if (event->key.keysym.mod & KMOD_META) {
#else
if (event->key.keysym.mod & KMOD_CTRL) {
#endif
world->nextRoom();
}
break;
Expand Down Expand Up @@ -192,6 +214,11 @@ static void eventLoop() {
}

int main(int argc, char** argv) {

#ifndef __APPLE__
glutInit(&argc, argv);
#endif

SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);

SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
Expand Down
6 changes: 5 additions & 1 deletion src/material.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// -*- C++ -*-

#include <OpenGL/gl.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#include <iostream>
#include <math.h>
#include <stdlib.h>
Expand Down
9 changes: 7 additions & 2 deletions src/model.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// -*- C++ -*-

#include <GLUT/glut.h>
#include <OpenGL/glu.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#include <OpenGL/glu.h>
#else
#include <GL/glut.h>
#include <GL/glu.h>
#endif
#include <algorithm>
#include <iostream>
#include <math.h>
Expand Down
6 changes: 5 additions & 1 deletion src/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
#ifndef MBOSTOCK_MODEL_H
#define MBOSTOCK_MODEL_H

#include <OpenGL/glu.h>
#ifdef __APPLE__
#include <OpenGL/glu.h>
#else
#include <GL/glu.h>
#endif

#include "physics/shape.h"
#include "physics/vector.h"
Expand Down
12 changes: 9 additions & 3 deletions src/player.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// -*- C++ -*-

#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#endif
#include <iostream>
#include <math.h>
#include <stdio.h>
Expand Down
6 changes: 5 additions & 1 deletion src/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
using namespace mbostock;

const char* Resources::path() {
return "Contents/Resources/";
#ifdef __APPLE__
return "Contents/Resources/";
#else
return "resources/";
#endif
}

const char* Resources::readFile(const char* p) {
Expand Down
6 changes: 5 additions & 1 deletion src/seesaw.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// -*- C++ -*-

#include <OpenGL/gl.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif

#include "material.h"
#include "physics/constraint.h"
Expand Down
3 changes: 3 additions & 0 deletions src/shader.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// -*- C++ -*-

#include <stdlib.h>
#ifndef __APPLE__
#include <GL/glew.h>
#endif

#include "model.h"
#include "resource.h"
Expand Down
6 changes: 5 additions & 1 deletion src/shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
#ifndef _SHADER_H
#define _SHADER_H

#include <OpenGL/gl.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif

namespace mbostock {

Expand Down
6 changes: 5 additions & 1 deletion src/simulation.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// -*- C++ -*-

#include <SDL/sdl.h>
#ifdef __APPLE_
#include <SDL/sdl.h>
#else
#include <SDL/SDL.h>
#endif

#include "simulation.h"

Expand Down
9 changes: 7 additions & 2 deletions src/sound.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// -*- C++ -*-

#include <SDL/SDL_error.h>
#include <SDL_mixer/SDL_mixer.h>
#ifdef __APPLE__
#include <SDL/SDL_error.h>
#include <SDL_mixer/SDL_mixer.h>
#else
#include <SDL/SDL_error.h>
#include <SDL/SDL_mixer.h>
#endif
#include <iostream>
#include <string>
#include <vector>
Expand Down
15 changes: 11 additions & 4 deletions src/texture.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
// -*- C++ -*-

#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <SDL/sdl.h>
#include <SDL_image/SDL_image.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <SDL/sdl.h>
#include <SDL_image/SDL_image.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#endif
#include <iostream>
#include <string>
#include <vector>
Expand Down
6 changes: 5 additions & 1 deletion src/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
#ifndef MBOSTOCK_TEXTURE_H
#define MBOSTOCK_TEXTURE_H

#include <OpenGL/gl.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif

namespace mbostock {

Expand Down
6 changes: 5 additions & 1 deletion src/world.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// -*- C++ -*-

#include <OpenGL/gl.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif

#include "material.h"
#include "portal.h"
Expand Down
9 changes: 8 additions & 1 deletion src/worlds.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#include <TinyXML/tinyxml.h>
#ifdef __APPLE__
#include <TinyXML/tinyxml.h>
#else
#ifndef TIXML_USE_STL
#define TIXML_USE_STL
#endif
#include <tinyxml.h>
#endif
#include <iostream>
#include <list>
#include <map>
Expand Down