Compare commits
14 Commits
ca64248ace
...
29042d5d05
Author | SHA1 | Date | |
---|---|---|---|
29042d5d05 | |||
4489eb5f76 | |||
de5e107b86 | |||
5fc67ab5e5 | |||
05cdcf83cc | |||
37975021cb | |||
a3dfa96efd | |||
651b267dd2 | |||
970d7064ed | |||
3808955237 | |||
fcf736af92 | |||
a67f2e1096 | |||
c990b68e07 | |||
ddd6c15292 |
4
.editorconfig
Normal file
4
.editorconfig
Normal file
@ -0,0 +1,4 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# Normalize EOL for all files that Git considers text files.
|
||||
* text=auto eol=lf
|
10
.gitignore
vendored
10
.gitignore
vendored
@ -1,7 +1,3 @@
|
||||
# Build artifacts
|
||||
build/
|
||||
|
||||
# Direnv stuff for the flake
|
||||
.envrc
|
||||
.direnv
|
||||
|
||||
# Godot 4+ specific ignores
|
||||
.godot/
|
||||
/android/
|
||||
|
33
Makefile
33
Makefile
@ -1,33 +0,0 @@
|
||||
CC=g++
|
||||
|
||||
CFLAGS= -c -g -Wall
|
||||
|
||||
LDLIBS = -lglfw
|
||||
|
||||
TARGET := untap
|
||||
|
||||
BUILD_DIR := ./build
|
||||
SRC_DIRS := ./src
|
||||
|
||||
SRCS := $(shell find $(SRC_DIRS) -name '*.cpp')
|
||||
SRCS += $(shell find $(SRC_DIRS) -name '*.c')
|
||||
|
||||
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
|
||||
|
||||
$(BUILD_DIR)/$(TARGET): $(OBJS)
|
||||
$(CC) $(OBJS) -o $@ $(LDLIBS)
|
||||
cp -r $(SRC_DIRS)/shaders $(BUILD_DIR)/
|
||||
cp -r $(SRC_DIRS)/textures $(BUILD_DIR)/
|
||||
|
||||
$(BUILD_DIR)/%.cpp.o: %.cpp
|
||||
mkdir -p $(dir $@)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.c.o: %.c
|
||||
mkdir -p $(dir $@)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
141
card.gd
Normal file
141
card.gd
Normal file
@ -0,0 +1,141 @@
|
||||
extends TextureRect
|
||||
## The card class [br][br]
|
||||
##
|
||||
##
|
||||
## Contains helper text for the text, the cards ID, and the image path.
|
||||
## The goal of this class is to make card management easier.
|
||||
|
||||
# we want to use this to convert the mana cost into text
|
||||
# in the helper text box, but thats for the future
|
||||
const ManaCosts = preload("res://data/mana.gd")
|
||||
|
||||
signal cache_done
|
||||
|
||||
var card_id = "placedholder_id"
|
||||
var card_name = "placeholder_name"
|
||||
var card_type = "placeholder_card_type"
|
||||
var oracle_text = "placeholder_oracle_text"
|
||||
var _png_path = "placeholder_image_path"
|
||||
var _jpg_path = "placeholder_image_path"
|
||||
|
||||
|
||||
func _card_error(error_type: String) -> String:
|
||||
return "CARD::" + card_id + "::" + error_type + "\n"
|
||||
|
||||
|
||||
func _init(id) -> void:
|
||||
card_id = id
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if _check_cache(card_id):
|
||||
return
|
||||
await _do_cache_grab()
|
||||
|
||||
|
||||
func _do_cache_grab() -> void:
|
||||
await _do_http_request_card()
|
||||
await _do_http_request_imgs(_png_path, true)
|
||||
await _do_http_request_imgs(_jpg_path, false)
|
||||
cache_done.emit()
|
||||
|
||||
|
||||
func _check_cache(id: String) -> bool:
|
||||
if !FileAccess.file_exists("user://card_cache/" + id + "/card.json"):
|
||||
return false
|
||||
if !FileAccess.file_exists("user://card_cache/" + id + "/card.png"):
|
||||
return false
|
||||
if !FileAccess.file_exists("user://card_cache/" + id + "/card.jpg"):
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
func _do_http_request_imgs(image_path: String, png: bool) -> void:
|
||||
var httpr = HTTPRequest.new()
|
||||
add_child(httpr)
|
||||
|
||||
var headers = PackedStringArray(["User-Agent: MTGUntapClone/0.1", "Accept: */*"])
|
||||
var error = httpr.request(image_path, headers)
|
||||
if error != OK:
|
||||
push_error(_card_error("GET_REQUEST") + "An error occurred in the Scryfall request.")
|
||||
var response = await httpr.request_completed
|
||||
|
||||
var img = Image.new()
|
||||
var imgerr
|
||||
if png:
|
||||
imgerr = img.load_png_from_buffer(response[3])
|
||||
else:
|
||||
imgerr = img.load_jpg_from_buffer(response[3])
|
||||
if imgerr != OK:
|
||||
push_error(_card_error("IMG_LOADING") + "Couldn't load the image.")
|
||||
|
||||
img.save_png("user://card_cache/" + card_id + ("/card.png" if png else "/card.jpg"))
|
||||
img = null
|
||||
|
||||
|
||||
func _do_http_request_card() -> void:
|
||||
var httpr = HTTPRequest.new()
|
||||
add_child(httpr)
|
||||
#httpr.request_completed.connect(_scryfall_card_response)
|
||||
var headers = PackedStringArray(["User-Agent: MTGUntapClone/0.1", "Accept: */*"])
|
||||
var error = httpr.request("https://api.scryfall.com/cards/" + card_id, headers)
|
||||
if error != OK:
|
||||
push_error(_card_error("GET_REQUEST") + "An error occurred in the Scryfall request.")
|
||||
|
||||
var response = await httpr.request_completed
|
||||
|
||||
if response[0] != HTTPRequest.RESULT_SUCCESS:
|
||||
push_error(_card_error("GET_REQUEST") + "Failed to fetch card data from Scryfall")
|
||||
return
|
||||
|
||||
var unprocessed_body = response[3].get_string_from_utf8()
|
||||
var card_content = JSON.parse_string(unprocessed_body)
|
||||
if card_content == null:
|
||||
push_error(_card_error("PARSING") + "Failed to parse the Scryfall card results.")
|
||||
|
||||
var dir = DirAccess.open("user://")
|
||||
dir.make_dir_recursive("user://card_cache/" + card_id + "/") # lets ensure the path is there
|
||||
dir = null
|
||||
|
||||
var card_cache = FileAccess.open(
|
||||
"user://card_cache/" + card_id + "/card.json", FileAccess.WRITE
|
||||
)
|
||||
card_cache.store_string(unprocessed_body) # cache the json response
|
||||
card_cache = null # closes the file
|
||||
|
||||
var image_uris = card_content["image_uris"]
|
||||
_png_path = image_uris["png"]
|
||||
_jpg_path = image_uris["normal"]
|
||||
|
||||
|
||||
## load_card
|
||||
##
|
||||
## Loads the card, returns false, and triggers
|
||||
## a cache fetch if the card is not in the cache,
|
||||
## otherwise sets the cards variables if the cache is present.
|
||||
func load_card() -> bool:
|
||||
if !_check_cache(card_id):
|
||||
await _do_cache_grab()
|
||||
push_error(
|
||||
(
|
||||
_card_error("CACHE_FAIL")
|
||||
+ "Cache wasn't ready, this card will need to be reinitialized"
|
||||
)
|
||||
)
|
||||
return false
|
||||
|
||||
var ondisk_card = FileAccess.open(
|
||||
"user://card_cache/" + card_id + "/card.json", FileAccess.READ
|
||||
)
|
||||
var card_json = JSON.parse_string(ondisk_card.get_as_text())
|
||||
|
||||
card_name = card_json["name"]
|
||||
card_type = card_json["type_line"]
|
||||
oracle_text = card_json["oracle_text"]
|
||||
|
||||
var img = Image.new()
|
||||
img.load("user://card_cache/" + card_id + "/card.jpg")
|
||||
texture = ImageTexture.create_from_image(img)
|
||||
|
||||
ondisk_card = null
|
||||
return true
|
1
card.gd.uid
Normal file
1
card.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://b3yqd1qu7dyq
|
1
data/mana.gd
Normal file
1
data/mana.gd
Normal file
@ -0,0 +1 @@
|
||||
enum ManaCosts { WHITE, BLUE, BLACK, RED, GREEN, COLOURLESS, GENERIC, LIFE }
|
1
data/mana.gd.uid
Normal file
1
data/mana.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://brn2sbfea8fyf
|
61
flake.lock
generated
61
flake.lock
generated
@ -1,61 +0,0 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1744868846,
|
||||
"narHash": "sha256-5RJTdUHDmj12Qsv7XOhuospjAjATNiTMElplWnJE9Hs=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "ebe4301cbd8f81c4f8d3244b3632338bbeb6d49c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
30
flake.nix
30
flake.nix
@ -1,30 +0,0 @@
|
||||
{
|
||||
description = "Template node project";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system: let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
};
|
||||
in {
|
||||
devShell = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
gnumake
|
||||
glfw
|
||||
pkg-config
|
||||
glib.dev
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
1
icon.svg
Normal file
1
icon.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg>
|
After Width: | Height: | Size: 994 B |
37
icon.svg.import
Normal file
37
icon.svg.import
Normal file
@ -0,0 +1,37 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://nrgr3sfkdosx"
|
||||
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.svg"
|
||||
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
43
library.gd
Normal file
43
library.gd
Normal file
@ -0,0 +1,43 @@
|
||||
extends Node2D
|
||||
|
||||
var _card_class = preload("res://card.gd")
|
||||
|
||||
var lib_cards
|
||||
var num_cards
|
||||
|
||||
|
||||
func _load_card_callback(card) -> void:
|
||||
card.load_card()
|
||||
|
||||
|
||||
func _init(card_ids: Array) -> void:
|
||||
lib_cards = Array()
|
||||
var temp_card
|
||||
for id in card_ids:
|
||||
temp_card = _card_class.new(id)
|
||||
temp_card.cache_done.connect(_load_card_callback.bind(temp_card))
|
||||
lib_cards.push_back(temp_card)
|
||||
num_cards += 1
|
||||
|
||||
|
||||
func add_cards(cards: Array, top: bool) -> void:
|
||||
for card in cards:
|
||||
add_card(card, top)
|
||||
|
||||
|
||||
func add_card(card, top: bool) -> void:
|
||||
if top:
|
||||
lib_cards.push_front(card)
|
||||
else:
|
||||
lib_cards.push_back(card)
|
||||
|
||||
|
||||
func shuffle() -> void:
|
||||
lib_cards.shuffle()
|
||||
|
||||
|
||||
func draw_cards(num) -> Array:
|
||||
var ret = Array()
|
||||
for i in num:
|
||||
ret.push_back(lib_cards.pop_front())
|
||||
return ret
|
1
library.gd.uid
Normal file
1
library.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://bc51go8t8uvts
|
34
player.gd
Normal file
34
player.gd
Normal file
@ -0,0 +1,34 @@
|
||||
extends Node2D
|
||||
|
||||
var _card_class = preload("res://card.gd")
|
||||
|
||||
var card
|
||||
|
||||
|
||||
func _on_request_completed(result, response_code, headers, body):
|
||||
var json = JSON.parse_string(body.get_string_from_utf8())
|
||||
print(json["name"])
|
||||
|
||||
|
||||
func _test_func():
|
||||
card.load_card()
|
||||
print(card.card_id)
|
||||
print(card.card_name)
|
||||
print(card.card_type)
|
||||
print(card.oracle_text)
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
# TODO: Create 2-4 player instances as children of this tabletop node.
|
||||
card = _card_class.new("d3f10f07-7cfe-4a6f-8de6-373e367a731b")
|
||||
add_child(card)
|
||||
|
||||
card.cache_done.connect(_test_func)
|
||||
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
1
player.gd.uid
Normal file
1
player.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://w2rqm1u7p7im
|
22
player.tscn
Normal file
22
player.tscn
Normal file
@ -0,0 +1,22 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://cx0vga81xwckh"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://w2rqm1u7p7im" path="res://player.gd" id="1_4flbx"]
|
||||
[ext_resource type="Script" uid="uid://bc51go8t8uvts" path="res://library.gd" id="2_onrkg"]
|
||||
[ext_resource type="Script" uid="uid://b3yqd1qu7dyq" path="res://card.gd" id="3_i3pqv"]
|
||||
|
||||
[node name="Player" type="Node2D"]
|
||||
script = ExtResource("1_4flbx")
|
||||
|
||||
[node name="Field" type="Node2D" parent="."]
|
||||
|
||||
[node name="Hand" type="Node2D" parent="."]
|
||||
|
||||
[node name="Library" type="Node2D" parent="."]
|
||||
script = ExtResource("2_onrkg")
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
offset_left = -1.0
|
||||
offset_top = 1.0
|
||||
offset_right = 39.0
|
||||
offset_bottom = 41.0
|
||||
script = ExtResource("3_i3pqv")
|
26
project.godot
Normal file
26
project.godot
Normal file
@ -0,0 +1,26 @@
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=5
|
||||
|
||||
[application]
|
||||
|
||||
config/name="mtg-tabletop"
|
||||
run/main_scene="uid://b4ldtb3gw0jlu"
|
||||
config/features=PackedStringArray("4.4", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=1920
|
||||
window/size/viewport_height=1080
|
||||
window/size/mode=3
|
||||
|
||||
[editor_plugins]
|
||||
|
||||
enabled=PackedStringArray()
|
1140
src/glad.c
1140
src/glad.c
File diff suppressed because it is too large
Load Diff
3611
src/include/glad.h
3611
src/include/glad.h
File diff suppressed because it is too large
Load Diff
@ -1,114 +0,0 @@
|
||||
#ifndef SHADER_H
|
||||
#define SHADER_H
|
||||
|
||||
#include "glad.h"
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
class Shader
|
||||
{
|
||||
public:
|
||||
// program ID
|
||||
unsigned int ID;
|
||||
|
||||
// constructor reads and builds the shader
|
||||
Shader(const char* vertexPath, const char* fragmentPath)
|
||||
{
|
||||
std::string vertexCode;
|
||||
std::string fragmentCode;
|
||||
std::ifstream vShaderFile;
|
||||
std::ifstream fShaderFile;
|
||||
|
||||
// setup exceptions for bad files
|
||||
vShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
fShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
try {
|
||||
// open files
|
||||
vShaderFile.open(vertexPath);
|
||||
fShaderFile.open(fragmentPath);
|
||||
std::stringstream vShaderStream, fShaderStream;
|
||||
|
||||
// read file buffers into streams
|
||||
vShaderStream << vShaderFile.rdbuf();
|
||||
fShaderStream << fShaderFile.rdbuf();
|
||||
|
||||
// close file handlers
|
||||
vShaderFile.close();
|
||||
fShaderFile.close();
|
||||
|
||||
// convert stream into string
|
||||
vertexCode = vShaderStream.str();
|
||||
fragmentCode = fShaderStream.str();
|
||||
} catch (std::ifstream::failure& e) {
|
||||
std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ:" << e.what() << "\n";
|
||||
}
|
||||
|
||||
const char* vShaderCode = vertexCode.c_str();
|
||||
const char* fShaderCode = fragmentCode.c_str();
|
||||
|
||||
unsigned int vertex, fragment;
|
||||
int success;
|
||||
char infoLog[512];
|
||||
vertex = glCreateShader(GL_VERTEX_SHADER);
|
||||
|
||||
glShaderSource(vertex, 1, &vShaderCode, NULL);
|
||||
glCompileShader(vertex);
|
||||
|
||||
glGetShaderiv(vertex, GL_COMPILE_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetShaderInfoLog(vertex, 512, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << "\n";
|
||||
}
|
||||
|
||||
fragment = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment, 1, &fShaderCode, NULL);
|
||||
glCompileShader(fragment);
|
||||
|
||||
glGetShaderiv(fragment, GL_COMPILE_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetShaderInfoLog(fragment, 512, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << "\n";
|
||||
}
|
||||
|
||||
ID = glCreateProgram();
|
||||
glAttachShader(ID, vertex);
|
||||
glAttachShader(ID, fragment);
|
||||
glLinkProgram(ID);
|
||||
|
||||
glGetProgramiv(ID, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetProgramInfoLog(ID, 512, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << "\n";
|
||||
}
|
||||
|
||||
// delete shaders, no longer needed
|
||||
glDeleteShader(vertex);
|
||||
glDeleteShader(fragment);
|
||||
|
||||
}
|
||||
|
||||
// use/activate the shader
|
||||
void use()
|
||||
{
|
||||
glUseProgram(ID);
|
||||
}
|
||||
|
||||
// utility uniform functions
|
||||
void setBool(const std::string &name, bool value) const
|
||||
{
|
||||
glUniform1i(glGetUniformLocation(ID, name.c_str()), (int) value);
|
||||
}
|
||||
void setInt(const std::string &name, int value) const
|
||||
{
|
||||
glUniform1i(glGetUniformLocation(ID, name.c_str()), value);
|
||||
}
|
||||
void setFloat(const std::string &name, float value) const
|
||||
{
|
||||
glUniform1f(glGetUniformLocation(ID, name.c_str()), value);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
157
src/main.cpp
157
src/main.cpp
@ -1,157 +0,0 @@
|
||||
#include "include/glad.h"
|
||||
#include "include/shader.h"
|
||||
#include "include/stb_image.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
|
||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||
void processInput(GLFWwindow* window);
|
||||
void setupGLFW(GLFWwindow** window);
|
||||
|
||||
typedef struct {
|
||||
int width, height, nrChannels;
|
||||
unsigned char* data;
|
||||
} texture_t;
|
||||
|
||||
float vertices[] = {
|
||||
// positions colours texture coords
|
||||
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right
|
||||
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right
|
||||
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom left
|
||||
-0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f // bottom left
|
||||
};
|
||||
|
||||
unsigned int indices[] = {
|
||||
0, 1, 3, 1, 2, 3,
|
||||
};
|
||||
|
||||
bool wireframe = false;
|
||||
|
||||
int main()
|
||||
{
|
||||
GLFWwindow* window;
|
||||
setupGLFW(&window);
|
||||
|
||||
Shader myShader("shaders/shader.vs", "shaders/shader.fs");
|
||||
|
||||
texture_t tex;
|
||||
|
||||
stbi_set_flip_vertically_on_load(true);
|
||||
|
||||
tex.data = stbi_load("textures/wg.jpg", &tex.width, &tex.height, &tex.nrChannels, 0);
|
||||
|
||||
unsigned int texture;
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
if (tex.data) {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.width, tex.height, 0, GL_RGB, GL_UNSIGNED_BYTE, tex.data);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
} else {
|
||||
std::cout << "Failed to load texture\n";
|
||||
}
|
||||
|
||||
stbi_image_free(tex.data);
|
||||
|
||||
unsigned int VAO;
|
||||
glGenVertexArrays(1, &VAO);
|
||||
|
||||
unsigned int VBO;
|
||||
glGenBuffers(1, &VBO);
|
||||
|
||||
unsigned int EBO;
|
||||
glGenBuffers(1, &EBO);
|
||||
|
||||
// bind Vertex Array Object
|
||||
glBindVertexArray(VAO);
|
||||
// copy our vertices into a buffer for opengl to use
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
// copy our indices
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
|
||||
|
||||
// set the vertex attributes pointers
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
|
||||
glEnableVertexAttribArray(2);
|
||||
|
||||
myShader.use();
|
||||
myShader.setInt("tex", 0);
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
// input
|
||||
processInput(window);
|
||||
|
||||
// rendering
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
myShader.use();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
glBindVertexArray(VAO);
|
||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||
glBindVertexArray(0); // unbinds the VAO so its ready to be bound again for the next render
|
||||
|
||||
// check and call events and swap buffers
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void setupGLFW(GLFWwindow** window)
|
||||
{
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
*window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
|
||||
if (window == NULL) {
|
||||
std::cout << "Failed to create GLFW window\n";
|
||||
glfwTerminate();
|
||||
exit(-1);
|
||||
}
|
||||
glfwMakeContextCurrent(*window);
|
||||
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||
std::cout << "Failed to init GLAD\n";
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
glViewport(0, 0, 800, 600);
|
||||
glfwSetFramebufferSizeCallback(*window, framebuffer_size_callback);
|
||||
}
|
||||
|
||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
void processInput(GLFWwindow* window)
|
||||
{
|
||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
if (glfwGetKey(window, GLFW_KEY_ENTER) == GLFW_PRESS) // triggers wireframe mode
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
if (glfwGetKey(window, GLFW_KEY_BACKSPACE) == GLFW_PRESS) // disables wireframe mode
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#version 330 core
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec3 ourColor;
|
||||
in vec2 TexCoord;
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(tex, TexCoord);
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#version 330 core
|
||||
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aColor;
|
||||
layout (location = 2) in vec2 aTexCoord;
|
||||
|
||||
out vec3 ourColor;
|
||||
out vec2 TexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(aPos, 1.0);
|
||||
ourColor = aColor;
|
||||
TexCoord = aTexCoord;
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "include/stb_image.h"
|
Binary file not shown.
Before Width: | Height: | Size: 43 KiB |
Binary file not shown.
Before Width: | Height: | Size: 119 KiB |
Binary file not shown.
Before Width: | Height: | Size: 142 KiB |
18
tabletop.gd
Normal file
18
tabletop.gd
Normal file
@ -0,0 +1,18 @@
|
||||
extends Node2D
|
||||
|
||||
var player_class = preload("res://player.gd")
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
# TODO: Create 2-4 player instances as children of this tabletop node.
|
||||
|
||||
var player = player_class.new()
|
||||
add_child(player)
|
||||
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
1
tabletop.gd.uid
Normal file
1
tabletop.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://cfkew150yl1y3
|
6
tabletop.tscn
Normal file
6
tabletop.tscn
Normal file
@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://b4ldtb3gw0jlu"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cfkew150yl1y3" path="res://tabletop.gd" id="1_3we3x"]
|
||||
|
||||
[node name="Tabletop" type="Node2D"]
|
||||
script = ExtResource("1_3we3x")
|
Loading…
x
Reference in New Issue
Block a user