Much added. Basic asset access functions using fopen() techniques. Currently the system attempts to load from the CWD on most platforms, but on Android it attempts to load from the assets archive. Once updated, it will likely attempt to load from at least 3 locations before falling back to the built-in application assets (external device, user directory, application data directory). Creation/Loading of RtB is now managed by a Core class. This class is, to some extent, a service locator combined with larger engine functionality. A global instance of the class is provided as 'core'. It is responsible for updating the yet-to-be-added States, the base rendering, and the management of assets and much more.
parent
adcf6cd1b5
commit
a0eeec21b2
|
@ -40,5 +40,6 @@
|
|||
<uses-feature android:glEsVersion="0x00020000" />
|
||||
|
||||
<!-- Allow writing to external storage -->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
</manifest>
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
../../../data
|
|
@ -14,4 +14,4 @@
|
|||
# 'key.store' for the location of your keystore and
|
||||
# 'key.alias' for the name of the key to use.
|
||||
# The password will be asked during the build when you use the 'release' target.
|
||||
|
||||
assets.dir=${base.dir}/assets
|
||||
|
|
|
@ -28,7 +28,9 @@
|
|||
|
||||
-->
|
||||
<property file="ant.properties" />
|
||||
|
||||
<!-- set our assets dir -->
|
||||
<property name="asset.dir" value="assets" />
|
||||
<property name="asset.absolute.dir" location="${asset.dir}" />
|
||||
<!-- if sdk.dir was not set from one of the property file, then
|
||||
get it from the ANDROID_HOME env var.
|
||||
This must be done before we load project.properties since
|
||||
|
@ -68,6 +70,17 @@
|
|||
-pre-clean
|
||||
-->
|
||||
<import file="custom_rules.xml" optional="true" />
|
||||
<!-- <target name="package-resources">
|
||||
<echo>Packaging resources!!!</echo>
|
||||
<aaptexec executable="${aapt}"
|
||||
command="package"
|
||||
manifest="AndroidManifest.xml"
|
||||
resources="${resource.dir}"
|
||||
assets="${asset.dir}"
|
||||
androidjar="${android.jar}"
|
||||
outfolder="${out.dir}"
|
||||
basename="${ant.project.name}" />
|
||||
</target>-->
|
||||
|
||||
<!-- Import the actual build file.
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
# See CPLUSPLUS-SUPPORT.html in the NDK documentation for more information
|
||||
APP_STL := stlport_static
|
||||
|
||||
APP_ABI := armeabi armeabi-v7a x86
|
||||
#APP_ABI := armeabi armeabi-v7a x86
|
||||
APP_ABI := armeabi armeabi-v7a
|
||||
|
||||
APP_CPPFLAGS += -fexceptions
|
||||
|
|
|
@ -26,13 +26,21 @@ LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
|
|||
../../../../src/RenderSet.hpp \
|
||||
../../../../src/RenderView.cpp \
|
||||
../../../../src/RenderView.hpp \
|
||||
../../../../src/Program.cpp \
|
||||
../../../../src/Program.hpp \
|
||||
../../../../src/Vec.cpp \
|
||||
../../../../src/Vec.hpp \
|
||||
../../../../src/Quat.cpp \
|
||||
../../../../src/Quat.hpp \
|
||||
../../../../src/fio.cpp \
|
||||
../../../../src/fio.hpp \
|
||||
../../../../src/common.hpp \
|
||||
../../../../src/Core.cpp \
|
||||
../../../../src/Core.hpp \
|
||||
../../../../src/main.cpp
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := SDL2
|
||||
|
||||
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog
|
||||
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog -landroid
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
|
|
@ -1,7 +1,20 @@
|
|||
package com.polymathic.RtB;
|
||||
|
||||
import org.libsdl.app.SDLActivity;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.*;
|
||||
|
||||
public class RtB extends SDLActivity {
|
||||
// Java-side to provide access to the AssetManager in C/C++
|
||||
// See Android-section in fio.cpp/fio.hpp for the C/C++ portion of asset management.
|
||||
private AssetManager manager;
|
||||
private static native void setAssetManager(AssetManager manager);
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
manager = getResources().getAssets();
|
||||
setAssetManager(manager);
|
||||
// Pass on to SDLActivity
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,24 @@
|
|||
0097E2D912F70C4E00724AC5 /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0097E2D512F70C4D00724AC5 /* libSDL2.a */; };
|
||||
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
|
||||
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
|
||||
20517C8F1A9B40A200DE49E9 /* Program.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20517C8B1A9B40A200DE49E9 /* Program.cpp */; };
|
||||
20517C901A9B40A200DE49E9 /* Quat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20517C8D1A9B40A200DE49E9 /* Quat.cpp */; };
|
||||
20517CA11A9B40E800DE49E9 /* chest.obj in Copy Models */ = {isa = PBXBuildFile; fileRef = 205723DB1A9B4053001400FA /* chest.obj */; };
|
||||
20517D161A9B449200DE49E9 /* default_fs.100.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 20517D121A9B449200DE49E9 /* default_fs.100.glsl */; };
|
||||
20517D171A9B449200DE49E9 /* default_vs.100.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 20517D131A9B449200DE49E9 /* default_vs.100.glsl */; };
|
||||
20517D181A9B449200DE49E9 /* fb_fs.100.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 20517D141A9B449200DE49E9 /* fb_fs.100.glsl */; };
|
||||
20517D191A9B449200DE49E9 /* fb_vs.100.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 20517D151A9B449200DE49E9 /* fb_vs.100.glsl */; };
|
||||
20517D1A1A9B449700DE49E9 /* default_fs.100.glsl in Copy Shaders */ = {isa = PBXBuildFile; fileRef = 20517D121A9B449200DE49E9 /* default_fs.100.glsl */; };
|
||||
20517D1B1A9B449700DE49E9 /* default_vs.100.glsl in Copy Shaders */ = {isa = PBXBuildFile; fileRef = 20517D131A9B449200DE49E9 /* default_vs.100.glsl */; };
|
||||
20517D1C1A9B449700DE49E9 /* fb_fs.100.glsl in Copy Shaders */ = {isa = PBXBuildFile; fileRef = 20517D141A9B449200DE49E9 /* fb_fs.100.glsl */; };
|
||||
20517D1D1A9B449700DE49E9 /* fb_vs.100.glsl in Copy Shaders */ = {isa = PBXBuildFile; fileRef = 20517D151A9B449200DE49E9 /* fb_vs.100.glsl */; };
|
||||
20517DB91A9C237D00DE49E9 /* checksum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20517DB51A9C237D00DE49E9 /* checksum.cpp */; };
|
||||
20517DBA1A9C237D00DE49E9 /* fio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20517DB71A9C237D00DE49E9 /* fio.cpp */; };
|
||||
20517E5A1A9D4A0300DE49E9 /* Core.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20517E581A9D4A0300DE49E9 /* Core.cpp */; };
|
||||
2056AE551A8A423E00833760 /* Mat4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2056AE4F1A8A423E00833760 /* Mat4.cpp */; };
|
||||
2056AE561A8A423E00833760 /* RenderObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2056AE511A8A423E00833760 /* RenderObject.cpp */; };
|
||||
2056AE571A8A423E00833760 /* Vec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2056AE531A8A423E00833760 /* Vec.cpp */; };
|
||||
205723E11A9B4053001400FA /* chest.obj in Resources */ = {isa = PBXBuildFile; fileRef = 205723DB1A9B4053001400FA /* chest.obj */; };
|
||||
20A7A91D1A89F91300EDC1A0 /* RenderCamera.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20A7A9151A89F91300EDC1A0 /* RenderCamera.cpp */; };
|
||||
20A7A91E1A89F91300EDC1A0 /* RenderScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20A7A9171A89F91300EDC1A0 /* RenderScene.cpp */; };
|
||||
20A7A91F1A89F91300EDC1A0 /* RenderSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20A7A9191A89F91300EDC1A0 /* RenderSet.cpp */; };
|
||||
|
@ -29,6 +44,34 @@
|
|||
FDB8BFC60E5A0F6A00980157 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDB8BFC50E5A0F6A00980157 /* CoreGraphics.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
20517CBD1A9B411300DE49E9 /* Copy Models */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = data/models;
|
||||
dstSubfolderSpec = 7;
|
||||
files = (
|
||||
20517CA11A9B40E800DE49E9 /* chest.obj in Copy Models */,
|
||||
);
|
||||
name = "Copy Models";
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
20517CBE1A9B411300DE49E9 /* Copy Shaders */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = data/shaders;
|
||||
dstSubfolderSpec = 7;
|
||||
files = (
|
||||
20517D1A1A9B449700DE49E9 /* default_fs.100.glsl in Copy Shaders */,
|
||||
20517D1B1A9B449700DE49E9 /* default_vs.100.glsl in Copy Shaders */,
|
||||
20517D1C1A9B449700DE49E9 /* fb_fs.100.glsl in Copy Shaders */,
|
||||
20517D1D1A9B449700DE49E9 /* fb_vs.100.glsl in Copy Shaders */,
|
||||
);
|
||||
name = "Copy Shaders";
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
0097E29A12F70C4D00724AC5 /* begin_code.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = begin_code.h; sourceTree = "<group>"; };
|
||||
0097E29B12F70C4D00724AC5 /* close_code.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = close_code.h; sourceTree = "<group>"; };
|
||||
|
@ -92,12 +135,27 @@
|
|||
1D6058910D05DD3D006BFB54 /* Roll them Bones.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Roll them Bones.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
|
||||
20020C301A8A006300F985D8 /* common.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = common.hpp; path = ../../src/common.hpp; sourceTree = SOURCE_ROOT; };
|
||||
20517C8B1A9B40A200DE49E9 /* Program.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Program.cpp; path = ../../src/Program.cpp; sourceTree = SOURCE_ROOT; };
|
||||
20517C8C1A9B40A200DE49E9 /* Program.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Program.hpp; path = ../../src/Program.hpp; sourceTree = SOURCE_ROOT; };
|
||||
20517C8D1A9B40A200DE49E9 /* Quat.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Quat.cpp; path = ../../src/Quat.cpp; sourceTree = SOURCE_ROOT; };
|
||||
20517C8E1A9B40A200DE49E9 /* Quat.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Quat.hpp; path = ../../src/Quat.hpp; sourceTree = SOURCE_ROOT; };
|
||||
20517D121A9B449200DE49E9 /* default_fs.100.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = default_fs.100.glsl; sourceTree = "<group>"; };
|
||||
20517D131A9B449200DE49E9 /* default_vs.100.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = default_vs.100.glsl; sourceTree = "<group>"; };
|
||||
20517D141A9B449200DE49E9 /* fb_fs.100.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = fb_fs.100.glsl; sourceTree = "<group>"; };
|
||||
20517D151A9B449200DE49E9 /* fb_vs.100.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = fb_vs.100.glsl; sourceTree = "<group>"; };
|
||||
20517DB51A9C237D00DE49E9 /* checksum.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = checksum.cpp; path = ../../src/checksum.cpp; sourceTree = SOURCE_ROOT; };
|
||||
20517DB61A9C237D00DE49E9 /* checksum.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = checksum.hpp; path = ../../src/checksum.hpp; sourceTree = SOURCE_ROOT; };
|
||||
20517DB71A9C237D00DE49E9 /* fio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = fio.cpp; path = ../../src/fio.cpp; sourceTree = SOURCE_ROOT; };
|
||||
20517DB81A9C237D00DE49E9 /* fio.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = fio.hpp; path = ../../src/fio.hpp; sourceTree = SOURCE_ROOT; };
|
||||
20517E581A9D4A0300DE49E9 /* Core.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Core.cpp; path = ../../src/Core.cpp; sourceTree = SOURCE_ROOT; };
|
||||
20517E591A9D4A0300DE49E9 /* Core.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Core.hpp; path = ../../src/Core.hpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE4F1A8A423E00833760 /* Mat4.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Mat4.cpp; path = ../../src/Mat4.cpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE501A8A423E00833760 /* Mat4.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Mat4.hpp; path = ../../src/Mat4.hpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE511A8A423E00833760 /* RenderObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RenderObject.cpp; path = ../../src/RenderObject.cpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE521A8A423E00833760 /* RenderObject.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = RenderObject.hpp; path = ../../src/RenderObject.hpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE531A8A423E00833760 /* Vec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Vec.cpp; path = ../../src/Vec.cpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE541A8A423E00833760 /* Vec.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Vec.hpp; path = ../../src/Vec.hpp; sourceTree = SOURCE_ROOT; };
|
||||
205723DB1A9B4053001400FA /* chest.obj */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = chest.obj; path = ../../data/models/chest.obj; sourceTree = SOURCE_ROOT; };
|
||||
20A7A9151A89F91300EDC1A0 /* RenderCamera.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RenderCamera.cpp; path = ../../src/RenderCamera.cpp; sourceTree = SOURCE_ROOT; };
|
||||
20A7A9161A89F91300EDC1A0 /* RenderCamera.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = RenderCamera.hpp; path = ../../src/RenderCamera.hpp; sourceTree = SOURCE_ROOT; };
|
||||
20A7A9171A89F91300EDC1A0 /* RenderScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RenderScene.cpp; path = ../../src/RenderScene.cpp; sourceTree = SOURCE_ROOT; };
|
||||
|
@ -231,9 +289,45 @@
|
|||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
205723D91A9B4053001400FA /* data */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
205723DC1A9B4053001400FA /* shaders */,
|
||||
205723DA1A9B4053001400FA /* models */,
|
||||
);
|
||||
name = data;
|
||||
path = ../../data;
|
||||
sourceTree = SOURCE_ROOT;
|
||||
};
|
||||
205723DA1A9B4053001400FA /* models */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
205723DB1A9B4053001400FA /* chest.obj */,
|
||||
);
|
||||
name = models;
|
||||
path = "../../../../../../$(SOURCE_ROOT)";
|
||||
sourceTree = SOURCE_ROOT;
|
||||
};
|
||||
205723DC1A9B4053001400FA /* shaders */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
20517D121A9B449200DE49E9 /* default_fs.100.glsl */,
|
||||
20517D131A9B449200DE49E9 /* default_vs.100.glsl */,
|
||||
20517D141A9B449200DE49E9 /* fb_fs.100.glsl */,
|
||||
20517D151A9B449200DE49E9 /* fb_vs.100.glsl */,
|
||||
);
|
||||
path = shaders;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
20A7A9131A89F8F600EDC1A0 /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
20517E581A9D4A0300DE49E9 /* Core.cpp */,
|
||||
20517E591A9D4A0300DE49E9 /* Core.hpp */,
|
||||
20517C8B1A9B40A200DE49E9 /* Program.cpp */,
|
||||
20517C8C1A9B40A200DE49E9 /* Program.hpp */,
|
||||
20517C8D1A9B40A200DE49E9 /* Quat.cpp */,
|
||||
20517C8E1A9B40A200DE49E9 /* Quat.hpp */,
|
||||
20E3F3371A8CEC110071FD41 /* Log.cpp */,
|
||||
20E3F3381A8CEC110071FD41 /* Log.hpp */,
|
||||
20E3F3391A8CEC110071FD41 /* Mesh.cpp */,
|
||||
|
@ -267,6 +361,7 @@
|
|||
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
205723D91A9B4053001400FA /* data */,
|
||||
29B97315FDCFA39411CA2CEA /* Sources */,
|
||||
20A7A9131A89F8F600EDC1A0 /* Classes */,
|
||||
20A7A9221A89F91B00EDC1A0 /* Other Sources */,
|
||||
|
@ -281,6 +376,10 @@
|
|||
29B97315FDCFA39411CA2CEA /* Sources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
20517DB51A9C237D00DE49E9 /* checksum.cpp */,
|
||||
20517DB61A9C237D00DE49E9 /* checksum.hpp */,
|
||||
20517DB71A9C237D00DE49E9 /* fio.cpp */,
|
||||
20517DB81A9C237D00DE49E9 /* fio.hpp */,
|
||||
20FD2D3A1A67470A00B32F7B /* main.cpp */,
|
||||
);
|
||||
name = Sources;
|
||||
|
@ -320,6 +419,8 @@
|
|||
1D60588D0D05DD3D006BFB54 /* Resources */,
|
||||
1D60588E0D05DD3D006BFB54 /* Sources */,
|
||||
1D60588F0D05DD3D006BFB54 /* Frameworks */,
|
||||
20517CBD1A9B411300DE49E9 /* Copy Models */,
|
||||
20517CBE1A9B411300DE49E9 /* Copy Shaders */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
|
@ -361,6 +462,11 @@
|
|||
files = (
|
||||
FD77A07D0E26BD8C00F39101 /* Icon.png in Resources */,
|
||||
FD77A07F0E26BDA900F39101 /* Default.png in Resources */,
|
||||
205723E11A9B4053001400FA /* chest.obj in Resources */,
|
||||
20517D161A9B449200DE49E9 /* default_fs.100.glsl in Resources */,
|
||||
20517D171A9B449200DE49E9 /* default_vs.100.glsl in Resources */,
|
||||
20517D181A9B449200DE49E9 /* fb_fs.100.glsl in Resources */,
|
||||
20517D191A9B449200DE49E9 /* fb_vs.100.glsl in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -381,6 +487,11 @@
|
|||
2056AE571A8A423E00833760 /* Vec.cpp in Sources */,
|
||||
20E3F33B1A8CEC110071FD41 /* Log.cpp in Sources */,
|
||||
20E3F33C1A8CEC110071FD41 /* Mesh.cpp in Sources */,
|
||||
20517C8F1A9B40A200DE49E9 /* Program.cpp in Sources */,
|
||||
20517C901A9B40A200DE49E9 /* Quat.cpp in Sources */,
|
||||
20517DB91A9C237D00DE49E9 /* checksum.cpp in Sources */,
|
||||
20517DBA1A9C237D00DE49E9 /* fio.cpp in Sources */,
|
||||
20517E5A1A9D4A0300DE49E9 /* Core.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -9,9 +9,19 @@
|
|||
/* Begin PBXBuildFile section */
|
||||
20138FCC1A3DC7A700FD0095 /* SDL2_image.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 20138FCB1A3DC7A700FD0095 /* SDL2_image.framework */; };
|
||||
20138FCE1A3DC7A700FD0095 /* SDL2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 20138FCD1A3DC7A700FD0095 /* SDL2.framework */; };
|
||||
20517D531A9BFB1B00DE49E9 /* fio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20517D511A9BFB1B00DE49E9 /* fio.cpp */; };
|
||||
20517D601A9C083B00DE49E9 /* checksum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20517D5E1A9C083B00DE49E9 /* checksum.cpp */; };
|
||||
20517DCE1A9D44DB00DE49E9 /* Core.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20517DCC1A9D44DB00DE49E9 /* Core.cpp */; };
|
||||
2056AE3C1A8A421500833760 /* Mat4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2056AE361A8A421500833760 /* Mat4.cpp */; };
|
||||
2056AE3D1A8A421500833760 /* RenderObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2056AE381A8A421500833760 /* RenderObject.cpp */; };
|
||||
2056AE3E1A8A421500833760 /* Vec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2056AE3A1A8A421500833760 /* Vec.cpp */; };
|
||||
205723781A9B3EA3001400FA /* chest.obj in Resources */ = {isa = PBXBuildFile; fileRef = 205723771A9B3EA3001400FA /* chest.obj */; };
|
||||
2057237B1A9B3EB2001400FA /* default_fs.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 205723791A9B3EB2001400FA /* default_fs.glsl */; };
|
||||
2057237C1A9B3EB2001400FA /* default_vs.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 2057237A1A9B3EB2001400FA /* default_vs.glsl */; };
|
||||
205723911A9B3ECF001400FA /* default_fs.glsl in Copy Shaders */ = {isa = PBXBuildFile; fileRef = 205723791A9B3EB2001400FA /* default_fs.glsl */; };
|
||||
205723921A9B3ECF001400FA /* default_vs.glsl in Copy Shaders */ = {isa = PBXBuildFile; fileRef = 2057237A1A9B3EB2001400FA /* default_vs.glsl */; };
|
||||
205723931A9B3ED3001400FA /* chest.obj in Copy Models */ = {isa = PBXBuildFile; fileRef = 205723771A9B3EA3001400FA /* chest.obj */; };
|
||||
205723A11A9B3F04001400FA /* Quat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2057239F1A9B3F04001400FA /* Quat.cpp */; };
|
||||
205D36CE1A6749FB00C05BD8 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 205D36CD1A6749FB00C05BD8 /* main.cpp */; };
|
||||
205D370C1A674B1D00C05BD8 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 205D370B1A674B1D00C05BD8 /* OpenGL.framework */; };
|
||||
206662951A9305FF00631FC0 /* fb_fs.glsl in Copy Shaders */ = {isa = PBXBuildFile; fileRef = 209930A31A92CAB10089E661 /* fb_fs.glsl */; };
|
||||
|
@ -33,6 +43,7 @@
|
|||
dstPath = data/models;
|
||||
dstSubfolderSpec = 7;
|
||||
files = (
|
||||
205723931A9B3ED3001400FA /* chest.obj in Copy Models */,
|
||||
);
|
||||
name = "Copy Models";
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
@ -43,6 +54,8 @@
|
|||
dstPath = data/shaders;
|
||||
dstSubfolderSpec = 7;
|
||||
files = (
|
||||
205723911A9B3ECF001400FA /* default_fs.glsl in Copy Shaders */,
|
||||
205723921A9B3ECF001400FA /* default_vs.glsl in Copy Shaders */,
|
||||
206662951A9305FF00631FC0 /* fb_fs.glsl in Copy Shaders */,
|
||||
206662961A9305FF00631FC0 /* fb_vs.glsl in Copy Shaders */,
|
||||
);
|
||||
|
@ -56,12 +69,23 @@
|
|||
20020C6F1A8A01EE00F985D8 /* common.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = common.hpp; path = ../../src/common.hpp; sourceTree = SOURCE_ROOT; };
|
||||
20138FCB1A3DC7A700FD0095 /* SDL2_image.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2_image.framework; path = /Library/Frameworks/SDL2_image.framework; sourceTree = "<absolute>"; };
|
||||
20138FCD1A3DC7A700FD0095 /* SDL2.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL2.framework; path = /Library/Frameworks/SDL2.framework; sourceTree = "<absolute>"; };
|
||||
20517D511A9BFB1B00DE49E9 /* fio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = fio.cpp; path = ../../src/fio.cpp; sourceTree = SOURCE_ROOT; };
|
||||
20517D521A9BFB1B00DE49E9 /* fio.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = fio.hpp; path = ../../src/fio.hpp; sourceTree = SOURCE_ROOT; };
|
||||
20517D5E1A9C083B00DE49E9 /* checksum.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = checksum.cpp; path = ../../src/checksum.cpp; sourceTree = SOURCE_ROOT; };
|
||||
20517D5F1A9C083B00DE49E9 /* checksum.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = checksum.hpp; path = ../../src/checksum.hpp; sourceTree = SOURCE_ROOT; };
|
||||
20517DCC1A9D44DB00DE49E9 /* Core.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Core.cpp; path = ../../src/Core.cpp; sourceTree = SOURCE_ROOT; };
|
||||
20517DCD1A9D44DB00DE49E9 /* Core.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Core.hpp; path = ../../src/Core.hpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE361A8A421500833760 /* Mat4.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Mat4.cpp; path = ../../src/Mat4.cpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE371A8A421500833760 /* Mat4.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Mat4.hpp; path = ../../src/Mat4.hpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE381A8A421500833760 /* RenderObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RenderObject.cpp; path = ../../src/RenderObject.cpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE391A8A421500833760 /* RenderObject.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = RenderObject.hpp; path = ../../src/RenderObject.hpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE3A1A8A421500833760 /* Vec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Vec.cpp; path = ../../src/Vec.cpp; sourceTree = SOURCE_ROOT; };
|
||||
2056AE3B1A8A421500833760 /* Vec.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Vec.hpp; path = ../../src/Vec.hpp; sourceTree = SOURCE_ROOT; };
|
||||
205723771A9B3EA3001400FA /* chest.obj */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = chest.obj; path = models/chest.obj; sourceTree = "<group>"; };
|
||||
205723791A9B3EB2001400FA /* default_fs.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = default_fs.glsl; sourceTree = "<group>"; };
|
||||
2057237A1A9B3EB2001400FA /* default_vs.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = default_vs.glsl; sourceTree = "<group>"; };
|
||||
2057239F1A9B3F04001400FA /* Quat.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Quat.cpp; path = ../../src/Quat.cpp; sourceTree = SOURCE_ROOT; };
|
||||
205723A01A9B3F04001400FA /* Quat.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Quat.hpp; path = ../../src/Quat.hpp; sourceTree = SOURCE_ROOT; };
|
||||
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 = "<absolute>"; };
|
||||
209930811A92ADB00089E661 /* Program.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Program.cpp; path = ../../src/Program.cpp; sourceTree = SOURCE_ROOT; };
|
||||
|
@ -101,6 +125,10 @@
|
|||
080E96DDFE201D6D7F000001 /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
20517DCC1A9D44DB00DE49E9 /* Core.cpp */,
|
||||
20517DCD1A9D44DB00DE49E9 /* Core.hpp */,
|
||||
2057239F1A9B3F04001400FA /* Quat.cpp */,
|
||||
205723A01A9B3F04001400FA /* Quat.hpp */,
|
||||
209930811A92ADB00089E661 /* Program.cpp */,
|
||||
209930821A92ADB00089E661 /* Program.hpp */,
|
||||
20E3F2901A8CE8470071FD41 /* Log.cpp */,
|
||||
|
@ -155,9 +183,21 @@
|
|||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
205723721A9B3E90001400FA /* models */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
205723771A9B3EA3001400FA /* chest.obj */,
|
||||
);
|
||||
name = models;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
205D36C31A6749DF00C05BD8 /* Sources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
20517D5E1A9C083B00DE49E9 /* checksum.cpp */,
|
||||
20517D5F1A9C083B00DE49E9 /* checksum.hpp */,
|
||||
20517D511A9BFB1B00DE49E9 /* fio.cpp */,
|
||||
20517D521A9BFB1B00DE49E9 /* fio.hpp */,
|
||||
205D36CD1A6749FB00C05BD8 /* main.cpp */,
|
||||
);
|
||||
indentWidth = 2;
|
||||
|
@ -170,6 +210,7 @@
|
|||
2099309F1A92CAB10089E661 /* data */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
205723721A9B3E90001400FA /* models */,
|
||||
209930A01A92CAB10089E661 /* shaders */,
|
||||
);
|
||||
name = data;
|
||||
|
@ -179,6 +220,8 @@
|
|||
209930A01A92CAB10089E661 /* shaders */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
205723791A9B3EB2001400FA /* default_fs.glsl */,
|
||||
2057237A1A9B3EB2001400FA /* default_vs.glsl */,
|
||||
209930A31A92CAB10089E661 /* fb_fs.glsl */,
|
||||
209930A41A92CAB10089E661 /* fb_vs.glsl */,
|
||||
);
|
||||
|
@ -281,6 +324,9 @@
|
|||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
205723781A9B3EA3001400FA /* chest.obj in Resources */,
|
||||
2057237B1A9B3EB2001400FA /* default_fs.glsl in Resources */,
|
||||
2057237C1A9B3EB2001400FA /* default_vs.glsl in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -302,6 +348,10 @@
|
|||
20E3F2941A8CE8470071FD41 /* Log.cpp in Sources */,
|
||||
20E3F2951A8CE8470071FD41 /* Mesh.cpp in Sources */,
|
||||
209930831A92ADB00089E661 /* Program.cpp in Sources */,
|
||||
205723A11A9B3F04001400FA /* Quat.cpp in Sources */,
|
||||
20517D531A9BFB1B00DE49E9 /* fio.cpp in Sources */,
|
||||
20517D601A9C083B00DE49E9 /* checksum.cpp in Sources */,
|
||||
20517DCE1A9D44DB00DE49E9 /* Core.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#version 100
|
||||
precision mediump float;
|
||||
// uniform data
|
||||
uniform sampler2D texture_sampler;
|
||||
// in
|
||||
varying vec2 frag_uv;
|
||||
|
||||
void main() {
|
||||
//gl_FragColor = texture2D(texture_sampler, frag_uv);
|
||||
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
#version 120
|
||||
|
||||
// uniform data
|
||||
uniform sampler2D texture_sampler;
|
||||
// in
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#version 100
|
||||
// shared data
|
||||
// our projection and translation matrices
|
||||
uniform mat4 proj_matrix, mv_matrix;
|
||||
// attributes
|
||||
attribute vec3 vp;
|
||||
attribute vec2 uv;
|
||||
attribute vec3 normal;
|
||||
// out
|
||||
varying vec2 frag_uv;
|
||||
|
||||
void main() {
|
||||
vec4 eye = mv_matrix * vec4(vp, 1.0);
|
||||
gl_Position = proj_matrix * eye;
|
||||
frag_uv = uv;
|
||||
}
|
|
@ -13,4 +13,4 @@ void main() {
|
|||
vec4 eye = mv_matrix * vec4(vp, 1.0);
|
||||
gl_Position = proj_matrix * eye;
|
||||
frag_uv = uv;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
#version 100
|
||||
precision mediump float;
|
||||
// in
|
||||
varying vec2 UV;
|
||||
|
||||
uniform sampler2D tex1;
|
||||
|
||||
//
|
||||
void main() {
|
||||
gl_FragColor = vec4(texture2D(tex1, UV).xyz, 1.0);
|
||||
//gl_FragColor = vec4(UV.xy, 1.0, 1.0);
|
||||
//gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
#version 120
|
||||
|
||||
// in
|
||||
varying vec2 UV;
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#version 100
|
||||
// in
|
||||
attribute vec3 vp;
|
||||
// out
|
||||
varying vec2 UV;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(vp, 1.0);
|
||||
UV = (vp.xy + vec2(1.0, 1.0)) / 2.0;
|
||||
///UV = vp.xy;
|
||||
}
|
|
@ -0,0 +1,210 @@
|
|||
/* ================================================================
|
||||
Core
|
||||
----------------
|
||||
Core is somewhat like a service locator, but with larger engine capabilities - in essence, it is a lot of glue that would normally exist in a global scope. An instance of Core, "core," is provided in the global scope and is the instance that is referenced from other contexts.
|
||||
================================================================ */
|
||||
#include "Core.hpp"
|
||||
#include "Log.hpp"
|
||||
#include "RenderScene.hpp"
|
||||
#include "RenderCamera.hpp"
|
||||
#include "RenderSet.hpp"
|
||||
#include "RenderObject.hpp"
|
||||
|
||||
Core core;
|
||||
|
||||
Core::Core() {
|
||||
v_window = NULL;
|
||||
v_context = 0;
|
||||
v_fbo = 0;
|
||||
}
|
||||
Core::~Core() {
|
||||
|
||||
}
|
||||
int Core::initSystem() {
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING & ~SDL_INIT_HAPTIC) != 0) {
|
||||
LOG(LOG_ERROR) << FUNC_NAME << " " << SDL_GetError();
|
||||
return 1;
|
||||
}
|
||||
#if defined(HAVE_OPENGLES)
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
||||
#endif
|
||||
// Get our maximum windowed display size and use it
|
||||
SDL_DisplayMode display_mode;
|
||||
SDL_GetDesktopDisplayMode(0, &display_mode);
|
||||
v_width = display_mode.w;
|
||||
v_height = display_mode.h;
|
||||
// create our window
|
||||
v_window = SDL_CreateWindow("Roll them Bones", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, v_width, v_height, v_flags);
|
||||
if (v_window == NULL) {
|
||||
LOG(LOG_ERROR) << "SDL_CreateWindow: " << SDL_GetError();
|
||||
return 1;
|
||||
}
|
||||
// Ensure our v_width/v_height match the window dimensions
|
||||
SDL_GetWindowSize(v_window, &v_width, &v_height);
|
||||
// Get our OpenGL context
|
||||
v_context = SDL_GL_CreateContext(v_window);
|
||||
if (v_context == NULL) {
|
||||
LOG(LOG_ERROR) << "SDL_GL_CreateContext: " << SDL_GetError();
|
||||
return 1;
|
||||
}
|
||||
// If using glew, initialize it (windows only thus far)
|
||||
#ifdef USE_GLEW
|
||||
glewExperimental = GL_TRUE;
|
||||
if (glewInit() != GLEW_OK) {
|
||||
LOG(LOG_ERROR) << "Could not initialize GLEW";
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
// bind content to window
|
||||
SDL_GL_MakeCurrent(v_window, v_context);
|
||||
// Get our window's FBO id for iOS
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &v_fbo);
|
||||
// enable depth testing
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
//
|
||||
glDepthFunc(GL_LESS);
|
||||
// enable back-face culling
|
||||
//glEnable(GL_CULL_FACE);
|
||||
LOG(LOG_INFO) << "OpenGL Renderer: " << glGetString(GL_RENDERER) << "\nOpenGL Version: " << glGetString(GL_VERSION) << "\nGLSL Version: " << glGetString(GL_SHADING_LANGUAGE_VERSION);
|
||||
// FIXME: temporary location for adding cameras/etc. for testing
|
||||
// Create our basic RenderScene
|
||||
scene = new RenderScene();
|
||||
// TEMP: our framebuffer rendering program
|
||||
Program *program = new Program();
|
||||
// FIXME: check for GLSL version and automagically load the appropriate shader file
|
||||
#ifdef HAVE_OPENGLES
|
||||
if (program->addShader("data/shaders/fb_fs.100.glsl", GL_FRAGMENT_SHADER) != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to add Shader!";
|
||||
return 1;
|
||||
}
|
||||
if (program->addShader("data/shaders/fb_vs.100.glsl", GL_VERTEX_SHADER) != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to add Shader!";
|
||||
return 1;
|
||||
}
|
||||
if (program->doCompile() != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to compile GLSL Program!";
|
||||
return 1;
|
||||
}
|
||||
// TEMP: our model rendering program
|
||||
Program *program_model = new Program();
|
||||
if (program_model->addShader("data/shaders/default_fs.100.glsl", GL_FRAGMENT_SHADER) != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to add Shader!";
|
||||
return 1;
|
||||
}
|
||||
if (program_model->addShader("data/shaders/default_vs.100.glsl", GL_VERTEX_SHADER) != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to add Shdaer!";
|
||||
return 1;
|
||||
}
|
||||
if (program_model->doCompile() != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to compile GLSL Program!";
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
if (program->addShader("data/shaders/fb_fs.glsl", GL_FRAGMENT_SHADER) != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to add Shader!";
|
||||
return 1;
|
||||
}
|
||||
if (program->addShader("data/shaders/fb_vs.glsl", GL_VERTEX_SHADER) != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to add Shader!";
|
||||
return 1;
|
||||
}
|
||||
if (program->doCompile() != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to compile GLSL Program!";
|
||||
return 1;
|
||||
}
|
||||
// TEMP: our model rendering program
|
||||
Program *program_model = new Program();
|
||||
if (program_model->addShader("data/shaders/default_fs.glsl", GL_FRAGMENT_SHADER) != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to add Shader!";
|
||||
return 1;
|
||||
}
|
||||
if (program_model->addShader("data/shaders/default_vs.glsl", GL_VERTEX_SHADER) != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to add Shdaer!";
|
||||
return 1;
|
||||
}
|
||||
if (program_model->doCompile() != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to compile GLSL Program!";
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
RenderCamera *camera = new RenderCamera();
|
||||
camera->setRenderView(new RenderView(v_width, v_height));
|
||||
camera->updateProjection(v_width, v_height);
|
||||
camera->setPitch(75.0f);
|
||||
camera->setPosition(0, 35, -10);
|
||||
camera->doRefresh();
|
||||
|
||||
scene->addCamera(camera);
|
||||
|
||||
program->attachTexture(0, camera->getRenderView()->getFBO());
|
||||
|
||||
(camera->getRenderView()->setProgram(program));
|
||||
|
||||
RenderObject *objerct = new RenderObject();
|
||||
Mesh *mersh = new Mesh("data/models/chest.obj");
|
||||
mersh->buildMesh();
|
||||
objerct->setMesh(mersh);
|
||||
RenderSet *sert = new RenderSet();
|
||||
sert->setProgram(program_model);
|
||||
sert->addObject(objerct);
|
||||
scene->addSet(sert);
|
||||
|
||||
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
|
||||
|
||||
flags |= IS_RUNNING;
|
||||
return 0;
|
||||
}
|
||||
int Core::closeSystem() {
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
/* doProcess
|
||||
*/
|
||||
void Core::doProcess() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
flags &= ~IS_RUNNING;
|
||||
}
|
||||
}
|
||||
doRender();
|
||||
}
|
||||
void Core::doRender() {
|
||||
scene->doRender(); // Render our main scene using loaded cameras
|
||||
// Now let's actually render the framebuffers
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, v_fbo);
|
||||
glViewport(0, 0, v_width, v_height);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
RenderCamera *r_camera;
|
||||
RenderView *r_view;
|
||||
Program *r_program;
|
||||
// Iterate over each camera's RenderView and send the FBO/mesh to the shader
|
||||
std::vector<RenderCamera*>::iterator camera_it, camera_end;
|
||||
for (camera_it = scene->getCameras()->begin(), camera_end = scene->getCameras()->end(); camera_it != camera_end; ++camera_it) {
|
||||
r_camera = *camera_it;
|
||||
if ((r_view = r_camera->getRenderView()) == NULL) continue;
|
||||
if ((r_program = r_view->getProgram()) == NULL) continue;
|
||||
// FIXME: iOS doesn't like enabling the view's program - black screen if enabled.
|
||||
r_program->activate();
|
||||
GLuint program_p = r_program->getProgram();
|
||||
GLuint program_vp = glGetAttribLocation(program_p, "vp");
|
||||
// enable vertex positions and UV map
|
||||
glEnableVertexAttribArray(program_vp);
|
||||
// Get our mesh
|
||||
Mesh *mesh = r_view->getMesh();
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mesh->vbo);
|
||||
glEnableVertexAttribArray(program_vp);
|
||||
glVertexAttribPointer(program_vp, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
// and draw
|
||||
glDrawArrays(GL_TRIANGLES, 0, mesh->vertices.size());
|
||||
// close 'em
|
||||
glDisableVertexAttribArray(program_vp);
|
||||
}
|
||||
// And update!
|
||||
SDL_GL_SwapWindow(v_window);
|
||||
}
|
||||
SDL_Window* Core::getWindow() {
|
||||
return v_window;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/* ================================================================
|
||||
Core
|
||||
----------------
|
||||
Core is somewhat like a service locator, but with larger engine capabilities - in essence, it is a lot of glue that would normally exist in a global scope. An instance of Core, "core," is provided in the global scope and is the instance that is referenced from other contexts.
|
||||
================================================================ */
|
||||
#ifndef CORE_HPP
|
||||
#define CORE_HPP
|
||||
#include "common.hpp"
|
||||
#include "RenderScene.hpp"
|
||||
class Core {
|
||||
public:
|
||||
Core();
|
||||
~Core();
|
||||
int initSystem();
|
||||
int closeSystem();
|
||||
void doProcess();
|
||||
void doRender();
|
||||
enum Flags { IS_RUNNING = (1 << 1) };
|
||||
//
|
||||
SDL_Window* getWindow();
|
||||
RenderScene *getScene();
|
||||
// Audio* getAudio();
|
||||
// Net* getNet();
|
||||
unsigned int flags; // Core state flags
|
||||
private:
|
||||
SDL_Window *v_window; // Our window
|
||||
SDL_GLContext v_context; // OpenGL context
|
||||
GLint v_fbo; // window framebuffer object
|
||||
int v_width; // width of our display
|
||||
int v_height; // height of our display
|
||||
int v_flags; // video flags
|
||||
RenderScene *scene; // our current render scene
|
||||
// Audio *audio_service;
|
||||
// Net *net_service;
|
||||
};
|
||||
extern Core core;
|
||||
#endif
|
10
src/Log.cpp
10
src/Log.cpp
|
@ -4,6 +4,10 @@ Log
|
|||
This file defines the class for Log.
|
||||
================================================================ */
|
||||
#include "Log.hpp"
|
||||
#ifdef __ANDROID__
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
void (*logHook)(const char*, const char*) = NULL;
|
||||
|
||||
|
@ -45,6 +49,10 @@ Log::~Log() {
|
|||
if (logHook != NULL) {
|
||||
logHook(title, os.str().c_str());
|
||||
}
|
||||
#ifdef __ANDROID__
|
||||
__android_log_print(ANDROID_LOG_INFO, "RtB", "%s: %s", title, os.str().c_str());
|
||||
#else
|
||||
fprintf(stderr, "%s: %s\n", title, os.str().c_str());
|
||||
fflush(stderr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "Mesh.hpp"
|
||||
#include "Log.hpp"
|
||||
#include "fio.hpp"
|
||||
#include <stdio.h> // fscanf
|
||||
#include <string.h> // strcmp
|
||||
#include <stdlib.h> // atof
|
||||
|
@ -34,14 +35,8 @@ int Mesh::loadObj(const char *filename) {
|
|||
std::vector <unsigned int> uv_indices;
|
||||
std::vector <unsigned int> normal_indices;
|
||||
int ret;
|
||||
#ifdef _WIN32
|
||||
FILE *file;
|
||||
fopen_s(&file, filename, "r");
|
||||
#else
|
||||
FILE *file = fopen(filename, "r");
|
||||
#endif
|
||||
FILE *file = asset_fopen(filename, "r");
|
||||
if (file == NULL) {
|
||||
// TODO: error report
|
||||
LOG(LOG_ERROR) << "Could not open model: " << filename;
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ loading, creating, and compiling OpenGL programs.
|
|||
================================================================ */
|
||||
#include "Program.hpp"
|
||||
#include "Log.hpp"
|
||||
#include "fio.hpp"
|
||||
#include <fstream>
|
||||
#include <sstream> // ostringstream
|
||||
#include <stdexcept> // oor
|
||||
|
@ -20,12 +21,13 @@ Program::~Program() {
|
|||
// add given shader to Program. During doCompile(), it is compiled and attached to the program
|
||||
int Program::addShader(const char *file, GLenum type) {
|
||||
// Load in our shader file
|
||||
std::ifstream in(file);
|
||||
if (!in) {
|
||||
char *buffer = NULL;
|
||||
size_t length = asset_fileToMem(file, &buffer);
|
||||
buffer[length] = '\0';
|
||||
if (buffer == NULL) {
|
||||
LOG(LOG_ERROR) << FUNC_NAME << ": Could not open \"" << file << "\" for reading";
|
||||
return 1;
|
||||
}
|
||||
std::string contents((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
|
||||
// Create our shader
|
||||
GLuint shader = glCreateShader(type);
|
||||
if (shader == 0) {
|
||||
|
@ -33,11 +35,12 @@ int Program::addShader(const char *file, GLenum type) {
|
|||
return 2;
|
||||
}
|
||||
// Load GLSL program into OpenGL
|
||||
const char *c_str = contents.c_str();
|
||||
const char *c_str = buffer;
|
||||
glShaderSource(shader, 1, &c_str, NULL);
|
||||
// Push the shader and its type onto the appropriate vectors
|
||||
shader_prog.push_back(shader);
|
||||
shader_type.push_back(type);
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
int Program::doCompile() {
|
||||
|
@ -149,4 +152,4 @@ Program::Variable::Variable(VariableType type_) {
|
|||
}
|
||||
Program::Variable::~Variable() {
|
||||
if (data != NULL) free(data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,8 +85,8 @@ int RenderScene::doRender() {
|
|||
glUniformMatrix4fv(shader_projection, 1, GL_FALSE, camera->p_matrix.toFloats(pm));
|
||||
// enable attribs
|
||||
glEnableVertexAttribArray(shader_vp);
|
||||
glEnableVertexAttribArray(shader_uv);
|
||||
glEnableVertexAttribArray(shader_normal);
|
||||
//glEnableVertexAttribArray(shader_uv);
|
||||
//glEnableVertexAttribArray(shader_normal);
|
||||
// Iterate over the set's render objects
|
||||
std::vector<RenderObject*>::iterator obj_it, obj_end;
|
||||
for (obj_it = set->objects.begin(), obj_end = set->objects.end(); obj_it != obj_end; ++obj_it) {
|
||||
|
@ -103,12 +103,12 @@ int RenderScene::doRender() {
|
|||
// bind vp
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mesh->vbo);
|
||||
glVertexAttribPointer(shader_vp, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
// bind uvs/texture coords
|
||||
/*// bind uvs/texture coords
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mesh->uvbo);
|
||||
glVertexAttribPointer(shader_uv, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
// bind normals
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mesh->nbo);
|
||||
glVertexAttribPointer(shader_normal, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
glVertexAttribPointer(shader_normal, 3, GL_FLOAT, GL_FALSE, 0, NULL);*/
|
||||
glDrawArrays(GL_TRIANGLES, 0, mesh->vertices.size());
|
||||
// TODO: maybe other things? Should this be managed by Program somehow?
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ RenderView::RenderView(int width, int height) {
|
|||
x = y = 0;
|
||||
flags = 0;
|
||||
mesh = NULL;
|
||||
program = NULL;
|
||||
createView(width, height);
|
||||
}
|
||||
RenderView::~RenderView() {
|
||||
|
@ -26,6 +27,9 @@ GLuint RenderView::getFBO() {
|
|||
Mesh *RenderView::getMesh() {
|
||||
return mesh;
|
||||
}
|
||||
Program* RenderView::getProgram() {
|
||||
return program;
|
||||
}
|
||||
/* ======== Setters ======== */
|
||||
int RenderView::createView(int width, int height) {
|
||||
// TODO: call destroyView() and create new FBO at width and height
|
||||
|
@ -107,3 +111,7 @@ int RenderView::setView(int width, int height) {
|
|||
h = height;
|
||||
return 0;
|
||||
}
|
||||
int RenderView::setProgram(Program *program_) {
|
||||
program = program_;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ object. For all intents and purposes, it is a wrapper around a FBO.
|
|||
#define RENDERVIEW_HPP
|
||||
#include "common.hpp"
|
||||
#include "Mesh.hpp"
|
||||
#include "Program.hpp"
|
||||
#define RENDERVIEW_ACTIVE (1 << 1)
|
||||
class RenderView {
|
||||
friend class RenderScene;
|
||||
|
@ -18,6 +19,8 @@ class RenderView {
|
|||
~RenderView();
|
||||
GLuint getFBO();
|
||||
Mesh *getMesh();
|
||||
int setProgram(Program *program);
|
||||
Program *getProgram();
|
||||
protected:
|
||||
GLuint fbo; // The fbo that RenderScene will draw to
|
||||
private:
|
||||
|
@ -30,5 +33,6 @@ class RenderView {
|
|||
int x, y; // x and y offsets of rendering to screen
|
||||
Mesh *mesh; // rendering Mesh, created as quad in CreateView
|
||||
unsigned int flags; // byte flag
|
||||
Program *program; // program that this RenderView should be rendered with
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/* ================================================================
|
||||
Checksum functionality
|
||||
----------------
|
||||
checksum.cpp/checksum.hpp provide functionality for checking and generating checksums.
|
||||
================================================================ */
|
||||
#include "checksum.hpp"
|
||||
#include <stdio.h>
|
||||
|
||||
uint32_t crc32(uint32_t crc, const char *buf, size_t len) {
|
||||
static uint32_t table[256];
|
||||
static int table_gen = 0;
|
||||
uint32_t rem;
|
||||
uint8_t octet;
|
||||
int i, j;
|
||||
const char *p, *q;
|
||||
|
||||
if (table_gen == 0) {
|
||||
for (i = 0; i < 256; i++) {
|
||||
rem = i;
|
||||
for (j = 0; j < 8; j++) {
|
||||
if (rem & 1) {
|
||||
rem >>= 1;
|
||||
rem ^= 0xedb88320;
|
||||
} else {
|
||||
rem >>= 1;
|
||||
}
|
||||
}
|
||||
table[i] = rem;
|
||||
}
|
||||
table_gen = 1;
|
||||
}
|
||||
|
||||
crc = ~crc;
|
||||
q = buf + len;
|
||||
for (p = buf; p < q; p++) {
|
||||
octet = *p;
|
||||
crc = (crc >> 8) ^ table[(crc & 0xff) ^ octet];
|
||||
}
|
||||
return ~crc;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
/* ================================================================
|
||||
Checksum functionality
|
||||
----------------
|
||||
checksum.cpp/checksum.hpp provide functionality for checking and generating checksums.
|
||||
================================================================ */
|
||||
#ifndef CHECKSUM_HPP
|
||||
#define CHECKSUM_HPP
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
uint32_t crc32(uint32_t crc, const char *buf, size_t len);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,87 @@
|
|||
/* ================================================================
|
||||
FIO functionality
|
||||
----------------
|
||||
fio.cpp/fio.hpp provide functionality for accessing files within RtB. File access is generally assumed to be C-style *FILE.
|
||||
|
||||
If any file is attempted to be read or written to, fio.hpp should be included first.
|
||||
================================================================ */
|
||||
#include "fio.hpp"
|
||||
#include "Log.hpp"
|
||||
#include <string.h> // malloc
|
||||
/* ======== Asset data access ======== */
|
||||
// Assets are files that may exist in an external storage directory (iOS/Android), a user data directory(all), or in the application itself (iOS/Android/OSX).
|
||||
/* asset_fileToMem
|
||||
This function attempts to load in the given filename into a memory buffer. This memory buffer is allocated by the function and _MUST_ be free()d by the user. If the file does not exist, an error is reported and NULL is returned.
|
||||
*/
|
||||
size_t asset_fileToMem(const char *filename, char **buffer) {
|
||||
char chunk[1024];
|
||||
FILE *file = asset_fopen(filename, "r");
|
||||
if (file == NULL) {
|
||||
LOG(LOG_ERROR) << FUNC_NAME << ": could not open " << filename;
|
||||
return 0;
|
||||
}
|
||||
fseek(file, 0, SEEK_END);
|
||||
size_t size = ftell(file)+1;
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
*buffer = (char*)malloc(size*sizeof(char));
|
||||
int n = 0;
|
||||
size_t offset = 0;
|
||||
while ((n = fread(chunk, 1, 1024, file))) {
|
||||
memcpy((*buffer)+offset, chunk, n);
|
||||
offset += n;
|
||||
}
|
||||
fclose(file);
|
||||
return offset;
|
||||
}
|
||||
FILE *asset_fopen(const char *filename, const char *mode) {
|
||||
// TODO: this function should first check the user assets directory for the given filename then fallback to the built-in assets directory
|
||||
// OS X: Library/RtB/ OR RtB.app/Contents/Resources
|
||||
// iOS: <Application_Home>/Library/ OR RtB.app/Contents/Resources
|
||||
// Android: /data/data/com.polymathic.RtB/files/ OR Assets (jar)
|
||||
// Linux: <current dir> OR ~/.RtB
|
||||
// Windows: <current dir> OR <User Dir>/AppData/Local/RtB
|
||||
#ifdef __ANDROID__
|
||||
return apk_fopen(filename, mode);
|
||||
#elif _WIN32
|
||||
FILE *file;
|
||||
fopen_s(&file, filename, mode);
|
||||
return file;
|
||||
#else
|
||||
return fopen(filename, mode);
|
||||
#endif
|
||||
}
|
||||
/* ======== Android apk access ======== */
|
||||
#ifdef __ANDROID__
|
||||
#include <errno.h>
|
||||
#include <jni.h>
|
||||
#include <android/asset_manager.h>
|
||||
#include <android/asset_manager_jni.h>
|
||||
static int apk_read(void *asset, char *buf, int size) {
|
||||
return AAsset_read((AAsset*)asset, buf, size);
|
||||
}
|
||||
static int apk_write(void *asset, const char *buf, int size) {
|
||||
return EACCES;
|
||||
}
|
||||
static fpos_t apk_seek(void *asset, fpos_t offset, int whence) {
|
||||
return AAsset_seek((AAsset*)asset, offset, whence);
|
||||
}
|
||||
static int apk_close(void *asset) {
|
||||
AAsset_close((AAsset*)asset);
|
||||
return 0;
|
||||
}
|
||||
AAssetManager* asset_manager;
|
||||
void apk_set_asset_manager(AAssetManager* manager) {
|
||||
asset_manager = manager;
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_com_polymathic_RtB_RtB_setAssetManager(JNIEnv* env, jobject obj, jobject assetManager) {
|
||||
AAssetManager *mgr = AAssetManager_fromJava(env, assetManager);
|
||||
apk_set_asset_manager(mgr);
|
||||
}
|
||||
FILE* apk_fopen(const char *filename, const char *mode) {
|
||||
if (mode[0] == 'w') return NULL;
|
||||
AAsset *asset = AAssetManager_open(asset_manager, filename, 0);
|
||||
if (!asset) return NULL;
|
||||
return funopen(asset, apk_read, apk_write, apk_seek, apk_close);
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,25 @@
|
|||
/* ================================================================
|
||||
FIO functionality
|
||||
----------------
|
||||
fio.cpp/fio.hpp provide functionality for accessing files within RtB. File access is generally assumed to be C-style *FILE.
|
||||
|
||||
If any file is attempted to be read or written to, fio.hpp should be included first.
|
||||
================================================================ */
|
||||
#ifndef FIO_HPP
|
||||
#define FIO_HPP
|
||||
#include <stdio.h>
|
||||
/* ======== Asset data access ======== */
|
||||
size_t asset_fileToMem(const char *filename, char **buffer);
|
||||
FILE *asset_fopen(const char *filename, const char *mode);
|
||||
/* ======== Android apk access ======== */
|
||||
#ifdef __ANDROID__
|
||||
#include <jni.h>
|
||||
#include <android/asset_manager.h>
|
||||
#include <android/asset_manager_jni.h>
|
||||
extern "C" {
|
||||
void apk_set_asset_manager(AAssetManager* manager);
|
||||
FILE *apk_fopen(const char *filename, const char *mode);
|
||||
JNIEXPORT void JNICALL Java_com_polymathic_RtB_RtB_setAssetManager(JNIEnv* env, jobject obj, jobject assetManager);
|
||||
}
|
||||
#endif
|
||||
#endif
|
159
src/main.cpp
159
src/main.cpp
|
@ -1,13 +1,11 @@
|
|||
#include "common.hpp"
|
||||
#include "Program.hpp"
|
||||
#include "RenderScene.hpp"
|
||||
#include "RenderView.hpp"
|
||||
#include "RenderCamera.hpp"
|
||||
#include "Log.hpp"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include "CoreFoundation/CoreFoundation.h"
|
||||
#endif
|
||||
#include "Core.hpp"
|
||||
|
||||
extern "C" void iPhoneFrame(void *) {
|
||||
core.doProcess();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
#ifdef __APPLE__
|
||||
|
@ -17,146 +15,17 @@ int main(int argc, char *argv[]) {
|
|||
CFRelease(res);
|
||||
chdir(path);
|
||||
#endif
|
||||
// TEMP location of video vars
|
||||
SDL_Window *v_window = NULL;
|
||||
SDL_GLContext v_context = 0;
|
||||
GLint v_fbo;
|
||||
SDL_Event event;
|
||||
int v_width = 640;
|
||||
int v_height = 480;
|
||||
int v_flags = SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE;
|
||||
int g_running = 0;
|
||||
|
||||
// initialize SDL
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING & ~SDL_INIT_HAPTIC) != 0) {
|
||||
LOG(LOG_ERROR) << "SDL_Init: " << SDL_GetError();
|
||||
return 1;
|
||||
}
|
||||
// create our window
|
||||
v_window = SDL_CreateWindow("Roll them Bones", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, v_width, v_height, v_flags);
|
||||
if (v_window == NULL) {
|
||||
LOG(LOG_ERROR) << "SDL_CreateWindow: " << SDL_GetError();
|
||||
return 1;
|
||||
}
|
||||
SDL_GetWindowSize(v_window, &v_width, &v_height);
|
||||
// get our OpenGL context
|
||||
v_context = SDL_GL_CreateContext(v_window);
|
||||
if (v_context == NULL) {
|
||||
LOG(LOG_ERROR) << "SDL_GL_CreateContext: " << SDL_GetError();
|
||||
return 1;
|
||||
}
|
||||
#ifdef USE_GLEW
|
||||
glewExperimental = GL_TRUE;
|
||||
if (glewInit() != GLEW_OK) {
|
||||
LOG(LOG_ERROR) << "Could not initialize GLEW";
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
// bind content to window
|
||||
SDL_GL_MakeCurrent(v_window, v_context);
|
||||
// Get our window's FBO id for iOS
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &v_fbo);
|
||||
// enable depth testing
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
//
|
||||
glDepthFunc(GL_LESS);
|
||||
// enable back-face culling
|
||||
//glEnable(GL_CULL_FACE);
|
||||
LOG(LOG_INFO) << "OpenGL Renderer: " << glGetString(GL_RENDERER) << "\nOpenGL Version: " << glGetString(GL_VERSION);
|
||||
//
|
||||
// Create our basic RenderScene
|
||||
RenderScene *scene = new RenderScene();
|
||||
// TEMP: our framebuffer rendering program
|
||||
Program *program = new Program();
|
||||
if (program->addShader("data/shaders/fb_fs.glsl", GL_FRAGMENT_SHADER) != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to add Shader!";
|
||||
return 1;
|
||||
}
|
||||
if (program->addShader("data/shaders/fb_vs.glsl", GL_VERTEX_SHADER) != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to add Shader!";
|
||||
return 1;
|
||||
}
|
||||
if (program->doCompile() != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to compile GLSL Program!";
|
||||
return 1;
|
||||
}
|
||||
// TEMP: our model rendering program
|
||||
Program *program_model = new Program();
|
||||
if (program_model->addShader("data/shaders/default_fs.glsl", GL_FRAGMENT_SHADER) != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to add Shader!";
|
||||
return 1;
|
||||
}
|
||||
if (program_model->addShader("data/shaders/default_vs.glsl", GL_VERTEX_SHADER) != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to add Shdaer!";
|
||||
return 1;
|
||||
}
|
||||
if (program_model->doCompile() != 0) {
|
||||
LOG(LOG_ERROR) << "Failed to compile GLSL Program!";
|
||||
return 1;
|
||||
}
|
||||
|
||||
int camera_id = scene->addCamera(new RenderCamera());
|
||||
RenderCamera *camera = scene->getCamera(camera_id);
|
||||
camera->setRenderView(new RenderView(v_width, v_height));
|
||||
camera->updateProjection(v_width, v_height);
|
||||
camera->setPitch(70.0f);
|
||||
camera->setPosition(0, 35, -10);
|
||||
camera->doRefresh();
|
||||
|
||||
program->attachTexture(0, camera->getRenderView()->getFBO());
|
||||
|
||||
RenderObject *objerct = new RenderObject();
|
||||
Mesh *mersh = new Mesh("data/models/chest.obj");
|
||||
mersh->buildMesh();
|
||||
objerct->setMesh(mersh);
|
||||
RenderSet *sert = new RenderSet();
|
||||
sert->setProgram(program_model);
|
||||
sert->addObject(objerct);
|
||||
scene->addSet(sert);
|
||||
|
||||
core.initSystem();
|
||||
#if __IPHONEOS__
|
||||
//InitGameCenter();
|
||||
SDL_iPhoneSetAnimationCallback(core.getWindow(), 1, iPhoneFrame, 0);
|
||||
#else
|
||||
// begin our main loop
|
||||
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
|
||||
g_running = 1;
|
||||
while (g_running) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
g_running = 0;
|
||||
}
|
||||
}
|
||||
scene->doRender(); // Render our main scene using loaded cameras
|
||||
|
||||
//glBindFramebuffer(GL_FRAMEBUFFER, v_fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glViewport(0, 0, v_width, v_height);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
// Alright, let's render our scene to the screen. We bind textures equal to the # of RenderCamera's Renderviews available.
|
||||
RenderCamera *r_camera;
|
||||
RenderView *r_view;
|
||||
std::vector<RenderCamera*>::iterator camera_it, camera_end;
|
||||
program->activate();
|
||||
for (camera_it = scene->getCameras()->begin(), camera_end = scene->getCameras()->end(); camera_it != camera_end; ++camera_it) {
|
||||
r_camera = *camera_it;
|
||||
if ((r_view = camera->getRenderView()) == NULL) continue;
|
||||
//
|
||||
GLuint program_p = program->getProgram();
|
||||
GLuint program_vp = glGetAttribLocation(program_p, "vp");
|
||||
// enable vertex positions and UV map
|
||||
glEnableVertexAttribArray(program_vp);
|
||||
// Get our mesh
|
||||
Mesh *mesh = r_view->getMesh();
|
||||
glBindBuffer(GL_ARRAY_BUFFER, mesh->vbo);
|
||||
glEnableVertexAttribArray(program_vp);
|
||||
glVertexAttribPointer(program_vp, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
// and draw
|
||||
glDrawArrays(GL_TRIANGLES, 0, mesh->vertices.size());
|
||||
// close 'em
|
||||
glDisableVertexAttribArray(program_vp);
|
||||
}
|
||||
program->deactivate();
|
||||
|
||||
SDL_GL_SwapWindow(v_window);
|
||||
while (core.flags & Core::IS_RUNNING) {
|
||||
core.doProcess();
|
||||
SDL_Delay(1);
|
||||
}
|
||||
SDL_Quit();
|
||||
core.closeSystem();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue