Browse Source

add another example application

testing
cinnaboot 6 years ago
parent
commit
7c5046df6d
  1. 35
      examples/Makefile
  2. 59
      examples/assimp_loading/main.cpp
  3. 4
      examples/hello_world/main.cpp
  4. 2
      include/mesh.h
  5. 3
      include/renderer.h

35
examples/Makefile

@ -1,12 +1,29 @@
CXX = g++ 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 LDFLAGS = -lSDL2 -lGLEW -lGL -lassimp
OBJDIR = ../build OBJDIR = build
BINARY = example LIB = ../build/libTangerine.a
BINDIR = ../bin BINDIR = bin
all:
$(CXX) $(CXXFLAGS) -c -MMD main.cpp -o $(OBJDIR)/$(BINARY).o all: mkdirs $(OBJDIR)/hello_world.o $(OBJDIR)/assimp_loading.o
mkdir -p $(BINDIR) .PHONY: all
$(CXX) -o $(BINDIR)/$(BINARY) $(LDFLAGS) $(OBJDIR)/$(BINARY).o $(OBJDIR)/libTangerine.a
-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

59
examples/assimp_loading/main.cpp

@ -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;
}

4
examples/main.cpp → examples/hello_world/main.cpp

@ -18,9 +18,11 @@ main()
frameStart = SDL_GetTicks(); frameStart = SDL_GetTicks();
while (SDL_PollEvent(&e)) { 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; running = false;
} }
}
renRenderFrame(rs, nullptr, 0); renRenderFrame(rs, nullptr, 0);
SDL_GL_SwapWindow(rs->handles.window); SDL_GL_SwapWindow(rs->handles.window);

2
include/mesh.h

@ -35,6 +35,8 @@ struct meMeshGroup
bool meInitAssimp(); 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); bool meLoadFromFile(meMeshGroup& mesh_group, const char* data_dir, const char* filename);
void meFreeMeshGroup(meMeshGroup& mesh_group); void meFreeMeshGroup(meMeshGroup& mesh_group);

3
include/renderer.h

@ -1,8 +1,6 @@
#pragma once #pragma once
#include <vector>
#if defined (_WIN32) #if defined (_WIN32)
#include <SDL.h> #include <SDL.h>
#else #else
@ -22,7 +20,6 @@ struct SDL_Handles
SDL_Window *window; SDL_Window *window;
SDL_GLContext glContext; SDL_GLContext glContext;
SDL_DisplayMode currentDisplayMode; SDL_DisplayMode currentDisplayMode;
std::vector<SDL_Surface*> texSurfaces;
}; };
struct rg_point_light; struct rg_point_light;

Loading…
Cancel
Save