Added the example application; Added the default window icon

This commit is contained in:
Grayson Riffe (Laptop) 2021-09-11 17:39:18 -05:00
parent 805a1cef1f
commit 30e725b2f4
13 changed files with 244 additions and 4 deletions

110
Game/Game.rc Normal file
View File

@ -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: <Company name>"
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

View File

@ -188,8 +188,15 @@
<ClCompile Include="src\MainState.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h" />
<ClInclude Include="src\include\MainState.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Game.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="res\icons\exeicon.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@ -26,5 +26,18 @@
<ClInclude Include="src\include\MainState.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Game.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="res\icons\exeicon.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>

BIN
Game/res/icons/exeicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 649 KiB

16
Game/resource.h Normal file
View File

@ -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

View File

@ -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;
}

View File

@ -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;
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

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!");

View File

@ -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);

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,

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;

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;