git.haldean.org ana / e86e3b3
windows build support using tup Haldean Brown 1 year, 5 months ago
12 changed file(s) with 142 addition(s) and 77 deletion(s). Raw diff Collapse all Expand all
0 include_rules
1
2 # : src/*.o lib/*.o |> g++ %f -Llib -lglfw3 -lglew32 -o %o |> ana
3 : src/*.o lib/*.o |> !link_exe |> ana
0 CFLAGS += -Wall
1 CFLAGS += -Werror
2 CFLAGS += -isystem ../lib/glew-2.1.0/include
3 CFLAGS += -isystem ../lib/glfw-3.2.1/include
4 CFLAGS += -isystem ../lib/glm
5 CFLAGS += -I ../lib/imgui
6 CFLAGS += -I ../lib/imgui/examples
7
8 CCFLAGS += /nologo
9 CCFLAGS += /c
10 CCFLAGS += /errorReport:prompt
11 CCFLAGS += /W3
12 CCFLAGS += /TP
13 CCFLAGS += /Od
14 CCFLAGS += /Z7
15 CCFLAGS += /EHsc
16 CCFLAGS += /I../lib/glew-2.1.0/include
17 CCFLAGS += /I../lib/glfw-3.2.1/include
18 CCFLAGS += /I../lib/glm
19 CCFLAGS += /I../lib/imgui
20 CCFLAGS += /I../lib/imgui/examples
21
22 LINKFLAGS += /nologo
23 LINKFLAGS += /DEBUG
24 LINKFLAGS += /INCREMENTAL:NO
25 LINKFLAGS += /SUBSYSTEM:CONSOLE
26
27 # !cxx = |> g++ $(CFLAGS) -c %f -o %o |> %B.o
28 !cxx = |> cl %f $(CCFLAGS) /Fo%B.obj |> %B.obj
29 # !ar = |> ar crs %o %f |>
30 !link_exe = |> link $(LINKFLAGS) %f /OUT:%o /PDB:%O.pdb |> %O.pdb %O.ilk
0 include_rules
1
2 CCFLAGS += /DIMGUI_IMPL_OPENGL_LOADER_GLEW
3
4 : foreach imgui/*.cpp imgui/examples/imgui_impl_opengl3.cpp imgui/examples/imgui_impl_glfw.cpp |> !cxx |>
lib/glew-2.1.0/bin/Release/x64/glew32.dll less more
Binary diff not shown
lib/glew-2.1.0/lib/Release/x64/glew32.lib less more
Binary diff not shown
Binary diff not shown
Binary diff not shown
0 : foreach *.cpp |> g++ -Wall -Werror -isystem ../lib/glew-2.1.0/include -isystem ../lib/glfw-3.2.1/include -isystem ../lib/glm -c %f -o %o |> %B.o
1 : *.o |> g++ %f -o %o |> ana
0 include_rules
1
2 : foreach *.cpp |> !cxx |>
22 #include <iostream>
33
44 #include <GL/glew.h>
5 #include <SDL2/SDL.h>
5 #include <GLFW/glfw3.h>
66
77 #include "imgui.h"
88 #include "imgui_impl_opengl3.h"
9 #include "imgui_impl_sdl.h"
9 #include "imgui_impl_glfw.h"
1010
1111 #include "node.hpp"
1212 #include "shaders.hpp"
1313 #include "ui.hpp"
1414
15 void error_callback(int error, const char* description) {
16 std::cerr << "[E] glfw error: " << description << std::endl;
17 }
18
1519 int main(void) {
16 SDL_Init(SDL_INIT_VIDEO);
17 SDL_Window* window = SDL_CreateWindow("ana",
18 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 400,
19 SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
20 if (!glfwInit()) {
21 std::cerr << "[E] init glfw" << std::endl;
22 return EXIT_FAILURE;
23 }
24 glfwSetErrorCallback(error_callback);
2025
21 if (window == NULL) {
22 std::cerr << "[E] create window: " << SDL_GetError() << std::endl;
23 return EXIT_FAILURE;
24 }
25 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
26 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
27 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
28 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 1);
29 SDL_GLContext context = SDL_GL_CreateContext(window);
30 if (context == NULL) {
31 std::cerr << "[E] SDL_GL_CreateContext: " << SDL_GetError() << std::endl;
32 return EXIT_FAILURE;
33 }
26 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
27 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
28 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
29 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
3430
35 GLenum glew_status = glewInit();
36 if (glew_status != GLEW_OK) {
37 std::cerr << "[E] glewInit: " << glewGetErrorString(glew_status) << std::endl;
38 return EXIT_FAILURE;
39 }
31 GLFWwindow *window = glfwCreateWindow(800, 800, "ana", NULL, NULL);
32 if (!window) {
33 std::cerr << "[E] failed to create window" << std::endl;
34 return EXIT_FAILURE;
35 }
4036
41 if (!ana::shaders::init())
42 return EXIT_FAILURE;
37 glfwMakeContextCurrent(window);
38 GLenum glew_status = glewInit();
39 if (glew_status != GLEW_OK) {
40 std::cerr << "[E] glewInit: " << glewGetErrorString(glew_status) << std::endl;
41 return EXIT_FAILURE;
42 }
4343
44 glEnable(GL_BLEND);
45 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
44 if (!ana::shaders::init())
45 return EXIT_FAILURE;
4646
47 ana::nodeset nodes;
48 nodes.nodes.push_back(ana::node{glm::vec2(0, 0), glm::vec2(0.1, 0.2), "hello"});
49 nodes.nodes.push_back(ana::node{glm::vec2(-0.5, -0.5), glm::vec2(0.2, 0.2), "hello"});
47 glEnable(GL_BLEND);
48 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
5049
51 ana::ui ui;
50 ana::nodeset nodes;
51 nodes.nodes.push_back(ana::node{glm::vec2(0, 0), glm::vec2(0.1, 0.2), "hello"});
52 nodes.nodes.push_back(ana::node{glm::vec2(-0.5, -0.5), glm::vec2(0.2, 0.2), "hello"});
5253
53 ImGui::CreateContext();
54 ImGuiIO &io = ImGui::GetIO();
55 ImGui_ImplOpenGL3_Init("#version 420");
56 ImGui_ImplSDL2_InitForOpenGL(window, context);
54 ana::ui ui;
5755
58 bool run = true;
59 while (run) {
60 ImGui_ImplOpenGL3_NewFrame();
61 ImGui_ImplSDL2_NewFrame(window);
62 SDL_Event ev;
63 while (SDL_PollEvent(&ev)) {
64 ImGui_ImplSDL2_ProcessEvent(&ev);
65 switch (ev.type) {
66 case SDL_QUIT:
67 run = false;
68 break;
56 ImGui::CreateContext();
57 //ImGuiIO &io = ImGui::GetIO();
58 ImGui_ImplGlfw_InitForOpenGL(window, true);
59 ImGui_ImplOpenGL3_Init("#version 410");
6960
70 case SDL_WINDOWEVENT:
71 if (ev.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
72 glViewport(0, 0, ev.window.data1, ev.window.data2);
73 ui.set_aspect(ev.window.data1, ev.window.data2);
74 }
75 break;
61 while (!glfwWindowShouldClose(window)) {
62 glfwPollEvents();
63 ImGui_ImplOpenGL3_NewFrame();
64 ImGui_ImplGlfw_NewFrame();
65 ImGui::NewFrame();
7666
77 case SDL_MOUSEWHEEL:
78 if (!io.WantCaptureMouse && ev.wheel.y != 0) {
79 ui.view_step(ev.wheel.y);
80 }
81 break;
67 //ImGui_ImplSDL2_NewFrame(window);
68 /*
69 SDL_Event ev;
70 while (SDL_PollEvent(&ev)) {
71 ImGui_ImplSDL2_ProcessEvent(&ev);
72 switch (ev.type) {
73 case SDL_WINDOWEVENT:
74 if (ev.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
75 glViewport(0, 0, ev.window.data1, ev.window.data2);
76 ui.set_aspect(ev.window.data1, ev.window.data2);
77 }
78 break;
8279
83 case SDL_MOUSEMOTION:
84 if (!io.WantCaptureMouse && ev.motion.state & SDL_BUTTON_MMASK) {
85 ui.translate(-ev.motion.xrel, ev.motion.yrel);
86 }
87 break;
88 }
89 }
90 glClearColor(0.15, 0.12, 0.1, 1.0);
91 glClear(GL_COLOR_BUFFER_BIT);
80 case SDL_MOUSEWHEEL:
81 if (!io.WantCaptureMouse && ev.wheel.y != 0) {
82 ui.view_step(ev.wheel.y);
83 }
84 break;
9285
93 ana::shaders::draw(ui, nodes);
86 case SDL_MOUSEMOTION:
87 if (!io.WantCaptureMouse && ev.motion.state & SDL_BUTTON_MMASK) {
88 ui.translate(-ev.motion.xrel, ev.motion.yrel);
89 }
90 break;
91 }
92 }
93 */
94 ImGui::Render();
9495
95 SDL_GL_SwapWindow(window);
96 }
96 int display_w, display_h;
9797
98 ana::shaders::destroy();
99 ImGui_ImplOpenGL3_Shutdown();
100 ImGui_ImplSDL2_Shutdown();
101 return EXIT_SUCCESS;
98 glfwMakeContextCurrent(window);
99 glfwGetFramebufferSize(window, &display_w, &display_h);
100 glViewport(0, 0, display_w, display_h);
101
102 glClearColor(0.15, 0.12, 0.1, 1.0);
103 glClear(GL_COLOR_BUFFER_BIT);
104
105 ana::shaders::draw(ui, nodes);
106 ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
107
108 glfwMakeContextCurrent(window);
109 glfwSwapBuffers(window);
110 }
111
112 ana::shaders::destroy();
113 ImGui_ImplOpenGL3_Shutdown();
114 ImGui_ImplGlfw_Shutdown();
115 glfwTerminate();
116 return EXIT_SUCCESS;
102117 }
1414 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515 */
1616
17 /* if this is defined, then we already have an implementation of reallocarray available */
18 #ifndef _GNU_SOURCE
19
1720 #include <sys/types.h>
1821 #include <errno.h>
1922 #include <stdint.h>
2528 */
2629 #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
2730
28 extern inline void *
31 void *
2932 reallocarray(void *optr, size_t nmemb, size_t size)
3033 {
3134 if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
3538 }
3639 return realloc(optr, size * nmemb);
3740 }
41
42 #endif
0 #include <stdlib.h>
1
2 void *reallocarray(void *ptr, size_t nmemb, size_t size);
00 #include "shaders.hpp"
11 #include "glerr.hpp"
22 #include "node.hpp"
3 #include "reallocarray.h"
34
45 #include <glm/glm.hpp>
56 #include <glm/gtc/matrix_transform.hpp>