增加wayland下的窗口图标
This commit is contained in:
parent
8718b67942
commit
d88811e125
|
@ -1,2 +1,3 @@
|
||||||
build
|
build
|
||||||
|
release-build
|
||||||
.vscode
|
.vscode
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
#ifndef NATIVE_H
|
||||||
|
#define NATIVE_H
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
// A temprary .desktop needed under wayland
|
||||||
|
std::string desktop_file =
|
||||||
|
"[Desktop Entry]\n"
|
||||||
|
"Name=jungle\n"
|
||||||
|
"Icon={cwd}/icon.png\n"
|
||||||
|
"Type=Application\n"
|
||||||
|
"Categories=Game;\n";
|
||||||
|
std::string desktop_path = "{home}/.local/share/applications/jungle.desktop";
|
||||||
|
std::string home_path = std::getenv("HOME");
|
||||||
|
|
||||||
|
void nativeSetIcon()
|
||||||
|
{
|
||||||
|
// setting desktop file
|
||||||
|
std::string cwd = "{cwd}";
|
||||||
|
int pos = desktop_file.find(cwd);
|
||||||
|
desktop_file.replace(pos, cwd.length(), std::filesystem::current_path());
|
||||||
|
std::string home = "{home}";
|
||||||
|
pos = desktop_path.find(home);
|
||||||
|
desktop_path.replace(pos, home.length(), home_path);
|
||||||
|
std::ofstream desktop(desktop_path);
|
||||||
|
desktop << desktop_file;
|
||||||
|
desktop.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
35
src/main.cpp
35
src/main.cpp
|
@ -10,13 +10,14 @@
|
||||||
#include "shader_m.h"
|
#include "shader_m.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "cube_model.h"
|
#include "cube_model.h"
|
||||||
|
#include "native.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
//#include <pthread.h>
|
// #include <pthread.h>
|
||||||
//#include <unistd.h>
|
// #include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
@ -24,7 +25,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
@ -68,13 +69,17 @@ int curr_x;
|
||||||
int curr_y;
|
int curr_y;
|
||||||
|
|
||||||
// monitors controlling
|
// monitors controlling
|
||||||
int monitor_count;
|
// int monitor_count;
|
||||||
// GLFWmonitor **monitors;
|
// GLFWmonitor **monitors;
|
||||||
|
|
||||||
GLFWimage icon;
|
GLFWimage icon;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
#ifdef __linux__
|
||||||
|
nativeSetIcon();
|
||||||
|
#endif
|
||||||
|
|
||||||
// std::cout << "debug";
|
// std::cout << "debug";
|
||||||
// glfw: initialize and configure
|
// glfw: initialize and configure
|
||||||
// ------------------------------
|
// ------------------------------
|
||||||
|
@ -132,7 +137,6 @@ int main()
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
Shader ourShader("demo.vs", "demo.fs");
|
Shader ourShader("demo.vs", "demo.fs");
|
||||||
|
|
||||||
|
|
||||||
unsigned int VBO, VAO;
|
unsigned int VBO, VAO;
|
||||||
glGenVertexArrays(1, &VAO);
|
glGenVertexArrays(1, &VAO);
|
||||||
glGenBuffers(1, &VBO);
|
glGenBuffers(1, &VBO);
|
||||||
|
@ -180,7 +184,6 @@ int main()
|
||||||
}
|
}
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
|
|
||||||
|
|
||||||
// tell opengl for each sampler to which texture unit it belongs to (only has to be done once)
|
// tell opengl for each sampler to which texture unit it belongs to (only has to be done once)
|
||||||
// -------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------
|
||||||
ourShader.use();
|
ourShader.use();
|
||||||
|
@ -256,13 +259,14 @@ int main()
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
timer += deltaTime;
|
timer += deltaTime;
|
||||||
if(timer > 0.3f){
|
if (timer > 0.3f)
|
||||||
|
{
|
||||||
glfwSetWindowTitle(window, ("fps:" + std::to_string(int(1.0f / deltaTime)) + " X:" + std::to_string(camera.Position.x) + " Y:" + std::to_string(camera.Position.y) + " Z:" + std::to_string(camera.Position.z)).c_str());
|
glfwSetWindowTitle(window, ("fps:" + std::to_string(int(1.0f / deltaTime)) + " X:" + std::to_string(camera.Position.x) + " Y:" + std::to_string(camera.Position.y) + " Z:" + std::to_string(camera.Position.z)).c_str());
|
||||||
timer -= 0.3f;
|
timer -= 0.3f;
|
||||||
}
|
}
|
||||||
|
|
||||||
//double renderTime = glfwGetTime() - lastFrame;
|
// double renderTime = glfwGetTime() - lastFrame;
|
||||||
// delay_fps(fps, (int)(renderTime * 1000 * 1000));
|
// delay_fps(fps, (int)(renderTime * 1000 * 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
running = false;
|
running = false;
|
||||||
|
@ -396,8 +400,8 @@ void focus_callback(GLFWwindow *window, int focused)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void glfwDump(GLFWwindow *window)
|
||||||
void glfwDump(GLFWwindow *window){
|
{
|
||||||
int clientAPI = glfwGetWindowAttrib(window, GLFW_CLIENT_API);
|
int clientAPI = glfwGetWindowAttrib(window, GLFW_CLIENT_API);
|
||||||
int contextAPI = glfwGetWindowAttrib(window, GLFW_CONTEXT_CREATION_API);
|
int contextAPI = glfwGetWindowAttrib(window, GLFW_CONTEXT_CREATION_API);
|
||||||
int contextVersionMajor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
|
int contextVersionMajor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
|
||||||
|
@ -424,7 +428,10 @@ void glfwDump(GLFWwindow *window){
|
||||||
std::cout << "Forward compatibility: " << forwardCompat << std::endl;
|
std::cout << "Forward compatibility: " << forwardCompat << std::endl;
|
||||||
std::cout << "Debug context: " << debugContext << std::endl;
|
std::cout << "Debug context: " << debugContext << std::endl;
|
||||||
|
|
||||||
std::cout << "Window size: " << " width-" << windowSizeWidth << " height-" << windowSizeHeight << std::endl;
|
std::cout << "Window size: "
|
||||||
std::cout << "FrameBuffer size: " << " width-" << bufferSizeWidth << " height-" << bufferSizeHeight << std::endl;
|
<< " width-" << windowSizeWidth << " height-" << windowSizeHeight << std::endl;
|
||||||
std::cout << "Window Scale: " << " X-" << bufferSizeWidth << " Y-" << bufferSizeHeight << std::endl;
|
std::cout << "FrameBuffer size: "
|
||||||
|
<< " width-" << bufferSizeWidth << " height-" << bufferSizeHeight << std::endl;
|
||||||
|
std::cout << "Window Scale: "
|
||||||
|
<< " X-" << bufferSizeWidth << " Y-" << bufferSizeHeight << std::endl;
|
||||||
}
|
}
|
Loading…
Reference in New Issue