2016-08-31 19:30:31 +02:00
|
|
|
#define GLFW_EXPOSE_NATIVE_GLX
|
|
|
|
#define GLFW_EXPOSE_NATIVE_X11
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#include <GLFW/glfw3native.h>
|
|
|
|
|
2016-08-29 22:31:11 +02:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2016-09-16 17:29:17 +02:00
|
|
|
#include <unistd.h>
|
2016-08-29 22:31:11 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "bgfx/bgfxplatform.h"
|
2016-08-31 19:30:31 +02:00
|
|
|
#include "bx/timer.h"
|
2016-08-29 22:31:11 +02:00
|
|
|
#include "Renderer.h"
|
2016-09-16 17:29:17 +02:00
|
|
|
#include "RuntimeModuleManager.h"
|
2016-08-29 22:31:11 +02:00
|
|
|
|
2016-09-19 22:55:42 +02:00
|
|
|
#include "Globals.h"
|
|
|
|
Renderer* gRenderer = nullptr;
|
|
|
|
GLFWwindow* gWindow = nullptr;
|
2016-08-29 22:31:11 +02:00
|
|
|
|
2016-09-19 22:55:42 +02:00
|
|
|
using namespace std;
|
2016-08-31 19:30:31 +02:00
|
|
|
|
|
|
|
namespace bgfx {
|
|
|
|
inline void glfwSetWindow(GLFWwindow* _window)
|
|
|
|
{
|
|
|
|
bgfx::PlatformData pd;
|
|
|
|
# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
|
|
|
|
pd.ndt = glfwGetX11Display();
|
|
|
|
pd.nwh = (void*)(uintptr_t)glfwGetGLXWindow(_window);
|
|
|
|
pd.context = glfwGetGLXContext(_window);
|
|
|
|
# elif BX_PLATFORM_OSX
|
|
|
|
pd.ndt = NULL;
|
|
|
|
pd.nwh = glfwGetCocoaWindow(_window);
|
|
|
|
pd.context = glfwGetNSGLContext(_window);
|
|
|
|
# elif BX_PLATFORM_WINDOWS
|
|
|
|
pd.ndt = NULL;
|
|
|
|
pd.nwh = glfwGetWin32Window(_window);
|
|
|
|
pd.context = NULL;
|
|
|
|
# endif // BX_PLATFORM_WINDOWS
|
|
|
|
pd.backBuffer = NULL;
|
|
|
|
pd.backBufferDS = NULL;
|
|
|
|
bgfx::setPlatformData(pd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-29 22:31:11 +02:00
|
|
|
static void error_callback(int error, const char* description)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error (%d): %s\n", error, description);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
|
|
|
{
|
|
|
|
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
|
|
|
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
// TODO GLFW error checking
|
|
|
|
glfwSetErrorCallback(error_callback);
|
|
|
|
glfwInit();
|
|
|
|
|
|
|
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
|
|
|
|
|
2016-09-19 22:55:42 +02:00
|
|
|
gWindow = glfwCreateWindow(800, 600, "ProtoT", NULL, NULL);
|
|
|
|
glfwMakeContextCurrent(gWindow);
|
2016-08-31 19:30:31 +02:00
|
|
|
int width, height;
|
2016-09-19 22:55:42 +02:00
|
|
|
glfwGetWindowSize(gWindow, &width, &height);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
2016-08-31 19:30:31 +02:00
|
|
|
Renderer renderer;
|
2016-09-19 22:55:42 +02:00
|
|
|
bgfx::glfwSetWindow(gWindow);
|
2016-08-31 19:30:31 +02:00
|
|
|
bgfx::renderFrame();
|
2016-08-29 22:31:11 +02:00
|
|
|
|
2016-08-31 19:30:31 +02:00
|
|
|
renderer.initialize(width, height);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
2016-09-19 22:55:42 +02:00
|
|
|
gRenderer = &renderer;
|
|
|
|
|
2016-08-31 19:30:31 +02:00
|
|
|
// bgfx::init();
|
|
|
|
// bgfx::reset(width, height, BGFX_RESET_VSYNC);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
2016-08-31 19:30:31 +02:00
|
|
|
// printf("bgfx renderer is %s\n", bgfx::getRendererName(bgfx::getRendererType()));
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
|
|
// Enable debug text.
|
2016-08-31 19:30:31 +02:00
|
|
|
// bgfx::setDebug(BGFX_DEBUG_TEXT);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
|
|
// Set view 0 clear state.
|
2016-08-31 19:30:31 +02:00
|
|
|
// bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x3070F0FF);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
2016-09-03 16:18:51 +02:00
|
|
|
printf("Initializing ModuleManager...\n");
|
2016-09-16 17:29:17 +02:00
|
|
|
RuntimeModuleManager module_manager;
|
|
|
|
module_manager.RegisterModule("libTestModule.so");
|
2016-09-03 16:18:51 +02:00
|
|
|
|
2016-08-29 22:31:11 +02:00
|
|
|
printf("Starting main loop...\n");
|
2016-09-19 22:55:42 +02:00
|
|
|
glfwSetKeyCallback(gWindow, key_callback);
|
2016-08-31 19:30:31 +02:00
|
|
|
int64_t time_offset = bx::getHPCounter();
|
|
|
|
|
2016-09-19 22:55:42 +02:00
|
|
|
while(!glfwWindowShouldClose(gWindow)) {
|
2016-08-31 19:30:31 +02:00
|
|
|
int64_t now = bx::getHPCounter();
|
|
|
|
static int64_t last = now;
|
|
|
|
const int64_t frameTime = now - last;
|
|
|
|
last = now;
|
|
|
|
const double freq = double(bx::getHPFrequency() );
|
|
|
|
const double toMs = 1000.0/freq;
|
|
|
|
|
|
|
|
float time = (float)( (now-time_offset)/double(bx::getHPFrequency() ) );
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
|
|
int width, height;
|
2016-09-19 22:55:42 +02:00
|
|
|
glfwGetWindowSize(gWindow, &width, &height);
|
2016-08-31 19:30:31 +02:00
|
|
|
if (width != renderer.width || height != renderer.height) {
|
|
|
|
renderer.resize(width, height);
|
|
|
|
}
|
|
|
|
|
2016-09-16 17:29:17 +02:00
|
|
|
module_manager.Update((float)(frameTime / freq));
|
2016-09-03 16:18:51 +02:00
|
|
|
|
2016-09-08 23:35:12 +02:00
|
|
|
renderer.paintGL();
|
2016-09-03 16:18:51 +02:00
|
|
|
|
2016-08-31 19:30:31 +02:00
|
|
|
// bgfx::setViewRect(0, 0, 0, width, height);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
|
|
|
// Dummy submit call to make sure view 0 is cleared
|
2016-08-31 19:30:31 +02:00
|
|
|
// bgfx::touch(0);
|
2016-08-29 22:31:11 +02:00
|
|
|
|
2016-08-31 19:30:31 +02:00
|
|
|
// bgfx::dbgTextClear();
|
|
|
|
// bgfx::dbgTextPrintf(0, 1, 0x4f, "Test text");
|
|
|
|
// bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs);
|
|
|
|
//
|
|
|
|
// bgfx::frame();
|
2016-08-29 22:31:11 +02:00
|
|
|
|
2016-08-31 19:30:31 +02:00
|
|
|
glfwPollEvents();
|
2016-09-08 23:35:12 +02:00
|
|
|
|
|
|
|
// send inputs to the input state of the renderer
|
|
|
|
double mouse_x, mouse_y;
|
2016-09-19 22:55:42 +02:00
|
|
|
glfwGetCursorPos(gWindow, &mouse_x, &mouse_y);
|
2016-09-08 23:35:12 +02:00
|
|
|
renderer.inputState.mouseX = mouse_x;
|
|
|
|
renderer.inputState.mouseY = mouse_y;
|
|
|
|
renderer.inputState.mouseButton =
|
2016-09-19 22:55:42 +02:00
|
|
|
glfwGetMouseButton(gWindow, 0)
|
|
|
|
+ (glfwGetMouseButton(gWindow, 1) << 1)
|
|
|
|
+ (glfwGetMouseButton(gWindow, 2) << 2);
|
2016-09-08 23:35:12 +02:00
|
|
|
|
2016-09-16 17:29:17 +02:00
|
|
|
usleep(16000);
|
2016-08-29 22:31:11 +02:00
|
|
|
}
|
2016-09-16 17:29:17 +02:00
|
|
|
|
|
|
|
module_manager.UnloadModules();
|
2016-09-19 22:55:42 +02:00
|
|
|
|
|
|
|
gRenderer = nullptr;
|
2016-08-29 22:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//! [code]
|