Browse Source

update libTangerine add note about SDL input loop

main
cinnaboot 5 years ago
parent
commit
d2f42abd55
  1. 2
      ext/tangerine
  2. 24
      src/gooey.cpp
  3. 7
      src/gooey.h
  4. 48
      src/main.cpp

2
ext/tangerine

@ -1 +1 @@
Subproject commit 6be56bc532c12fe02c8de9218c97c2d354f64a2e
Subproject commit e412f21c7e3ca25283cdd8fe7db7d093bc63bc92

24
src/gooey.cpp

@ -32,17 +32,33 @@ gooFree()
ImGui::DestroyContext();
}
bool
gooProcessEvent(SDL_Event& e)
{
ImGui_ImplSDL2_ProcessEvent(&e);
return (ImGui::GetIO().WantCaptureMouse
|| ImGui::GetIO().WantCaptureKeyboard);
}
void
gooDraw(SDL_Window* window)
gooDraw(SDL_Window* window, orbital_elements& orbit)
{
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame(window);
ImGui::NewFrame();
ImGui::Begin("Hello, world!");
ImGui::Text("This is some useful text.");
ImGui::Button("Hey");
ImGui::SetNextWindowPos(ImVec2(0,0));
ImGui::SetNextWindowSize(ImVec2(300,400));
ImGui::Begin("Orbital Elements");
ImGui::Text("a: %f km", orbit.ep.a);
ImGui::Text("e: %f", orbit.ep.e);
ImGui::Text("mu: %f km^3/s^2", orbit.mu);
static char str0[128] = "Hello";
ImGui::InputText("testing", str0, IM_ARRAYSIZE(str0));
ImGui::End();
ImGui::Render();

7
src/gooey.h

@ -3,6 +3,8 @@
#include <SDL2/SDL.h>
#include "orbits.h"
bool
gooInit(SDL_Window* window, SDL_GLContext gl_context);
@ -10,6 +12,9 @@ gooInit(SDL_Window* window, SDL_GLContext gl_context);
void
gooFree();
bool
gooProcessEvent(SDL_Event &e);
void
gooDraw(SDL_Window* window);
gooDraw(SDL_Window* window, orbital_elements& orbit);

48
src/main.cpp

@ -6,6 +6,7 @@
#include <glm/glm.hpp>
#include "dumbLog.h"
#include "input.h"
#include "mesh.h"
#include "renderer.h"
#include "util.h"
@ -77,8 +78,19 @@ initOrbit()
}
void
doFrameCallback(render_state* rs)
doFrameCallbackPre(render_state* rs)
{
// handle input
static input_state is = {};
// TODO: probably need to break the while loop out of inputProcessEvents
// so we can send individual sdl events to ImGui_ImplSDL2_ProcessEvent()
// via gooProcessEvent()
inputProcessEvents(&is);
if (is.window_closed || is.escape)
rs->running = false;
// update satellite position
const static glm::mat4 xform =
glm::rotate(glm::mat4(1.0), (float) M_PI_2, glm::vec3(1, 0, 0));
entity& satellite = rs->render_groups[0].entities[2];
@ -93,37 +105,10 @@ doFrameCallback(render_state* rs)
entSetWorldPosition(satellite, xform * glm::vec4(v.x, v.y, v.z, 1));
}
// TODO: needs cleaning
// could maybe split up renderer callbacks into pre and post 'renderFrame'
// which is what ogre3d used IIRC
// TODO: (renderer) need to re-add input handling to libTangerine
void
doCustomRenderLoop(render_state* rs, uint framerate, frame_callback_fn cb_func)
doFrameCallbackPost(render_state* rs)
{
uint delay = (framerate > 0) ? 1 / framerate : 0;
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;
}
}
if (cb_func != nullptr) cb_func(rs);
renRenderFrame(rs);
gooDraw(rs->handles->window);
SDL_GL_SwapWindow(rs->handles->window);
frameTime = SDL_GetTicks() - frameStart;
if (delay > frameTime)
SDL_Delay(delay - frameTime);
}
gooDraw(rs->handles->window, g_orbit);
}
int
@ -175,8 +160,7 @@ main()
entRotate(satellite_entity, (float) M_PI_2, glm::vec3(1, 0, 0));
entSetWorldPosition(satellite_entity, g_ellipse.vertices[0]);
//renDoRenderLoop(rs, 60, doFrameCallback);
doCustomRenderLoop(rs, 60, doFrameCallback);
renDoRenderLoop(rs, 60 , doFrameCallbackPre, doFrameCallbackPost);
// TODO: clean up mesh pointers? don't remember if renderer does that
// automatically

Loading…
Cancel
Save