5 changed files with 90 additions and 13 deletions
@ -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 |
||||
|
||||
@ -0,0 +1,59 @@
|
||||
|
||||
#include <SDL2/SDL.h> |
||||
|
||||
#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; |
||||
} |
||||
Loading…
Reference in new issue