mirror of
https://github.com/mlaux/gb6.git
synced 2024-05-31 21:41:58 +00:00
168 lines
4.8 KiB
C++
168 lines
4.8 KiB
C++
#include "imgui.h"
|
|
#include "imgui_impl_glfw.h"
|
|
#include "imgui_impl_opengl3.h"
|
|
#include "imgui_memory_editor.h"
|
|
#include <stdio.h>
|
|
#include <GL/gl3w.h> // Initialize with gl3wInit()
|
|
#include <GLFW/glfw3.h>
|
|
|
|
static MemoryEditor memory_editor;
|
|
|
|
const int window_width = 1280;
|
|
const int window_height = 720;
|
|
|
|
static GLuint output_texture;
|
|
|
|
char mem_block[1024];
|
|
int mem_block_size = 1024;
|
|
|
|
static void glfw_error_callback(int error, const char* description)
|
|
{
|
|
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
|
|
}
|
|
|
|
static void gen_output_texture(void)
|
|
{
|
|
glGenTextures(1, &output_texture);
|
|
}
|
|
|
|
static void emulation_start()
|
|
{
|
|
|
|
}
|
|
|
|
static void emulation_stop()
|
|
{
|
|
|
|
}
|
|
|
|
static void emulation_step()
|
|
{
|
|
|
|
}
|
|
|
|
int main(int, char **)
|
|
{
|
|
// Setup window
|
|
glfwSetErrorCallback(glfw_error_callback);
|
|
if (!glfwInit())
|
|
return 1;
|
|
|
|
// Decide GL+GLSL versions
|
|
#if __APPLE__
|
|
// GL 3.2 + GLSL 150
|
|
const char* glsl_version = "#version 150";
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
|
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
|
|
#else
|
|
// GL 3.0 + GLSL 130
|
|
const char* glsl_version = "#version 130";
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
|
#endif
|
|
|
|
// Create window with graphics context
|
|
GLFWwindow* window = glfwCreateWindow(window_width, window_height, "gb6", NULL, NULL);
|
|
if (window == NULL)
|
|
return 1;
|
|
glfwMakeContextCurrent(window);
|
|
glfwSwapInterval(1); // Enable vsync
|
|
|
|
// Initialize OpenGL loader
|
|
bool err = gl3wInit() != 0;
|
|
if (err) {
|
|
fprintf(stderr, "Failed to initialize OpenGL loader!\n");
|
|
return 1;
|
|
}
|
|
|
|
// Setup Dear ImGui context
|
|
IMGUI_CHECKVERSION();
|
|
ImGui::CreateContext();
|
|
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
|
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
|
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
|
|
|
// Setup Dear ImGui style
|
|
ImGui::StyleColorsDark();
|
|
//ImGui::StyleColorsClassic();
|
|
|
|
// Setup Platform/Renderer bindings
|
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
|
ImGui_ImplOpenGL3_Init(glsl_version);
|
|
|
|
// Our state
|
|
bool show_demo_window = true;
|
|
bool show_another_window = false;
|
|
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
|
|
|
gen_output_texture();
|
|
|
|
// Main loop
|
|
while (!glfwWindowShouldClose(window))
|
|
{
|
|
glfwPollEvents();
|
|
|
|
// Start the Dear ImGui frame
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
ImGui_ImplGlfw_NewFrame();
|
|
ImGui::NewFrame();
|
|
|
|
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
|
|
{
|
|
static float f = 0.0f;
|
|
static int counter = 0;
|
|
|
|
ImGui::Begin("Output"); // Create a window called "Hello, world!" and append into it.
|
|
|
|
ImGui::Text("Control"); // Display some text (you can use a format strings too)
|
|
ImGui::SameLine();
|
|
if (ImGui::Button("Start")) {
|
|
emulation_start();
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
if (ImGui::Button("Stop")) {
|
|
emulation_stop();
|
|
}
|
|
ImGui::SameLine();
|
|
if (ImGui::Button("Step")) {
|
|
emulation_step();
|
|
}
|
|
|
|
ImGui::Image((void *) (uintptr_t) output_texture, ImVec2(160, 144));
|
|
|
|
// ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
|
|
// 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::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
|
ImGui::End();
|
|
|
|
memory_editor.DrawWindow("Memory Editor", mem_block, mem_block_size, 0x0000);
|
|
}
|
|
|
|
// Rendering
|
|
ImGui::Render();
|
|
int display_w, display_h;
|
|
glfwGetFramebufferSize(window, &display_w, &display_h);
|
|
glViewport(0, 0, display_w, display_h);
|
|
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
glfwSwapBuffers(window);
|
|
}
|
|
|
|
// Cleanup
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
ImGui_ImplGlfw_Shutdown();
|
|
ImGui::DestroyContext();
|
|
|
|
glfwDestroyWindow(window);
|
|
glfwTerminate();
|
|
|
|
return 0;
|
|
}
|