A small OpenGL 3+ renderer and game engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

105 lines
2.5 KiB

#include <SDL2/SDL.h>
#include <glm/glm.hpp>
#include "camera.h"
#include "dumbLog.h"
#include "renderer.h"
#include "entity.h"
typedef void (*frame_callback_fn) (render_state*);
void
doFrameCallback(render_state* rs)
{
}
void
doRenderLoop(render_state* rs, frame_callback_fn callback_fn)
{
// TODO: move frame delay to renderFrame()
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();
// TODO: add a better structure for input, and provide a callback to use
// here
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);
SDL_GL_SwapWindow(rs->handles.window);
frameTime = SDL_GetTicks() - frameStart;
if (FRAME_DELAY > frameTime)
SDL_Delay(FRAME_DELAY - frameTime);
}
}
// TODO: remove/refactor this when we get animation working
#include "animation_testing.cpp"
int
main()
{
// TODO: would be nice to be able to pass in viewport_dims, window title
// here
render_state* rs = renInit();
meInitAssimp();
// TODO: entInit() doesn't allocate memory because we want to do the
// allocation in one big block, but this is really clunky to use
render_group* group_1 = renAllocateGroup(1, *rs->default_shader);
entity spaceship = group_1->entities[0];
// TODO: this should be handled in entInit
entSetWorldPosition(spaceship, 0, 0, 0);
entScale(spaceship, glm::vec3(20, 20, 20));
// TODO: implement setting rotation from entity
//spaceship.rotation = glm::vec4(0, 0, 0, 0);
// setup camera
cameraInitPerspective(
rs->cam,
glm::vec3(200, -150, 150),
glm::vec3(0, 0, 0),
glm::vec3(0,0,1)
);
// TODO: renderer::setDefaults() allocates 10 lights based on a MACRO in
// renderer.cpp probably need an interface to add more than that add a
// light
rs->num_lights = 1;
rs->lights[0].position = glm::vec3(200, -150, 150);
// TODO: look into setting up git-annex for large files. git-lfs works fine
// for gitlab, but has no real implementation for self-hosting:
// https://github.com/git-lfs/git-lfs/issues/1044
// https://git-annex.branchable.com/
//
// NOTE: testing assimp animation info
logDebugAnimationInfo("../data/spaceship.glb");
if (entInit(spaceship, "../data/spaceship.glb"))
doRenderLoop(rs, doFrameCallback);
else
LOG(Error) << "Error initializing entity, exiting\n";
renShutdown(rs);
meShutdownAssimp();
return 0;
}