diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85735dc --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +# vim swap files +.*.sw? +# compiled stuff +*.o diff --git a/build/osx/Roll them Bones.xcodeproj/project.pbxproj b/build/osx/Roll them Bones.xcodeproj/project.pbxproj index 8bdf7d4..9afb41d 100644 --- a/build/osx/Roll them Bones.xcodeproj/project.pbxproj +++ b/build/osx/Roll them Bones.xcodeproj/project.pbxproj @@ -11,6 +11,8 @@ 20138FCE1A3DC7A700FD0095 /* SDL2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 20138FCD1A3DC7A700FD0095 /* SDL2.framework */; }; 205D36CE1A6749FB00C05BD8 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 205D36CD1A6749FB00C05BD8 /* main.cpp */; }; 205D370C1A674B1D00C05BD8 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 205D370B1A674B1D00C05BD8 /* OpenGL.framework */; }; + 20A8CE541A899B72004D2504 /* RenderCamera.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20A8CE501A899B72004D2504 /* RenderCamera.cpp */; }; + 20A8CE551A899B72004D2504 /* RenderView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20A8CE521A899B72004D2504 /* RenderView.cpp */; }; 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; /* End PBXBuildFile section */ @@ -20,6 +22,11 @@ 20138FCD1A3DC7A700FD0095 /* SDL2.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2.framework; path = /Library/Frameworks/SDL2.framework; sourceTree = ""; }; 205D36CD1A6749FB00C05BD8 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = ../../src/main.cpp; sourceTree = SOURCE_ROOT; }; 205D370B1A674B1D00C05BD8 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework; sourceTree = ""; }; + 20A8CE501A899B72004D2504 /* RenderCamera.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RenderCamera.cpp; path = ../../src/RenderCamera.cpp; sourceTree = SOURCE_ROOT; }; + 20A8CE511A899B72004D2504 /* RenderCamera.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = RenderCamera.hpp; path = ../../src/RenderCamera.hpp; sourceTree = SOURCE_ROOT; }; + 20A8CE521A899B72004D2504 /* RenderView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RenderView.cpp; path = ../../src/RenderView.cpp; sourceTree = SOURCE_ROOT; }; + 20A8CE531A899B72004D2504 /* RenderView.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = RenderView.hpp; path = ../../src/RenderView.hpp; sourceTree = SOURCE_ROOT; }; + 20A8CE681A899CF6004D2504 /* GL.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = GL.hpp; path = ../../src/GL.hpp; sourceTree = SOURCE_ROOT; }; 8D1107320486CEB800E47090 /* Roll them Bones.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Roll them Bones.app"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -41,6 +48,10 @@ 080E96DDFE201D6D7F000001 /* Classes */ = { isa = PBXGroup; children = ( + 20A8CE501A899B72004D2504 /* RenderCamera.cpp */, + 20A8CE511A899B72004D2504 /* RenderCamera.hpp */, + 20A8CE521A899B72004D2504 /* RenderView.cpp */, + 20A8CE531A899B72004D2504 /* RenderView.hpp */, ); name = Classes; sourceTree = ""; @@ -95,6 +106,7 @@ 29B97315FDCFA39411CA2CEA /* Other Sources */ = { isa = PBXGroup; children = ( + 20A8CE681A899CF6004D2504 /* GL.hpp */, ); name = "Other Sources"; sourceTree = ""; @@ -179,6 +191,8 @@ buildActionMask = 2147483647; files = ( 205D36CE1A6749FB00C05BD8 /* main.cpp in Sources */, + 20A8CE541A899B72004D2504 /* RenderCamera.cpp in Sources */, + 20A8CE551A899B72004D2504 /* RenderView.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/GL.hpp b/src/GL.hpp new file mode 100644 index 0000000..10175fa --- /dev/null +++ b/src/GL.hpp @@ -0,0 +1,12 @@ +/* ================================================================ +This file provides common includes to access OpenGL types and functions +================================================================ */ +#if defined(__IPHONEOS__) || defined(__ANDROID__) +#define HAVE_OPENGLES +#endif + +#ifdef HAVE_OPENGLES +#include "SDL_opengles.h" +#else +#include "SDL_opengl.h" +#endif diff --git a/src/RenderCamera.cpp b/src/RenderCamera.cpp new file mode 100644 index 0000000..6413f52 --- /dev/null +++ b/src/RenderCamera.cpp @@ -0,0 +1,19 @@ +/* ================================================================ +RenderCamera +---------------- +This header file defines the RenderCamera class. +================================================================ */ +#include "RenderCamera.hpp" +/* ======== Constructors and Destructors ======== */ +RenderCamera::RenderCamera() { + render_mode = 0; + render_view = NULL; +} +RenderCamera::~RenderCamera() { +} +/* ======== Setter functions ======== */ +int RenderCamera::setRenderView(RenderView *rv) { + if (rv == NULL) return 1; + render_view = rv; + return 0; +} diff --git a/src/RenderCamera.hpp b/src/RenderCamera.hpp new file mode 100644 index 0000000..1aa2248 --- /dev/null +++ b/src/RenderCamera.hpp @@ -0,0 +1,24 @@ +/* ================================================================ +RenderCamera +---------------- +This header file describes the RenderCamera class. + +A RenderCamera is the object responsible for providing a rendering position, +orientation, and perspective transformations. A RenderCamera exists within a +RenderScene and outputs all data to the friend class, RenderView. +================================================================ */ +#ifndef RENDERCAMERA_HPP +#define RENDERCAMERA_HPP +#include "GL.hpp" +#include "RenderView.hpp" +class RenderCamera { + public: + RenderCamera(); + ~RenderCamera(); + int setRenderView(RenderView *view); + private: + //Vec3 x, y, z; // TODO: replace with quaternion + int render_mode; // 0 = perspective, 1 = orthogonal + RenderView *render_view; // RenderView to render the scene to +}; +#endif diff --git a/src/RenderView.cpp b/src/RenderView.cpp new file mode 100644 index 0000000..c06db37 --- /dev/null +++ b/src/RenderView.cpp @@ -0,0 +1,25 @@ +/* ================================================================ +RenderView +---------------- +This file defines our RenderView object. +================================================================ */ +#include "RenderView.hpp" +/* ======== Constructors and Destructors ======== */ +RenderView::RenderView(unsigned int width, unsigned int height) { + program = fbo = fbo_depth = fbo_tex = 0; + w = h = 0; + x = y = 0; + createView(width, height); +} +RenderView::~RenderView() { + destroyView(); +} +/* ======== Setters ======== */ +int RenderView::createView(unsigned int width, unsigned int height) { + // TODO: call destroyView() and create new FBO at width and height + return 0; +} +int RenderView::destroyView() { + // TODO: destroy FBO + return 0; +} diff --git a/src/RenderView.hpp b/src/RenderView.hpp new file mode 100644 index 0000000..ef8c6d9 --- /dev/null +++ b/src/RenderView.hpp @@ -0,0 +1,28 @@ +/* ================================================================ +RenderView +---------------- +This header file describes our RenderView object. + +A RenderView is the target of a RenderCamera and consists of a framebuffer +object and shader program to render said framebuffer. For all intents and +purposes, it is a wrapper around a FBO. +================================================================ */ +#ifndef RENDERVIEW_HPP +#define RENDERVIEW_HPP +#include "GL.hpp" +class RenderView { + friend class RenderCamera; + public: + RenderView(unsigned int width, unsigned int height); + ~RenderView(); + private: + GLuint program; // Compiled shader program to render with + GLuint fbo; // The fbo that RenderCamera will draw to + GLuint fbo_depth; // The fbo depth buffer + GLuint fbo_tex; // The texture of the fbo + unsigned int w, h; // width and height of this view (also of fbo) + int x, y; // x and y offsets of rendering to screen + int createView(unsigned int width, unsigned int height); + int destroyView(); +}; +#endif diff --git a/src/main.cpp b/src/main.cpp index 4582180..d80c32f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,14 +1,5 @@ #include "SDL.h" - -#if defined(__IPHONEOS__) || defined(__ANDROID__) -#define HAVE_OPENGLES -#endif - -#ifdef HAVE_OPENGLES -#include "SDL_opengles.h" -#else -#include "SDL_opengl.h" -#endif +#include "GL.hpp" int main(int argc, char *argv[]) { // TEMP location of video vars