Skip to content

Commit 8fda7bf

Browse files
committed
Basic OpenGL render engine for C++
1 parent 75641e2 commit 8fda7bf

File tree

95 files changed

+3181
-60
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+3181
-60
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
[submodule "submodules/imgui"]
88
path = submodules/imgui
99
url = https://github.com/ocornut/imgui.git
10+
[submodule "submodules/json"]
11+
path = submodules/json
12+
url = https://github.com/nlohmann/json.git

Documentation/~$Examples Info.xlsx

-165 Bytes
Binary file not shown.

Kaiju/Xcode/Kaiju/Kaiju.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
CD6FEB6C29170AE600F674D3 /* KaijuTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD6FEB6B29170AE600F674D3 /* KaijuTests.mm */; };
2828
CD6FEB7629170AE600F674D3 /* KaijuUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = CD6FEB7529170AE600F674D3 /* KaijuUITests.m */; };
2929
CD6FEB7829170AE600F674D3 /* KaijuUITestsLaunchTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CD6FEB7729170AE600F674D3 /* KaijuUITestsLaunchTests.m */; };
30+
CDF0FB7829EE11DA00B9EF1F /* AppDelegateBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDF0FB7729EE11DA00B9EF1F /* AppDelegateBridge.swift */; };
3031
/* End PBXBuildFile section */
3132

3233
/* Begin PBXContainerItemProxy section */
@@ -89,6 +90,7 @@
8990
CD6FEB7129170AE600F674D3 /* KaijuUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KaijuUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
9091
CD6FEB7529170AE600F674D3 /* KaijuUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KaijuUITests.m; sourceTree = "<group>"; };
9192
CD6FEB7729170AE600F674D3 /* KaijuUITestsLaunchTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KaijuUITestsLaunchTests.m; sourceTree = "<group>"; };
93+
CDF0FB7729EE11DA00B9EF1F /* AppDelegateBridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegateBridge.swift; sourceTree = "<group>"; };
9294
/* End PBXFileReference section */
9395

9496
/* Begin PBXFrameworksBuildPhase section */
@@ -179,6 +181,7 @@
179181
CD5FB81D291E13D5004F2FB4 /* SwiftBridge.swift */,
180182
CD5FB83029200602004F2FB4 /* ObjCBridge.h */,
181183
CD5FB83129200602004F2FB4 /* ObjCBridge.mm */,
184+
CDF0FB7729EE11DA00B9EF1F /* AppDelegateBridge.swift */,
182185
);
183186
path = Kaiju;
184187
sourceTree = "<group>";
@@ -335,6 +338,7 @@
335338
CD5FB81C291E130D004F2FB4 /* FilesProcessorView.swift in Sources */,
336339
CD6FEB5A29170AE500F674D3 /* ViewController.mm in Sources */,
337340
CD420AE92959FE6900C5D3E1 /* SDLTest.cpp in Sources */,
341+
CDF0FB7829EE11DA00B9EF1F /* AppDelegateBridge.swift in Sources */,
338342
CD6FEB6129170AE600F674D3 /* main.m in Sources */,
339343
CD5FB81E291E13D5004F2FB4 /* SwiftBridge.swift in Sources */,
340344
CD5FB83229200602004F2FB4 /* ObjCBridge.mm in Sources */,

Kaiju/Xcode/Kaiju/Kaiju/AppDelegate.mm

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
//
77

88
#import "AppDelegate.h"
9-
#import <PhaseJump/Class.h>
9+
#import <PhaseJump/PhaseJump.h>
1010
#include "SDLTest.h"
11-
#include <PhaseJump/SQLDatabase.h>
12-
#include <PhaseJump/FileManager.h>
13-
#include <PhaseJump/FilePath.h>
1411

1512
using namespace PJ;
1613

@@ -22,28 +19,45 @@ @interface AppDelegate ()
2219
@implementation AppDelegate
2320

2421
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
22+
// Must specify full path (resources/pj_shaders, not pj/shaders)
23+
// Files must have extension
24+
NSArray *shaderProgramPaths = [[NSBundle mainBundle] pathsForResourcesOfType:@".shprog" inDirectory:@"resources/pj_shaders"];
25+
26+
// We can't load programs yet, there is no GL context
27+
for (NSString *path in shaderProgramPaths) {
28+
GLShaderProgramLoader loader;
29+
auto programInfo = loader.InfoFromPath([path UTF8String]);
30+
if (programInfo) {
31+
GLShaderProgram::Info::registry.Add(programInfo.value());
32+
}
33+
}
34+
2535
// A simple test of an SDL window
2636
SDLFoo();
2737

2838
SQLDatabase db;
39+
//
40+
// NSString* libraryPath;
41+
// libraryPath = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES)[0];
42+
//
43+
// FilePath folderPath([libraryPath UTF8String]);
44+
// folderPath.append("Test");
45+
//
46+
// FileManager fm;
47+
// fm.CreateDirectories(folderPath);
48+
//
49+
// folderPath.append("Hello.sqlite");
2950

30-
NSString* libraryPath;
31-
libraryPath = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES)[0];
32-
33-
FilePath folderPath([libraryPath UTF8String]);
34-
folderPath.append("Test");
35-
36-
FileManager fm;
37-
fm.CreateDirectories(folderPath);
38-
39-
folderPath.append("Hello.sqlite");
4051

41-
try {
42-
db.TryOpen(folderPath, SQLDatabaseOpenType::AtPath, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
43-
}
44-
catch (int error) {
45-
std::cout << "Error" << error;
46-
}
52+
// GLShaderProgramsLoader loader;
53+
// loader.LoadAllProgramsFromPath(
54+
55+
// try {
56+
// db.TryOpen(folderPath, SQLDatabaseOpenType::AtPath, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
57+
// }
58+
// catch (int error) {
59+
// std::cout << "Error" << error;
60+
// }
4761
}
4862

4963
- (void)applicationWillTerminate:(NSNotification *)aNotification {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// AppDelegateBridge.swift
3+
// Kaiju
4+
//
5+
// Created by Jeremy Vineyard on 4/17/23.
6+
//
7+
8+
import Foundation
9+
10+
class AppDelegateBridge: NSObject {
11+
func appDidFinishLaunching() {
12+
}
13+
}

Kaiju/Xcode/Kaiju/Kaiju/SDLTest.cpp

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,72 @@
1515
using namespace PJ;
1616
using namespace std;
1717

18+
void foo1(std::shared_ptr<SDLWorld> world) {
19+
auto pathNode = std::make_shared<WorldNode>();
20+
auto pathComponent = std::make_shared<CirclePathLayout2D>(500);
21+
pathNode->AddComponent(pathComponent);
22+
world->Add(pathNode);
23+
24+
int count = 20;
25+
for (int i = 0; i < count; i++) {
26+
auto meshNode = std::make_shared<WorldNode>();
27+
auto meshRenderer = std::make_shared<MeshRenderer>();
28+
meshNode->AddComponent(meshRenderer);
29+
30+
float progress = (float)i/(float)count;
31+
32+
auto material = std::make_shared<RenderMaterial>();
33+
auto program = GLShaderProgram::registry["colorUniform"];
34+
if (program) {
35+
material->shaderProgram = program;
36+
material->uniformColors.Add(Color(progress, 1.0f - progress, 0, 1));
37+
38+
EllipseRenderMeshBuilder builder(Angle::DegreesAngle(5.0f), Vector2(40, 20));
39+
auto renderMesh = builder.BuildRenderMesh();
40+
meshRenderer->material = material;
41+
meshRenderer->mesh = renderMesh;
42+
}
43+
// window->World()->Add(meshNode);
44+
meshNode->transform->scale = Vector3(1.0f + progress, 1.0f + progress, 1);
45+
// meshNode->transform->rotation.z() = -(progress * 360.0f);
46+
pathNode->AddChild(meshNode);
47+
}
48+
49+
pathComponent->ApplyLayout();
50+
}
51+
52+
void foo2(std::shared_ptr<SDLWorld> world) {
53+
auto pathNode = std::make_shared<WorldNode>();
54+
auto pathComponent = std::make_shared<CirclePathLayout2D>(500);
55+
pathNode->AddComponent(pathComponent);
56+
world->Add(pathNode);
57+
58+
int count = 20;
59+
for (int i = 0; i < count; i++) {
60+
auto meshNode = std::make_shared<WorldNode>();
61+
auto meshRenderer = std::make_shared<MeshRenderer>();
62+
meshNode->AddComponent(meshRenderer);
63+
64+
float progress = (float)i/(float)count;
65+
66+
auto material = std::make_shared<RenderMaterial>();
67+
auto program = GLShaderProgram::registry["colorUniform"];
68+
if (program) {
69+
material->shaderProgram = program;
70+
material->uniformColors.Add(Color(1.0f, 0, 0, 1));
71+
72+
EllipseRenderMeshBuilder builder(Angle::DegreesAngle(5.0f), Vector2(40, 20));
73+
auto renderMesh = builder.BuildRenderMesh();
74+
meshRenderer->material = material;
75+
meshRenderer->mesh = renderMesh;
76+
}
77+
pathNode->AddChild(meshNode);
78+
}
79+
80+
pathComponent->orientToPath = false;
81+
pathComponent->ApplyLayout();
82+
}
83+
1884
bool my_tool_active = false;
1985
float my_color[4];
2086
bool isDone = false;
@@ -82,9 +148,13 @@ void SDLFoo() {
82148
auto node = std::make_shared<WorldNode>();
83149
auto component = std::make_shared<FuncRenderer>([] (RenderIntoModel renderIntoModel) { ImGui::ShowDemoWindow(&show_demo_window); });
84150
node->AddComponent(component);
85-
window->World()->root->AddEdge(StandardEdgeModel(), node);
151+
window->World()->Add(node);
86152
window->World()->SetRenderContext(renderContext);
87153
window->World()->uiEventPoller = std::make_shared<SDLImGuiEventPoller>(*window);
154+
155+
foo1(window->World());
156+
foo2(window->World());
157+
88158
window->World()->Go();
89159
#else
90160
auto windowConfig = SDLWindow::Configuration::native;
@@ -108,11 +178,11 @@ void SDLFoo() {
108178
auto pathNode = std::make_shared<WorldNode>();
109179
auto pathComponent = std::make_shared<CirclePathLayout2D>(100);
110180
pathNode->AddComponent(pathComponent);
111-
window->World()->root->AddEdge(StandardEdgeModel(), pathNode);
181+
window->World()->Add(pathNode);
112182

113183
for (int i = 0; i < 20; i++) {
114184
auto node = std::make_shared<WorldNode>();
115-
pathNode->AddEdge(StandardEdgeModel(), node);
185+
pathNode->AddChild(node);
116186
auto renderer = std::make_shared<SDLTextureRenderer>(sprite);
117187
node->Add(renderer);
118188
node->transform->position = Vector3(StandardRandom().Value() * 100.0f, StandardRandom().Value() * 100.0f, 0);
@@ -123,5 +193,4 @@ void SDLFoo() {
123193
window->World()->Go();
124194
#endif
125195
}
126-
127196
#endif
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": "colorUniform",
3+
"shader.vertex": "colorUniform",
4+
"shader.fragment": "colorUniform"
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
Render uniform color
3+
*/
4+
uniform vec4 u_color;
5+
6+
out vec4 fragColor;
7+
8+
void main()
9+
{
10+
fragColor = u_color;
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
in vec4 a_position;
2+
3+
uniform mat4 u_mvpMatrix;
4+
5+
/*
6+
Uniform color across vertices
7+
*/
8+
void main()
9+
{
10+
gl_Position = u_mvpMatrix * a_position;
11+
}

PhaseJump/PhaseJump/Classes/Collections/List.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace PJ {
2929
void Append(T const& value) { this->push_back(value); }
3030
void Add(T const& value) { this->push_back(value); }
3131

32-
COLLECTION_METHODS(T)
32+
COLLECTION_METHODS(List<T>, T)
3333
};
3434
}
3535

0 commit comments

Comments
 (0)