Examples: Apple: Tweak code and sync with other examples better (untested).

This commit is contained in:
omar 2018-01-31 00:16:44 +01:00
parent cca9c3e3da
commit 6c38aa2dc7
4 changed files with 45 additions and 23 deletions

View File

@ -294,6 +294,13 @@ GLfloat gCubeVertexData[216] =
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{ {
// Start the dear imgui frame
[self.imgui newFrame];
// Create some UI elements
DebugHUD_DoInterface( &_hud );
// Render
glClearColor(0.65f, 0.65f, 0.65f, 1.0f); glClearColor(0.65f, 0.65f, 0.65f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -301,28 +308,19 @@ GLfloat gCubeVertexData[216] =
// Render the object with GLKit // Render the object with GLKit
[self.effect prepareToDraw]; [self.effect prepareToDraw];
glDrawArrays(GL_TRIANGLES, 0, 36); glDrawArrays(GL_TRIANGLES, 0, 36);
// Render the object again with ES2 // Render the object again with ES2
glUseProgram(_program); glUseProgram(_program);
glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, _modelViewProjectionMatrix.m); glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, _modelViewProjectionMatrix.m);
glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, _normalMatrix.m); glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, _normalMatrix.m);
glUniform3f(uniforms[UNIFORM_DIFFUSE_COLOR], _hud.cubeColor1[0], _hud.cubeColor1[1], _hud.cubeColor1[2] ); glUniform3f(uniforms[UNIFORM_DIFFUSE_COLOR], _hud.cubeColor1[0], _hud.cubeColor1[1], _hud.cubeColor1[2] );
glDrawArrays(GL_TRIANGLES, 0, 36); glDrawArrays(GL_TRIANGLES, 0, 36);
[self.imgui newFrame];
// Now do our ImGUI UI
DebugHUD_DoInterface( &_hud );
self.effect.light0.diffuseColor = GLKVector4Make( _hud.cubeColor2[0], _hud.cubeColor2[1], _hud.cubeColor2[2], 1.0f); self.effect.light0.diffuseColor = GLKVector4Make( _hud.cubeColor2[0], _hud.cubeColor2[1], _hud.cubeColor2[2], 1.0f);
// Now render Imgui // Render dear imgui as the last thing in the frame if possible
[self.imgui render]; [self.imgui render];
} }
#pragma mark - OpenGL ES 2 shader compilation #pragma mark - OpenGL ES 2 shader compilation

View File

@ -10,7 +10,7 @@
void DebugHUD_InitDefaults( DebugHUD *hud ) void DebugHUD_InitDefaults( DebugHUD *hud )
{ {
hud->show_demo_window = true; hud->show_demo_window = true;
hud->show_example_window = true; hud->show_another_window = true;
hud->rotation_speed = 15.0f; hud->rotation_speed = 15.0f;
hud->cubeColor1[0] = 0.4f; hud->cubeColor1[0] = 0.4f;
@ -26,19 +26,43 @@ void DebugHUD_InitDefaults( DebugHUD *hud )
void DebugHUD_DoInterface(DebugHUD *hud) void DebugHUD_DoInterface(DebugHUD *hud)
{ {
if (hud->show_demo_window) // 1. Show a simple window.
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug".
{ {
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! static float f = 0.0f;
ImGui::ShowDemoWindow(&hud->show_demo_window ); static int counter = 0;
ImGui::Text("Hello, world!"); // Display some text (you can use a format string too)
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
ImGui::Checkbox("Demo Window", &hud->show_demo_window); // Edit bools storing our windows open/close state
ImGui::Checkbox("Another Window", &hud->show_another_window);
if (ImGui::Button("Button")) // Buttons return true when clicked (NB: most widgets return true when edited/activated)
counter++;
ImGui::SameLine();
ImGui::Text("counter = %d", counter);
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
} }
if (hud->show_example_window) // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name your windows.
if (hud->show_another_window)
{ {
ImGui::Begin("Another Window", &hud->show_example_window); ImGui::Begin("Another Window", &hud-?show_another_window);
ImGui::Text("Hello from another window!"); ImGui::Text("Hello from another window!");
ImGui::ColorEdit3("Cube 1 Color", hud->cubeColor1); ImGui::ColorEdit3("Cube 1 Color", hud->cubeColor1);
ImGui::ColorEdit3("Cube 2 Color", hud->cubeColor2); ImGui::ColorEdit3("Cube 2 Color", hud->cubeColor2);
ImGui::SliderFloat("Rotation Speed", &hud->rotation_speed, 0.0f, 200.0f); ImGui::SliderFloat("Rotation Speed", &hud->rotation_speed, 0.0f, 200.0f);
if (ImGui::Button("Close Me"))
hud->show_another_window = false;
ImGui::End(); ImGui::End();
} }
// 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). Read its code to learn more about Dear ImGui!
if (hud->show_demo_window)
{
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly!
ImGui::ShowDemoWindow(&hud->show_demo_window);
}
} }

View File

@ -7,7 +7,7 @@
typedef struct DebugHUD typedef struct DebugHUD
{ {
bool show_demo_window; bool show_demo_window;
bool show_example_window; bool show_another_window;
float rotation_speed; float rotation_speed;
float cubeColor1[4]; float cubeColor1[4];
float cubeColor2[4]; float cubeColor2[4];
@ -17,8 +17,8 @@ typedef struct DebugHUD
extern "C" { extern "C" {
#endif #endif
void DebugHUD_InitDefaults( DebugHUD *hud ); void DebugHUD_InitDefaults(DebugHUD *hud);
void DebugHUD_DoInterface( DebugHUD *hud ); void DebugHUD_DoInterface(DebugHUD *hud);
#if __cplusplus #if __cplusplus
} }

View File

@ -263,7 +263,7 @@ void ImGui_KeyboardCallback(uSynergyCookie cookie, uint16_t key,
uint16_t modifiers, uSynergyBool down, uSynergyBool repeat) uint16_t modifiers, uSynergyBool down, uSynergyBool repeat)
{ {
int scanCode = key-1; int scanCode = key-1;
// printf("Synergy: keyboard callback: 0x%02X (%s)", scanCode, down?"true":"false"); // printf("Synergy: keyboard callback: 0x%02X (%s)", scanCode, down?"true":"false");
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
io.KeysDown[key] = down; io.KeysDown[key] = down;
io.KeyShift = (modifiers & USYNERGY_MODIFIER_SHIFT); io.KeyShift = (modifiers & USYNERGY_MODIFIER_SHIFT);