From b4e2c43852020ef679ca6a0011c67ea84db89d8a Mon Sep 17 00:00:00 2001 From: Austin Morlan Date: Fri, 28 Oct 2022 13:58:52 -0700 Subject: [PATCH] Update README --- CMakeLists.txt | 7 +++++-- README.md | 2 +- Source/Platform.cpp | 27 ++++++++++++++++++++++----- Source/Platform.hpp | 11 ++++++----- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7815fb2..d237f65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,9 @@ project(chip8) set(CMAKE_CXX_STANDARD 11) -find_package(SDL2 REQUIRED) +add_subdirectory(3rdParty/glad EXCLUDE_FROM_ALL) +add_subdirectory(3rdParty/sdl-2.0.20 EXCLUDE_FROM_ALL) +add_subdirectory(3rdParty/imgui-1.88 EXCLUDE_FROM_ALL) add_executable( chip8 @@ -13,4 +15,5 @@ add_executable( target_compile_options(chip8 PRIVATE -Wall) -target_link_libraries(chip8 PRIVATE SDL2::SDL2) +target_link_libraries(chip8 PRIVATE glad SDL2 imgui) + diff --git a/README.md b/README.md index 86df1d1..bc2a325 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# CHIP-8 Emulator +# CHIP-8 Emulator (2019) A simple emulator for the CHIP-8. diff --git a/Source/Platform.cpp b/Source/Platform.cpp index b4199d5..cbd96b7 100644 --- a/Source/Platform.cpp +++ b/Source/Platform.cpp @@ -1,17 +1,34 @@ #include "Platform.hpp" -#include +#include +#include Platform::Platform(char const* title, int windowWidth, int windowHeight, int textureWidth, int textureHeight) { SDL_Init(SDL_INIT_VIDEO); - window = SDL_CreateWindow(title, 0, 0, windowWidth, windowHeight, SDL_WINDOW_SHOWN); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); - renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + window = SDL_CreateWindow( + title, + SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + windowWidth, windowHeight, + SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); - texture = SDL_CreateTexture( - renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, textureWidth, textureHeight); + gl_context = SDL_GL_CreateContext(window); + SDL_GL_SetSwapInterval(1); + gladLoadGL((GLADloadfunc)SDL_GL_GetProcAddress); + + glGenTextures(1, &framebuffer_texture); + glBindTexture(GL_TEXTURE_2D, framebuffer_texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 640, 320, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, 0); } Platform::~Platform() diff --git a/Source/Platform.hpp b/Source/Platform.hpp index bcf7e30..819c126 100644 --- a/Source/Platform.hpp +++ b/Source/Platform.hpp @@ -1,15 +1,14 @@ #pragma once #include - - -class SDL_Window; -class SDL_Renderer; -class SDL_Texture; +#include +#include class Platform { + friend class Imgui; + public: Platform(char const* title, int windowWidth, int windowHeight, int textureWidth, int textureHeight); ~Platform(); @@ -18,6 +17,8 @@ public: private: SDL_Window* window{}; + SDL_GLContext gl_context{}; + GLuint framebuffer_texture; SDL_Renderer* renderer{}; SDL_Texture* texture{}; };