minor adjustments
parent
5ac0cc5dc5
commit
34bc3ee3eb
|
@ -64,7 +64,7 @@ SET ( protot_SRCS
|
||||||
3rdparty/glfw/deps/glad.c
|
3rdparty/glfw/deps/glad.c
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_EXECUTABLE (protot_glfw src/main_glfw.cc ${protot_SRCS})
|
ADD_EXECUTABLE (protot src/main.cc ${protot_SRCS})
|
||||||
|
|
||||||
file(GLOB glcpp-library_sources
|
file(GLOB glcpp-library_sources
|
||||||
3rdparty/bgfx/3rdparty/glsl-optimizer/src/mesa/main/*.c
|
3rdparty/bgfx/3rdparty/glsl-optimizer/src/mesa/main/*.c
|
||||||
|
@ -110,7 +110,7 @@ SET (glfw_dependencies
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
)
|
)
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES ( protot_glfw
|
TARGET_LINK_LIBRARIES ( protot
|
||||||
#glew
|
#glew
|
||||||
glfw
|
glfw
|
||||||
${glfw_dependencies}
|
${glfw_dependencies}
|
||||||
|
|
|
@ -510,12 +510,12 @@ void Renderer::initialize(int width, int height) {
|
||||||
|
|
||||||
createGeometries();
|
createGeometries();
|
||||||
|
|
||||||
setupShaders();
|
// setupShaders();
|
||||||
|
|
||||||
setupRenderPasses();
|
// setupRenderPasses();
|
||||||
|
|
||||||
// imgui initialization.
|
// imgui initialization.
|
||||||
imguiCreate();
|
// imguiCreate();
|
||||||
|
|
||||||
// // Start the imgui frame such that widgets can be submitted
|
// // Start the imgui frame such that widgets can be submitted
|
||||||
// imguiBeginFrame (inputState.mouseX,
|
// imguiBeginFrame (inputState.mouseX,
|
||||||
|
|
116
src/main.cc
116
src/main.cc
|
@ -24,6 +24,8 @@
|
||||||
//========================================================================
|
//========================================================================
|
||||||
//! [code]
|
//! [code]
|
||||||
|
|
||||||
|
//#define USE_GLAD
|
||||||
|
|
||||||
#ifdef USE_GLEW
|
#ifdef USE_GLEW
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -32,7 +34,11 @@
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "GLFW/glfw3.h"
|
#define GLFW_EXPOSE_NATIVE_GLX
|
||||||
|
#define GLFW_EXPOSE_NATIVE_X11
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <GLFW/glfw3native.h>
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -40,10 +46,63 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "bgfx/bgfxplatform.h"
|
#include "bgfx/bgfxplatform.h"
|
||||||
|
#include "bx/timer.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
static const struct
|
||||||
|
{
|
||||||
|
float x, y;
|
||||||
|
float r, g, b;
|
||||||
|
} vertices[3] =
|
||||||
|
{
|
||||||
|
{ -0.6f, -0.4f, 1.f, 0.f, 0.f },
|
||||||
|
{ 0.6f, -0.4f, 0.f, 1.f, 0.f },
|
||||||
|
{ 0.f, 0.6f, 0.f, 0.f, 1.f }
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char* vertex_shader_text =
|
||||||
|
"uniform mat4 MVP;\n"
|
||||||
|
"attribute vec3 vCol;\n"
|
||||||
|
"attribute vec2 vPos;\n"
|
||||||
|
"varying vec3 color;\n"
|
||||||
|
"void main()\n"
|
||||||
|
"{\n"
|
||||||
|
" gl_Position = MVP * vec4(vPos, 0.0, 1.0);\n"
|
||||||
|
" color = vCol;\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
static const char* fragment_shader_text =
|
||||||
|
"varying vec3 color;\n"
|
||||||
|
"void main()\n"
|
||||||
|
"{\n"
|
||||||
|
" gl_FragColor = vec4(color, 1.0);\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void error_callback(int error, const char* description)
|
static void error_callback(int error, const char* description)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error (%d): %s\n", error, description);
|
fprintf(stderr, "Error (%d): %s\n", error, description);
|
||||||
|
@ -55,6 +114,12 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
|
||||||
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void glfw_simple_example_init () {
|
||||||
|
}
|
||||||
|
|
||||||
|
void glfw_simple_example_draw () {
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
// TODO GLFW error checking
|
// TODO GLFW error checking
|
||||||
|
@ -66,40 +131,61 @@ int main(void)
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
|
||||||
|
|
||||||
GLFWwindow* win = glfwCreateWindow(800, 600, "Test application", NULL, NULL);
|
GLFWwindow* win = glfwCreateWindow(800, 600, "ProtoT", NULL, NULL);
|
||||||
glfwMakeContextCurrent(win);
|
glfwMakeContextCurrent(win);
|
||||||
|
|
||||||
bgfx::glfwSetWindow(win);
|
|
||||||
|
|
||||||
int width, height;
|
int width, height;
|
||||||
glfwGetWindowSize(win, &width, &height);
|
glfwGetWindowSize(win, &width, &height);
|
||||||
|
|
||||||
bgfx::init();
|
Renderer renderer;
|
||||||
bgfx::reset(width, height, BGFX_RESET_VSYNC);
|
bgfx::glfwSetWindow(win);
|
||||||
|
bgfx::renderFrame();
|
||||||
|
|
||||||
printf("bgfx renderer is %s\n", bgfx::getRendererName(bgfx::getRendererType()));
|
renderer.initialize(width, height);
|
||||||
|
|
||||||
|
// bgfx::init();
|
||||||
|
// bgfx::reset(width, height, BGFX_RESET_VSYNC);
|
||||||
|
|
||||||
|
// printf("bgfx renderer is %s\n", bgfx::getRendererName(bgfx::getRendererType()));
|
||||||
|
|
||||||
// Enable debug text.
|
// Enable debug text.
|
||||||
bgfx::setDebug(BGFX_DEBUG_TEXT);
|
// bgfx::setDebug(BGFX_DEBUG_TEXT);
|
||||||
|
|
||||||
// Set view 0 clear state.
|
// Set view 0 clear state.
|
||||||
bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x3070F0FF);
|
// bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x3070F0FF);
|
||||||
|
|
||||||
printf("Starting main loop...\n");
|
printf("Starting main loop...\n");
|
||||||
glfwSetKeyCallback(win, key_callback);
|
glfwSetKeyCallback(win, key_callback);
|
||||||
|
int64_t time_offset = bx::getHPCounter();
|
||||||
|
|
||||||
while(!glfwWindowShouldClose(win)) {
|
while(!glfwWindowShouldClose(win)) {
|
||||||
|
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() ) );
|
||||||
|
|
||||||
int width, height;
|
int width, height;
|
||||||
glfwGetWindowSize(win, &width, &height);
|
glfwGetWindowSize(win, &width, &height);
|
||||||
bgfx::setViewRect(0, 0, 0, width, height);
|
if (width != renderer.width || height != renderer.height) {
|
||||||
|
renderer.resize(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.paintGLSimple();
|
||||||
|
// bgfx::setViewRect(0, 0, 0, width, height);
|
||||||
|
|
||||||
// Dummy submit call to make sure view 0 is cleared
|
// Dummy submit call to make sure view 0 is cleared
|
||||||
bgfx::touch(0);
|
// bgfx::touch(0);
|
||||||
|
|
||||||
bgfx::dbgTextClear();
|
// bgfx::dbgTextClear();
|
||||||
bgfx::dbgTextPrintf(0, 1, 0x4f, "Test text");
|
// bgfx::dbgTextPrintf(0, 1, 0x4f, "Test text");
|
||||||
|
// bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs);
|
||||||
|
//
|
||||||
|
// bgfx::frame();
|
||||||
|
|
||||||
bgfx::frame();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
185
src/main_glfw.cc
185
src/main_glfw.cc
|
@ -1,185 +0,0 @@
|
||||||
//========================================================================
|
|
||||||
// Simple GLFW example
|
|
||||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied
|
|
||||||
// warranty. In no event will the authors be held liable for any damages
|
|
||||||
// arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it
|
|
||||||
// freely, subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
// claim that you wrote the original software. If you use this software
|
|
||||||
// in a product, an acknowledgment in the product documentation would
|
|
||||||
// be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such, and must not
|
|
||||||
// be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source
|
|
||||||
// distribution.
|
|
||||||
//
|
|
||||||
//========================================================================
|
|
||||||
//! [code]
|
|
||||||
|
|
||||||
//#define USE_GLAD
|
|
||||||
|
|
||||||
#ifdef USE_GLEW
|
|
||||||
#include <GL/glew.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_GLAD
|
|
||||||
#include <glad/glad.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define GLFW_EXPOSE_NATIVE_GLX
|
|
||||||
#define GLFW_EXPOSE_NATIVE_X11
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
#include <GLFW/glfw3native.h>
|
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "bgfx/bgfxplatform.h"
|
|
||||||
#include "bx/timer.h"
|
|
||||||
//#include "Renderer.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
static const struct
|
|
||||||
{
|
|
||||||
float x, y;
|
|
||||||
float r, g, b;
|
|
||||||
} vertices[3] =
|
|
||||||
{
|
|
||||||
{ -0.6f, -0.4f, 1.f, 0.f, 0.f },
|
|
||||||
{ 0.6f, -0.4f, 0.f, 1.f, 0.f },
|
|
||||||
{ 0.f, 0.6f, 0.f, 0.f, 1.f }
|
|
||||||
};
|
|
||||||
|
|
||||||
static const char* vertex_shader_text =
|
|
||||||
"uniform mat4 MVP;\n"
|
|
||||||
"attribute vec3 vCol;\n"
|
|
||||||
"attribute vec2 vPos;\n"
|
|
||||||
"varying vec3 color;\n"
|
|
||||||
"void main()\n"
|
|
||||||
"{\n"
|
|
||||||
" gl_Position = MVP * vec4(vPos, 0.0, 1.0);\n"
|
|
||||||
" color = vCol;\n"
|
|
||||||
"}\n";
|
|
||||||
|
|
||||||
static const char* fragment_shader_text =
|
|
||||||
"varying vec3 color;\n"
|
|
||||||
"void main()\n"
|
|
||||||
"{\n"
|
|
||||||
" gl_FragColor = vec4(color, 1.0);\n"
|
|
||||||
"}\n";
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void glfw_simple_example_init () {
|
|
||||||
}
|
|
||||||
|
|
||||||
void glfw_simple_example_draw () {
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
GLFWwindow* win = glfwCreateWindow(800, 600, "Test application", NULL, NULL);
|
|
||||||
glfwMakeContextCurrent(win);
|
|
||||||
|
|
||||||
bgfx::glfwSetWindow(win);
|
|
||||||
bgfx::renderFrame();
|
|
||||||
|
|
||||||
int width, height;
|
|
||||||
glfwGetWindowSize(win, &width, &height);
|
|
||||||
|
|
||||||
bgfx::init();
|
|
||||||
bgfx::reset(width, height, BGFX_RESET_VSYNC);
|
|
||||||
|
|
||||||
printf("bgfx renderer is %s\n", bgfx::getRendererName(bgfx::getRendererType()));
|
|
||||||
|
|
||||||
// Enable debug text.
|
|
||||||
bgfx::setDebug(BGFX_DEBUG_TEXT);
|
|
||||||
|
|
||||||
// Set view 0 clear state.
|
|
||||||
bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x3070F0FF);
|
|
||||||
|
|
||||||
printf("Starting main loop...\n");
|
|
||||||
glfwSetKeyCallback(win, key_callback);
|
|
||||||
int64_t time_offset = bx::getHPCounter();
|
|
||||||
|
|
||||||
while(!glfwWindowShouldClose(win)) {
|
|
||||||
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() ) );
|
|
||||||
|
|
||||||
int width, height;
|
|
||||||
glfwGetWindowSize(win, &width, &height);
|
|
||||||
bgfx::setViewRect(0, 0, 0, width, height);
|
|
||||||
|
|
||||||
// Dummy submit call to make sure view 0 is cleared
|
|
||||||
bgfx::touch(0);
|
|
||||||
|
|
||||||
bgfx::dbgTextClear();
|
|
||||||
bgfx::dbgTextPrintf(0, 1, 0x4f, "Test text");
|
|
||||||
bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs);
|
|
||||||
|
|
||||||
bgfx::frame();
|
|
||||||
|
|
||||||
glfwPollEvents();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//! [code]
|
|
Loading…
Reference in New Issue