Skip to content

Commit b2dabae

Browse files
committed
Initial commit
0 parents  commit b2dabae

20 files changed

+35800
-0
lines changed

.clang-format

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
AccessModifierOffset: -4
3+
AlignAfterOpenBracket: 'AlwaysBreak'
4+
AllowAllParametersOfDeclarationOnNextLine: 'false'
5+
AllowShortFunctionsOnASingleLine: 'true'
6+
AlwaysBreakBeforeMultilineStrings: 'true'
7+
AlwaysBreakTemplateDeclarations: 'true'
8+
BinPackArguments: 'false'
9+
BinPackParameters: 'false'
10+
BraceWrapping: {
11+
AfterClass: 'true'
12+
AfterControlStatement: 'true'
13+
AfterEnum: 'true'
14+
AfterFunction: 'true'
15+
AfterNamespace: 'true'
16+
AfterStruct: 'true'
17+
AfterUnion: 'true'
18+
BeforeCatch: 'true'
19+
BeforeElse: 'true'
20+
IndentBraces: 'false'
21+
}
22+
BreakBeforeBraces: Custom
23+
ColumnLimit: 100
24+
Cpp11BracedListStyle: 'true'
25+
DerivePointerAlignment: 'false'
26+
IndentCaseLabels: 'true'
27+
IndentWidth: 4
28+
PenaltyExcessCharacter: 100000000
29+
PenaltyReturnTypeOnItsOwnLine: 100000000
30+
PointerAlignment: Left
31+
PointerBindsToType: 'true'
32+
SortIncludes: 'false'
33+
SpaceAfterTemplateKeyword: 'false'
34+
SpaceBeforeParens: ControlStatements
35+
TabWidth: 8
36+
UseTab: Never
37+
...

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# imgui-node-editor

example/main.cpp

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#include "imgui.h"
2+
#include "imgui_impl_sdl.h"
3+
#include "imgui_impl_opengl3.h"
4+
#include <stdio.h>
5+
#include <SDL.h>
6+
#include <GL/gl3w.h>
7+
8+
class SimpleNodeEditor
9+
{
10+
public:
11+
void show()
12+
{
13+
ImGui::Begin("hello, world");
14+
ImGui::End();
15+
}
16+
17+
private:
18+
};
19+
20+
int main(int, char**)
21+
{
22+
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
23+
{
24+
printf("Error: %s\n", SDL_GetError());
25+
return -1;
26+
}
27+
28+
#if __APPLE__
29+
// GL 3.2 Core + GLSL 150
30+
const char* glsl_version = "#version 150";
31+
SDL_GL_SetAttribute(
32+
SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); // Always required on Mac
33+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
34+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
35+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
36+
#else
37+
// GL 3.0 + GLSL 130
38+
const char* glsl_version = "#version 130";
39+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
40+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
41+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
42+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
43+
#endif
44+
45+
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
46+
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
47+
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
48+
SDL_DisplayMode current;
49+
SDL_GetCurrentDisplayMode(0, &current);
50+
SDL_Window* window = SDL_CreateWindow(
51+
"imgui-node-editor example",
52+
SDL_WINDOWPOS_CENTERED,
53+
SDL_WINDOWPOS_CENTERED,
54+
1280,
55+
720,
56+
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
57+
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
58+
SDL_GL_SetSwapInterval(1); // Enable vsync
59+
60+
IMGUI_CHECKVERSION();
61+
ImGui::CreateContext();
62+
ImGuiIO& io = ImGui::GetIO();
63+
(void)io;
64+
65+
ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
66+
ImGui_ImplOpenGL3_Init(glsl_version);
67+
68+
// Setup style
69+
ImGui::StyleColorsDark();
70+
71+
// Simple node editor
72+
SimpleNodeEditor node_example;
73+
74+
bool done = false;
75+
while (!done)
76+
{
77+
SDL_Event event;
78+
while (SDL_PollEvent(&event))
79+
{
80+
ImGui_ImplSDL2_ProcessEvent(&event);
81+
if (event.type == SDL_QUIT)
82+
done = true;
83+
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE &&
84+
event.window.windowID == SDL_GetWindowID(window))
85+
done = true;
86+
}
87+
88+
// Start the Dear ImGui frame
89+
ImGui_ImplOpenGL3_NewFrame();
90+
ImGui_ImplSDL2_NewFrame(window);
91+
ImGui::NewFrame();
92+
93+
node_example.show();
94+
95+
// Rendering
96+
ImGui::Render();
97+
SDL_GL_MakeCurrent(window, gl_context);
98+
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
99+
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
100+
glClear(GL_COLOR_BUFFER_BIT);
101+
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
102+
SDL_GL_SwapWindow(window);
103+
}
104+
105+
ImGui_ImplOpenGL3_Shutdown();
106+
ImGui_ImplSDL2_Shutdown();
107+
ImGui::DestroyContext();
108+
109+
SDL_GL_DeleteContext(gl_context);
110+
SDL_DestroyWindow(window);
111+
SDL_Quit();
112+
}

gl3w/include/GL/gl3w.h

Lines changed: 1458 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)