Skip to content
Browse files

Merging in linux changes by gamaral.

  • Loading branch information...
1 parent 10be10c commit 8529fdc77e50ea820c1696d1e7874ac98bcc036a @zaphire committed Mar 16, 2011
View
1 .gitignore
@@ -0,0 +1 @@
+Build
View
0 Build/.keep
No changes.
View
48 CMakeLists.txt
@@ -0,0 +1,48 @@
+project(Monocle)
+cmake_minimum_required(VERSION 2.6.0)
+if(COMMAND cmake_policy)
+ cmake_policy(SET CMP0003 NEW)
+endif(COMMAND cmake_policy)
+
+set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
+
+include_directories(AFTER SYSTEM ${PROJECT_BINARY_DIR} Code)
+
+set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
+set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(BUILD_TESTS OFF CACHE BOOL "Build tests")
+set(WITH_OPENAL ON CACHE BOOL "Use OpenAL")
+set(WITH_OPENGL ON CACHE BOOL "Use OpenGL")
+
+if(WIN32)
+ add_definitions(-DMONOCLE_WINDOWS)
+ set(WINDOWS ON)
+endif(WIN32)
+
+if (APPLE)
+ add_definitions(-DMONOCLE_APPLE)
+ set(MACOSX ON)
+ set(APPLE ON)
+endif(APPLE)
+
+if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
+ find_package(X11 REQUIRED)
+ add_definitions(-DMONOCLE_LINUX)
+ set(LINUX ON)
+endif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
+
+if(WITH_OPENGL)
+ find_package(OpenGL REQUIRED)
+ add_definitions(-DMONOCLE_OPENGL)
+endif(WITH_OPENGL)
+
+if(WITH_OPENAL)
+ find_package(OpenAL REQUIRED)
+ add_definitions(-DMONOCLE_OPENAL)
+endif(WITH_OPENAL)
+
+add_subdirectory(Code)
+
View
32 Code/CMakeLists.txt
@@ -0,0 +1,32 @@
+file(GLOB CORE_SRCS *.cpp)
+file(GLOB COLLIDERS_SRCS Colliders/*.cpp)
+file(GLOB OPENAL_SRCS OpenAL/*.cpp)
+file(GLOB OPENGL_SRCS OpenGL/*.cpp OpenGL/glpng/*.c OpenGL/glpng/*/*.c)
+
+set(CORE_LINK ${CORE_LINK} ${OPENGL_LIBRARIES} ${OPENAL_LIBRARY})
+
+if(WINDOWS)
+ file(GLOB WINDOWS_SRCS Windows/*.cpp)
+ set(PLATFORM_SRCS ${PLATFORM_SRCS} ${WINDOWS_SRCS})
+endif(WINDOWS)
+
+if(LINUX)
+ include_directories(${X11_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${OPENAL_INCLUDE_DIR})
+ set(CORE_LINK ${CORE_LINK} ${X11_LIBRARIES})
+ file(GLOB LINUX_SRCS Linux/*.cpp)
+ set(PLATFORM_SRCS ${PLATFORM_SRCS} ${LINUX_SRCS})
+endif(LINUX)
+
+add_library(MonocleCore
+ ${CORE_SRCS}
+ ${COLLIDERS_SRCS}
+ ${PLATFORM_SRCS}
+ ${OPENAL_SRCS}
+ ${OPENGL_SRCS}
+)
+
+# TODO: Add proper dependency handling
+target_link_libraries(MonocleCore ${CORE_LINK})
+
+add_subdirectory(Tests)
+
View
3 Code/Collision.cpp
@@ -1,4 +1,7 @@
#include "Collision.h"
+
+#include <stdio.h>
+
#include "Entity.h"
namespace Monocle
View
245 Code/Linux/LinuxPlatform.cpp
@@ -0,0 +1,245 @@
+#ifdef MONOCLE_LINUX
+
+#include "LinuxPlatform.h"
+
+#include<X11/X.h>
+#include<X11/extensions/Xrandr.h>
+
+#include <stdio.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "../Debug.h"
+#include "../Core.h"
+#include "../Graphics.h"
+
+// opengl/windows init code baesd on http://nehe.gamedev.net
+// keyboard code based on SDL http://www.libsdl.org/
+
+#ifndef VK_0
+#define VK_0 '0'
+#define VK_1 '1'
+#define VK_2 '2'
+#define VK_3 '3'
+#define VK_4 '4'
+#define VK_5 '5'
+#define VK_6 '6'
+#define VK_7 '7'
+#define VK_8 '8'
+#define VK_9 '9'
+#define VK_A 'A'
+#define VK_B 'B'
+#define VK_C 'C'
+#define VK_D 'D'
+#define VK_E 'E'
+#define VK_F 'F'
+#define VK_G 'G'
+#define VK_H 'H'
+#define VK_I 'I'
+#define VK_J 'J'
+#define VK_K 'K'
+#define VK_L 'L'
+#define VK_M 'M'
+#define VK_N 'N'
+#define VK_O 'O'
+#define VK_P 'P'
+#define VK_Q 'Q'
+#define VK_R 'R'
+#define VK_S 'S'
+#define VK_T 'T'
+#define VK_U 'U'
+#define VK_V 'V'
+#define VK_W 'W'
+#define VK_X 'X'
+#define VK_Y 'Y'
+#define VK_Z 'Z'
+#endif /* VK_0 */
+
+#define VK_SEMICOLON 0xBA
+#define VK_EQUALS 0xBB
+#define VK_COMMA 0xBC
+#define VK_MINUS 0xBD
+#define VK_PERIOD 0xBE
+#define VK_SLASH 0xBF
+#define VK_GRAVE 0xC0
+#define VK_LBRACKET 0xDB
+#define VK_BACKSLASH 0xDC
+#define VK_RBRACKET 0xDD
+#define VK_APOSTROPHE 0xDE
+#define VK_BACKTICK 0xDF
+#define VK_OEM_102 0xE2
+
+#define REPEATED_KEYMASK (1<<30)
+#define EXTENDED_KEYMASK (1<<24)
+
+namespace Monocle
+{
+ LinuxPlatform *LinuxPlatform::instance = NULL;
+
+ //TODO: cleanup code, replace message boxes
+ bool LinuxPlatform::CreatePlatformWindow(const char* title, int width, int height, int bits, bool fullscreenflag)
+ {
+ const char *windowName = "Monocle Engine\0";
+ Window hRootWindow;
+ GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, bits, GLX_DOUBLEBUFFER, None };
+ XVisualInfo *vi;
+ Colormap cmap;
+ XSetWindowAttributes swa;
+
+ fullscreen=fullscreenflag; // Set The Global Fullscreen Flag
+
+ hDisplay = XOpenDisplay(NULL);
+ if (hDisplay == NULL) {
+ fprintf(stderr, "Cannot open display\n");
+ return(false);
+ }
+
+ hRootWindow = DefaultRootWindow(hDisplay);
+ hScreen = DefaultScreen(hDisplay);
+
+ vi = glXChooseVisual(hDisplay, 0, att);
+
+ if(vi == NULL) {
+ fprintf(stderr, "No visual was found.\n");
+ return(false);
+ }
+ cmap = XCreateColormap(hDisplay, hRootWindow, vi->visual, AllocNone);
+
+ swa.colormap = cmap;
+ swa.event_mask = ExposureMask | KeyPressMask;
+
+ hWindow = XCreateWindow(
+ hDisplay, // display
+ hRootWindow, // parent
+ 0, 0, width, height, // rect
+ 1, // border width
+ bits, // depth
+ InputOutput, // class
+ vi->visual, // visual
+ CWColormap | CWEventMask, // value mask
+ &swa);
+ XMapWindow(hDisplay, hWindow);
+ XStoreName(hDisplay, hWindow, title);
+
+ GC = glXCreateContext(hDisplay, vi, NULL, GL_TRUE);
+ glXMakeCurrent(hDisplay, hWindow, GC);
+ glEnable(GL_DEPTH_TEST);
+
+ // TODO: IMPLEMENT fullscreen
+
+ CenterWindow();
+
+ return true;
+ }
+
+ void LinuxPlatform::GetDesktopSize(int *width, int *height)
+ {
+ *width = 800;
+ *height = 600;
+ // TODO: IMPLEMENT
+ }
+
+ void LinuxPlatform::CenterWindow()
+ {
+ // TODO: IMPLEMENT
+ }
+
+ void LinuxPlatform::KillPlatformWindow()
+ {
+ glXMakeCurrent(hDisplay, None, NULL);
+ glXDestroyContext(hDisplay, GC);
+ XDestroyWindow(hDisplay, hWindow);
+ XCloseDisplay(hDisplay);
+ }
+
+ Platform *Platform::instance = NULL;
+
+ bool Platform::keys[KEY_MAX];
+ bool Platform::mouseButtons[3];
+ Vector2 Platform::mousePosition;
+
+ Platform::Platform()
+ {
+ LinuxPlatform::instance = new LinuxPlatform();
+ instance = this;
+ LinuxPlatform::instance->platform = this;
+
+ for (int i = 0; i < KEY_MAX; i++)
+ {
+ keys[i] = false;
+ localKeymap[i] = KEY_UNDEFINED;
+ }
+ }
+
+ void Platform::Init()
+ {
+ Init(800, 600, 24, false);
+ }
+
+ void Platform::Init(int w, int h, int bits, bool fullscreen)
+ {
+ LinuxPlatform::instance->CreatePlatformWindow("Monocle Powered", w, h, bits, fullscreen);
+ width = w;
+ height = h;
+ }
+
+ void Platform::Update()
+ {
+ XEvent event;
+
+ while (XPending(LinuxPlatform::instance->hDisplay)) {
+ XNextEvent(LinuxPlatform::instance->hDisplay, &event);
+ switch(event.type) {
+ case Expose:
+ glViewport(0, 0, width, height);
+ ShowBuffer();
+ break;
+ case KeyPress:
+ break;
+ }
+ }
+ }
+
+ void Platform::SetMouseButton(int button, bool on)
+ {
+ mouseButtons[button] = on;
+ }
+
+ long Platform::GetMilliseconds()
+ {
+ return (long)time(0);
+ }
+
+ bool Platform::IsKeyPressed(KeyCode keyCode)
+ {
+ return instance->keys[(int)keyCode];
+ }
+
+ void Platform::ShowBuffer()
+ {
+ glXSwapBuffers(LinuxPlatform::instance->hDisplay, LinuxPlatform::instance->hWindow);
+ }
+
+ int Platform::GetWidth()
+ {
+ return instance->width;
+ }
+
+ int Platform::GetHeight()
+ {
+ return instance->height;
+ }
+
+ void Platform::WindowSizeChanged(int w, int h)
+ {
+ instance->width = w;
+ instance->height = h;
+ Graphics::Resize(w, h);
+ }
+
+ void Platform::SetLocalKey(int key, bool on)
+ {
+ }
+}
+
+#endif
View
48 Code/Linux/LinuxPlatform.h
@@ -0,0 +1,48 @@
+#ifdef MONOCLE_LINUX
+
+#pragma once
+
+#include "../Platform.h"
+
+#define LINUX_LEAN_AND_MEAN
+
+#include <X11/Xlib.h>
+#include<GL/glx.h>
+
+namespace Monocle
+{
+ class LinuxPlatform
+ {
+ public:
+
+ Display *hDisplay;
+ int hScreen;
+ Window hWindow;
+ GLXContext GC;
+
+ bool active; // Window Active Flag Set To TRUE By Default
+ bool fullscreen; // Fullscreen Flag Set To Fullscreen Mode By Default
+
+ static LinuxPlatform* instance;
+ Platform *platform;
+
+ LinuxPlatform()
+ : hDisplay(NULL),
+ hScreen(NULL),
+ hWindow(NULL),
+ GC(NULL)
+ {
+ active = true;
+ fullscreen = true;
+ instance = this;
+ }
+
+ bool CreatePlatformWindow(const char* title, int width, int height, int bits, bool fullscreenflag);
+ void KillPlatformWindow();
+ void CenterWindow();
+ static void GetDesktopSize(int *width, int *height);
+ };
+
+}
+
+#endif
View
19 Code/OpenGL/OpenGLGraphics.cpp
@@ -6,19 +6,24 @@
#include "../TextureAsset.h"
#include "../Color.h"
+#include <cstdio>
+
#ifdef MONOCLE_WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#endif
-#ifdef MONOCLE_MAC
-#include <OpenGL/gl.h>
-#include <OpenGL/glext.h>
-#include <OpenGL/glu.h>
+#if defined(MONOCLE_MAC)
+ #include <OpenGL/gl.h>
+ #include <OpenGL/glext.h>
+ #include <OpenGL/glu.h>
+#elif defined(MONOCLE_LINUX)
+ #include <GL/gl.h>
+ #include <GL/glu.h>
#else
-#include <gl/GL.h>
-#include <gl/GLU.h>
+ #include <gl/GL.h>
+ #include <gl/GLU.h>
#endif
// some opengl/windows init code based on http://nehe.gamedev.net
@@ -266,4 +271,4 @@ namespace Monocle
}
}
-#endif
+#endif
View
16 Code/OpenGL/OpenGLTextureAsset.cpp
@@ -10,12 +10,16 @@
#include <Windows.h>
#endif
-#ifdef MONOCLE_MAC
-#include <OpenGL/gl.h>
-#include <OpenGL/glext.h>
+
+#if defined(MONOCLE_MAC)
+ #include <OpenGL/gl.h>
+ #include <OpenGL/glext.h>
+#elif defined(MONOCLE_LINUX)
+ #include <GL/gl.h>
+ #include <GL/glu.h>
#else
-#include <gl/GL.h>
-#include <gl/GLu.h>
+ #include <gl/GL.h>
+ #include <gl/GLu.h>
#endif
namespace Monocle
@@ -70,4 +74,4 @@ namespace Monocle
}
}
-#endif
+#endif
View
7 Code/OpenGL/glpng/glpng.c
@@ -28,12 +28,17 @@
#include "glpng.h"
+/* NOTE: This should be handled by build system's include path not hardcoded. */
#ifdef __APPLE__
/* Mac OS X GL headers */
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#else
- #include <gl/GL.h>
+ #include <GL/gl.h>
+#endif
+
+#ifdef __linux__
+# undef GL_COLOR_INDEX1_EXT
#endif
#include <stdlib.h>
View
4 Code/Tests/CMakeLists.txt
@@ -0,0 +1,4 @@
+if(BUILD_TESTS)
+ add_subdirectory(Jumper)
+endif(BUILD_TESTS)
+
View
8 Code/Tests/Jumper/CMakeLists.txt
@@ -0,0 +1,8 @@
+set(PONG_SRCS
+ Jumper.cpp
+)
+
+add_executable(TestJumper ${PONG_SRCS})
+
+target_link_libraries(TestJumper MonocleCore ${CORE_LINK})
+
View
4 Code/Tests/Pong/Pong.cpp
@@ -2,6 +2,8 @@
#include "../../Input.h"
#include "../../Collision.h"
+#include <stdlib.h>
+
namespace Pong
{
/*
@@ -217,4 +219,4 @@ namespace Pong
delete paddle1;
delete paddle2;
}
-}
+}

0 comments on commit 8529fdc

Please sign in to comment.
Something went wrong with that request. Please try again.