diff --git a/examples/Makefile b/examples/Makefile index 2018d8f..385e9e9 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,12 +1,29 @@ CXX = g++ -CXXFLAGS = -std=c++11 -g -ggdb3 -Wall -I../include -I/usr/include/SDL2 -I../ext/stb_libs +CXXFLAGS = -std=c++11 -g -ggdb3 -Wall -I../include -I/usr/include/SDL2 LDFLAGS = -lSDL2 -lGLEW -lGL -lassimp -OBJDIR = ../build -BINARY = example -BINDIR = ../bin - -all: - $(CXX) $(CXXFLAGS) -c -MMD main.cpp -o $(OBJDIR)/$(BINARY).o - mkdir -p $(BINDIR) - $(CXX) -o $(BINDIR)/$(BINARY) $(LDFLAGS) $(OBJDIR)/$(BINARY).o $(OBJDIR)/libTangerine.a +OBJDIR = build +LIB = ../build/libTangerine.a +BINDIR = bin + + +all: mkdirs $(OBJDIR)/hello_world.o $(OBJDIR)/assimp_loading.o +.PHONY: all + +-include $(OBJDIR)/*.d + +mkdirs: + mkdir -p $(BINDIR) $(OBJDIR) +.PHONY: mkdirs + +$(OBJDIR)/hello_world.o: + $(CXX) $(CXXFLAGS) -c -MMD hello_world/main.cpp -o $@ + $(CXX) -o $(BINDIR)/hello_world $(LDFLAGS) $@ $(LIB) + +$(OBJDIR)/assimp_loading.o: + $(CXX) $(CXXFLAGS) -c -MMD assimp_loading/main.cpp -o $@ + $(CXX) -o $(BINDIR)/assimp_loading $(LDFLAGS) $@ $(LIB) + +clean: + rm -rf $(OBJDIR)/* bin/* +.PHONY: clean diff --git a/examples/assimp_loading/main.cpp b/examples/assimp_loading/main.cpp new file mode 100644 index 0000000..c4794ee --- /dev/null +++ b/examples/assimp_loading/main.cpp @@ -0,0 +1,59 @@ + +#include + +#include "dumbLog.h" +#include "renderer.h" +#include "mesh.h" + + +void +doFrameCallback(render_state* rs) +{ +} + +void +doRenderLoop(render_state* rs, void (*callback_fn) (render_state*)) +{ + const uint TARGET_FPS = 60; + const uint FRAME_DELAY = 1000 / TARGET_FPS; + uint frameStart, frameTime; + bool running = true; + SDL_Event e; + + while (running) { + frameStart = SDL_GetTicks(); + + while (SDL_PollEvent(&e)) { + if ((e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE) + || e.type == SDL_QUIT) { + running = false; + } + } + + callback_fn(rs); + renRenderFrame(rs, nullptr, 0); + SDL_GL_SwapWindow(rs->handles.window); + frameTime = SDL_GetTicks() - frameStart; + + if (FRAME_DELAY > frameTime) + SDL_Delay(FRAME_DELAY - frameTime); + } +} + +int +main() +{ + render_state* rs = renInit(); + meInitAssimp(); + + meMeshGroup mg; + if (meLoadFromFile(mg, "../data", "../data/spaceship.glb")) { + + doRenderLoop(rs, doFrameCallback); + } else { + LOG(Error) << "Error loading mesh, exiting\n"; + } + + meShutdownAssimp(); + return 0; +} diff --git a/examples/main.cpp b/examples/hello_world/main.cpp similarity index 84% rename from examples/main.cpp rename to examples/hello_world/main.cpp index e2af800..571565d 100644 --- a/examples/main.cpp +++ b/examples/hello_world/main.cpp @@ -18,8 +18,10 @@ main() frameStart = SDL_GetTicks(); while (SDL_PollEvent(&e)) { - if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE) + if ((e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE) + || e.type == SDL_QUIT) { running = false; + } } renRenderFrame(rs, nullptr, 0); diff --git a/include/mesh.h b/include/mesh.h index dde1486..a8271ad 100644 --- a/include/mesh.h +++ b/include/mesh.h @@ -35,6 +35,8 @@ struct meMeshGroup bool meInitAssimp(); +// NOTE: data_dir gets passed to an internal function, filename is a fullpath, wtfs/min++ +// TODO: maybe pass data_dir in to init function and store as a static variable? bool meLoadFromFile(meMeshGroup& mesh_group, const char* data_dir, const char* filename); void meFreeMeshGroup(meMeshGroup& mesh_group); diff --git a/include/renderer.h b/include/renderer.h index ab868ff..152617c 100644 --- a/include/renderer.h +++ b/include/renderer.h @@ -1,8 +1,6 @@ #pragma once -#include - #if defined (_WIN32) #include #else @@ -22,7 +20,6 @@ struct SDL_Handles SDL_Window *window; SDL_GLContext glContext; SDL_DisplayMode currentDisplayMode; - std::vector texSurfaces; }; struct rg_point_light;