diff --git a/Game/Game.rc b/Game/Game.rc new file mode 100644 index 0000000..ba47f47 --- /dev/null +++ b/Game/Game.rc @@ -0,0 +1,110 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_ICON1 ICON "res\\icons\\exeicon.ico" + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,0 + PRODUCTVERSION 1,0,0,1 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "TODO: " + VALUE "FileDescription", "Nothin' Fancy Example Application" + VALUE "FileVersion", "1.0.0.0" + VALUE "InternalName", "Game.exe" + VALUE "LegalCopyright", "Copyright (C) 2021 Grayson Riffe" + VALUE "OriginalFilename", "Game.exe" + VALUE "ProductName", "Nothin' Fancy" + VALUE "ProductVersion", "1.0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/Game/Game.vcxproj b/Game/Game.vcxproj index 9e6899e..3ee775f 100644 --- a/Game/Game.vcxproj +++ b/Game/Game.vcxproj @@ -188,8 +188,15 @@ + + + + + + + diff --git a/Game/Game.vcxproj.filters b/Game/Game.vcxproj.filters index 204f178..2dc0f2c 100644 --- a/Game/Game.vcxproj.filters +++ b/Game/Game.vcxproj.filters @@ -26,5 +26,18 @@ Header Files + + Header Files + + + + + Resource Files + + + + + Resource Files + \ No newline at end of file diff --git a/Game/res/icons/exeicon.ico b/Game/res/icons/exeicon.ico new file mode 100644 index 0000000..8fa2aee Binary files /dev/null and b/Game/res/icons/exeicon.ico differ diff --git a/Game/resource.h b/Game/resource.h new file mode 100644 index 0000000..db97781 --- /dev/null +++ b/Game/resource.h @@ -0,0 +1,16 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Game.rc +// +#define IDI_ICON1 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/Game/src/MainState.cpp b/Game/src/MainState.cpp index 6872c7a..7a9866e 100644 --- a/Game/src/MainState.cpp +++ b/Game/src/MainState.cpp @@ -2,17 +2,73 @@ void MainState::onEnter() { Log("MainState onEnter!"); - + camera->setType(nf::Camera::Type::FIRST_PERSON); + ap.load("CubeTest.nfpack"); + test.create(ap["spec.obj"]); + test.setPosition(0.0, 0.0, -5.0); + plane.create(nf::BaseAssets::plane); + plane.setPosition(0.0, -2.0, 0.0); + plane.setScale(10.0); + text.create("This is a test text.", nf::Vec2(0.1, 0.025), nf::Vec3(0.7)); + text.centered(true); + uiTex.create(nf::BaseAssets::logo, nf::Vec2(0.025, 0.025), 0.5); + button.create(nf::Vec2(0.8, 0.025), "Reset"); + light.create(nf::Vec3(0.0, 5.0, 0.0), nf::Vec3(1.0, 1.0, 1.0), 1.3); + cm.create(nf::BaseAssets::cubemap); } void MainState::update(double deltaTime) { + if (app->isKeyPressed(NFI_U)) + camera->setType(nf::Camera::Type::UI); + if (app->isKeyPressed(NFI_P)) + camera->setType(nf::Camera::Type::FIRST_PERSON); + double speed = 5.0; + if (camera->getType() == nf::Camera::Type::FIRST_PERSON) { + if (app->isKeyHeld(NFI_SHIFT)) + speed = 20.0; + else + speed = 5.0; + if (app->isKeyHeld(NFI_W)) + camera->moveForward(speed * deltaTime); + if (app->isKeyHeld(NFI_S)) + camera->moveBackward(speed * deltaTime); + if (app->isKeyHeld(NFI_D)) + camera->moveRight(speed * deltaTime); + if (app->isKeyHeld(NFI_A)) + camera->moveLeft(speed * deltaTime); + } + + float offset = 0.5f; + if (app->isKeyHeld(NFI_UP)) + yrot += offset; + if (app->isKeyHeld(NFI_DOWN)) + yrot -= offset; + if (app->isKeyHeld(NFI_LEFT)) + xrot += offset; + if (app->isKeyHeld(NFI_RIGHT)) + xrot -= offset; + test.setRotation(-yrot, -xrot, 0.0); + + text.setText("FPS: " + std::to_string(app->getFPS())); + + if (button.isClicked()) + app->changeState("Main State"); + if (app->isKeyPressed(NFI_ESCAPE)) + app->quit(); } void MainState::render(nf::Renderer& renderer) { - + renderer.render(test); + renderer.render(plane); + renderer.render(text); + renderer.render(uiTex); + renderer.render(button); + renderer.render(light); + renderer.render(cm); } void MainState::onExit() { Log("MainState onExit!"); + xrot = yrot = 0.0f; } \ No newline at end of file diff --git a/Game/src/include/MainState.h b/Game/src/include/MainState.h index 1111322..64ce382 100644 --- a/Game/src/include/MainState.h +++ b/Game/src/include/MainState.h @@ -10,5 +10,15 @@ public: void onExit() override; private: + nf::AssetPack ap; + nf::Entity test; + nf::Entity plane; + nf::Text text; + nf::UITexture uiTex; + nf::Button button; + nf::Light light; + nf::Cubemap cm; + + float xrot, yrot; }; \ No newline at end of file diff --git a/NFPackCreator/AssetBuild/base/textures/defaultwindowicon.png b/NFPackCreator/AssetBuild/base/textures/defaultwindowicon.png new file mode 100644 index 0000000..5691d1b Binary files /dev/null and b/NFPackCreator/AssetBuild/base/textures/defaultwindowicon.png differ diff --git a/NothinFancy/src/Application.cpp b/NothinFancy/src/Application.cpp index d1aa2b2..8ec5490 100644 --- a/NothinFancy/src/Application.cpp +++ b/NothinFancy/src/Application.cpp @@ -10,6 +10,8 @@ namespace nf { Application::Application(Config& config) : m_currentConfig(config), m_running(false), + m_quit(false), + m_customWindowIconSet(false), m_altWidth(1280), m_altHeight(720), m_defaultStateAdded(false), @@ -34,7 +36,8 @@ namespace nf { } void Application::setWindowIcon(HANDLE hIcon) { - SendMessage(m_window, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); + m_customWindowIconSet = true; + SendMessage(m_window, WM_SETICON, ICON_BIG, (LPARAM)hIcon); SendMessage(m_window, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); } //TODO: Test these top-level features @@ -93,6 +96,10 @@ namespace nf { mainThread.join(); } + bool Application::isCustomWindowIcon() { + return m_customWindowIconSet; + } + void Application::changeState(const std::string& stateName) { if (m_states.find(stateName) == m_states.end()) Error("State \"" + (std::string)stateName + (std::string)"\" doesn't exist!"); diff --git a/NothinFancy/src/Renderer/Drawable/UITexture.cpp b/NothinFancy/src/Renderer/Drawable/UITexture.cpp index e148b1e..e056a73 100644 --- a/NothinFancy/src/Renderer/Drawable/UITexture.cpp +++ b/NothinFancy/src/Renderer/Drawable/UITexture.cpp @@ -81,7 +81,7 @@ namespace nf { posX + width, posY, posX + width, posY + height }; - + m_texture->bind(); m_vao->setBufferData(0, vb, sizeof(vb)); shader->setUniform("opacity", m_opacity); diff --git a/NothinFancy/src/Renderer/Renderer.cpp b/NothinFancy/src/Renderer/Renderer.cpp index 23b6de5..ca84f7d 100644 --- a/NothinFancy/src/Renderer/Renderer.cpp +++ b/NothinFancy/src/Renderer/Renderer.cpp @@ -3,6 +3,7 @@ #include "GL/glew.h" #include "GL\wglew.h" #include "glm/glm.hpp" +#include "stb_image.h" #include "Application.h" #include "Shader.h" @@ -69,6 +70,22 @@ namespace nf { loadBaseAssets(); + if (!m_app->isCustomWindowIcon()) { + ATexture& windowTex = *(ATexture*)m_baseAP["defaultwindowicon.png"]; + int width, height, nChannels; + unsigned char* tex = stbi_load_from_memory((const unsigned char*)windowTex.data, windowTex.size, &width, &height, &nChannels, 0); + std::vector pixels(width * height * 4); + for (unsigned int i = 0; i < pixels.size() / 4; i++) { + pixels[i * 4 + 0] = tex[i * 4 + 2]; + pixels[i * 4 + 1] = tex[i * 4 + 1]; + pixels[i * 4 + 2] = tex[i * 4 + 0]; + pixels[i * 4 + 3] = tex[i * 4 + 3]; + } + HICON windowIcon = CreateIcon(GetModuleHandle(NULL), width, height, 1, 32, NULL, &pixels[0]); + SendMessage(m_app->getWindow(), WM_SETICON, ICON_BIG, (LPARAM)windowIcon); + SendMessage(m_app->getWindow(), WM_SETICON, ICON_SMALL, (LPARAM)windowIcon); + } + float fadeVB[] = { -1.0, -1.0, 1.0, -1.0, diff --git a/NothinFancy/src/include/Application.h b/NothinFancy/src/include/Application.h index 1f0ccb4..d09b1f3 100644 --- a/NothinFancy/src/include/Application.h +++ b/NothinFancy/src/include/Application.h @@ -23,6 +23,7 @@ namespace nf { void addDefaultState(const std::string& stateName); const std::string& getDefaultState(); void run(); + bool isCustomWindowIcon(); void changeState(const std::string& stateName); Gamestate* getCurrentState(); void showWindow(bool show); @@ -59,6 +60,7 @@ namespace nf { HINSTANCE m_hInst; LPCWSTR m_wclassName; HWND m_window; + bool m_customWindowIconSet; LONG m_defaultWindowStyle; unsigned int m_altWidth, m_altHeight; diff --git a/NothinFancy/src/include/NothinFancy.h b/NothinFancy/src/include/NothinFancy.h index 83d41cb..f4896fe 100644 --- a/NothinFancy/src/include/NothinFancy.h +++ b/NothinFancy/src/include/NothinFancy.h @@ -77,6 +77,7 @@ namespace nf { void addDefaultState(const std::string& stateName); const std::string& getDefaultState(); void run(); + bool isCustomWindowIcon(); void changeState(const std::string& stateName); Gamestate* getCurrentState(); void showWindow(bool show); @@ -113,6 +114,7 @@ namespace nf { HINSTANCE m_hInst; LPCWSTR m_wclassName; HWND m_window; + bool m_customWindowIconSet; LONG m_defaultWindowStyle; unsigned int m_altWidth, m_altHeight;