Continue to work on GUI for the testbed application

This commit is contained in:
Daniel Chappuis 2015-06-01 23:40:44 +02:00
parent fadedbdb30
commit 5ab2ee4df1
11 changed files with 411 additions and 65 deletions

View File

@ -60,7 +60,7 @@ GLuint Box::mCubeIndices[36] = { 0, 1, 2,
// Constructor // Constructor
Box::Box(const openglframework::Vector3& size, const openglframework::Vector3 &position, Box::Box(const openglframework::Vector3& size, const openglframework::Vector3 &position,
reactphysics3d::CollisionWorld* world, openglframework::Shader& shader) reactphysics3d::CollisionWorld* world, openglframework::Shader& shader)
: openglframework::Object3D(), mColor(0.5f, 0.5f, 0.5f, 1.0f) { : openglframework::Object3D(), mColor(0.01f, 0.62f, 0.39f, 1.0f) {
// Initialize the size of the box // Initialize the size of the box
mSize[0] = size.x * 0.5f; mSize[0] = size.x * 0.5f;
@ -107,7 +107,7 @@ Box::Box(const openglframework::Vector3& size, const openglframework::Vector3 &p
// Constructor // Constructor
Box::Box(const openglframework::Vector3& size, const openglframework::Vector3 &position, Box::Box(const openglframework::Vector3& size, const openglframework::Vector3 &position,
float mass, reactphysics3d::DynamicsWorld* world, openglframework::Shader& shader) float mass, reactphysics3d::DynamicsWorld* world, openglframework::Shader& shader)
: openglframework::Object3D(), mColor(0.5f, 0.5f, 0.5f, 1.0f) { : openglframework::Object3D(), mColor(0.01f, 0.62f, 0.39f, 1.0f) {
// Initialize the size of the box // Initialize the size of the box
mSize[0] = size.x * 0.5f; mSize[0] = size.x * 0.5f;

View File

@ -32,7 +32,7 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3& pos
const std::string& meshFolderPath, openglframework::Shader& shader) const std::string& meshFolderPath, openglframework::Shader& shader)
: openglframework::Mesh(), mRadius(radius), mHeight(height), mVBOVertices(GL_ARRAY_BUFFER), : openglframework::Mesh(), mRadius(radius), mHeight(height), mVBOVertices(GL_ARRAY_BUFFER),
mVBONormals(GL_ARRAY_BUFFER), mVBOTextureCoords(GL_ARRAY_BUFFER), mVBONormals(GL_ARRAY_BUFFER), mVBOTextureCoords(GL_ARRAY_BUFFER),
mVBOIndices(GL_ELEMENT_ARRAY_BUFFER), mColor(1.0f, 0.5f, 0.5f, 1.0f) { mVBOIndices(GL_ELEMENT_ARRAY_BUFFER), mColor(0.5f, 0.5f, 0.5f, 1.0f) {
// Load the mesh from a file // Load the mesh from a file
openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "capsule.obj", *this); openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "capsule.obj", *this);

View File

@ -0,0 +1,70 @@
/********************************************************************************
* OpenGL-Framework *
* Copyright (c) 2015 Daniel Chappuis *
*********************************************************************************
* *
* 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. *
* *
********************************************************************************/
// Libraries
#include "VertexArrayObject.h"
using namespace openglframework;
// Constructor
VertexArrayObject::VertexArrayObject() : mVertexArrayID(0) {
}
// Destructor
VertexArrayObject::~VertexArrayObject() {
}
// Create the vertex buffer object
bool VertexArrayObject::create() {
// Destroy the current VAO
destroy();
// Check that the needed OpenGL extensions are available
bool isExtensionOK = checkOpenGLExtensions();
if (!isExtensionOK) {
std::cerr << "Error : Impossible to use Vertex Array Object on this platform" << std::endl;
assert(false);
return false;
}
// Generate a new VAO
glGenVertexArrays(1, &mVertexArrayID);
assert(mVertexArrayID != 0);
return true;
}
// Destroy the VAO
void VertexArrayObject::destroy() {
// Delete the vertex buffer object
if (mVertexArrayID) {
glDeleteVertexArrays(1, &mVertexArrayID);
mVertexArrayID = 0;
}
}

View File

@ -0,0 +1,99 @@
/********************************************************************************
* OpenGL-Framework *
* Copyright (c) 2013 Daniel Chappuis *
*********************************************************************************
* *
* 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. *
* *
********************************************************************************/
#ifndef VERTEX_ARRAY_OBJECT_H
#define VERTEX_ARRAY_OBJECT_H
// Libraries
#include <GL/glew.h>
#include <cassert>
#include <iostream>
namespace openglframework {
// Class VertexArrayObject
class VertexArrayObject {
private :
// -------------------- Attributes -------------------- //
/// ID of the Vertex Array Object
GLuint mVertexArrayID;
public :
// -------------------- Methods -------------------- //
/// Constructor
VertexArrayObject();
/// Destructor
~VertexArrayObject();
/// Create the vertex buffer object
bool create();
/// Bind the VAO
void bind() const;
/// Unbind the VAO
void unbind() const;
/// Return true if the needed OpenGL extensions are available for VAO
static bool checkOpenGLExtensions();
/// Destroy the VAO
void destroy();
};
// Bind the VAO
inline void VertexArrayObject::bind() const {
assert(mVertexArrayID != 0);
// Bind the VAO
glBindVertexArray(mVertexArrayID);
}
// Unbind the VAO
inline void VertexArrayObject::unbind() const {
assert(mVertexArrayID != 0);
// Unbind the VAO
glBindVertexArray(0);
}
// Return true if the needed OpenGL extensions are available for VAO
inline bool VertexArrayObject::checkOpenGLExtensions() {
// Check that OpenGL version is at least 3.0 or there the vertex array object extension exists
return (GLEW_VERSION_3_0 || GL_ARB_vertex_array_object);
}
}
#endif

10
testbed/shaders/gui.frag Normal file
View File

@ -0,0 +1,10 @@
#version 330
uniform sampler2D Texture;
in vec2 Frag_UV;
in vec4 Frag_Color;
out vec4 Out_Color;
void main()
{
Out_Color = Frag_Color * texture( Texture, Frag_UV.st);
}

15
testbed/shaders/gui.vert Normal file
View File

@ -0,0 +1,15 @@
#version 330
uniform mat4 ProjMtx;
in vec2 Position;
in vec2 UV;
in vec4 Color;
out vec2 Frag_UV;
out vec4 Frag_Color;
void main()
{
Frag_UV = UV;
Frag_Color = Color;
gl_Position = ProjMtx * vec4(Position.xy,0,1);
}

View File

@ -26,6 +26,7 @@
// Libraries // Libraries
#include "Gui.h" #include "Gui.h"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include "TestbedApplication.h"
GLFWwindow* Gui::mWindow = NULL; GLFWwindow* Gui::mWindow = NULL;
double Gui::g_Time = 0.0f; double Gui::g_Time = 0.0f;
@ -33,14 +34,16 @@ bool Gui::g_MousePressed[3] = {false, false, false};
float Gui::g_MouseWheel = 0.0f; float Gui::g_MouseWheel = 0.0f;
GLuint Gui::g_FontTexture = 0; GLuint Gui::g_FontTexture = 0;
size_t Gui::g_VboSize = 0; size_t Gui::g_VboSize = 0;
unsigned int Gui::g_VboHandle = 0;
unsigned int Gui::g_VaoHandle = 0;
int Gui::g_AttribLocationTex = 0, Gui::g_AttribLocationProjMtx = 0; int Gui::g_AttribLocationTex = 0, Gui::g_AttribLocationProjMtx = 0;
int Gui::g_AttribLocationPosition = 0, Gui::g_AttribLocationUV = 0, Gui::g_AttribLocationColor = 0; int Gui::g_AttribLocationPosition = 0, Gui::g_AttribLocationUV = 0, Gui::g_AttribLocationColor = 0;
Shader Gui::mShader; Shader Gui::mShader;
openglframework::VertexBufferObject Gui::mVBO(GL_ARRAY_BUFFER);
openglframework::VertexArrayObject Gui::mVAO;
Gui::LeftPane Gui::mLeftPane = SCENES;
// Constructor // Constructor
Gui::Gui() { Gui::Gui() {
g_Time = 0.0f; g_Time = 0.0f;
g_MousePressed[0] = false; g_MousePressed[0] = false;
g_MousePressed[1] = false; g_MousePressed[1] = false;
@ -48,16 +51,13 @@ Gui::Gui() {
g_MouseWheel = 0.0f; g_MouseWheel = 0.0f;
g_FontTexture = 0; g_FontTexture = 0;
g_VboSize = 0; g_VboSize = 0;
g_VboHandle = 0, g_VaoHandle = 0;
} }
// Destructor // Destructor
Gui::~Gui() { Gui::~Gui() {
if (g_VaoHandle) glDeleteVertexArrays(1, &g_VaoHandle); mVAO.destroy();
if (g_VboHandle) glDeleteBuffers(1, &g_VboHandle); mVBO.destroy();
g_VaoHandle = 0;
g_VboHandle = 0;
mShader.destroy(); mShader.destroy();
@ -101,72 +101,164 @@ void Gui::init() {
io.RenderDrawListsFn = renderDrawLists; io.RenderDrawListsFn = renderDrawLists;
io.SetClipboardTextFn = setClipboardText; io.SetClipboardTextFn = setClipboardText;
io.GetClipboardTextFn = getClipboardText; io.GetClipboardTextFn = getClipboardText;
io.FontGlobalScale = GUI_SCALING;
}
void Gui::displayHeader() {
ImVec2 buttonSize(120, 40);
int display_w, display_h;
glfwGetFramebufferSize(mWindow, &display_w, &display_h);
ImGuiWindowFlags window_flags = 0;
window_flags |= ImGuiWindowFlags_NoTitleBar;
window_flags |= ImGuiWindowFlags_NoResize;
window_flags |= ImGuiWindowFlags_NoMove;
ImGui::PushID("Header");
ImGui::PushStyleColor(ImGuiCol_WindowBg, BACKGROUND_COLOR);
ImGui::Begin("Header", NULL, ImVec2(display_w, HEADER_HEIGHT), 1.0f, window_flags);
ImGui::SetWindowPos(ImVec2(0, 0));
ImGui::Button("Play", buttonSize); ImGui::SameLine();
ImGui::Button("Pause", buttonSize); ImGui::SameLine();
ImGui::Button("Step", buttonSize); ImGui::SameLine();
ImGui::Button("Restart", buttonSize); ImGui::SameLine();
ImGui::End();
ImGui::PopStyleColor(1);
ImGui::PopID();
}
void Gui::displayLeftPane() {
const int nbButtonsHeader = 4;
ImVec2 buttonSize(LEFT_PANE_WIDTH / nbButtonsHeader - 9, LEFT_PANE_HEADER_HEIGHT);
int display_w, display_h;
glfwGetFramebufferSize(mWindow, &display_w, &display_h);
ImGuiWindowFlags window_flags = 0;
window_flags |= ImGuiWindowFlags_NoTitleBar;
window_flags |= ImGuiWindowFlags_NoResize;
window_flags |= ImGuiWindowFlags_NoMove;
ImGui::PushID("LeftPane");
ImGui::PushStyleColor(ImGuiCol_WindowBg, BACKGROUND_COLOR);
ImGui::Begin("LeftPane", NULL, ImVec2(LEFT_PANE_WIDTH, display_h - HEADER_HEIGHT), 1.0f, window_flags);
ImGui::SetWindowPos(ImVec2(0, HEADER_HEIGHT));
// ----- Left Pane Header ----- //
ImGui::Button("Scenes", buttonSize); ImGui::SameLine();
ImGui::Button("Physics", buttonSize); ImGui::SameLine();
ImGui::Button("Rendering", buttonSize); ImGui::SameLine();
ImGui::Button("Profiling", buttonSize);
// Display the left pane content
switch(mLeftPane) {
case SCENES: displayScenesPane(); break;
case PHYSICS: displayPhysicsPane(); break;
case RENDERING: displayRenderingPane(); break;
case PROFILING: displayProfilingPane(); break;
}
ImGui::End();
ImGui::PopStyleColor(1);
ImGui::PopID();
}
// Display the list of scenes
void Gui::displayScenesPane() {
static int choice = 0;
int startChoice = choice;
TestbedApplication& app = TestbedApplication::getInstance();
std::vector<Scene*> scenes = app.getScenes();
// For each scene
for (int i=0; i<scenes.size(); i++) {
// Display a radio button
ImGui::RadioButton(scenes[i]->getName().c_str(), &choice, i);
}
// If the user changed scene
if (choice != startChoice) {
app.switchScene(scenes[choice]);
}
}
void Gui::displayPhysicsPane() {
}
void Gui::displayRenderingPane() {
}
void Gui::displayProfilingPane() {
} }
void Gui::createDeviceObjects() { void Gui::createDeviceObjects() {
/*
mShader.create("shaders/gui.vert", "shaders/gui.frag"); mShader.create("shaders/gui.vert", "shaders/gui.frag");
GLuint shaderID = mShader.getProgramObjectId(); GLuint shaderID = mShader.getProgramObjectId();
g_AttribLocationTex = glGetUniformLocation(shaderID, "Texture"); g_AttribLocationTex = glGetUniformLocation(shaderID, "Texture");
g_AttribLocationProjMtx = glGetUniformLocation(shaderID, "ProjMtx"); g_AttribLocationProjMtx = glGetUniformLocation(shaderID, "ProjMtx");
g_AttribLocationPosition = glGetAttribLocation(shaderID, "Position"); g_AttribLocationPosition = glGetAttribLocation(shaderID, "Position");
g_AttribLocationUV = glGetAttribLocation(shaderID, "UV"); g_AttribLocationUV = glGetAttribLocation(shaderID, "UV");
g_AttribLocationColor = glGetAttribLocation(shaderID, "Color"); g_AttribLocationColor = glGetAttribLocation(shaderID, "Color");
glGenBuffers(1, &g_VboHandle); mVBO.create();
glGenVertexArrays(1, &g_VaoHandle); mVAO.create();
glBindVertexArray(g_VaoHandle); mVAO.bind();
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle); mVBO.bind();
glEnableVertexAttribArray(g_AttribLocationPosition); glEnableVertexAttribArray(g_AttribLocationPosition);
glEnableVertexAttribArray(g_AttribLocationUV); glEnableVertexAttribArray(g_AttribLocationUV);
glEnableVertexAttribArray(g_AttribLocationColor); glEnableVertexAttribArray(g_AttribLocationColor);
#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) #define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))
glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, pos)); glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, pos));
glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, uv)); glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, uv));
glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, col)); glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, col));
#undef OFFSETOF #undef OFFSETOF
glBindVertexArray(0); mVAO.unbind();
glBindBuffer(GL_ARRAY_BUFFER, 0); mVBO.unbind();
createFontTextures(); createFontTextures();
*/
} }
// Display the GUI // Display the GUI
void Gui::render() { void Gui::render() {
/*
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
//glfwPollEvents(); //glfwPollEvents();
beginNewFrame(); beginNewFrame();
bool show_test_window = true; bool show_test_window = true;
bool show_another_window = false; bool show_another_window = false;
ImVec4 clear_color = ImColor(255, 255, 255); ImVec4 clear_color = ImColor(255, 255, 255);
// 1. Show a simple window displayHeader();
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" displayLeftPane();
{
ImGui::Text("Hello, world!");
}
ImGui::ShowTestWindow();
// Render the GUI // Render the GUI
ImGui::Render(); ImGui::Render();
*/
} }
void Gui::beginNewFrame() { void Gui::beginNewFrame() {
/*
if (!g_FontTexture) if (!g_FontTexture)
createDeviceObjects(); createDeviceObjects();
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
// Setup display size (every frame to accommodate for window resizing) // Setup display size (every frame to accommodate for window resizing)
@ -210,7 +302,6 @@ void Gui::beginNewFrame() {
// Start the frame // Start the frame
ImGui::NewFrame(); ImGui::NewFrame();
*/
} }
void Gui::createFontTextures() void Gui::createFontTextures()
@ -236,7 +327,6 @@ void Gui::createFontTextures()
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
void Gui::renderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) void Gui::renderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
{ {
std::cout << "OpenGLVersion : " << glGetString(GL_VERSION) << std::endl;
if (cmd_lists_count == 0) if (cmd_lists_count == 0)
return; return;
@ -252,7 +342,7 @@ void Gui::renderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
/*
// Setup orthographic projection matrix // Setup orthographic projection matrix
const float width = ImGui::GetIO().DisplaySize.x; const float width = ImGui::GetIO().DisplaySize.x;
const float height = ImGui::GetIO().DisplaySize.y; const float height = ImGui::GetIO().DisplaySize.y;
@ -279,12 +369,13 @@ void Gui::renderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
size_t total_vtx_count = 0; size_t total_vtx_count = 0;
for (int n = 0; n < cmd_lists_count; n++) for (int n = 0; n < cmd_lists_count; n++)
total_vtx_count += cmd_lists[n]->vtx_buffer.size(); total_vtx_count += cmd_lists[n]->vtx_buffer.size();
glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle); mVBO.bind();
size_t needed_vtx_size = total_vtx_count * sizeof(ImDrawVert); size_t needed_vtx_size = total_vtx_count * sizeof(ImDrawVert);
if (g_VboSize < needed_vtx_size) if (g_VboSize < needed_vtx_size)
{ {
g_VboSize = needed_vtx_size + 5000 * sizeof(ImDrawVert); // Grow buffer g_VboSize = needed_vtx_size + 5000 * sizeof(ImDrawVert); // Grow buffer
glBufferData(GL_ARRAY_BUFFER, g_VboSize, NULL, GL_STREAM_DRAW); mVBO.copyDataIntoVBO(g_VboSize, NULL, GL_STREAM_DRAW);
//glBufferData(GL_ARRAY_BUFFER, g_VboSize, NULL, GL_STREAM_DRAW);
} }
// Copy and convert all vertices into a single contiguous buffer // Copy and convert all vertices into a single contiguous buffer
@ -298,8 +389,8 @@ void Gui::renderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
buffer_data += cmd_list->vtx_buffer.size() * sizeof(ImDrawVert); buffer_data += cmd_list->vtx_buffer.size() * sizeof(ImDrawVert);
} }
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
glBindBuffer(GL_ARRAY_BUFFER, 0); mVBO.unbind();
glBindVertexArray(g_VaoHandle); mVAO.bind();
int cmd_offset = 0; int cmd_offset = 0;
for (int n = 0; n < cmd_lists_count; n++) for (int n = 0; n < cmd_lists_count; n++)
@ -324,14 +415,11 @@ void Gui::renderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
cmd_offset = vtx_offset; cmd_offset = vtx_offset;
} }
// Restore modified state // Restore modified state
glBindVertexArray(0); mVAO.unbind();
glUseProgram(last_program); glUseProgram(last_program);
glDisable(GL_SCISSOR_TEST); glDisable(GL_SCISSOR_TEST);
glBindTexture(GL_TEXTURE_2D, last_texture); glBindTexture(GL_TEXTURE_2D, last_texture);
*/
} }
const char* Gui::getClipboardText() { const char* Gui::getClipboardText() {

View File

@ -32,13 +32,25 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include "openglframework.h" #include "openglframework.h"
// Constants
const float GUI_SCALING = 2.0f;
const int HEADER_HEIGHT = 80;
const int LEFT_PANE_WIDTH = 700;
const int LEFT_PANE_HEADER_HEIGHT = 60;
const ImColor BACKGROUND_COLOR = ImColor(41, 41, 41, 255);
using namespace openglframework; using namespace openglframework;
// Declarations
class TestbedApplication;
// Class Gui // Class Gui
class Gui { class Gui {
protected : protected :
enum LeftPane {SCENES, PHYSICS, RENDERING, PROFILING};
// -------------------- Constants -------------------- // // -------------------- Constants -------------------- //
@ -48,7 +60,6 @@ class Gui {
static GLFWwindow* mWindow; static GLFWwindow* mWindow;
static Shader mShader; static Shader mShader;
static double g_Time; static double g_Time;
static bool g_MousePressed[3]; static bool g_MousePressed[3];
static float g_MouseWheel; static float g_MouseWheel;
@ -57,7 +68,9 @@ class Gui {
static int g_AttribLocationTex, g_AttribLocationProjMtx; static int g_AttribLocationTex, g_AttribLocationProjMtx;
static int g_AttribLocationPosition, g_AttribLocationUV, g_AttribLocationColor; static int g_AttribLocationPosition, g_AttribLocationUV, g_AttribLocationColor;
static size_t g_VboSize; static size_t g_VboSize;
static unsigned int g_VboHandle, g_VaoHandle; static openglframework::VertexBufferObject mVBO;
static openglframework::VertexArrayObject mVAO;
static LeftPane mLeftPane;
// -------------------- Methods -------------------- // // -------------------- Methods -------------------- //
@ -74,6 +87,16 @@ class Gui {
static void setClipboardText(const char* text); static void setClipboardText(const char* text);
static void displayHeader();
static void displayLeftPane();
/// Display the list of scenes
static void displayScenesPane();
static void displayPhysicsPane();
static void displayRenderingPane();
static void displayProfilingPane();
public : public :
// -------------------- Methods -------------------- // // -------------------- Methods -------------------- //

View File

@ -152,6 +152,9 @@ class Scene {
/// Set the interpolation factor /// Set the interpolation factor
void setInterpolationFactor(float interpolationFactor); void setInterpolationFactor(float interpolationFactor);
/// Return the name of the scene
std::string getName() const;
}; };
// Called when a keyboard event occurs // Called when a keyboard event occurs
@ -185,4 +188,9 @@ inline void Scene::setInterpolationFactor(float interpolationFactor) {
mInterpolationFactor = interpolationFactor; mInterpolationFactor = interpolationFactor;
} }
// Return the name of the scene
inline std::string Scene::getName() const {
return mName;
}
#endif #endif

View File

@ -137,7 +137,7 @@ void TestbedApplication::init() {
Gui::getInstance().setWindow(mWindow); Gui::getInstance().setWindow(mWindow);
// Init the GUI // Init the GUI
//Gui::getInstance().init(); Gui::getInstance().init();
mTimer.start(); mTimer.start();
} }
@ -149,21 +149,17 @@ void TestbedApplication::createScenes() {
CubesScene* cubeScene = new CubesScene("Cubes"); CubesScene* cubeScene = new CubesScene("Cubes");
mScenes.push_back(cubeScene); mScenes.push_back(cubeScene);
/*
// Joints scene // Joints scene
JointsScene* jointsScene = new JointsScene("Joints"); JointsScene* jointsScene = new JointsScene("Joints");
mScenes.push_back(jointsScene); mScenes.push_back(jointsScene);
*/
// Collision shapes scene // Collision shapes scene
CollisionShapesScene* collisionShapesScene = new CollisionShapesScene("Collision Shapes"); CollisionShapesScene* collisionShapesScene = new CollisionShapesScene("Collision Shapes");
mScenes.push_back(collisionShapesScene); mScenes.push_back(collisionShapesScene);
/*
// Raycast scene // Raycast scene
RaycastScene* raycastScene = new RaycastScene("Raycast"); RaycastScene* raycastScene = new RaycastScene("Raycast");
mScenes.push_back(raycastScene); mScenes.push_back(raycastScene);
*/
assert(mScenes.size() > 0); assert(mScenes.size() > 0);
mCurrentScene = mScenes[1]; mCurrentScene = mScenes[1];
@ -225,11 +221,22 @@ void TestbedApplication::update() {
// Render // Render
void TestbedApplication::render() { void TestbedApplication::render() {
// Get the framebuffer dimension
int width, height;
glfwGetFramebufferSize(mWindow, &width, &height);
// Resize the OpenGL viewport
glViewport(LEFT_PANE_WIDTH, HEADER_HEIGHT,
width - LEFT_PANE_WIDTH, height - HEADER_HEIGHT);
// Render the scene // Render the scene
mCurrentScene->render(); mCurrentScene->render();
// Resize the OpenGL viewport
glViewport(0, 0, width, height);
// Display the GUI // Display the GUI
//Gui::getInstance().render(); Gui::getInstance().render();
// Check the OpenGL errors // Check the OpenGL errors
checkOpenGLErrors(); checkOpenGLErrors();
@ -243,10 +250,11 @@ void TestbedApplication::reshape() {
glfwGetFramebufferSize(mWindow, &width, &height); glfwGetFramebufferSize(mWindow, &width, &height);
// Resize the camera viewport // Resize the camera viewport
mCurrentScene->reshape(width, height); mCurrentScene->reshape(width - LEFT_PANE_WIDTH, height - HEADER_HEIGHT);
// Resize the OpenGL viewport // Resize the OpenGL viewport
glViewport(0, 0, width, height); //glViewport(LEFT_PANE_WIDTH, HEADER_HEIGHT,
// width - LEFT_PANE_WIDTH, height - HEADER_HEIGHT);
// Update the window size of the scene // Update the window size of the scene
int windowWidth, windowHeight; int windowWidth, windowHeight;
@ -281,6 +289,17 @@ void TestbedApplication::startMainLoop() {
} }
} }
// Change the current scene
void TestbedApplication::switchScene(Scene* newScene) {
if (newScene == mCurrentScene) return;
mCurrentScene = newScene;
// Reset the scene
mCurrentScene->reset();
}
// Check the OpenGL errors // Check the OpenGL errors
void TestbedApplication::checkOpenGLErrors() { void TestbedApplication::checkOpenGLErrors() {
GLenum glError; GLenum glError;

View File

@ -135,7 +135,10 @@ class TestbedApplication {
void createScenes(); void createScenes();
/// Remove all the scenes /// Remove all the scenes
void destroyScenes() ; void destroyScenes();
/// Return the list of the scenes
std::vector<Scene*> getScenes();
public : public :
@ -152,8 +155,19 @@ class TestbedApplication {
/// Start the main loop where rendering occur /// Start the main loop where rendering occur
void startMainLoop(); void startMainLoop();
/// Change the current scene
void switchScene(Scene* newScene);
// -------------------- Friendship -------------------- //
friend class Gui;
}; };
// Return the list of the scenes
inline std::vector<Scene*> TestbedApplication::getScenes() {
return mScenes;
}
#endif #endif