Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI + Model Loading #56

Merged
merged 100 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
7570f5b
imgui attempt 1
Tyler-Lentz Apr 25, 2024
85cd764
start custom gui
Tyler-Lentz Apr 25, 2024
fb455ed
start laying out widgets
Tyler-Lentz Apr 25, 2024
49c1f47
more gui setup
Tyler-Lentz Apr 26, 2024
0230929
add untested font loading code
Tyler-Lentz Apr 26, 2024
c4a51a4
add zlib to nix shell
atar13 Apr 27, 2024
a9bc44c
add assimp and stb
atar13 Apr 28, 2024
470f26f
model loading
atar13 Apr 28, 2024
744c7aa
make target to automate model downloads
atar13 Apr 28, 2024
87e5ddb
successfully running font loading code
Tyler-Lentz Apr 28, 2024
a4dc0be
theoretically this should be rendering fonts
Tyler-Lentz Apr 28, 2024
777fa9a
random location rendering for debuggin
Tyler-Lentz Apr 28, 2024
675bcef
docs and cleanup
atar13 Apr 29, 2024
758ef8e
pass std::string to shader constructor
atar13 Apr 30, 2024
42c1888
rendering... something
Tyler-Lentz Apr 30, 2024
476cfbd
fix incorrect defaults for dyntext options
Tyler-Lentz Apr 30, 2024
3337619
Enabled polygon fill for text drawing, removed imgui from CMakeLists
dmin12 Apr 30, 2024
192c8e7
click handling logic
Tyler-Lentz Apr 30, 2024
95564c2
integrate w/ david's text fixing code
Tyler-Lentz Apr 30, 2024
9a93035
merge w/ camera branch
Tyler-Lentz Apr 30, 2024
ddce9b7
first click handling attmept
Tyler-Lentz Apr 30, 2024
0bc2cfd
fix click hitbox for gui
Tyler-Lentz Apr 30, 2024
48b6390
in progress: flexbox horrors
Tyler-Lentz Apr 30, 2024
2286c73
in progress
Tyler-Lentz Apr 30, 2024
7f9d9c1
fix compile issue
Tyler-Lentz Apr 30, 2024
591e33b
working flexbox!
Tyler-Lentz May 1, 2024
1328df8
add center alignment to flexbox
Tyler-Lentz May 1, 2024
cebcc2a
start image loading
Tyler-Lentz May 1, 2024
c73f6d1
broken img loading
Tyler-Lentz May 1, 2024
718e861
fix center and add way to center in entire screen
Tyler-Lentz May 1, 2024
ef164ab
attempt to render lobby menu BUT NOTHING IS F---- WORKING RIGHT!!!
Tyler-Lentz May 1, 2024
bf72365
render lobby screen, but it seg faults with more than 1
Tyler-Lentz May 1, 2024
3f86eae
working lobby screen with dummy data
Tyler-Lentz May 1, 2024
5c0a54e
add hover handling
Tyler-Lentz May 1, 2024
798896b
change borrow to template function
Tyler-Lentz May 1, 2024
d04c739
create CenterText macro widget for easier use
Tyler-Lentz May 1, 2024
f7948cc
add text input widget
Tyler-Lentz May 2, 2024
27c91f1
scuffed caret behavior for text input :alien:
Tyler-Lentz May 2, 2024
6fc94e9
allow holding backspace for deletions
Tyler-Lentz May 2, 2024
f97c2d8
remove lato because it doesn't fit fantasy theme
Tyler-Lentz May 2, 2024
2478d26
merge with dev
Tyler-Lentz May 2, 2024
6eb9371
fix lobby still broadcasting after server start
Tyler-Lentz May 2, 2024
cc0372d
in progress refactor
Tyler-Lentz May 2, 2024
7141e4a
refactor gui layout to be more in the gui class
Tyler-Lentz May 2, 2024
6c40d5a
make lobby name serializable and sent to player
Tyler-Lentz May 2, 2024
e65a9f5
make lobby broadcast say accurate player info
Tyler-Lentz May 2, 2024
53ccd2d
minor refactor for lobby broadcast continued
Tyler-Lentz May 2, 2024
0c7adf7
add keyboard input for player name
Tyler-Lentz May 2, 2024
93bbd14
add message in lobby browser if no lobby found
Tyler-Lentz May 2, 2024
61b1574
start documentation
Tyler-Lentz May 2, 2024
9939ad3
continue documenting
Tyler-Lentz May 2, 2024
4cfc2ab
continue documentation
Tyler-Lentz May 3, 2024
b7e3b4d
move assets to assets folder, and continue documentation
Tyler-Lentz May 3, 2024
a02ccc3
refactor how shaders are passed around in the gui land
Tyler-Lentz May 3, 2024
227eb53
finish documentation and make unit tests compile
Tyler-Lentz May 3, 2024
32b84f2
attempt to fix windows compile
Tyler-Lentz May 3, 2024
d287fc6
load and render model materials
atar13 May 3, 2024
1698639
refactor sprite loading but it still doesn't work...
Tyler-Lentz May 3, 2024
0552cc9
fix frag and vert shaders being swapped, but still doesn't work
Tyler-Lentz May 3, 2024
a2faa76
messing around w/ stuff and it still doesn't work
Tyler-Lentz May 3, 2024
24d4f20
merge dev and can walk around textured warren bear
atar13 May 4, 2024
f263d92
move graphics models/materials/textures to assets/graphics
atar13 May 4, 2024
f8b35f2
update make pull_models to pull entire drive folder
atar13 May 4, 2024
070d07d
add renderable class
atar13 May 5, 2024
914415c
populated objectTypeToString
atar13 May 5, 2024
4bd91e2
clean up client draw function
atar13 May 5, 2024
29d6826
renamed solid color shaders to cube shader
atar13 May 5, 2024
07dfe93
lint
atar13 May 5, 2024
481bcf4
Modified existing texture code using LearnOpenGL tutorial
dmin12 May 6, 2024
1ad3754
Client main using LearnOpenGL texture code
dmin12 May 6, 2024
7fe6abd
Resolved texture rendering from cull_face
dmin12 May 6, 2024
f784d70
add TODO comments to remind myself what I need to do
Tyler-Lentz May 6, 2024
77c98f6
refactor font loading to only load one size and then scale, but text …
Tyler-Lentz May 6, 2024
8745871
messing around with stuff
Tyler-Lentz May 6, 2024
ff8d4ba
more fiddling around...
Tyler-Lentz May 6, 2024
8f80a52
JESUS CHRIST HOW WAS THIS CAUSING THE FLICKERING
Tyler-Lentz May 6, 2024
670b6e9
switch font render to not load in separate textures for different sizes
Tyler-Lentz May 6, 2024
54d21ba
Removed problematic call to glUniform in StaticImg::render()
dmin12 May 7, 2024
70a9903
add player to camera pos
atar13 May 7, 2024
ca99983
windows fixes
atar13 May 7, 2024
1d6d90c
working variable screen size with config
Tyler-Lentz May 7, 2024
b502ae9
refactor gui shader loading
Tyler-Lentz May 7, 2024
5cc7345
see other players and don't render yourself
atar13 May 7, 2024
5c48cbd
remove old code
Tyler-Lentz May 7, 2024
8ef42f9
rendering other players works?!
atar13 May 7, 2024
90a9bb9
merge w/ dev
Tyler-Lentz May 7, 2024
e4d44b8
Merge remote-tracking branch 'origin/dev' into feat/obj-loading
atar13 May 7, 2024
2b092c7
merge with anthony's model code w/o solving all conflicts
Tyler-Lentz May 7, 2024
5e6ef07
resolve merge
Tyler-Lentz May 7, 2024
a16c2ee
fix serialize test f'ing up
Tyler-Lentz May 7, 2024
f4bbadd
attempt to fix actions & compiling
Tyler-Lentz May 7, 2024
4ad15bd
add loading screen
Tyler-Lentz May 7, 2024
6b70a20
exit button calls glfwShouldClose instead of glfwDestroyWindow
atar13 May 7, 2024
ce716a7
fix cube min/max
Tyler-Lentz May 7, 2024
58dfed8
merge w/ dev
Tyler-Lentz May 7, 2024
1b9f9c1
fix lint
Tyler-Lentz May 7, 2024
4cb9cbd
make player eye level a constant
Tyler-Lentz May 7, 2024
439ab1c
add warren bear spawning
Tyler-Lentz May 7, 2024
ff7caca
add spawnpoint to default maze so hopefully it works in shared test a…
Tyler-Lentz May 8, 2024
8e29da6
fix troll speedrun sound for meme
Tyler-Lentz May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS True)

# Tell CMake to ignore warnings from stuff in our dependencies. Surely GLM
# knows what it is doing... https://7tv.app/emotes/61e8fae862858c6406126ced
IF (NOT WIN32)
set_property(
DIRECTORY build
PROPERTY COMPILE_OPTIONS "-w"
)
ENDIF()

# Add google test to CMake
add_subdirectory(dependencies/google-test)
Expand Down Expand Up @@ -57,6 +63,8 @@ add_custom_target(lint
--inline-suppr
# return error exit code 1 on failures
--error-exitcode=1
# ignore certain warnings that are annoying
--suppress=unusedVariable
# tell it about our include directory
-I ${CMAKE_SOURCE_DIR}/include
# only check include and src
Expand All @@ -66,4 +74,9 @@ add_custom_target(lint
-i${CMAKE_SOURCE_DIR}/src/client/tests
-i${CMAKE_SOURCE_DIR}/src/server/tests
-i${CMAKE_SOURCE_DIR}/src/shared/tests
)
)

add_custom_target(pull_models
COMMAND
gdown 1N7a5cDgMcXbPO0RtgznnEo-1XUfdMScM -O ${CMAKE_SOURCE_DIR}/assets/graphics --folder
)
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ Depending on where you need to link the library (client, server, shared), you wi
- [C++ Intellisense](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)
- [General Productivity](https://marketplace.visualstudio.com/items?itemName=jirkavrba.subway-surfers)

## Models

You can download models from our Google Drive folder [here](https://drive.google.com/drive/folders/1N7a5cDgMcXbPO0RtgznnEo-1XUfdMScM?usp=sharing) and place them in `src/client/models`. Alternatively, you can install [gdown](https://github.com/wkentaro/gdown) and run `make pull_models` to automatically pull them.

## Documentation

View deployed documentation [here](https://cse125.ucsd.edu/2024/cse125g3/site/docs/html/)
Expand Down
Binary file added assets/.DS_Store
Binary file not shown.
Binary file added assets/fonts/AncientModernTales-a7Po.ttf
Binary file not shown.
2 changes: 2 additions & 0 deletions assets/graphics/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
Binary file added assets/imgs/Yoshi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/imgs/awesomeface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/imgs/pikachu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
"server_port": 2355
},
"server": {
"lobby_name": "My Test Lobby",
"lobby_broadcast": false,
"lobby_name": "Unnamed Lobby",
"lobby_broadcast": true,
"max_players": 1
},
"client": {
"default_name": "Player",
"lobby_discovery": false
"default_name": "John Doe",
"lobby_discovery": true,
"window_width": 1500
}
}
15 changes: 15 additions & 0 deletions dependencies/assimp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include(FetchContent)

FetchContent_Declare(assimp
GIT_REPOSITORY https://github.com/assimp/assimp
GIT_TAG v5.3.1
GIT_PROGRESS TRUE
)

FetchContent_MakeAvailable(assimp)

set(ASSIMP_INCLUDE_DIRS
${CMAKE_BINARY_DIR}/_deps/assimp-src/include/
${CMAKE_BINARY_DIR}/_deps/assimp-build/include/
PARENT_SCOPE
)
9 changes: 9 additions & 0 deletions dependencies/freetype/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#shoutout chatgpt

FetchContent_Declare(
freetype
GIT_REPOSITORY https://gitlab.freedesktop.org/freetype/freetype.git
GIT_TAG VER-2-13-2
)

FetchContent_MakeAvailable(freetype)
6 changes: 3 additions & 3 deletions dependencies/glew/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ FetchContent_Declare(glew

FetchContent_MakeAvailable(glew)

# find_package(GLEW 2.0 REQUIRED)
# target_link_libraries(Starting GLEW::GLEW)

set(GLEW_INCLUDE_DIRS
${CMAKE_BINARY_DIR}/_deps/glew-src/include
PARENT_SCOPE)
15 changes: 8 additions & 7 deletions dependencies/imgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ FetchContent_MakeAvailable(imgui)
set(imgui-directory ${CMAKE_BINARY_DIR}/_deps/imgui-src/ PARENT_SCOPE)
set(imgui-directory ${CMAKE_BINARY_DIR}/_deps/imgui-src/)

set(imgui-source
${imgui-directory}/imconfig.h
${imgui-directory}/imgui.h
set(IMGUI_INCLUDE_DIRS
${imgui-directory}
${imgui-directory}/backends
PARENT_SCOPE
)

set(IMGUI_SOURCES
${imgui-directory}/imgui.cpp
${imgui-directory}/imgui_draw.cpp
${imgui-directory}/imgui_internal.h
${imgui-directory}/imgui_widgets.cpp
${imgui-directory}/imstb_rectpack.h
${imgui-directory}/imstb_textedit.h
${imgui-directory}/imstb_truetype.h
${imgui-directory}/imgui_tables.cpp
${imgui-directory}/imgui_demo.cpp
${imgui-directory}/backends/imgui_impl_glfw.cpp
${imgui-directory}/backends/imgui_impl_opengl3.cpp
${imgui-directory}misc/cpp/imgui_stdlib.cpp
PARENT_SCOPE
)
11 changes: 11 additions & 0 deletions dependencies/stb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include(FetchContent)

FetchContent_Declare(stb
GIT_REPOSITORY https://github.com/nothings/stb
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(stb)

set(STB_INCLUDE_DIRS
${CMAKE_BINARY_DIR}/_deps/stb-src/
PARENT_SCOPE)
2 changes: 2 additions & 0 deletions include/client/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Camera {
glm::mat4 getViewProj();
void updatePos(glm::vec3 pos);

glm::vec3 getPos();

private:
// Perspective controls
float FOV; // Field of View Angle (degrees)
Expand Down
51 changes: 42 additions & 9 deletions include/client/client.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#pragma once

#include "client/core.hpp"

#include <iostream>
#include <ostream>
#include <utility>
#include <unordered_map>
#include <chrono>

#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/filesystem.hpp>

#include "client/cube.hpp"
#include "client/lightsource.hpp"
#include "client/shader.hpp"
#include "client/model.hpp"
#include "client/util.hpp"
#include "client/lobbyfinder.hpp"
#include "client/gui/gui.hpp"
#include "client/camera.hpp"

//#include "shared/game/gamestate.hpp"
Expand All @@ -22,20 +25,35 @@
#include "shared/network/session.hpp"
#include "shared/utilities/config.hpp"

#define WINDOW_WIDTH Client::getWindowSize().x
#define WINDOW_HEIGHT Client::getWindowSize().y

// position something a "frac" of the way across the screen
// e.g. WIDTH_FRAC(1, 4) -> a fourth of the way from the left
// HEIGHT_FRAC(2, 3) -> two thirds of the way from the bottom
#define FRAC_WINDOW_WIDTH(num, denom) Client::window_width * static_cast<float>(num) / static_cast<float>(denom)
#define FRAC_WINDOW_HEIGHT(num, denom) Client::window_height * static_cast<float>(num) / static_cast<float>(denom)

using namespace boost::asio::ip;

class Client {

public:
// Callbacks
void displayCallback();

void idleCallback(boost::asio::io_context& context);
void handleKeys(int eid, int keyType, bool keyHeld, bool *eventSent, glm::vec3 movement = glm::vec3(0.0f));

// Bound window callbacks
static void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods);
static void mouseCallback(GLFWwindow *window, double xposIn, double yposIn);
static void mouseCallback(GLFWwindow* window, double xposIn, double yposIn);
static void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
static void charCallback(GLFWwindow* window, unsigned int codepoint);

static glm::vec2 getWindowSize();

static time_t getTimeOfLastKeystroke();

// Getter / Setters
GLFWwindow* getWindow() { return window; }
Expand All @@ -49,19 +67,27 @@ class Client {
void draw();
void connectAndListen(std::string ip_addr);

boost::filesystem::path getRootPath();

private:
void processClientInput();
void processServerInput(boost::asio::io_context& context);

SharedGameState gameState;

float cubeMovementDelta = 0.05f;
std::shared_ptr<Shader> cube_shader;
std::shared_ptr<Shader> model_shader;
std::shared_ptr<Shader> light_source_shader;

std::unique_ptr<Model> player_model;
std::unique_ptr<Model> bear_model;
std::unique_ptr<LightSource> light_source;

float playerMovementDelta = 0.05f;

GLFWwindow *window;
GLuint cubeShaderProgram;

friend class gui::GUI;
gui::GUI gui;
gui::GUIState gui_state;
Camera *cam;

// Flags
Expand All @@ -77,17 +103,24 @@ class Client {
static bool cam_is_held_right;
static bool cam_is_held_left;

static bool is_left_mouse_down;
static bool is_click_available;
static float mouse_xpos;
static float mouse_ypos;

static int window_width;
static int window_height;

static time_t time_of_last_keystroke;

GameConfig config;
tcp::resolver resolver;
tcp::socket socket;

LobbyFinder lobby_finder;

/// @brief Generate endpoints the client can connect to
basic_resolver_results<class boost::asio::ip::tcp> endpoints;
std::shared_ptr<Session> session;

boost::filesystem::path root_path;
};

11 changes: 11 additions & 0 deletions include/client/constants.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#define MIN_WINDOW_WIDTH 900
#define MIN_WINDOW_HEIGHT 600

// The screen width that's defined as 1:1, from which other
// resolutions can calculate pixel sizes
#define UNIT_WINDOW_WIDTH 1500
#define UNIT_WINDOW_HEIGHT 1000

#define PLAYER_EYE_LEVEL 2.0f
3 changes: 2 additions & 1 deletion include/client/core.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
16 changes: 8 additions & 8 deletions include/client/cube.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "client/core.hpp"
#include "client/renderable.hpp"

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/transform.hpp>
Expand All @@ -11,23 +12,22 @@
#include <ostream>
#include <vector>

class Cube {
class Cube : public Renderable {
public:
Cube(glm::vec3 newColor, glm::vec3 scale);
explicit Cube(glm::vec3 newColor);
~Cube();

void draw(glm::mat4 viewProjMat, GLuint shader, bool fill);
void update(glm::vec3 new_pos);
void update_delta(glm::vec3 delta);

void draw(std::shared_ptr<Shader> shader,
glm::mat4 viewProj,
glm::vec3 camPos,
glm::vec3 lightPos,
bool fill) override;
private:
GLuint VAO;
GLuint VBO_positions, VBO_normals, EBO;

glm::mat4 model;
glm::vec3 color;


// Cube Information
std::vector<glm::vec3> positions;
std::vector<glm::vec3> normals;
Expand Down
63 changes: 63 additions & 0 deletions include/client/gui/font/font.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#pragma once

#include "client/core.hpp"

#include <cstddef>
#include <string>
#include <unordered_map>

namespace gui::font {


/**
* Abstract representation of the different fonts to use in our game
*
* NOTE: currently I haven't found a good font for "Text", so both of these
* map to the same font.
*/
enum class Font {
MENU,
TEXT
};

/**
* Mappings from our specified abstract fonts to the file to load
*/
std::string getFilepath(Font font);

/**
* Preset colors for text
*/
enum class Color {
BLACK,
RED,
BLUE,
GRAY,
WHITE,
TORCHLIGHT_GAMES
};

/**
* Mapping from preset font colors to RGB values
*/
glm::vec3 getRGB(Color color);

const int UNIT_LARGE_SIZE_PX = 128; // how many pixels a small font is on the unit screen size
enum class Size {
SMALL,
MEDIUM,
LARGE,
XLARGE
};
const std::unordered_map<Size, float> SIZE_TO_SCALE = {
{Size::SMALL, 0.25f},
{Size::MEDIUM, 0.50f},
{Size::LARGE, 1.0f},
{Size::XLARGE, 2.0f},
};

int getFontSizePx(Size size);
float getScaleFactor(Size size);


}
Loading