- Created project files for ConnectTool including filters and user settings. - Added README.md with setup instructions and prerequisites for building the project. - Implemented imgui_hello.cpp as a simple Dear ImGui application using GLFW and OpenGL. - Developed online_game_tool.cpp for hosting and joining game rooms using Steam Networking. - Created p2p_chat.cpp for a peer-to-peer chat application utilizing Steam Networking. - Implemented steam_friends.cpp to display the user's Steam friends list. - Added TCP client and server classes for handling network communication. - Integrated TCP server and client functionality into online_game_tool for real-time data exchange.
103 lines
3.0 KiB
C++
103 lines
3.0 KiB
C++
#include <GLFW/glfw3.h>
|
|
#include <imgui.h>
|
|
#include <imgui_impl_glfw.h>
|
|
#include <imgui_impl_opengl3.h>
|
|
#include <iostream>
|
|
#include <vector>
|
|
#include <string>
|
|
#include <steam_api.h>
|
|
|
|
int main() {
|
|
// Initialize Steam API
|
|
if (!SteamAPI_Init()) {
|
|
std::cerr << "Failed to initialize Steam API" << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
// Initialize GLFW
|
|
if (!glfwInit()) {
|
|
std::cerr << "Failed to initialize GLFW" << std::endl;
|
|
SteamAPI_Shutdown();
|
|
return -1;
|
|
}
|
|
|
|
// Create window
|
|
GLFWwindow* window = glfwCreateWindow(1280, 720, "Steam Friends List", nullptr, nullptr);
|
|
if (!window) {
|
|
std::cerr << "Failed to create GLFW window" << std::endl;
|
|
glfwTerminate();
|
|
SteamAPI_Shutdown();
|
|
return -1;
|
|
}
|
|
glfwMakeContextCurrent(window);
|
|
glfwSwapInterval(1); // Enable vsync
|
|
|
|
// Initialize ImGui
|
|
IMGUI_CHECKVERSION();
|
|
ImGui::CreateContext();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
(void)io;
|
|
// Load Chinese font
|
|
io.Fonts->AddFontFromFileTTF("font.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesChineseSimplifiedCommon());
|
|
ImGui::StyleColorsDark();
|
|
|
|
// Initialize ImGui backends
|
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
|
ImGui_ImplOpenGL3_Init("#version 130");
|
|
|
|
// Get friends list
|
|
std::vector<std::string> friendsList;
|
|
int friendCount = SteamFriends()->GetFriendCount(k_EFriendFlagAll);
|
|
for (int i = 0; i < friendCount; ++i) {
|
|
CSteamID friendID = SteamFriends()->GetFriendByIndex(i, k_EFriendFlagAll);
|
|
const char* name = SteamFriends()->GetFriendPersonaName(friendID);
|
|
friendsList.push_back(std::string("Friend ") + std::to_string(i + 1) + ": " + name);
|
|
}
|
|
|
|
// Main loop
|
|
while (!glfwWindowShouldClose(window)) {
|
|
// Poll events
|
|
glfwPollEvents();
|
|
|
|
// Start ImGui frame
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
ImGui_ImplGlfw_NewFrame();
|
|
ImGui::NewFrame();
|
|
|
|
// Create a window for friends list
|
|
ImGui::Begin("Steam Friends List");
|
|
ImGui::Text("Number of friends: %d", friendCount);
|
|
ImGui::Separator();
|
|
if (friendCount > 0) {
|
|
ImGui::Columns(4, nullptr, true); // 4 columns, with borders
|
|
for (const auto& friendName : friendsList) {
|
|
ImGui::Text("%s", friendName.c_str());
|
|
ImGui::NextColumn();
|
|
}
|
|
ImGui::Columns(1); // Reset to 1 column
|
|
}
|
|
ImGui::End();
|
|
|
|
// Rendering
|
|
ImGui::Render();
|
|
int display_w, display_h;
|
|
glfwGetFramebufferSize(window, &display_w, &display_h);
|
|
glViewport(0, 0, display_w, display_h);
|
|
glClearColor(0.45f, 0.55f, 0.60f, 1.00f);
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
// Swap buffers
|
|
glfwSwapBuffers(window);
|
|
}
|
|
|
|
// Cleanup
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
ImGui_ImplGlfw_Shutdown();
|
|
ImGui::DestroyContext();
|
|
glfwDestroyWindow(window);
|
|
glfwTerminate();
|
|
SteamAPI_Shutdown();
|
|
|
|
return 0;
|
|
} |