Added the example application; Added the default window icon

This commit is contained in:
grayson committed 2021-09-11 17:39:18 -05:00
1 parent 805a1cef1f
commit 30e725b2f4
13 files changed
+244 -4

No files matched your search

+8 -1
View File
@@ -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!");
@@ -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);
+17
View File
@@ -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<unsigned char> 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,
+2
View File
@@ -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;
+2
View File
@@ -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;