Compare commits
365 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e73d1f7f90 | |||
| f71fdea463 | |||
| ca46bd0ef7 | |||
| 0596e1ba3b | |||
| f6c44a223b | |||
| ea763a9f38 | |||
| f35658a971 | |||
| b300310239 | |||
| b1ccea1397 | |||
| 2de3bd93f7 | |||
| f5db354aec | |||
| a8f65e54ac | |||
| 2ac3b5b8cc | |||
| 4380f1ed01 | |||
| cadbbf9d8b | |||
| 1288ef88b8 | |||
| 5a7a5e3f7c | |||
| a3c63e6e96 | |||
| afc0845006 | |||
| 45d3bff620 | |||
| 96f6725428 | |||
| 8901257bb6 | |||
| 24da7f45e0 | |||
| 416a71f744 | |||
| 813c0dab17 | |||
| 7b0cf72ac4 | |||
| 8dbb0e0211 | |||
| 0f7a4bbabc | |||
| d8db86e40c | |||
| 910bad0fb7 | |||
| 6e8f060882 | |||
| c313c5134f | |||
| 7b46a85cec | |||
| fcc292a40f | |||
| ea4267ef2d | |||
| 80591ff6ee | |||
| 76aa838e8e | |||
| c1f1dd75bd | |||
| 60333f6d02 | |||
| f240d14052 | |||
| 962c18fcac | |||
| 085d593b66 | |||
| d601d95d40 | |||
| 2cf035089b | |||
| 186a6e0f14 | |||
| 624871486f | |||
| 57d4e44bbe | |||
| 8ff2a3d37f | |||
| ea0edcf07f | |||
| 1854c4cb51 | |||
| 35a6b38d16 | |||
| 53d8248b8c | |||
| ff5d719fcf | |||
| 75a53f635d | |||
| 043afc4e3d | |||
| c87bed2a59 | |||
| 5144c197d5 | |||
| 5c5d9fe09a | |||
| 43354fc9b4 | |||
| 4a6a20342d | |||
| b9936e5867 | |||
| ff44ec7b7a | |||
| c1cc476094 | |||
| ba504c7efc | |||
| faed79c653 | |||
| 8db01a0957 | |||
| 173aea31c9 | |||
| 9928a3599e | |||
| 2bb0cbaf6b | |||
| 869b41c38a | |||
| 8a0946eb3a | |||
| dcbce9a153 | |||
| a024e7015d | |||
| 07f32ee129 | |||
| d57d01c4b4 | |||
| 9c4c6152c9 | |||
| 9b683e9a5c | |||
| d70ca4a6c1 | |||
| 3c7a5d148d | |||
| 82343f0835 | |||
| 0a5eb397c7 | |||
| 84f0a83bee | |||
| 605e0df902 | |||
| 36c6024649 | |||
| a8fa3981f4 | |||
| b78ddba11e | |||
| c20c79cfd3 | |||
| 1c7cc31b52 | |||
| 46bc8eb5d8 | |||
| 05b59a4677 | |||
| 7f141a8930 | |||
| a4f7c90f63 | |||
| 54aefa4bdd | |||
| f2fc9d46b8 | |||
| 6007f52194 | |||
| 36af790293 | |||
| 0406a38895 | |||
| 2dc8050ce3 | |||
| cb4274bb1c | |||
| b6446e129b | |||
| 736f30c33a | |||
| 50e9300667 | |||
| c11d71aaaa | |||
| 99ae7f2236 | |||
| d7889ebac0 | |||
| bb205c6ad1 | |||
| 81f3e1e399 | |||
| 82e08d0785 | |||
| 9bea188686 | |||
| cc1f287a3a | |||
| b85b4ab601 | |||
| 69e5ae22d2 | |||
| cd9114bfd0 | |||
| b91bc22db1 | |||
| 038d997421 | |||
| 4dad1a5d75 | |||
| d3debea41a | |||
| ab11f7b9db | |||
| 3a7f91cb07 | |||
| deb9918b9b | |||
| 7c23f5dfd9 | |||
| 1c27fce58c | |||
| 4761473e86 | |||
| 3c6a842c9d | |||
| fc38bb59a9 | |||
| d12d60b1ba | |||
| 83f4d05df8 | |||
| c7d380c4b0 | |||
| 859e95eea8 | |||
| d678f3c7a0 | |||
| c83337b6a6 | |||
| c2c201c9e4 | |||
| 2f39299fc6 | |||
| 397120a973 | |||
| 4222d89eb2 | |||
| 9dc3a49207 | |||
| 8082309896 | |||
| 0170e8181b | |||
| 82cfe55a91 | |||
| 7967eaea2a | |||
| fc64fedb0e | |||
| fd108cc391 | |||
| d35ba0730e | |||
| 0ce1d25594 | |||
| b913c2024d | |||
| 315f2e9c41 | |||
| de789ad77e | |||
| 788e3f697e | |||
| 01b626d44e | |||
| e9ebb38090 | |||
| 54805c07f4 | |||
| 6a84af227c | |||
| 1902b92210 | |||
| 03cbba9a6c | |||
| 9621ea19bb | |||
| 8d57b3a72c | |||
| e97844a6e6 | |||
| 46af40bbb7 | |||
| b984f30968 | |||
| 0a75f0c2ed | |||
| cbd26a211d | |||
| 543542625d | |||
| d9697e2eae | |||
| 707cd7732c | |||
| bb28f5658f | |||
| 36e4894dc7 | |||
| 0e2a3525e4 | |||
| a172fbb323 | |||
| d48cc650a8 | |||
| 845b93fb48 | |||
| f6aa0246d3 | |||
| c082700891 | |||
| 7e79663dce | |||
| 81c7e34c58 | |||
| 2eec1c9f75 | |||
| b91b9f3768 | |||
| 0540f5d201 | |||
| 090646b61a | |||
| 60dd9bacb0 | |||
| 197b4df87f | |||
| 12b2413e23 | |||
| 080c4f77c3 | |||
| 6c96a3d9a1 | |||
| f71cfa86f2 | |||
| 227d58725d | |||
| d9f54b08ca | |||
| d971cd6cb2 | |||
| 56c24f7118 | |||
| 40e4f95452 | |||
| 0c76864b40 | |||
| 50439a58bd | |||
| 0d029817fe | |||
| 61b233f708 | |||
| f5d80aa46f | |||
| 3d9dda64ca | |||
| d73c787f40 | |||
| 421bf819d5 | |||
| dfe29acc1e | |||
| 03186ebea0 | |||
| 816cf3a072 | |||
| cfe064f02c | |||
| 7356bdebdd | |||
| 4193b3b719 | |||
| 9954c45fe9 | |||
| 30dc11f0d5 | |||
| 23cf17f9af | |||
| 7648c23e43 | |||
| c5648a5105 | |||
| 2b14977eed | |||
| 7402896ce6 | |||
| 7a694e8fd0 | |||
| f07be50bd3 | |||
| 96b61f0ee3 | |||
| 9b5bd9dcd0 | |||
| 035dd333da | |||
| 46bf27f4a4 | |||
| d94c7fcf9a | |||
| f8188c4358 | |||
| 5e27f820de | |||
| 7dedabba57 | |||
| b65cb9c2d2 | |||
| bd38e9e98f | |||
| c41fb6c013 | |||
| 7fd1ee5445 | |||
| 1cfd4adca4 | |||
| 6464838159 | |||
| db695f11f6 | |||
| 2a608805b5 | |||
| ed876ca64d | |||
| d49d91a294 | |||
| 6ee1752735 | |||
| 3855cdd541 | |||
| f62373dcbc | |||
| 919aa7740a | |||
| 6de6028ba4 | |||
| d34d20361d | |||
| 74a2ff028c | |||
| ea91d50a84 | |||
| 304e345a79 | |||
| ca5e2a399c | |||
| ebe3a648c5 | |||
| 02567eb225 | |||
| 4d69ff3a18 | |||
| b43f2fcca8 | |||
| c2b0d73888 | |||
| 3f38286049 | |||
| fc1fc7001a | |||
| 5d433a7b80 | |||
| 2da0f7e712 | |||
| f0d769c923 | |||
| 04db63aa49 | |||
| 48b501e355 | |||
| 17759992c8 | |||
| d7d8a23dc2 | |||
| 70f73c1d52 | |||
| 33270d9f7b | |||
| 0a5681c871 | |||
| e64d9cdce0 | |||
| 0a1c18548d | |||
| 363afe111b | |||
| 92f42a08fb | |||
| 66a4011f4b | |||
| c731cda1a2 | |||
| 82add50157 | |||
| 2be3c66a2d | |||
| 60653509fa | |||
| a72ebf3d15 | |||
| 5d391ef70c | |||
| fadd24fa51 | |||
| 391d617117 | |||
| acf96a0971 | |||
| 37d495fca3 | |||
| b78531a570 | |||
| 02912b857b | |||
| 4f04a8e7c9 | |||
| f7fcc2633c | |||
| 6f9b33be8f | |||
| b0d14b91e0 | |||
| 1332921174 | |||
| c09febc4d8 | |||
| 49f42e98f4 | |||
| ec8eb971a5 | |||
| 1a6cee0b25 | |||
| eb1f6303f1 | |||
| 32fddcd99d | |||
| f86a1ae90c | |||
| 18880ef17e | |||
| 976ddecd10 | |||
| 2a1851efb5 | |||
| d58c49421e | |||
| 0f08f10a0d | |||
| 2c76d3bc87 | |||
| d8af100691 | |||
| a96e78bca5 | |||
| e3c01d4897 | |||
| 6805e392a7 | |||
| afc1491718 | |||
| 92a561648e | |||
| a4a691fd48 | |||
| a6e6b915e6 | |||
| 532c6dafaf | |||
| 18ea713445 | |||
| 76d175ffd9 | |||
| 1194128627 | |||
| 72e1bfdade | |||
| c0f44016c6 | |||
| eef2690ada | |||
| e888626b03 | |||
| 24fa1e140e | |||
| 3364b921de | |||
| 7c6cf45d3c | |||
| e0d95a1135 | |||
| fa0fc72eb0 | |||
| 290c6643f5 | |||
| c7c1ff68fd | |||
| cdaed77bf7 | |||
| 3c209ba01b | |||
| 2e9701a15b | |||
| 390be8f740 | |||
| e75d373933 | |||
| 81b64e18d4 | |||
| a30fd37032 | |||
| cd32d0b7c2 | |||
| 10198484e7 | |||
| 858e721451 | |||
| ffb97d2b3a | |||
| 4d54968f83 | |||
| 24c3f14c8c | |||
| 762d26f368 | |||
| b2ca926a00 | |||
| f526b598e2 | |||
| 801ab1033f | |||
| fb58490bfe | |||
| e6718e7ef1 | |||
| da76c4b4d1 | |||
| 3477b72371 | |||
| 52fe72f31f | |||
| a1e4f9347a | |||
| 9e581ef859 | |||
| 8a3b5a17d8 | |||
| 29749e945a | |||
| 1a43bcd77a | |||
| dc04a12922 | |||
| 59a4f1347a | |||
| 624a979356 | |||
| 1a218532c0 | |||
| 66f3bb30d9 | |||
| a19944437b | |||
| e4c086a1eb | |||
| f3cada7ac8 | |||
| ddd41971e1 | |||
| ce575cc122 | |||
| b564758ff6 | |||
| b53ddfb3fa | |||
| cb2ea423dc | |||
| f5b7fa8178 | |||
| 093149e72c | |||
| f72178ffd0 | |||
| 6e14209aae | |||
| 2dd1187ff2 | |||
| 5c4eea4ae1 | |||
| 8b96338e24 | |||
| 2a111a237d | |||
| 1dc0ecf563 | |||
| 8c9c1e0997 |
471 changed files with 132355 additions and 9320 deletions
|
|
@ -1,77 +0,0 @@
|
||||||
|
|
||||||
local _systems = {
|
|
||||||
"Win32",
|
|
||||||
-- "Linux"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
-- Returns a string of all supported systems
|
|
||||||
function supported_systems()
|
|
||||||
return table.concat(_systems, ', ')
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Detect what system we currently are on.
|
|
||||||
function system()
|
|
||||||
|
|
||||||
local win = os.getenv('OS')
|
|
||||||
|
|
||||||
if win:lower():match('windows') then
|
|
||||||
return _systems[1]
|
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Defines a module
|
|
||||||
-- path: base path to source files.
|
|
||||||
-- src: table of source files.
|
|
||||||
function Module(path, src)
|
|
||||||
local r = {}
|
|
||||||
for k, v in pairs(src) do
|
|
||||||
r[k] = path .. "/" .. v
|
|
||||||
end
|
|
||||||
return r
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Copy a directory src to dst
|
|
||||||
-- src = "path/to/a", dest = "path/to/b" -> the whole content
|
|
||||||
-- of "a" will be copied to "path/to/b"
|
|
||||||
function CopyDir(dst, src)
|
|
||||||
local r = {}
|
|
||||||
local base = PathDir(src)
|
|
||||||
local files = CollectRecursive(Path(src) .. "/*")
|
|
||||||
|
|
||||||
for k, v in pairs(files) do
|
|
||||||
local rdir = PathDir(v:sub(base:len() + 1))
|
|
||||||
r[k] = CopyToDirectory(PathJoin(dst, rdir), v)
|
|
||||||
end
|
|
||||||
return r
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Build example binary.
|
|
||||||
-- This function Imports "examples/<name>/bam.lua"
|
|
||||||
-- that file must define a table "src" that contains the source files.
|
|
||||||
function BuildExample(settings, name, dependencies)
|
|
||||||
|
|
||||||
Import("examples/" .. name .. "/bam.lua")
|
|
||||||
|
|
||||||
exe = Link(settings, "examples/" .. name, Compile(settings, src))
|
|
||||||
|
|
||||||
if dependencies ~= nil and #dependencies > 0 then
|
|
||||||
AddDependency(exe, dependencies)
|
|
||||||
end
|
|
||||||
|
|
||||||
return exe
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Build examples binaries.
|
|
||||||
-- Just a wrapper for BuildExample. taking a table of names instead.
|
|
||||||
function BuildExamples(settings, names, dependencies)
|
|
||||||
|
|
||||||
local r = {}
|
|
||||||
for i = 1, #names do
|
|
||||||
r[i] = BuildExample(settings, names[i], dependencies)
|
|
||||||
end
|
|
||||||
return r
|
|
||||||
end
|
|
||||||
6
.clang-format
Normal file
6
.clang-format
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
UseTab: Always
|
||||||
|
TabWidth: 8
|
||||||
|
IndentWidth: 8
|
||||||
|
|
||||||
|
BreakBeforeBraces: Linux
|
||||||
4
.gitattributes
vendored
4
.gitattributes
vendored
|
|
@ -5,8 +5,12 @@
|
||||||
*.sh text eol=lf
|
*.sh text eol=lf
|
||||||
*.ini text eol=lf
|
*.ini text eol=lf
|
||||||
*.xml text eol=lf
|
*.xml text eol=lf
|
||||||
|
*.h eol=lf
|
||||||
|
*.hpp eol=lf
|
||||||
|
*.hxx eol=lf
|
||||||
*.c text eol=lf
|
*.c text eol=lf
|
||||||
*.cpp text eol=lf
|
*.cpp text eol=lf
|
||||||
|
*.cxx text eol=lf
|
||||||
*.htext eol=lf
|
*.htext eol=lf
|
||||||
*.txt text eol=lf
|
*.txt text eol=lf
|
||||||
*.glsl text eol=lf
|
*.glsl text eol=lf
|
||||||
|
|
|
||||||
13
.gitignore
vendored
13
.gitignore
vendored
|
|
@ -1,7 +1,10 @@
|
||||||
|
|
||||||
|
# Build system related files
|
||||||
build/
|
build/
|
||||||
.bam/*
|
|
||||||
!.bam/*.lua
|
# LSP related files
|
||||||
|
.ccls-cache/
|
||||||
|
compile_commands.json
|
||||||
|
|
||||||
# Thumbnail databases (Windows)
|
# Thumbnail databases (Windows)
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
@ -25,6 +28,12 @@ Thumbs.db
|
||||||
|
|
||||||
!vsproj/*
|
!vsproj/*
|
||||||
|
|
||||||
|
# Visual Studio Code
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
# Debug files
|
||||||
|
*.pdb
|
||||||
|
|
||||||
# Compiled Object files
|
# Compiled Object files
|
||||||
*.slo
|
*.slo
|
||||||
*.lo
|
*.lo
|
||||||
|
|
|
||||||
42
CMakeLists.txt
Normal file
42
CMakeLists.txt
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Spectre main Cmake config
|
||||||
|
#
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
cmake_minimum_required(VERSION 3.15)
|
||||||
|
cmake_policy(SET CMP0091 NEW)
|
||||||
|
|
||||||
|
|
||||||
|
# set the project name
|
||||||
|
project(Spectre
|
||||||
|
VERSION 0.0.1
|
||||||
|
DESCRIPTION ""
|
||||||
|
HOMEPAGE_URL "")
|
||||||
|
|
||||||
|
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake" )
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
# Compiler
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
add_definitions("/EHsc -D_CRT_SECURE_NO_WARNINGS")
|
||||||
|
|
||||||
|
# Staticly link with MSVCR
|
||||||
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||||
|
endif (MSVC)
|
||||||
|
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
|
# Include engine
|
||||||
|
include(engine.cmake)
|
||||||
|
|
||||||
|
# Include examples
|
||||||
|
add_subdirectory(examples)
|
||||||
38
README.md
38
README.md
|
|
@ -1,3 +1,41 @@
|
||||||
# Spectre 2D Engine
|
# Spectre 2D Engine
|
||||||
|
|
||||||
A simple 2D Game engine from scratch!
|
A simple 2D Game engine from scratch!
|
||||||
|
|
||||||
|
## Compiling
|
||||||
|
|
||||||
|
This project uses [cmake](https://cmake.org) build system
|
||||||
|
(Version 3.15 or greater) to compile the engine.
|
||||||
|
|
||||||
|
### Linux with make.
|
||||||
|
```sh
|
||||||
|
$ mkdir build
|
||||||
|
$ cd build
|
||||||
|
$ cmake .. -G "Unix Makefiles"
|
||||||
|
$ make
|
||||||
|
```
|
||||||
|
|
||||||
|
### Windows using NMake
|
||||||
|
```sh
|
||||||
|
$ mkdir build
|
||||||
|
$ cd build
|
||||||
|
$ cmake .. -G "NMake Makefiles"
|
||||||
|
$ nmake
|
||||||
|
```
|
||||||
|
|
||||||
|
### Or the best way (in my opinion)
|
||||||
|
install [Ninja](https://ninja-build.org) and run
|
||||||
|
```sh
|
||||||
|
$ mkdir build
|
||||||
|
$ cd build
|
||||||
|
$ cmake .. -G Ninja
|
||||||
|
$ ninja
|
||||||
|
```
|
||||||
|
|
||||||
|
The build will produce `spectre.lib` in the `build` directory that
|
||||||
|
should be used when linking.
|
||||||
|
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
Henrik Hautakoski - [henrik.hautakoski@gmail.com](mailto:henrik.hautakoski@gmail.com)
|
||||||
|
|
|
||||||
BIN
assets/app.ico
BIN
assets/app.ico
Binary file not shown.
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 101 KiB |
BIN
assets/debug_icon.ico
Normal file
BIN
assets/debug_icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
248
bam.lua
248
bam.lua
|
|
@ -1,248 +0,0 @@
|
||||||
--------------------------------
|
|
||||||
-- --
|
|
||||||
-- Spectre build config --
|
|
||||||
-- --
|
|
||||||
--------------------------------
|
|
||||||
Import(".bam/functions.lua")
|
|
||||||
CheckVersion("0.5")
|
|
||||||
|
|
||||||
--------------------------------
|
|
||||||
-- --
|
|
||||||
-- Environment Setup --
|
|
||||||
-- --
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
-- OS Detection
|
|
||||||
TARGET_OS = system()
|
|
||||||
if TARGET_OS == nil then
|
|
||||||
print ("System not supported" )
|
|
||||||
print ("Supported systems are: " .. supported_systems() )
|
|
||||||
return 1
|
|
||||||
end
|
|
||||||
|
|
||||||
-- paths used when building.
|
|
||||||
paths = {
|
|
||||||
build = "build",
|
|
||||||
object = "obj",
|
|
||||||
examples = "examples"
|
|
||||||
}
|
|
||||||
|
|
||||||
--------------------------------
|
|
||||||
-- --
|
|
||||||
-- Global Build Settings --
|
|
||||||
-- --
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
global_settings = NewSettings();
|
|
||||||
|
|
||||||
-- Build type
|
|
||||||
--------------------------------
|
|
||||||
global_settings.debug = 1
|
|
||||||
global_settings.optimize = 0
|
|
||||||
|
|
||||||
if ScriptArgs.type ~= nil and ScriptArgs.type:match("^release") then
|
|
||||||
global_settings.debug = 0
|
|
||||||
if ScriptArgs.type == "release-fast" then
|
|
||||||
global_settings.optimize = 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Output configuration
|
|
||||||
--------------------------------
|
|
||||||
global_settings.lib.prefix = Path(paths.build) .. "/"
|
|
||||||
|
|
||||||
global_settings.link.Output = function(settings, input)
|
|
||||||
return Path(PathJoin(paths.build, input))
|
|
||||||
end
|
|
||||||
|
|
||||||
global_settings.cc.Output = function(settings, input)
|
|
||||||
return Path(PathJoin(PathJoin(paths.build, paths.object), PathBase(input)))
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Compiler configuration
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
-- MSVC complains about exception handler without this flag.
|
|
||||||
if global_settings.cc.exe_cxx == "cl" then
|
|
||||||
global_settings.cc.flags:Add('/EHsc')
|
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------
|
|
||||||
-- --
|
|
||||||
-- Engine configuration --
|
|
||||||
-- --
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
local settings = global_settings
|
|
||||||
|
|
||||||
settings.cc.includes:Add("include/")
|
|
||||||
settings.cc.includes:Add("source/")
|
|
||||||
|
|
||||||
-- FreeType2
|
|
||||||
if TARGET_OS == "Win32" then
|
|
||||||
settings.cc.includes:Add("vendor/FreeType2/include")
|
|
||||||
else
|
|
||||||
settings.cc.includes:Add("/usr/include/freetype2")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- STB
|
|
||||||
settings.cc.includes:Add("vendor/stb/include")
|
|
||||||
|
|
||||||
-- Source files
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
local system_module = Module("source/System", {
|
|
||||||
"File.cpp",
|
|
||||||
"MessageHandler.cpp",
|
|
||||||
"MessageQueue.cpp",
|
|
||||||
"SystemEvent.cpp",
|
|
||||||
"Log.cpp"
|
|
||||||
})
|
|
||||||
|
|
||||||
local platform_common_module = Module("source/Platform", {
|
|
||||||
"PlatformDisplay.cpp"
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
-- if TARGET_OS == "Win32" then -- Needed later for unix.
|
|
||||||
platform_spec_module = Module("source/Platform/Win32", {
|
|
||||||
"Win32Application.cpp",
|
|
||||||
"Win32Display.cpp",
|
|
||||||
"Win32GLContext.cpp",
|
|
||||||
"Win32Input.cpp",
|
|
||||||
"Win32Internal.cpp",
|
|
||||||
"Win32Keyboard.cpp",
|
|
||||||
"Win32Misc.cpp",
|
|
||||||
"Win32Mouse.cpp",
|
|
||||||
"Win32MsgBuffer.cpp",
|
|
||||||
"Win32System.cpp",
|
|
||||||
"glad_wgl.c"
|
|
||||||
})
|
|
||||||
--end
|
|
||||||
|
|
||||||
local input_module = Module("source/Input", {
|
|
||||||
"InputDevice.cpp",
|
|
||||||
"InputEvent.cpp",
|
|
||||||
"InputListener.cpp",
|
|
||||||
"InputModule.cpp",
|
|
||||||
"Keyboard.cpp",
|
|
||||||
"Mouse.cpp"
|
|
||||||
})
|
|
||||||
|
|
||||||
local display_module = Module("source/Display", {
|
|
||||||
"Display.cpp",
|
|
||||||
"DisplayDescription.cpp",
|
|
||||||
"DisplayMode.cpp",
|
|
||||||
"GLContext.cpp"
|
|
||||||
})
|
|
||||||
|
|
||||||
local graphics_module = Module("source/Graphics", {
|
|
||||||
-- Primitives
|
|
||||||
"Vertex2D.cpp",
|
|
||||||
"Transformable.cpp",
|
|
||||||
"Sprite.cpp",
|
|
||||||
|
|
||||||
-- Rendering
|
|
||||||
"BatchRenderer2D.cpp",
|
|
||||||
"DefaultRenderer2D.cpp",
|
|
||||||
"Renderable2D.cpp",
|
|
||||||
"Renderer2D.cpp",
|
|
||||||
"RenderState.cpp",
|
|
||||||
"Shader.cpp",
|
|
||||||
"ShaderProgram.cpp",
|
|
||||||
"Texture.cpp",
|
|
||||||
|
|
||||||
-- Text
|
|
||||||
"Font/FontDriver.cpp",
|
|
||||||
"Font/FreeTypeDriver.cpp",
|
|
||||||
"Font/FreeTypeError.cpp",
|
|
||||||
"Font.cpp",
|
|
||||||
"Text.cpp",
|
|
||||||
|
|
||||||
-- Image
|
|
||||||
"Image.cpp",
|
|
||||||
"ImageLoader.cpp",
|
|
||||||
|
|
||||||
"OpenGL.cpp",
|
|
||||||
"GL/glad.c",
|
|
||||||
"GL/CheckError.cpp",
|
|
||||||
})
|
|
||||||
|
|
||||||
local core_module = Module("source/Core", {
|
|
||||||
"String.cpp"
|
|
||||||
})
|
|
||||||
|
|
||||||
local math_module = Module("source/Math", {
|
|
||||||
"Color.cpp",
|
|
||||||
"Logarithm.cpp",
|
|
||||||
"Math.cpp",
|
|
||||||
"Transform.cpp"
|
|
||||||
})
|
|
||||||
|
|
||||||
local game_module = Module("source", {
|
|
||||||
"Game/FPSCounter.cpp",
|
|
||||||
"Game/GameTime.cpp",
|
|
||||||
"Game.cpp",
|
|
||||||
})
|
|
||||||
|
|
||||||
local scene_module = Module("source/Scene", {
|
|
||||||
"Camera2D.cpp"
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Build target
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
local obj = Compile(settings, {
|
|
||||||
system_module,
|
|
||||||
platform_common_module,
|
|
||||||
platform_spec_module,
|
|
||||||
input_module,
|
|
||||||
display_module,
|
|
||||||
graphics_module,
|
|
||||||
core_module,
|
|
||||||
math_module,
|
|
||||||
game_module,
|
|
||||||
scene_module
|
|
||||||
})
|
|
||||||
|
|
||||||
local libspectre = StaticLibrary(settings,
|
|
||||||
"spectre",
|
|
||||||
obj
|
|
||||||
)
|
|
||||||
|
|
||||||
--------------------------------
|
|
||||||
-- --
|
|
||||||
-- Examples --
|
|
||||||
-- --
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
local example_settings = global_settings
|
|
||||||
|
|
||||||
-- Include spectre headers.
|
|
||||||
example_settings.cc.includes:Add("include/")
|
|
||||||
|
|
||||||
-- Link with spectre.
|
|
||||||
example_settings.link.extrafiles:Add(libspectre)
|
|
||||||
|
|
||||||
if TARGET_OS == "Win32" then
|
|
||||||
|
|
||||||
-- Windows needs to link against these.
|
|
||||||
example_settings.link.libs:Add("opengl32", "gdi32", "user32")
|
|
||||||
|
|
||||||
-- Staticly link freetype on windows.
|
|
||||||
example_settings.link.libpath:Add("vendor/FreeType2/lib/x86")
|
|
||||||
if example_settings.debug > 0 then
|
|
||||||
example_settings.link.libs:Add("freetype-d-s")
|
|
||||||
else
|
|
||||||
example_settings.link.libs:Add("freetype-s")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- For now, to get examples working
|
|
||||||
-- we copy the whole assets directory.
|
|
||||||
assets = CopyDir(PathJoin(paths.build, paths.examples), "assets")
|
|
||||||
|
|
||||||
BuildExamples(example_settings, {
|
|
||||||
"text"
|
|
||||||
}, assets)
|
|
||||||
7
cmake/Macros.cmake
Normal file
7
cmake/Macros.cmake
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
function(spectre_example NAME)
|
||||||
|
add_executable(example_${NAME} ${ARGN})
|
||||||
|
target_link_libraries(example_${NAME} PRIVATE Spectre)
|
||||||
|
set_target_properties(example_${NAME} PROPERTIES VS_GLOBAL_IgnoreImportLibrary "true")
|
||||||
|
#set_target_properties(${NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||||
|
endfunction()
|
||||||
31
cmake/SpectreConfig.cmake.in
Normal file
31
cmake/SpectreConfig.cmake.in
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
# This script provides the spectre as an import target
|
||||||
|
# ----------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Use find_package() so cmake will find spectre:
|
||||||
|
#
|
||||||
|
# find_package(spectre) # No specific version
|
||||||
|
# find_package(spectre REQUIRED) # No specific version, but the library must be found.
|
||||||
|
# find_package(spectre 0.1) # any 0.1.x, but the library is optional.
|
||||||
|
# find_package(spectre 0.1.0) # 0.1.0 or greater, but the library is optional.
|
||||||
|
#
|
||||||
|
# Then you just link your target with spectre:
|
||||||
|
#
|
||||||
|
# target_link_libraries( ${PROGRAM_EXE} PUBLIC spectre )
|
||||||
|
#
|
||||||
|
# if you do not specify REQUIRED. you must check the variable spectre_FOUND
|
||||||
|
# and and only link to it if it's defined:
|
||||||
|
#
|
||||||
|
# if (spectre_FOUND)
|
||||||
|
# ...
|
||||||
|
# target_link_libraries( ${PROGRAM_EXE} PUBLIC spectre )
|
||||||
|
# ..
|
||||||
|
# endif()
|
||||||
|
|
||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
find_package(OpenGL)
|
||||||
|
|
||||||
|
set_and_check( SPECTRE_ASSETS "@PACKAGE_ASSETS_DIR@" )
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/SpectreTargets.cmake")
|
||||||
|
check_required_components(Spectre)
|
||||||
240
engine.cmake
Normal file
240
engine.cmake
Normal file
|
|
@ -0,0 +1,240 @@
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Engine library build config
|
||||||
|
#
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
|
# Source
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
|
set( ENGINE_SRC
|
||||||
|
# Core
|
||||||
|
source/Core/String.cpp
|
||||||
|
|
||||||
|
# System
|
||||||
|
source/System/ByteOrder.cpp
|
||||||
|
source/System/Event.cpp
|
||||||
|
source/System/EventListener.cpp
|
||||||
|
source/System/File.cpp
|
||||||
|
source/System/Log.cpp
|
||||||
|
source/System/MessageHandler.cpp
|
||||||
|
source/System/MessageQueue.cpp
|
||||||
|
source/System/Path.cpp
|
||||||
|
source/System/Stopwatch.cpp
|
||||||
|
source/System/Log/FileWriter.cpp
|
||||||
|
|
||||||
|
# Platform
|
||||||
|
source/Platform/PlatformApplication.cpp
|
||||||
|
source/Platform/PlatformWindow.cpp
|
||||||
|
|
||||||
|
# Math
|
||||||
|
source/Math/Color.cpp
|
||||||
|
source/Math/Logarithm.cpp
|
||||||
|
source/Math/Time.cpp
|
||||||
|
source/Math/Transform.cpp
|
||||||
|
source/Math/Math.cpp
|
||||||
|
|
||||||
|
# Input
|
||||||
|
source/Input/InputDevice.cpp
|
||||||
|
source/Input/InputModule.cpp
|
||||||
|
source/Input/Keyboard.cpp
|
||||||
|
source/Input/Mouse.cpp
|
||||||
|
|
||||||
|
# Window
|
||||||
|
source/Window/Window.cpp
|
||||||
|
source/Window/WindowDescription.cpp
|
||||||
|
source/Window/DisplayMode.cpp
|
||||||
|
source/Window/GLWindow.cpp
|
||||||
|
source/Window/GLContext.cpp
|
||||||
|
|
||||||
|
# GfxDriver
|
||||||
|
source/GfxDriver/ShaderProgram.cpp
|
||||||
|
|
||||||
|
# Graphics
|
||||||
|
source/Graphics/BatchRenderer2D.cpp
|
||||||
|
source/Graphics/DefaultRenderer2D.cpp
|
||||||
|
source/Graphics/Renderable2D.cpp
|
||||||
|
source/Graphics/Renderer2D.cpp
|
||||||
|
source/Graphics/RenderState.cpp
|
||||||
|
source/Graphics/Sprite.cpp
|
||||||
|
source/Graphics/Text.cpp
|
||||||
|
source/Graphics/Texture.cpp
|
||||||
|
source/Graphics/Transformable.cpp
|
||||||
|
source/Graphics/Vertex2D.cpp
|
||||||
|
source/Graphics/Graphics.cpp
|
||||||
|
|
||||||
|
# Graphics - Font
|
||||||
|
source/Graphics/Font/Engine/FreeTypeEngine.cpp
|
||||||
|
source/Graphics/Font/Engine/FreeTypeError.cpp
|
||||||
|
source/Graphics/Font/Engine/FreeTypeLib.cpp
|
||||||
|
source/Graphics/Font/FontDescription.cpp
|
||||||
|
source/Graphics/Font.cpp
|
||||||
|
|
||||||
|
# Graphics - Image
|
||||||
|
source/Graphics/Image/IcoFormat.cpp
|
||||||
|
source/Graphics/ImageLoader.cpp
|
||||||
|
source/Graphics/PixelFormat.cpp
|
||||||
|
source/Graphics/Image.cpp
|
||||||
|
|
||||||
|
# Graphics - GL
|
||||||
|
source/Graphics/GL/glad.c
|
||||||
|
source/Graphics/GL/CheckError.cpp
|
||||||
|
|
||||||
|
# Scene
|
||||||
|
source/Scene/Camera2D.cpp
|
||||||
|
|
||||||
|
# Game
|
||||||
|
source/Game/FPSCounter.cpp
|
||||||
|
source/Game/GameTime.cpp
|
||||||
|
source/Game.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(ENGINE_GFXDRIVER_OPENGL_SRC
|
||||||
|
source/GfxDriver/OpenGL/OpenGLDrv.cpp
|
||||||
|
source/GfxDriver/OpenGL/OpenGLShaderProgram.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(ENGINE_PLATFORM_WIN32_SRC
|
||||||
|
source/Platform/Win32/Win32Application.cpp
|
||||||
|
source/Platform/Win32/Win32Window.cpp
|
||||||
|
source/Platform/Win32/Win32GLContext.cpp
|
||||||
|
source/Platform/Win32/Win32Input.cpp
|
||||||
|
source/Platform/Win32/Win32Internal.cpp
|
||||||
|
source/Platform/Win32/Win32Keyboard.cpp
|
||||||
|
source/Platform/Win32/Win32Misc.cpp
|
||||||
|
source/Platform/Win32/Win32Mouse.cpp
|
||||||
|
source/Platform/Win32/Win32EventQueue.cpp
|
||||||
|
source/Platform/Win32/Win32System.cpp
|
||||||
|
source/Platform/Win32/glad_wgl.c
|
||||||
|
)
|
||||||
|
|
||||||
|
set(ENGINE_PLATFORM_UNIX_SRC
|
||||||
|
source/Platform/Unix/UnixApplication.cpp
|
||||||
|
source/Platform/Unix/UnixSystem.cpp
|
||||||
|
source/Platform/Unix/UnixMisc.cpp
|
||||||
|
|
||||||
|
# GLContext
|
||||||
|
source/Platform/Unix/GLXContext.cpp
|
||||||
|
source/Platform/Unix/glad_glx.c
|
||||||
|
|
||||||
|
# X11
|
||||||
|
source/Platform/Unix/Xlib.cpp
|
||||||
|
source/Platform/Unix/Xrandr.cpp
|
||||||
|
source/Platform/Unix/X11Window.cpp
|
||||||
|
source/Platform/Unix/X11Input.cpp
|
||||||
|
source/Platform/Unix/X11Keyboard.cpp
|
||||||
|
source/Platform/Unix/X11Mouse.cpp
|
||||||
|
source/Platform/Unix/X11EventQueue.cpp
|
||||||
|
source/Platform/Unix/X11WindowEventHandler.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Library
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
|
add_library( Spectre STATIC ${ENGINE_SRC} )
|
||||||
|
target_include_directories(Spectre
|
||||||
|
PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:include>
|
||||||
|
PRIVATE
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/source
|
||||||
|
)
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
target_compile_options(Spectre PRIVATE "-DSPECTRE_PLATFORM_WIN=1")
|
||||||
|
else()
|
||||||
|
target_compile_options(Spectre PRIVATE "-DSPECTRE_PLATFORM_UNIX=1")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
# Dependancies
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
|
# Platform specific
|
||||||
|
if (WIN32)
|
||||||
|
target_sources(Spectre PRIVATE ${ENGINE_PLATFORM_WIN32_SRC})
|
||||||
|
else()
|
||||||
|
target_sources(Spectre PRIVATE ${ENGINE_PLATFORM_UNIX_SRC})
|
||||||
|
|
||||||
|
# Unix needs to link against X11
|
||||||
|
find_package(X11 REQUIRED COMPONENTS Xrandr)
|
||||||
|
target_link_libraries(Spectre PRIVATE X11::X11 X11::Xrandr)
|
||||||
|
endif (WIN32)
|
||||||
|
|
||||||
|
# Select graphics API
|
||||||
|
|
||||||
|
# Only OpenGL Driver for now
|
||||||
|
target_sources(Spectre PRIVATE ${ENGINE_GFXDRIVER_OPENGL_SRC})
|
||||||
|
if (WIN32)
|
||||||
|
find_package(OpenGL REQUIRED COMPONENTS OpenGL)
|
||||||
|
target_link_libraries(Spectre PRIVATE OpenGL::GL)
|
||||||
|
else()
|
||||||
|
find_package(OpenGL REQUIRED COMPONENTS OpenGL GLX)
|
||||||
|
target_link_libraries(Spectre PRIVATE OpenGL::OpenGL OpenGL::GLX)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# FreeType
|
||||||
|
add_subdirectory(vendor/FreeType2)
|
||||||
|
target_sources(Spectre PRIVATE $<TARGET_OBJECTS:freetype>)
|
||||||
|
target_include_directories(Spectre PRIVATE $<TARGET_PROPERTY:freetype,INTERFACE_INCLUDE_DIRECTORIES>)
|
||||||
|
|
||||||
|
# STB
|
||||||
|
target_include_directories(Spectre PRIVATE ${CMAKE_CURRENT_LIST_DIR}/vendor/stb/include)
|
||||||
|
|
||||||
|
# Install
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
|
# Includes
|
||||||
|
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/Spectre TYPE INCLUDE)
|
||||||
|
|
||||||
|
# Assets
|
||||||
|
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/assets DESTINATION ${CMAKE_INSTALL_DATADIR})
|
||||||
|
|
||||||
|
|
||||||
|
# Install - CMake targets
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
|
install(TARGETS Spectre
|
||||||
|
EXPORT SpectreTargets
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(EXPORT SpectreTargets
|
||||||
|
FILE SpectreTargets.cmake
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Spectre
|
||||||
|
)
|
||||||
|
|
||||||
|
# Build directory target
|
||||||
|
export(EXPORT SpectreTargets
|
||||||
|
FILE "${CMAKE_CURRENT_BINARY_DIR}/SpectreTargets.cmake"
|
||||||
|
)
|
||||||
|
|
||||||
|
# CMake config
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
|
# Version
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
write_basic_package_version_file(SpectreConfigVersion.cmake COMPATIBILITY SameMajorVersion)
|
||||||
|
|
||||||
|
set (ASSETS_DIR ${CMAKE_INSTALL_DATADIR}/assets)
|
||||||
|
configure_package_config_file(cmake/SpectreConfig.cmake.in
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/cmake/SpectreConfig.cmake
|
||||||
|
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Spectre
|
||||||
|
PATH_VARS ASSETS_DIR)
|
||||||
|
|
||||||
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/SpectreConfig.cmake
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/SpectreConfigVersion.cmake
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Spectre)
|
||||||
|
|
||||||
|
# CMake config - build directory
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
set (ASSETS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/assets)
|
||||||
|
configure_package_config_file(cmake/SpectreConfig.cmake.in
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/SpectreConfig.cmake
|
||||||
|
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
PATH_VARS ASSETS_DIR)
|
||||||
7
examples/CMakeLists.txt
Normal file
7
examples/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
include("Macros")
|
||||||
|
|
||||||
|
add_subdirectory(window)
|
||||||
|
add_subdirectory(events)
|
||||||
|
add_subdirectory(input)
|
||||||
|
add_subdirectory(text)
|
||||||
7
examples/events/CMakeLists.txt
Normal file
7
examples/events/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
#find_package(Spectre REQUIRED)
|
||||||
|
|
||||||
|
spectre_example(events
|
||||||
|
main.cpp
|
||||||
|
EventsExample.cpp
|
||||||
|
)
|
||||||
34
examples/events/EventsExample.cpp
Normal file
34
examples/events/EventsExample.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
|
||||||
|
#include <Spectre/System/MessageHandler.h>
|
||||||
|
#include <Spectre/System/Log.h>
|
||||||
|
#include "EventsExample.h"
|
||||||
|
|
||||||
|
void EventsExample::init()
|
||||||
|
{
|
||||||
|
getMessageHandler()->registerListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventsExample::onEvent(const sp::Event& event)
|
||||||
|
{
|
||||||
|
if (event.type == sp::Event::Key) {
|
||||||
|
std::string name = event.key.getKeyName();
|
||||||
|
const char* pressed = event.key.pressed ? "pressed" : "released";
|
||||||
|
sp::Log::info("Key: %s %s", name.c_str(), pressed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.type == sp::Event::MouseButton) {
|
||||||
|
std::string name = event.mouseButton.getName();
|
||||||
|
const char* pressed = event.mouseButton.pressed ? "pressed" : "released";
|
||||||
|
sp::Log::info("MouseButton: %s %s", name.c_str(), pressed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventsExample::update(double dt)
|
||||||
|
{
|
||||||
|
// Nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventsExample::render()
|
||||||
|
{
|
||||||
|
// Nothing to do
|
||||||
|
}
|
||||||
22
examples/events/EventsExample.h
Normal file
22
examples/events/EventsExample.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
|
||||||
|
#ifndef EVENTS_EXAMPLE_H
|
||||||
|
#define EVENTS_EXAMPLE_H
|
||||||
|
|
||||||
|
#include <Spectre/Game.h>
|
||||||
|
#include <Spectre/System/EventListener.h>
|
||||||
|
|
||||||
|
class EventsExample : public sp::Game, sp::EventListener
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
void onEvent(const sp::Event& event);
|
||||||
|
|
||||||
|
protected :
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
|
void update(double dt);
|
||||||
|
|
||||||
|
void render();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* EVENTS_EXAMPLE_H */
|
||||||
11
examples/events/main.cpp
Normal file
11
examples/events/main.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
#include "EventsExample.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
EventsExample game;
|
||||||
|
|
||||||
|
game.run();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
7
examples/input/CMakeLists.txt
Normal file
7
examples/input/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
#find_package(Spectre REQUIRED)
|
||||||
|
|
||||||
|
spectre_example(input
|
||||||
|
main.cpp
|
||||||
|
InputExample.cpp
|
||||||
|
)
|
||||||
99
examples/input/InputExample.cpp
Normal file
99
examples/input/InputExample.cpp
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
|
||||||
|
#include <Spectre/Input/InputModule.h>
|
||||||
|
#include <Spectre/Input/Keyboard.h>
|
||||||
|
#include <Spectre/Input/Mouse.h>
|
||||||
|
#include <Spectre/System/MessageHandler.h>
|
||||||
|
#include <Spectre/System/Log.h>
|
||||||
|
|
||||||
|
#include <Spectre/Graphics/BatchRenderer2D.h>
|
||||||
|
#include <Spectre/System/Log.h>
|
||||||
|
#include "InputExample.h"
|
||||||
|
|
||||||
|
void InputExample::init()
|
||||||
|
{
|
||||||
|
m_renderer = new sp::BatchRenderer2D();
|
||||||
|
|
||||||
|
getMessageHandler()->registerListener(this);
|
||||||
|
|
||||||
|
m_tux_texture.create("assets/textures/tux.png");
|
||||||
|
|
||||||
|
m_kb_sprite.setTexture(m_tux_texture);
|
||||||
|
m_kb_sprite.setColor(sp::Color::Green);
|
||||||
|
m_kb_sprite.setSize(sp::vec2f(100, 100));
|
||||||
|
|
||||||
|
m_mouse_sprite.setTexture(m_tux_texture);
|
||||||
|
m_mouse_sprite.setColor(sp::Color::Red);
|
||||||
|
m_mouse_sprite.setSize(sp::vec2f(100, 100));
|
||||||
|
m_mouse_sprite.setPosition(sp::vec2f(50, 50));
|
||||||
|
|
||||||
|
m_mouse_event_sprite.setTexture(m_tux_texture);
|
||||||
|
m_mouse_event_sprite.setColor(sp::Color::Blue);
|
||||||
|
m_mouse_event_sprite.setSize(sp::vec2f(100, 100));
|
||||||
|
m_mouse_event_sprite.setPosition(sp::vec2f(50, 50));
|
||||||
|
|
||||||
|
m_right_mouse_down = false;
|
||||||
|
|
||||||
|
m_renderer->setCamera(m_camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputExample::update(double dt)
|
||||||
|
{
|
||||||
|
sp::Keyboard* keyboard = getInput()->getKeyboard();
|
||||||
|
sp::Mouse* mouse = getInput()->getMouse();
|
||||||
|
double delta = 0.3 * dt;
|
||||||
|
|
||||||
|
// Handle keyboard input.
|
||||||
|
if (keyboard->isKeyDown(sp::Keyboard::Left)) {
|
||||||
|
m_kb_sprite.move(sp::vec2f(-delta, 0));
|
||||||
|
} else if (keyboard->isKeyDown(sp::Keyboard::Right)) {
|
||||||
|
m_kb_sprite.move(sp::vec2f( delta, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keyboard->isKeyDown(sp::Keyboard::Up)) {
|
||||||
|
m_kb_sprite.move(sp::vec2f(0, -delta));
|
||||||
|
} else if (keyboard->isKeyDown(sp::Keyboard::Down)) {
|
||||||
|
m_kb_sprite.move(sp::vec2f(0, delta));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle mouse input.
|
||||||
|
if (mouse->isButtonDown(sp::Mouse::Left)) {
|
||||||
|
m_mouse_sprite.setPosition(mouse->getPosition());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputExample::onSizeChanged(sp::Window* Window, int width, int height)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputExample::onEvent(const sp::Event& event)
|
||||||
|
{
|
||||||
|
if (event.type == event.Key && !event.key.pressed) {
|
||||||
|
if (event.key.code == sp::Keyboard::G) {
|
||||||
|
getGraphics()->getWindow()->grabCursor(true);
|
||||||
|
sp::Log::info("Mouse Grabbed");
|
||||||
|
} else if (event.key.code == sp::Keyboard::U) {
|
||||||
|
getGraphics()->getWindow()->grabCursor(false);
|
||||||
|
sp::Log::info("Mouse Released");
|
||||||
|
}
|
||||||
|
} else if (event.type == event.MouseButton && event.mouseButton.button == sp::Mouse::Right) {
|
||||||
|
m_right_mouse_down = event.mouseButton.pressed;
|
||||||
|
} else if (event.type == event.MouseMove && m_right_mouse_down) {
|
||||||
|
m_mouse_event_sprite.setPosition(event.mouseMove.x, event.mouseMove.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputExample::render()
|
||||||
|
{
|
||||||
|
sp::Graphics* g = getGraphics();
|
||||||
|
|
||||||
|
g->clearBuffer();
|
||||||
|
|
||||||
|
m_renderer->begin();
|
||||||
|
m_renderer->submit(m_mouse_sprite);
|
||||||
|
m_renderer->submit(m_mouse_event_sprite);
|
||||||
|
m_renderer->submit(m_kb_sprite);
|
||||||
|
m_renderer->render();
|
||||||
|
|
||||||
|
g->swapBuffers();
|
||||||
|
}
|
||||||
42
examples/input/InputExample.h
Normal file
42
examples/input/InputExample.h
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
|
||||||
|
#ifndef INPUT_EXAMPLE_H
|
||||||
|
#define INPUT_EXAMPLE_H
|
||||||
|
|
||||||
|
#include <Spectre/Scene/Camera2D.h>
|
||||||
|
#include <Spectre/Graphics/Texture.h>
|
||||||
|
#include <Spectre/Graphics/Sprite.h>
|
||||||
|
#include <Spectre/System/EventListener.h>
|
||||||
|
#include <Spectre/Game.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
class Renderer2D;
|
||||||
|
}
|
||||||
|
|
||||||
|
class InputExample : public sp::Game, sp::EventListener
|
||||||
|
{
|
||||||
|
protected :
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
|
void update(double dt);
|
||||||
|
|
||||||
|
void render();
|
||||||
|
|
||||||
|
void onSizeChanged(sp::Window* display, int width, int height);
|
||||||
|
|
||||||
|
void onEvent(const sp::Event& event);
|
||||||
|
|
||||||
|
private :
|
||||||
|
sp::Camera2D m_camera;
|
||||||
|
sp::Renderer2D *m_renderer;
|
||||||
|
|
||||||
|
sp::Sprite m_kb_sprite;
|
||||||
|
sp::Sprite m_mouse_sprite;
|
||||||
|
sp::Sprite m_mouse_event_sprite;
|
||||||
|
|
||||||
|
bool m_right_mouse_down;
|
||||||
|
|
||||||
|
sp::Texture m_tux_texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* INPUT_EXAMPLE_H*/
|
||||||
11
examples/input/main.cpp
Normal file
11
examples/input/main.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
#include "InputExample.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
InputExample game;
|
||||||
|
|
||||||
|
game.run();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
7
examples/text/CMakeLists.txt
Normal file
7
examples/text/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
#find_package(Spectre REQUIRED)
|
||||||
|
|
||||||
|
spectre_example(text
|
||||||
|
main.cpp
|
||||||
|
Game.cpp
|
||||||
|
)
|
||||||
|
|
@ -2,11 +2,9 @@
|
||||||
#ifndef TEXT_GAME_H
|
#ifndef TEXT_GAME_H
|
||||||
#define TEXT_GAME_H
|
#define TEXT_GAME_H
|
||||||
|
|
||||||
#include <Spectre/Math/Vector2.h>
|
|
||||||
#include <Spectre/Input/InputListener.h>
|
|
||||||
#include <Spectre/Game.h>
|
#include <Spectre/Game.h>
|
||||||
|
|
||||||
class TextExample : public sp::Game, public sp::InputListener
|
class TextExample : public sp::Game
|
||||||
{
|
{
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
|
|
@ -17,4 +15,4 @@ protected :
|
||||||
void render();
|
void render();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* TEXT_GAME_H*/
|
#endif /* TEXT_GAME_H*/
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
|
|
||||||
local base = PathDir(ModuleFilename())
|
|
||||||
|
|
||||||
src ={
|
|
||||||
base .. "/main.cpp",
|
|
||||||
base .. "/Game.cpp"
|
|
||||||
}
|
|
||||||
7
examples/window/CMakeLists.txt
Normal file
7
examples/window/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
#find_package(Spectre REQUIRED)
|
||||||
|
|
||||||
|
spectre_example(window
|
||||||
|
main.cpp
|
||||||
|
WindowExample.cpp
|
||||||
|
)
|
||||||
70
examples/window/WindowExample.cpp
Normal file
70
examples/window/WindowExample.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
|
||||||
|
#include <Spectre/Window/Window.h>
|
||||||
|
#include <Spectre/Graphics/BatchRenderer2D.h>
|
||||||
|
#include <Spectre/System/MessageHandler.h>
|
||||||
|
#include <Spectre/System/Log.h>
|
||||||
|
#include "WindowExample.h"
|
||||||
|
|
||||||
|
void WindowExample::init()
|
||||||
|
{
|
||||||
|
m_renderer = new sp::BatchRenderer2D();
|
||||||
|
m_mode = sp::Window::WINDOWED;
|
||||||
|
getMessageHandler()->registerListener(this);
|
||||||
|
|
||||||
|
m_texture.create("assets/textures/tux.png");
|
||||||
|
|
||||||
|
m_sprite.setTexture(m_texture);
|
||||||
|
m_sprite.setPosition(sp::vec2f(50, 50));
|
||||||
|
m_sprite.setSize(sp::vec2f(100, 100));
|
||||||
|
|
||||||
|
m_renderer->setCamera(m_camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowExample::onEvent(const sp::Event& event)
|
||||||
|
{
|
||||||
|
if (event.type == sp::Event::Key && event.key.pressed == false) {
|
||||||
|
|
||||||
|
if (event.key.code == sp::Keyboard::W) {
|
||||||
|
|
||||||
|
if (m_mode == sp::Window::WINDOWED) {
|
||||||
|
m_mode = sp::Window::WINDOWEDFULLSCREEN;
|
||||||
|
sp::Log::info("Windowed Fullscreen");
|
||||||
|
} else {
|
||||||
|
m_mode = sp::Window::WINDOWED;
|
||||||
|
sp::Log::info("Windowed");
|
||||||
|
}
|
||||||
|
|
||||||
|
getGraphics()->setWindowMode(m_mode);
|
||||||
|
|
||||||
|
} else if (event.key.code == sp::Keyboard::Space) {
|
||||||
|
|
||||||
|
if (m_mode == sp::Window::WINDOWED) {
|
||||||
|
m_mode = sp::Window::FULLSCREEN;
|
||||||
|
sp::Log::info("Fullscreen");
|
||||||
|
} else {
|
||||||
|
m_mode = sp::Window::WINDOWED;
|
||||||
|
sp::Log::info("Windowed");
|
||||||
|
}
|
||||||
|
|
||||||
|
getGraphics()->setWindowMode(m_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowExample::update(double dt)
|
||||||
|
{
|
||||||
|
// Nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowExample::render()
|
||||||
|
{
|
||||||
|
sp::Graphics* g = getGraphics();
|
||||||
|
|
||||||
|
g->clearBuffer();
|
||||||
|
|
||||||
|
m_renderer->begin();
|
||||||
|
m_renderer->submit(m_sprite);
|
||||||
|
m_renderer->render();
|
||||||
|
|
||||||
|
g->swapBuffers();
|
||||||
|
}
|
||||||
34
examples/window/WindowExample.h
Normal file
34
examples/window/WindowExample.h
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
|
||||||
|
#ifndef DISPLAY_EXAMPLE_H
|
||||||
|
#define DISPLAY_EXAMPLE_H
|
||||||
|
|
||||||
|
#include <Spectre/Scene/Camera2D.h>
|
||||||
|
#include <Spectre/Graphics/Texture.h>
|
||||||
|
#include <Spectre/Graphics/Sprite.h>
|
||||||
|
#include <Spectre/System/EventListener.h>
|
||||||
|
#include <Spectre/Game.h>
|
||||||
|
|
||||||
|
class WindowExample : public sp::Game, sp::EventListener
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
void onEvent(const sp::Event& event);
|
||||||
|
|
||||||
|
protected :
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
|
void update(double dt);
|
||||||
|
|
||||||
|
void render();
|
||||||
|
|
||||||
|
protected :
|
||||||
|
|
||||||
|
sp::Window::Mode m_mode;
|
||||||
|
|
||||||
|
sp::Camera2D m_camera;
|
||||||
|
sp::Renderer2D *m_renderer;
|
||||||
|
sp::Texture m_texture;
|
||||||
|
sp::Sprite m_sprite;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* DISPLAY_EXAMPLE_H */
|
||||||
11
examples/window/main.cpp
Normal file
11
examples/window/main.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
#include "WindowExample.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
WindowExample game;
|
||||||
|
|
||||||
|
game.run();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -8,13 +8,12 @@ class NonCopyable
|
||||||
{
|
{
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
NonCopyable() {}
|
NonCopyable() = default;
|
||||||
|
virtual ~NonCopyable() = default;
|
||||||
|
|
||||||
private :
|
// Delete Copy constructor and assignment.
|
||||||
|
NonCopyable(const NonCopyable&) = delete;
|
||||||
// Skip implementation to trigger compiler error.
|
NonCopyable& operator =(const NonCopyable&) = delete;
|
||||||
NonCopyable(const NonCopyable&);
|
|
||||||
NonCopyable& operator =(const NonCopyable&);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ namespace sp { namespace core
|
||||||
{
|
{
|
||||||
// Convertion functions from standard c/c++ types.
|
// Convertion functions from standard c/c++ types.
|
||||||
|
|
||||||
|
std::string to_string(int value);
|
||||||
|
|
||||||
std::string to_string(unsigned int value);
|
std::string to_string(unsigned int value);
|
||||||
|
|
||||||
std::string to_string(float value);
|
std::string to_string(float value);
|
||||||
|
|
|
||||||
|
|
@ -1,80 +0,0 @@
|
||||||
|
|
||||||
#ifndef SPECTRE_DISPLAY_DISPLAY_H
|
|
||||||
#define SPECTRE_DISPLAY_DISPLAY_H
|
|
||||||
|
|
||||||
#include "DisplayMode.h"
|
|
||||||
#include "DisplayDescription.h"
|
|
||||||
#include <Spectre/Display/GLContext.h>
|
|
||||||
#include <Spectre/System/SystemEvent.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
class PlatformDisplay;
|
|
||||||
class GLContext;
|
|
||||||
|
|
||||||
class Display
|
|
||||||
{
|
|
||||||
friend class PlatformDisplay;
|
|
||||||
public :
|
|
||||||
enum Mode {
|
|
||||||
WINDOWED = 0,
|
|
||||||
FULLSCREEN = 1,
|
|
||||||
WINDOWEDFULLSCREEN = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
public :
|
|
||||||
Display();
|
|
||||||
virtual ~Display();
|
|
||||||
|
|
||||||
bool create(DisplayDescription decription);
|
|
||||||
|
|
||||||
void destroy();
|
|
||||||
|
|
||||||
void setSize(unsigned int width, unsigned int height);
|
|
||||||
|
|
||||||
void setCaption(const std::string& title);
|
|
||||||
|
|
||||||
const std::string& getCaption() const;
|
|
||||||
|
|
||||||
void setIcon(const std::string& filename);
|
|
||||||
|
|
||||||
void setDisplayMode(const DisplayMode& mode);
|
|
||||||
|
|
||||||
const DisplayMode& getDisplayMode() const;
|
|
||||||
|
|
||||||
void setVideoMode(Mode mode);
|
|
||||||
|
|
||||||
enum Mode getVideoMode() const;
|
|
||||||
|
|
||||||
void showCursor(bool value);
|
|
||||||
|
|
||||||
bool activate(bool value);
|
|
||||||
|
|
||||||
// Enable/Disable Vertical Sync.
|
|
||||||
bool enableVSync(bool value);
|
|
||||||
|
|
||||||
void swapBuffers();
|
|
||||||
|
|
||||||
protected :
|
|
||||||
|
|
||||||
void init();
|
|
||||||
|
|
||||||
void onReshape(int width, int height);
|
|
||||||
|
|
||||||
protected :
|
|
||||||
enum Mode m_fmode;
|
|
||||||
|
|
||||||
DisplayDescription m_description;
|
|
||||||
DisplayDescription m_cacheDesc;
|
|
||||||
|
|
||||||
std::string m_caption;
|
|
||||||
|
|
||||||
PlatformDisplay* m_impl;
|
|
||||||
|
|
||||||
GLContext* m_context;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namepsace sp
|
|
||||||
|
|
||||||
#endif /* SPECTRE_DISPLAY_DISPLAY_H */
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
|
|
||||||
#ifndef SPECTRE_DISPLAY_DISPLAYDESCRIPTION_H
|
|
||||||
#define SPECTRE_DISPLAY_DISPLAYDESCRIPTION_H
|
|
||||||
|
|
||||||
#include "DisplayMode.h"
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
namespace DisplayDecorate {
|
|
||||||
|
|
||||||
enum Type {
|
|
||||||
None = 0,
|
|
||||||
Menu = 1 << 0,
|
|
||||||
Resize = 1 << 1,
|
|
||||||
Close = 1 << 2,
|
|
||||||
Default = Menu | Resize | Close,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DisplayDescription
|
|
||||||
{
|
|
||||||
public :
|
|
||||||
DisplayDescription();
|
|
||||||
DisplayDescription(DisplayMode mode, unsigned decoration = DisplayDecorate::Default);
|
|
||||||
|
|
||||||
public :
|
|
||||||
DisplayMode mode;
|
|
||||||
|
|
||||||
unsigned int decoration;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
||||||
#endif /* SPECTRE_DISPLAY_DISPLAYDESCRIPTION_H */
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
#define SPECTRE_GAME_H
|
#define SPECTRE_GAME_H
|
||||||
|
|
||||||
#include <Spectre/Graphics.h>
|
#include <Spectre/Graphics.h>
|
||||||
#include <Spectre/Input/InputEvent.h>
|
|
||||||
#include <Spectre/Game/FPSCounter.h>
|
#include <Spectre/Game/FPSCounter.h>
|
||||||
|
|
||||||
class InputModule;
|
class InputModule;
|
||||||
|
|
@ -13,6 +12,8 @@ class PlatformApplication;
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
|
namespace log { class Writer; }
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
@ -37,9 +38,9 @@ protected :
|
||||||
|
|
||||||
FPSCounter& getFpsCounter();
|
FPSCounter& getFpsCounter();
|
||||||
|
|
||||||
private :
|
MessageHandler* getMessageHandler() const;
|
||||||
|
|
||||||
void setup();
|
private :
|
||||||
|
|
||||||
void gameLoop();
|
void gameLoop();
|
||||||
|
|
||||||
|
|
@ -55,9 +56,10 @@ private :
|
||||||
|
|
||||||
MessageHandler* m_messageHandler;
|
MessageHandler* m_messageHandler;
|
||||||
|
|
||||||
|
log::Writer* m_log_writer;
|
||||||
|
|
||||||
FPSCounter m_fpsCounter;
|
FPSCounter m_fpsCounter;
|
||||||
|
|
||||||
double m_timestep;
|
|
||||||
|
|
||||||
bool m_running;
|
bool m_running;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
#ifndef SPECTRE_FPS_COUNTER_H
|
#ifndef SPECTRE_FPS_COUNTER_H
|
||||||
#define SPECTRE_FPS_COUNTER_H
|
#define SPECTRE_FPS_COUNTER_H
|
||||||
|
|
||||||
|
#include <Spectre/System/Stopwatch.h>
|
||||||
|
|
||||||
// Simple FPS counter.
|
// Simple FPS counter.
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
@ -15,11 +17,11 @@ public :
|
||||||
// Should be called whenever a frame has been rendered.
|
// Should be called whenever a frame has been rendered.
|
||||||
void addFrame();
|
void addFrame();
|
||||||
|
|
||||||
float getFPS() const;
|
double getFPS() const;
|
||||||
|
|
||||||
// Set the update rate (in seconds).
|
// Set the update rate (in seconds).
|
||||||
// How often the FPS should be sampled and calculated.
|
// How often the FPS should be sampled and calculated.
|
||||||
void setUpdateRate(unsigned int seconds);
|
void setUpdateRate(unsigned int rate);
|
||||||
|
|
||||||
// Update the internal time measurment.
|
// Update the internal time measurment.
|
||||||
bool update();
|
bool update();
|
||||||
|
|
@ -29,17 +31,18 @@ public :
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
// Frame counter.
|
// Number of frames since last update.
|
||||||
unsigned int m_count;
|
unsigned int m_count;
|
||||||
|
|
||||||
// time (in ms)
|
// Last time we updated the counter.
|
||||||
unsigned int m_time;
|
//Time m_time;
|
||||||
|
Stopwatch m_watch;
|
||||||
|
|
||||||
// Update rate (in ms)
|
// Update rate (at what interval should we update)
|
||||||
unsigned int m_updateRate;
|
Time m_updateRate;
|
||||||
|
|
||||||
// Calculated fps.
|
// Calculated Frames per second.
|
||||||
float m_fps;
|
double m_fps;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@
|
||||||
#ifndef SPECTRE_GAME_TIME_H
|
#ifndef SPECTRE_GAME_TIME_H
|
||||||
#define SPECTRE_GAME_TIME_H
|
#define SPECTRE_GAME_TIME_H
|
||||||
|
|
||||||
|
#include <Spectre/Math/Time.h>
|
||||||
|
#include <Spectre/System/Stopwatch.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class GameTime
|
class GameTime
|
||||||
|
|
@ -13,12 +16,12 @@ public :
|
||||||
|
|
||||||
double getTimeStep() const;
|
double getTimeStep() const;
|
||||||
|
|
||||||
unsigned long getElapsed() const;
|
Time getElapsed() const;
|
||||||
|
|
||||||
//bool shouldTick();
|
|
||||||
|
|
||||||
bool beginFrame();
|
bool beginFrame();
|
||||||
|
|
||||||
|
bool shouldTick() const;
|
||||||
|
|
||||||
bool tick();
|
bool tick();
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
@ -33,15 +36,13 @@ protected :
|
||||||
|
|
||||||
// TODO: min,max framerates
|
// TODO: min,max framerates
|
||||||
|
|
||||||
// Time(in ms) when the last update occured.
|
Stopwatch m_watch;
|
||||||
unsigned long m_current;
|
|
||||||
unsigned long m_lastUpdate;
|
|
||||||
double m_acc;
|
|
||||||
|
|
||||||
// timeslice in ms.
|
Time m_acc;
|
||||||
double m_slice;
|
Time m_max_acc;
|
||||||
|
|
||||||
bool m_inLoop;
|
// Timeslice.
|
||||||
|
Time m_slice;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
49
include/Spectre/GfxDriver/GfxDriver.h
Normal file
49
include/Spectre/GfxDriver/GfxDriver.h
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_GFXDRIVER_GFXDRIVER_H
|
||||||
|
#define SPECTRE_GFXDRIVER_GFXDRIVER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
class ShaderProgram;
|
||||||
|
|
||||||
|
class GfxDriver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum BufferFlags {
|
||||||
|
CLEAR_BUFFER_BIT,
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Get the name of the driver.
|
||||||
|
virtual std::string getName() const = 0;
|
||||||
|
|
||||||
|
// Get the version of the driver
|
||||||
|
virtual std::string getVersion() const = 0;
|
||||||
|
|
||||||
|
virtual std::string getVendor() const = 0;
|
||||||
|
|
||||||
|
virtual std::string getCardName() const = 0;
|
||||||
|
|
||||||
|
virtual void setViewport(int x, int y, int width, int height) = 0;
|
||||||
|
|
||||||
|
virtual void setClearColor(float r, float g, float b, float a) = 0;
|
||||||
|
|
||||||
|
virtual void clearBuffer(BufferFlags flags) = 0;
|
||||||
|
|
||||||
|
virtual void clearColorBuffer() = 0;
|
||||||
|
|
||||||
|
// Resources.
|
||||||
|
|
||||||
|
virtual ShaderProgram* createShaderProgram() = 0;
|
||||||
|
|
||||||
|
// CreateIndexBuffer()
|
||||||
|
// CreateVertexBuffer()
|
||||||
|
|
||||||
|
// Draw calls
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif /* SPECTRE_GFXDRIVER_GFXDRIVER_H */
|
||||||
77
include/Spectre/GfxDriver/ShaderProgram.h
Normal file
77
include/Spectre/GfxDriver/ShaderProgram.h
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_GFXDRIVER_SHADERPROGRAM_H
|
||||||
|
#define SPECTRE_GFXDRIVER_SHADERPROGRAM_H
|
||||||
|
|
||||||
|
#include <Spectre/Math/Matrix4.h>
|
||||||
|
#include <Spectre/Math/Color.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
enum ShaderType {
|
||||||
|
Vertex,
|
||||||
|
Fragment
|
||||||
|
};
|
||||||
|
|
||||||
|
class ShaderProgram
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~ShaderProgram();
|
||||||
|
|
||||||
|
// Load a shader program from file.
|
||||||
|
virtual bool loadFromFile(const std::string& filename);
|
||||||
|
|
||||||
|
// Load a shader from file.
|
||||||
|
virtual bool loadFromFile(const std::string& filename, ShaderType type);
|
||||||
|
|
||||||
|
// Load a shader from memory.
|
||||||
|
virtual bool loadFromMemory(const std::string& source, ShaderType type) = 0;
|
||||||
|
|
||||||
|
// Link the program.
|
||||||
|
virtual bool link() = 0;
|
||||||
|
|
||||||
|
// Returns true if the program was linked successfully
|
||||||
|
virtual bool isLinked() const;
|
||||||
|
|
||||||
|
// Enable this shader
|
||||||
|
// All shader operations after this call will affect this shader.
|
||||||
|
virtual void enable() const = 0;
|
||||||
|
|
||||||
|
// Disable this shader
|
||||||
|
// Operations will no longer affect this shader after this call.
|
||||||
|
virtual void disable() const = 0;
|
||||||
|
|
||||||
|
// Get the last shader error.
|
||||||
|
virtual std::string getLastError() const;
|
||||||
|
|
||||||
|
// ---------------------
|
||||||
|
// Variables.
|
||||||
|
// ---------------------
|
||||||
|
// TODO: Move this to a ShaderParameter class
|
||||||
|
|
||||||
|
virtual bool setMVPMatrix(const Matrix4f& matrix) = 0;
|
||||||
|
|
||||||
|
// ---------------------
|
||||||
|
// General Variables.
|
||||||
|
// ---------------------
|
||||||
|
|
||||||
|
virtual bool setAttribute(const std::string& name, float value) const = 0;
|
||||||
|
|
||||||
|
virtual bool setAttribute(const std::string& name, const Matrix4f& matrix) const = 0;
|
||||||
|
|
||||||
|
virtual bool setUniform(const std::string& name, const Matrix4f& matrix) const = 0;
|
||||||
|
|
||||||
|
virtual bool setUniform(const std::string& name, const Color& color) const = 0;
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
std::string m_extension;
|
||||||
|
|
||||||
|
mutable std::string m_error;
|
||||||
|
|
||||||
|
bool m_linked;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif /* SECTRE_GRAPHICS_SHADERPROGRAM_H */
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
#ifndef GRAPHICS_H
|
#ifndef GRAPHICS_H
|
||||||
#define GRAPHICS_H
|
#define GRAPHICS_H
|
||||||
|
|
||||||
#include <Spectre/Display/Display.h>
|
#include <Spectre/GfxDriver/GfxDriver.h>
|
||||||
|
#include <Spectre/Window/GLWindow.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
|
|
@ -30,7 +31,7 @@ public :
|
||||||
|
|
||||||
std::string getVersion() const;
|
std::string getVersion() const;
|
||||||
|
|
||||||
void setDisplayMode(Display::Mode mode);
|
void setWindowMode(Window::Mode mode);
|
||||||
|
|
||||||
void setSize(int width, int height);
|
void setSize(int width, int height);
|
||||||
|
|
||||||
|
|
@ -42,12 +43,19 @@ public :
|
||||||
|
|
||||||
void swapBuffers();
|
void swapBuffers();
|
||||||
|
|
||||||
|
GfxDriver* getDriver();
|
||||||
|
|
||||||
|
GLWindow* getWindow();
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
int m_width;
|
int m_width;
|
||||||
int m_height;
|
int m_height;
|
||||||
|
|
||||||
Display *m_display;
|
GLWindow *m_window;
|
||||||
|
|
||||||
|
// Graphics Driver. OpenGL/Vulcan/DirectX etc.
|
||||||
|
GfxDriver *m_gfxdrv;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,10 @@ protected :
|
||||||
|
|
||||||
struct Batch
|
struct Batch
|
||||||
{
|
{
|
||||||
RenderType type;
|
RenderType type;
|
||||||
const Texture* texture;
|
const Texture* texture;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
unsigned int offset;
|
unsigned int offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<Batch> BatchQueue;
|
typedef std::vector<Batch> BatchQueue;
|
||||||
|
|
@ -67,8 +67,8 @@ protected :
|
||||||
|
|
||||||
unsigned short m_size;
|
unsigned short m_size;
|
||||||
|
|
||||||
ShaderProgram m_textShader;
|
ShaderProgram* m_textShader;
|
||||||
ShaderProgram m_spriteShader;
|
ShaderProgram* m_spriteShader;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
|
class ShaderProgram;
|
||||||
|
|
||||||
class DefaultRenderer2D : public Renderer2D
|
class DefaultRenderer2D : public Renderer2D
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
@ -21,7 +23,7 @@ protected :
|
||||||
|
|
||||||
std::vector<const Renderable2D*> m_queue;
|
std::vector<const Renderable2D*> m_queue;
|
||||||
|
|
||||||
ShaderProgram m_shader;
|
ShaderProgram* m_shader;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
|
|
||||||
#ifndef SPECTRE_GRAPHCIS_FONT_H
|
#ifndef SPECTRE_GRAPHICS_FONT_H
|
||||||
#define SPECTRE_GRAPHCIS_FONT_H
|
#define SPECTRE_GRAPHICS_FONT_H
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <Spectre/Math/Vector4.h>
|
|
||||||
#include <Spectre/Math/Vector2.h>
|
#include <Spectre/Math/Vector2.h>
|
||||||
#include <Spectre/Graphics/Texture.h>
|
#include <Spectre/Graphics/Texture.h>
|
||||||
|
#include <Spectre/Graphics/Font/Glyph.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class FontDriver;
|
class FontEngine;
|
||||||
|
|
||||||
// TODO: Fixup this api :)
|
// TODO: Fixup this api :)
|
||||||
|
|
||||||
|
|
@ -24,16 +24,6 @@ public :
|
||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Glyph {
|
|
||||||
vec2b size; // Width, Height of bounding box.
|
|
||||||
vec2b offset; // Offset from cursor where the box begins.
|
|
||||||
unsigned char advance;
|
|
||||||
|
|
||||||
//vec4u tex_coords;
|
|
||||||
vec2u texture_origin;
|
|
||||||
const Texture* texture; // Texture atlas.
|
|
||||||
};
|
|
||||||
|
|
||||||
Font();
|
Font();
|
||||||
~Font();
|
~Font();
|
||||||
|
|
||||||
|
|
@ -65,7 +55,7 @@ protected :
|
||||||
Texture texture;
|
Texture texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
FontDriver *m_driver;
|
FontEngine *m_engine;
|
||||||
|
|
||||||
mutable std::map<unsigned char, Glyph> m_charset;
|
mutable std::map<unsigned char, Glyph> m_charset;
|
||||||
|
|
||||||
|
|
@ -77,4 +67,4 @@ protected :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* SPECTRE_GRAPHCIS_FONT_H */
|
#endif /* SPECTRE_GRAPHICS_FONT_H */
|
||||||
|
|
|
||||||
22
include/Spectre/Graphics/Font/FontDescription.h
Normal file
22
include/Spectre/Graphics/Font/FontDescription.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_GRAPHICS_FONT_FONTDESCRIPTION_H
|
||||||
|
#define SPECTRE_GRAPHICS_FONT_FONTDESCRIPTION_H
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
class FontDescription
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
void hinting(bool value = true);
|
||||||
|
|
||||||
|
bool isHintingEnabled() const;
|
||||||
|
|
||||||
|
protected :
|
||||||
|
|
||||||
|
// True if hinting is enabled. false otherwise.
|
||||||
|
bool m_hinting = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif /* SPECTRE_GRAPHICS_FONT_FONTDESCRIPTION_H */
|
||||||
21
include/Spectre/Graphics/Font/Glyph.h
Normal file
21
include/Spectre/Graphics/Font/Glyph.h
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_GRAPHICS_FONT_GLYPH_H
|
||||||
|
#define SPECTRE_GRAPHICS_FONT_GLYPH_H
|
||||||
|
|
||||||
|
#include <Spectre/Math/Vector2.h>
|
||||||
|
#include <Spectre/Graphics/Texture.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
struct Glyph {
|
||||||
|
vec2b size; // Width, Height of bounding box.
|
||||||
|
vec2b offset; // Offset from cursor where the box begins.
|
||||||
|
unsigned char advance;
|
||||||
|
|
||||||
|
vec2u texture_origin;
|
||||||
|
const Texture* texture; // Texture atlas.
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif // SPECTRE_GRAPHICS_FONT_GLYPH_H
|
||||||
|
|
@ -13,13 +13,16 @@ namespace sp {
|
||||||
class Image
|
class Image
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
enum Channels {
|
||||||
|
Alpha,
|
||||||
|
RGB,
|
||||||
|
RGBA
|
||||||
|
};
|
||||||
|
|
||||||
Image();
|
Image();
|
||||||
|
|
||||||
void create(unsigned width, unsigned height, const Color& color = Color::Black);
|
void create(unsigned width, unsigned height, const Color& color = Color::Black, enum Channels comp = Channels::RGBA);
|
||||||
|
void create(unsigned width, unsigned height, const void* pixels, PixelFormat format = PixelFormat::PF_RGBA);
|
||||||
void create(unsigned width, unsigned height, const void* pixels);
|
|
||||||
void create(PixelFormat format, unsigned width, unsigned height, const Color& color = Color::Black);
|
|
||||||
void create(PixelFormat format, unsigned width, unsigned height, const void* pixels);
|
|
||||||
|
|
||||||
const Vector2u& getSize() const;
|
const Vector2u& getSize() const;
|
||||||
|
|
||||||
|
|
@ -27,7 +30,7 @@ public :
|
||||||
|
|
||||||
unsigned int getHeight() const;
|
unsigned int getHeight() const;
|
||||||
|
|
||||||
unsigned int getBpp() const;
|
unsigned int getNumChannels() const;
|
||||||
|
|
||||||
unsigned int getStride() const;
|
unsigned int getStride() const;
|
||||||
|
|
||||||
|
|
@ -46,7 +49,7 @@ public :
|
||||||
|
|
||||||
Color getPixel(unsigned x, unsigned y) const;
|
Color getPixel(unsigned x, unsigned y) const;
|
||||||
|
|
||||||
void setPixels(const void* pixels);
|
void setPixels(const void* pixels, PixelFormat format = PixelFormat::PF_RGBA);
|
||||||
|
|
||||||
const unsigned char* getPixels() const;
|
const unsigned char* getPixels() const;
|
||||||
|
|
||||||
|
|
@ -56,7 +59,7 @@ private :
|
||||||
|
|
||||||
Vector2u m_size;
|
Vector2u m_size;
|
||||||
|
|
||||||
PixelFormat m_format;
|
enum Channels m_channels;
|
||||||
|
|
||||||
std::vector<unsigned char> m_pixels;
|
std::vector<unsigned char> m_pixels;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
|
|
||||||
#ifndef SPECTRE_OPENGL_H
|
|
||||||
#define SPECTRE_OPENGL_H
|
|
||||||
|
|
||||||
#include <Spectre/Graphics/GL/glad.h>
|
|
||||||
|
|
||||||
#endif /* SPECTRE_OPENGL_H */
|
|
||||||
|
|
@ -1,16 +1,49 @@
|
||||||
#ifndef SPECTRE_GRAPHICS_PIXELFORMAT_H
|
#ifndef SPECTRE_GRAPHICS_PIXELFORMAT_H
|
||||||
#define SPECTRE_GRAPHICS_PIXELFORMAT_H
|
#define SPECTRE_GRAPHICS_PIXELFORMAT_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
enum PixelFormat
|
enum PixelFormat
|
||||||
{
|
{
|
||||||
PF_Unknown = 0,
|
PF_Unknown = 0,
|
||||||
PF_RGB = 1,
|
PF_Alpha = 1, // 8 bit alpha channel.
|
||||||
PF_RGBA = 2,
|
|
||||||
PF_Alpha = 3, // 1 byte alpha channel.
|
// Byte-order formats.
|
||||||
|
// Pixels are always ordered with the first channel at the first byte, second channel at the second byte.
|
||||||
|
// ---------------------------
|
||||||
|
|
||||||
|
PF_RGB = 2, // Standard RGB: 24 bits per pixel, 8 bits are used for red, green, blue.
|
||||||
|
PF_RGBX = 3, // 32 bits per pixel, 8 bits are used for red, green, Last 8 bits are unused.
|
||||||
|
PF_RGBA = 4, // Standard RGBA: 32 bits per pixel, 8 bits are used for red, green, blue, alpha.
|
||||||
|
PF_BGR = 5, // 24 bits per pixel, 8 bits are used for blue, green, red.
|
||||||
|
PF_BGRX = 6, // 32 bits per pixel, 8 bits are used for blue, green, red. Last 8 bits are unused.
|
||||||
|
PF_BGRA = 7, // 32 bits per pixel, 8 bits are used for blue, green, red, alpha.
|
||||||
|
|
||||||
|
// Packed formats.
|
||||||
|
// ---------------------------
|
||||||
|
|
||||||
|
// 32-bit: Pixels are in ordered in 32-bit words. where the first channel is stored at the most significant byte (MSB).
|
||||||
|
// these formats are architecture dependant (litte/big-endian).
|
||||||
|
// (MSB) | byte 0 | byte 1 | byte 2 | byte 3 | (LSB)
|
||||||
|
PF_RGBX32 = 8, // | rrrr rrrr | gggg gggg | bbbb bbbb | xxxx xxxx |
|
||||||
|
PF_RGBA32 = 9, // | rrrr rrrr | gggg gggg | bbbb bbbb | aaaa aaaa |
|
||||||
|
PF_BGRX32 = 10, // | bbbb bbbb | gggg gggg | rrrr rrrr | xxxx xxxx |
|
||||||
|
PF_BGRA32 = 11, // | bbbb bbbb | gggg gggg | rrrr rrrr | aaaa aaaa |
|
||||||
|
|
||||||
|
// 24-bit (unsuppored for now)
|
||||||
|
//PF_RGB24 = 12, // | rrrr rrrr | gggg gggg | bbbb bbbb |
|
||||||
|
//PF_BGR24 = 13, // | bbbb bbbb | gggg gggg | rrrr rrrr |
|
||||||
|
|
||||||
|
// 16-bit (unsuppored for now)
|
||||||
|
//PF_RGB565 = 14, // | rrrr rggg | gggb bbbb |
|
||||||
|
//PF_RGBA5551 = 15 // | rrrr rggg | ggb bbbba |
|
||||||
|
//PF_RGBX5551 = 16 // | rrrr rggg | ggb bbbbx |
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uint8_t PF_getNumChannels(enum PixelFormat format);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
#endif /* SPECTRE_GRAPHICS_PIXELFORMAT_H */
|
#endif /* SPECTRE_GRAPHICS_PIXELFORMAT_H */
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
#define SPECTRE_GRAPHICS_RENDERER2D_H
|
#define SPECTRE_GRAPHICS_RENDERER2D_H
|
||||||
|
|
||||||
#include <Spectre/Graphics/Renderable.h>
|
#include <Spectre/Graphics/Renderable.h>
|
||||||
#include <Spectre/Graphics/ShaderProgram.h>
|
|
||||||
#include <Spectre/Scene/Camera2D.h>
|
#include <Spectre/Scene/Camera2D.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
|
|
||||||
#ifndef SPECTRE_GRAPHICS_SHADER_H
|
|
||||||
#define SPECTRE_GRAPHICS_SHADER_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
class Shader
|
|
||||||
{
|
|
||||||
public :
|
|
||||||
enum Type {
|
|
||||||
Vertex,
|
|
||||||
Fragment
|
|
||||||
};
|
|
||||||
|
|
||||||
Shader(Type type, const std::string& name = "");
|
|
||||||
~Shader();
|
|
||||||
|
|
||||||
unsigned int getHandle() const;
|
|
||||||
|
|
||||||
const std::string& getName() const;
|
|
||||||
|
|
||||||
// Load shader from file.
|
|
||||||
bool loadFromFile(const std::string& file);
|
|
||||||
|
|
||||||
// Load shader from memory
|
|
||||||
bool loadFromMemory(const std::string& source);
|
|
||||||
|
|
||||||
const std::string& getError() const;
|
|
||||||
|
|
||||||
// Is this shader compiled?
|
|
||||||
bool isCompiled() const;
|
|
||||||
|
|
||||||
protected :
|
|
||||||
|
|
||||||
// Compile the shader.
|
|
||||||
// Returns true if the shader compiled without errors. false otherwise.
|
|
||||||
bool compile();
|
|
||||||
|
|
||||||
std::string fetchErrorLog();
|
|
||||||
|
|
||||||
protected :
|
|
||||||
|
|
||||||
// Type of shader. Vertex, fragment, geometry etc.
|
|
||||||
Type m_type;
|
|
||||||
|
|
||||||
unsigned int m_handle; // Shader id.
|
|
||||||
|
|
||||||
// A name for the shader (usually the filename if loaded from file).
|
|
||||||
std::string m_name;
|
|
||||||
|
|
||||||
std::string m_error;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
||||||
#endif /* SPECTRE_GRAPHICS_SHADER_H */
|
|
||||||
|
|
@ -1,90 +0,0 @@
|
||||||
|
|
||||||
#ifndef SPECTRE_GRAPHICS_SHADER_PROGRAM_H
|
|
||||||
#define SPECTRE_GRAPHICS_SHADER_PROGRAM_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <Spectre/Math/Matrix4.h>
|
|
||||||
#include "Shader.h"
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
struct Color;
|
|
||||||
|
|
||||||
class ShaderProgram
|
|
||||||
{
|
|
||||||
public :
|
|
||||||
ShaderProgram();
|
|
||||||
~ShaderProgram();
|
|
||||||
|
|
||||||
void create();
|
|
||||||
|
|
||||||
void destroy();
|
|
||||||
|
|
||||||
void addShader(const Shader& shader);
|
|
||||||
|
|
||||||
// Load a shader program from file.
|
|
||||||
//
|
|
||||||
// The following naming conventions are supported:
|
|
||||||
// <name>.glsl - Virtual file, will load all real shader files with the same name.
|
|
||||||
// <name>.vert.glsl - Vertex shader.
|
|
||||||
// <name>.frag.glsl - Fragment shader.
|
|
||||||
bool loadFromFile(const std::string& filename);
|
|
||||||
|
|
||||||
// Load a shader from file.
|
|
||||||
bool loadFromFile(const std::string& filename, Shader::Type type);
|
|
||||||
|
|
||||||
// Load a shader from memory.
|
|
||||||
bool loadFromMemory(const std::string& source, Shader::Type type);
|
|
||||||
|
|
||||||
// Link the program.
|
|
||||||
bool link();
|
|
||||||
|
|
||||||
// Returns true if the program was linked successfully
|
|
||||||
bool isLinked() const;
|
|
||||||
|
|
||||||
// Enable this shader
|
|
||||||
// All shader operations after this call will affect this shader.
|
|
||||||
void enable() const;
|
|
||||||
|
|
||||||
// Disable this shader
|
|
||||||
// Operations will no longer affect this shader after this call.
|
|
||||||
void disable() const;
|
|
||||||
|
|
||||||
// Get the last shader error.
|
|
||||||
std::string getLastError() const;
|
|
||||||
|
|
||||||
// ---------------------
|
|
||||||
// Variables.
|
|
||||||
// ---------------------
|
|
||||||
|
|
||||||
bool setMVPMatrix(const Matrix4f& matrix);
|
|
||||||
|
|
||||||
// ---------------------
|
|
||||||
// General Variables.
|
|
||||||
// ---------------------
|
|
||||||
|
|
||||||
bool setAttribute(const std::string& name, float value) const;
|
|
||||||
|
|
||||||
bool setAttribute(const std::string& name, const Matrix4f& matrix) const;
|
|
||||||
|
|
||||||
bool setUniform(const std::string& name, const Matrix4f& matrix) const;
|
|
||||||
|
|
||||||
bool setUniform(const std::string& name, const Color& color) const;
|
|
||||||
|
|
||||||
protected :
|
|
||||||
|
|
||||||
bool getAttribLoc(const std::string& name, int& loc) const;
|
|
||||||
bool getUniformLoc(const std::string& name, int& loc) const;
|
|
||||||
|
|
||||||
std::string fetchErrorLog();
|
|
||||||
|
|
||||||
protected :
|
|
||||||
|
|
||||||
unsigned int m_id; // program id
|
|
||||||
|
|
||||||
mutable std::string m_error;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
||||||
#endif /* SPECTRE_GRAPHICS_SHADER_PROGRAM_H */
|
|
||||||
|
|
@ -16,19 +16,19 @@ class Texture : public NonCopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Filter {
|
enum Filter {
|
||||||
Nearest = 0x2600,
|
Nearest = 0x2600,
|
||||||
Linear = 0x2601,
|
Linear = 0x2601,
|
||||||
NearestMipmapNearest = 0x2700,
|
NearestMipmapNearest = 0x2700,
|
||||||
NearestMipmapLinear = 0x2702,
|
NearestMipmapLinear = 0x2702,
|
||||||
LinearMipmapNearest = 0x2701,
|
LinearMipmapNearest = 0x2701,
|
||||||
LinearMipmapLinear = 0x2703,
|
LinearMipmapLinear = 0x2703,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum WrapMode {
|
enum WrapMode {
|
||||||
Repeat = 0x2901,
|
Repeat = 0x2901,
|
||||||
RepeatMirror = 0x8370,
|
RepeatMirror = 0x8370,
|
||||||
ClampToEdge = 0x812F,
|
ClampToEdge = 0x812F,
|
||||||
ClampToBorder = 0x812D,
|
ClampToBorder = 0x812D,
|
||||||
};
|
};
|
||||||
|
|
||||||
Texture();
|
Texture();
|
||||||
|
|
@ -85,9 +85,9 @@ protected :
|
||||||
|
|
||||||
unsigned int m_id;
|
unsigned int m_id;
|
||||||
|
|
||||||
Vector2u m_size;
|
Vector2u m_size;
|
||||||
|
|
||||||
PixelFormat m_format;
|
PixelFormat m_format;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
#ifndef SPECTRE_INTPUT_DEVICE_H
|
#ifndef SPECTRE_INTPUT_DEVICE_H
|
||||||
#define SPECTRE_INTPUT_DEVICE_H
|
#define SPECTRE_INTPUT_DEVICE_H
|
||||||
|
|
||||||
#include "InputModule.h"
|
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
|
class InputModule;
|
||||||
|
|
||||||
class InputDevice
|
class InputDevice
|
||||||
{
|
{
|
||||||
friend class InputModule;
|
friend class InputModule;
|
||||||
|
|
|
||||||
|
|
@ -1,157 +0,0 @@
|
||||||
|
|
||||||
#ifndef SPECTRE_INPUT_EVENT_H
|
|
||||||
#define SPECTRE_INPUT_EVENT_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
namespace MouseButton {
|
|
||||||
|
|
||||||
enum Type {
|
|
||||||
Unknown,
|
|
||||||
Left,
|
|
||||||
Right,
|
|
||||||
Middle,
|
|
||||||
Button1,
|
|
||||||
Button2,
|
|
||||||
NUM_MBUTTONS,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace Key {
|
|
||||||
|
|
||||||
enum Type {
|
|
||||||
Unknown,
|
|
||||||
A,
|
|
||||||
B,
|
|
||||||
C,
|
|
||||||
D,
|
|
||||||
E,
|
|
||||||
F,
|
|
||||||
G,
|
|
||||||
H,
|
|
||||||
I,
|
|
||||||
J,
|
|
||||||
K,
|
|
||||||
L,
|
|
||||||
M,
|
|
||||||
N,
|
|
||||||
O,
|
|
||||||
P,
|
|
||||||
Q,
|
|
||||||
R,
|
|
||||||
S,
|
|
||||||
T,
|
|
||||||
U,
|
|
||||||
V,
|
|
||||||
W,
|
|
||||||
X,
|
|
||||||
Y,
|
|
||||||
Z,
|
|
||||||
One,
|
|
||||||
Two,
|
|
||||||
Three,
|
|
||||||
Four,
|
|
||||||
Five,
|
|
||||||
Six,
|
|
||||||
Seven,
|
|
||||||
Eight,
|
|
||||||
Nine,
|
|
||||||
Zero,
|
|
||||||
Period,
|
|
||||||
Comma,
|
|
||||||
Enter,
|
|
||||||
Backspace,
|
|
||||||
Escape,
|
|
||||||
Space,
|
|
||||||
Capslock,
|
|
||||||
Up,
|
|
||||||
Down,
|
|
||||||
Left,
|
|
||||||
Right,
|
|
||||||
NUMPAD_1,
|
|
||||||
NUMPAD_2,
|
|
||||||
NUMPAD_3,
|
|
||||||
NUMPAD_4,
|
|
||||||
NUMPAD_5,
|
|
||||||
NUMPAD_6,
|
|
||||||
NUMPAD_7,
|
|
||||||
NUMPAD_8,
|
|
||||||
NUMPAD_9,
|
|
||||||
NUMPAD_0,
|
|
||||||
NUMPAD_Enter,
|
|
||||||
Home,
|
|
||||||
End,
|
|
||||||
Insert,
|
|
||||||
Delete,
|
|
||||||
PageUp,
|
|
||||||
PageDown,
|
|
||||||
Pause,
|
|
||||||
F1,
|
|
||||||
F2,
|
|
||||||
F3,
|
|
||||||
F4,
|
|
||||||
F5,
|
|
||||||
F6,
|
|
||||||
F7,
|
|
||||||
F8,
|
|
||||||
F9,
|
|
||||||
F10,
|
|
||||||
F11,
|
|
||||||
F12,
|
|
||||||
Tab,
|
|
||||||
LShift,
|
|
||||||
RShift,
|
|
||||||
LCtrl,
|
|
||||||
RCtrl,
|
|
||||||
LAlt,
|
|
||||||
RAlt,
|
|
||||||
NUM_KEYS,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct InputEvent
|
|
||||||
{
|
|
||||||
enum Type
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Key,
|
|
||||||
MouseButton,
|
|
||||||
MousePosition
|
|
||||||
};
|
|
||||||
|
|
||||||
struct KeyEvent {
|
|
||||||
Key::Type code;
|
|
||||||
bool pressed; /* true if pressed, false if released. */
|
|
||||||
|
|
||||||
std::string getKeyName() const; /* Get the key name */
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MouseButtonEvent {
|
|
||||||
MouseButton::Type button;
|
|
||||||
bool pressed; /* true if pressed, false if released. */
|
|
||||||
|
|
||||||
std::string getName() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MouseEvent {
|
|
||||||
unsigned int x;
|
|
||||||
unsigned int y;
|
|
||||||
};
|
|
||||||
|
|
||||||
Type type;
|
|
||||||
union {
|
|
||||||
struct KeyEvent key;
|
|
||||||
struct MouseEvent mouse;
|
|
||||||
struct MouseButtonEvent mouseButton;
|
|
||||||
};
|
|
||||||
|
|
||||||
InputEvent(Type type = None);
|
|
||||||
|
|
||||||
} InputEvent;
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
||||||
#endif /* SPECTRE_INPUT_EVENT_H */
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
|
|
||||||
#ifndef SPECTRE_INPUT_LISTENER_H
|
|
||||||
#define SPECTRE_INPUT_LISTENER_H
|
|
||||||
|
|
||||||
#include "InputEvent.h"
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
class InputListener
|
|
||||||
{
|
|
||||||
public :
|
|
||||||
virtual void onInputEvent(const InputEvent& event);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
||||||
#endif /* SPECTRE_INPUT_LISTENER_H */
|
|
||||||
|
|
@ -5,9 +5,6 @@
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "InputListener.h"
|
|
||||||
#include "InputEvent.h"
|
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class Mouse;
|
class Mouse;
|
||||||
|
|
@ -28,12 +25,6 @@ public :
|
||||||
|
|
||||||
void addInputDevice(InputDevice *device);
|
void addInputDevice(InputDevice *device);
|
||||||
|
|
||||||
void registerListener(InputListener* listener);
|
|
||||||
|
|
||||||
void removeListener(InputListener* listener);
|
|
||||||
|
|
||||||
void postInputEvent(const InputEvent& event);
|
|
||||||
|
|
||||||
// NOTE: Update devices here! (for winapi, process keyboard/mouse messages)
|
// NOTE: Update devices here! (for winapi, process keyboard/mouse messages)
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
|
@ -48,11 +39,6 @@ protected :
|
||||||
|
|
||||||
Keyboard *m_keyboard;
|
Keyboard *m_keyboard;
|
||||||
|
|
||||||
// Buffered input queue.
|
|
||||||
std::deque<InputEvent> m_buffer;
|
|
||||||
|
|
||||||
std::vector<InputListener*> m_listeners;
|
|
||||||
|
|
||||||
PlatformInput *m_platform;
|
PlatformInput *m_platform;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,107 @@
|
||||||
#define SPECTRE_INPUT_KEYBOARD_H
|
#define SPECTRE_INPUT_KEYBOARD_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "InputEvent.h"
|
|
||||||
#include "InputDevice.h"
|
#include "InputDevice.h"
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class Keyboard : public InputDevice
|
class Keyboard : public InputDevice
|
||||||
{
|
{
|
||||||
|
public :
|
||||||
|
enum Key {
|
||||||
|
Unknown,
|
||||||
|
A,
|
||||||
|
B,
|
||||||
|
C,
|
||||||
|
D,
|
||||||
|
E,
|
||||||
|
F,
|
||||||
|
G,
|
||||||
|
H,
|
||||||
|
I,
|
||||||
|
J,
|
||||||
|
K,
|
||||||
|
L,
|
||||||
|
M,
|
||||||
|
N,
|
||||||
|
O,
|
||||||
|
P,
|
||||||
|
Q,
|
||||||
|
R,
|
||||||
|
S,
|
||||||
|
T,
|
||||||
|
U,
|
||||||
|
V,
|
||||||
|
W,
|
||||||
|
X,
|
||||||
|
Y,
|
||||||
|
Z,
|
||||||
|
One,
|
||||||
|
Two,
|
||||||
|
Three,
|
||||||
|
Four,
|
||||||
|
Five,
|
||||||
|
Six,
|
||||||
|
Seven,
|
||||||
|
Eight,
|
||||||
|
Nine,
|
||||||
|
Zero,
|
||||||
|
Period,
|
||||||
|
Comma,
|
||||||
|
Enter,
|
||||||
|
Backspace,
|
||||||
|
Escape,
|
||||||
|
Space,
|
||||||
|
Capslock,
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Numpad1,
|
||||||
|
Numpad2,
|
||||||
|
Numpad3,
|
||||||
|
Numpad4,
|
||||||
|
Numpad5,
|
||||||
|
Numpad6,
|
||||||
|
Numpad7,
|
||||||
|
Numpad8,
|
||||||
|
Numpad9,
|
||||||
|
Numpad0,
|
||||||
|
Home,
|
||||||
|
End,
|
||||||
|
Insert,
|
||||||
|
Delete,
|
||||||
|
PageUp,
|
||||||
|
PageDown,
|
||||||
|
Pause,
|
||||||
|
F1,
|
||||||
|
F2,
|
||||||
|
F3,
|
||||||
|
F4,
|
||||||
|
F5,
|
||||||
|
F6,
|
||||||
|
F7,
|
||||||
|
F8,
|
||||||
|
F9,
|
||||||
|
F10,
|
||||||
|
F11,
|
||||||
|
F12,
|
||||||
|
Tab,
|
||||||
|
LShift,
|
||||||
|
RShift,
|
||||||
|
LCtrl,
|
||||||
|
RCtrl,
|
||||||
|
LAlt,
|
||||||
|
RAlt,
|
||||||
|
NUM_KEYS,
|
||||||
|
};
|
||||||
|
|
||||||
public :
|
public :
|
||||||
virtual ~Keyboard() {};
|
virtual ~Keyboard() {};
|
||||||
|
|
||||||
virtual bool isKeyDown(Key::Type key) = 0;
|
virtual bool isKeyDown(Key key) = 0;
|
||||||
|
|
||||||
static std::string getKeyName(Key::Type key);
|
static std::string getKeyName(Key key);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -4,26 +4,39 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <Spectre/Math/Vector2.h>
|
#include <Spectre/Math/Vector2.h>
|
||||||
#include "InputEvent.h"
|
#include <Spectre/Input/InputDevice.h>
|
||||||
#include "InputDevice.h"
|
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class Mouse : public InputDevice
|
class Mouse : public InputDevice
|
||||||
{
|
{
|
||||||
|
public :
|
||||||
|
enum Button {
|
||||||
|
Unknown,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Middle,
|
||||||
|
XButton1,
|
||||||
|
XButton2,
|
||||||
|
NUM_MBUTTONS
|
||||||
|
};
|
||||||
|
|
||||||
public :
|
public :
|
||||||
virtual ~Mouse();
|
virtual ~Mouse();
|
||||||
|
|
||||||
// Get mouse position
|
// Get the position in relative (focused window) coordinates.
|
||||||
|
// coordinates are relative to the window's top-left corner.
|
||||||
virtual Vector2f getPosition() const = 0;
|
virtual Vector2f getPosition() const = 0;
|
||||||
|
|
||||||
//virtual Vector2i getPositionAbs() const = 0;
|
// Get the position in absolute (screen) coordinates.
|
||||||
|
// 0,0 is located at the screen's top-left corner.
|
||||||
|
virtual Vector2f getAbsPosition() const = 0;
|
||||||
|
|
||||||
virtual bool isButtonDown(MouseButton::Type button) const = 0;
|
virtual bool isButtonDown(Button button) const = 0;
|
||||||
|
|
||||||
static std::string getButtonName(MouseButton::Type button);
|
static std::string getButtonName(Button button);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
}; // namespace sp
|
||||||
|
|
||||||
#endif /* SPECTRE_INPUT_MOUSE_H */
|
#endif /* SPECTRE_INPUT_MOUSE_H */
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
#ifndef SPECTRE_MATH_MATH_H
|
#ifndef SPECTRE_MATH_MATH_H
|
||||||
#define SPECTRE_MATH_MATH_H
|
#define SPECTRE_MATH_MATH_H
|
||||||
|
|
||||||
|
#include "Transform.h"
|
||||||
|
#include "Vector4.h"
|
||||||
#include "Vector3.h"
|
#include "Vector3.h"
|
||||||
#include "Vector2.h"
|
#include "Vector2.h"
|
||||||
#include "Matrix4.h"
|
#include "Matrix4.h"
|
||||||
|
|
@ -32,21 +34,17 @@ namespace sp { namespace math
|
||||||
float bottom, float top,
|
float bottom, float top,
|
||||||
float zNear = -1.0f, float zFar = 1.0f);
|
float zNear = -1.0f, float zFar = 1.0f);
|
||||||
|
|
||||||
|
//
|
||||||
|
Vector2f Vector2UnProject(Vector2f point, Transform InverseMVP, Vector4u screen);
|
||||||
|
|
||||||
// Create a 2D rotation matrix. (rotation around Z-axis)
|
// Create a 2D rotation matrix. (rotation around Z-axis)
|
||||||
Matrix4f rotation(float theta);
|
Matrix4f rotation(float theta);
|
||||||
|
|
||||||
// Create a 2D translation matrix.
|
// Create a 2D translation matrix.
|
||||||
Matrix4f translate(const Vector2f& v);
|
Matrix4f translate(float x, float y);
|
||||||
|
|
||||||
// Create a 2D scale matrix.
|
// Create a 2D scale matrix.
|
||||||
Matrix4f scale(const Vector2f& f);
|
Matrix4f scale(float x, float y);
|
||||||
|
|
||||||
// Get translation part of a matrix.
|
|
||||||
Vector3f getTranslate(const Matrix4f matrix);
|
|
||||||
|
|
||||||
Vector3f getUpVector(const Matrix4f matrix);
|
|
||||||
|
|
||||||
Vector3f getForwardVector(const Matrix4f matrix);
|
|
||||||
|
|
||||||
} } // namespace sp
|
} } // namespace sp
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,16 @@ struct Matrix3
|
||||||
inline Matrix3<T> operator*(const Matrix3<T>& mat) const;
|
inline Matrix3<T> operator*(const Matrix3<T>& mat) const;
|
||||||
inline Matrix3<T> operator*=(const Matrix3<T>& mat);
|
inline Matrix3<T> operator*=(const Matrix3<T>& mat);
|
||||||
|
|
||||||
// Need scalar, vector arithmetic?
|
|
||||||
|
// -----------------
|
||||||
|
// Arithmetic: Scalar
|
||||||
|
// -----------------
|
||||||
|
|
||||||
|
inline Matrix3<T> operator/(T value) const;
|
||||||
|
inline Matrix3<T> operator/=(T value);
|
||||||
|
|
||||||
|
inline Matrix3<T> operator*(T value) const;
|
||||||
|
inline Matrix3<T> operator*=(T value);
|
||||||
|
|
||||||
// -----------------
|
// -----------------
|
||||||
// Named operations.
|
// Named operations.
|
||||||
|
|
@ -69,6 +78,9 @@ struct Matrix3
|
||||||
|
|
||||||
// Transpose matrix.
|
// Transpose matrix.
|
||||||
Matrix3<T> transpose() const;
|
Matrix3<T> transpose() const;
|
||||||
|
|
||||||
|
// Inverse
|
||||||
|
Matrix3<T> inverse() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
template <>
|
template<typename T>
|
||||||
Matrix3f Matrix3f::Identity(
|
sp::Matrix3<T> sp::Matrix3<T>::Identity(
|
||||||
1, 0, 0,
|
1, 0, 0,
|
||||||
0, 1, 0,
|
0, 1, 0,
|
||||||
0, 0, 1
|
0, 0, 1
|
||||||
|
|
@ -87,6 +87,39 @@ inline Matrix3<T> Matrix3<T>::operator*=(const Matrix3<T>& mat)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline Matrix3<T> Matrix3<T>::operator/(T value) const
|
||||||
|
{
|
||||||
|
return Matrix3<T>(
|
||||||
|
v[0] / value, v[1] / value, v[2] / value,
|
||||||
|
v[3] / value, v[4] / value, v[5] / value,
|
||||||
|
v[6] / value, v[7] / value, v[8] / value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline Matrix3<T> Matrix3<T>::operator/=(T value)
|
||||||
|
{
|
||||||
|
*this = *this / value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline Matrix3<T> Matrix3<T>::operator*(T value) const
|
||||||
|
{
|
||||||
|
return Matrix3<T>(
|
||||||
|
v[0] * value, v[1] * value, v[2] * value,
|
||||||
|
v[3] * value, v[4] * value, v[5] * value,
|
||||||
|
v[6] * value, v[7] * value, v[8] * value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline Matrix3<T> Matrix3<T>::operator*=(T value)
|
||||||
|
{
|
||||||
|
*this = *this * value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
float Matrix3<T>::det() const
|
float Matrix3<T>::det() const
|
||||||
{
|
{
|
||||||
|
|
@ -103,6 +136,30 @@ float Matrix3<T>::det() const
|
||||||
return det;
|
return det;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Matrix3<T> Matrix3<T>::inverse() const
|
||||||
|
{
|
||||||
|
float d = det();
|
||||||
|
|
||||||
|
if (d != 0.0f) {
|
||||||
|
float a00 = (v[4] * v[8]) - (v[7] * v[5]);
|
||||||
|
float a01 = -((v[1] * v[8]) - (v[7] * v[2]));
|
||||||
|
float a02 = (v[1] * v[5]) - (v[4] * v[2]);
|
||||||
|
|
||||||
|
float a10 = -((v[3] * v[8]) - (v[6] * v[5]));
|
||||||
|
float a11 = (v[0] * v[8]) - (v[6] * v[2]);
|
||||||
|
float a12 = -((v[0] * v[5]) - (v[3] * v[2]));
|
||||||
|
|
||||||
|
float a20 = (v[3] * v[7]) - (v[6] * v[4]);
|
||||||
|
float a21 = -((v[0] * v[7]) - (v[6] * v[1]));
|
||||||
|
float a22 = (v[0] * v[4]) - (v[3] * v[1]);
|
||||||
|
|
||||||
|
return Matrix3<T>(a00, a01, a02, a10, a11, a12, a20, a21, a22) / d;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Matrix3<T>::Identity;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Matrix3<T> Matrix3<T>::transpose() const
|
Matrix3<T> Matrix3<T>::transpose() const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
50
include/Spectre/Math/Time.h
Normal file
50
include/Spectre/Math/Time.h
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_MATH_TIME_H
|
||||||
|
#define SPECTRE_MATH_TIME_H
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
class Time {
|
||||||
|
public :
|
||||||
|
Time(long value = 0);
|
||||||
|
|
||||||
|
double seconds() const;
|
||||||
|
|
||||||
|
int milliseconds() const;
|
||||||
|
|
||||||
|
long microseconds() const;
|
||||||
|
|
||||||
|
// ----------------------------
|
||||||
|
// Helper construct functions
|
||||||
|
// ----------------------------
|
||||||
|
static Time seconds(double value);
|
||||||
|
static Time milliseconds(int value);
|
||||||
|
static Time microseconds(long value);
|
||||||
|
|
||||||
|
private :
|
||||||
|
|
||||||
|
// Microseconds (us)
|
||||||
|
long m_us;
|
||||||
|
};
|
||||||
|
|
||||||
|
// ----------------------------
|
||||||
|
// Compare
|
||||||
|
// ----------------------------
|
||||||
|
bool operator ==(const Time& a, const Time& b);
|
||||||
|
bool operator !=(const Time& a, const Time& b);
|
||||||
|
bool operator <(const Time& a, const Time& b);
|
||||||
|
bool operator <=(const Time& a, const Time& b);
|
||||||
|
bool operator >(const Time& a, const Time& b);
|
||||||
|
bool operator >=(const Time& a, const Time& b);
|
||||||
|
|
||||||
|
// ----------------------------
|
||||||
|
// Arithmetic
|
||||||
|
// ----------------------------
|
||||||
|
Time operator +(const Time& a, const Time& b);
|
||||||
|
Time& operator +=(Time& a, const Time& b);
|
||||||
|
Time operator -(const Time& a, const Time& b);
|
||||||
|
Time& operator -=(Time& a, const Time& b);
|
||||||
|
|
||||||
|
}; // namespace sp
|
||||||
|
|
||||||
|
#endif /* SPECTRE_MATH_TIME_H */
|
||||||
|
|
@ -53,7 +53,11 @@ public :
|
||||||
Transform& scale(Vector2f offset);
|
Transform& scale(Vector2f offset);
|
||||||
Transform& scale(float s);
|
Transform& scale(float s);
|
||||||
|
|
||||||
Transform& multiply(const Transform& other);
|
// Inverse
|
||||||
|
|
||||||
|
Transform inverse();
|
||||||
|
|
||||||
|
Transform& combine(const Transform& other);
|
||||||
|
|
||||||
Vector2f transformPoint(float x, float y) const;
|
Vector2f transformPoint(float x, float y) const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,16 +30,16 @@ struct Vector2
|
||||||
// Named operations.
|
// Named operations.
|
||||||
// -----------------
|
// -----------------
|
||||||
|
|
||||||
inline float length() const;
|
inline float len() const;
|
||||||
|
|
||||||
inline Vector2<T>& normalize();
|
inline Vector2<T>& normal();
|
||||||
|
|
||||||
// Dot product
|
// Dot product
|
||||||
inline T dot(const Vector2<T>& vec) const;
|
inline T dot(const Vector2<T>& vec) const;
|
||||||
|
|
||||||
inline Vector2<T>& reflect(const Vector2<T>& n);
|
inline Vector2<T>& reflect(const Vector2<T>& n);
|
||||||
|
|
||||||
std::string toString() const;
|
inline std::string toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ------------
|
// ------------
|
||||||
|
|
@ -182,14 +182,14 @@ inline std::ostream& operator<<(std::ostream &s, const Vector2<T>& v);
|
||||||
// Common specialization types
|
// Common specialization types
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
|
|
||||||
typedef Vector2<float> Vector2f;
|
typedef Vector2<float> Vector2f;
|
||||||
typedef Vector2<int> Vector2i;
|
typedef Vector2<int> Vector2i;
|
||||||
typedef Vector2<unsigned> Vector2u;
|
typedef Vector2<unsigned> Vector2u;
|
||||||
typedef Vector2<unsigned char> Vector2b;
|
typedef Vector2<unsigned char> Vector2b;
|
||||||
|
|
||||||
typedef Vector2<float> vec2f;
|
typedef Vector2<float> vec2f;
|
||||||
typedef Vector2<int> vec2i;
|
typedef Vector2<int> vec2i;
|
||||||
typedef Vector2<unsigned> vec2u;
|
typedef Vector2<unsigned> vec2u;
|
||||||
typedef Vector2<unsigned char> vec2b;
|
typedef Vector2<unsigned char> vec2b;
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -31,15 +31,15 @@ inline Vector2<T>::Vector2(const Vector2<U>& vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline float Vector2<T>::length() const
|
inline float Vector2<T>::len() const
|
||||||
{
|
{
|
||||||
return std::sqrt((x * x) + (y * y));
|
return std::sqrt((x * x) + (y * y));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline Vector2<T>& Vector2<T>::normalize()
|
inline Vector2<T>& Vector2<T>::normal()
|
||||||
{
|
{
|
||||||
float il = 1.0f / length();
|
float il = 1.0f / len();
|
||||||
x *= il; y *= il;
|
x *= il; y *= il;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +58,7 @@ inline Vector2<T>& Vector2<T>::reflect(const Vector2<T>& n)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::string Vector2<T>::toString() const
|
inline std::string Vector2<T>::toString() const
|
||||||
{
|
{
|
||||||
return core::to_string(x) + ", " + core::to_string(y);
|
return core::to_string(x) + ", " + core::to_string(y);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,9 @@ struct Vector3
|
||||||
// Named operations.
|
// Named operations.
|
||||||
// -----------------
|
// -----------------
|
||||||
|
|
||||||
inline float length() const;
|
inline float len() const;
|
||||||
|
|
||||||
inline Vector3<T>& normalize();
|
inline Vector3<T>& normal();
|
||||||
|
|
||||||
inline Vector2<T> toVec2();
|
inline Vector2<T> toVec2();
|
||||||
};
|
};
|
||||||
|
|
@ -159,14 +159,14 @@ inline std::ostream& operator<<(std::ostream &s, const Vector3<T>& v);
|
||||||
// Common specialization types
|
// Common specialization types
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
|
|
||||||
typedef Vector3<float> Vector3f;
|
typedef Vector3<float> Vector3f;
|
||||||
typedef Vector3<int> Vector3i;
|
typedef Vector3<int> Vector3i;
|
||||||
typedef Vector3<unsigned> Vector3u;
|
typedef Vector3<unsigned> Vector3u;
|
||||||
typedef Vector3<unsigned char> Vector3b;
|
typedef Vector3<unsigned char> Vector3b;
|
||||||
|
|
||||||
typedef Vector3<float> vec3f;
|
typedef Vector3<float> vec3f;
|
||||||
typedef Vector3<int> vec3i;
|
typedef Vector3<int> vec3i;
|
||||||
typedef Vector3<unsigned> vec3u;
|
typedef Vector3<unsigned> vec3u;
|
||||||
typedef Vector3<unsigned char> vec3b;
|
typedef Vector3<unsigned char> vec3b;
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ inline Vector3<T>::Vector3(const Vector2<U>& vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline float Vector3<T>::length() const
|
inline float Vector3<T>::len() const
|
||||||
{
|
{
|
||||||
return std::sqrt((x * x) + (y * y) + (z * z));
|
return std::sqrt((x * x) + (y * y) + (z * z));
|
||||||
}
|
}
|
||||||
|
|
@ -55,9 +55,9 @@ Vector2<T> Vector3<T>::toVec2()
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline Vector3<T>& Vector3<T>::normalize()
|
inline Vector3<T>& Vector3<T>::normal()
|
||||||
{
|
{
|
||||||
float il = 1.0f / length();
|
float il = 1.0f / len();
|
||||||
x *= il; y *= il; z *= il;
|
x *= il; y *= il; z *= il;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,9 @@ struct Vector4
|
||||||
|
|
||||||
// Named operations
|
// Named operations
|
||||||
|
|
||||||
inline float length() const;
|
inline float len() const;
|
||||||
|
|
||||||
inline Vector4<T>& normalize();
|
inline Vector4<T>& normal();
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------
|
// ---------
|
||||||
|
|
@ -145,14 +145,14 @@ inline bool operator>=(T s, const Vector4<T>& v);
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline std::ostream& operator<<(std::ostream &s, const Vector4<T>& v);
|
inline std::ostream& operator<<(std::ostream &s, const Vector4<T>& v);
|
||||||
|
|
||||||
typedef Vector4<float> Vector4f;
|
typedef Vector4<float> Vector4f;
|
||||||
typedef Vector4<int> Vector4i;
|
typedef Vector4<int> Vector4i;
|
||||||
typedef Vector4<unsigned> Vector4u;
|
typedef Vector4<unsigned> Vector4u;
|
||||||
typedef Vector4<unsigned char> Vector4b;
|
typedef Vector4<unsigned char> Vector4b;
|
||||||
|
|
||||||
typedef Vector4<float> vec4f;
|
typedef Vector4<float> vec4f;
|
||||||
typedef Vector4<int> vec4i;
|
typedef Vector4<int> vec4i;
|
||||||
typedef Vector4<unsigned> vec4u;
|
typedef Vector4<unsigned> vec4u;
|
||||||
typedef Vector4<unsigned char> vec4b;
|
typedef Vector4<unsigned char> vec4b;
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -36,15 +36,15 @@ Vector4<T>::Vector4(const Vector4<U>& vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
float Vector4<T>::length() const
|
float Vector4<T>::len() const
|
||||||
{
|
{
|
||||||
return std::sqrt((x * x) + (y * y) + (z * z) + (w * w));
|
return std::sqrt((x * x) + (y * y) + (z * z) + (w * w));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Vector4<T>& Vector4<T>::normalize()
|
Vector4<T>& Vector4<T>::normal()
|
||||||
{
|
{
|
||||||
float il = 1.0f / length();
|
float il = 1.0f / len();
|
||||||
x *= il; y *= il; z *= il; w *= il;
|
x *= il; y *= il; z *= il; w *= il;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15
include/Spectre/System/ByteOrder.h
Normal file
15
include/Spectre/System/ByteOrder.h
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_SYSTEM_BYTEORDER_H
|
||||||
|
#define SPECTRE_SYSTEM_BYTEORDER_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace sp { namespace system
|
||||||
|
{
|
||||||
|
uint16_t ltoh16(const uint8_t* bytes);
|
||||||
|
|
||||||
|
uint32_t ltoh32(const uint8_t* bytes);
|
||||||
|
|
||||||
|
} } // namespace sp::system
|
||||||
|
|
||||||
|
#endif /* SPECTRE_SYSTEM_BYTEORDER_H */
|
||||||
76
include/Spectre/System/Event.h
Normal file
76
include/Spectre/System/Event.h
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_SYSTEM_EVENT_H
|
||||||
|
#define SPECTRE_SYSTEM_EVENT_H
|
||||||
|
|
||||||
|
#include <Spectre/Input/Mouse.h>
|
||||||
|
#include <Spectre/Input/Keyboard.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
class Window;
|
||||||
|
|
||||||
|
struct Event
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
|
||||||
|
enum Type {
|
||||||
|
Unknown,
|
||||||
|
Quit,
|
||||||
|
Size,
|
||||||
|
Key,
|
||||||
|
MouseButton,
|
||||||
|
MouseMove
|
||||||
|
};
|
||||||
|
|
||||||
|
struct KeyEvent {
|
||||||
|
Keyboard::Key code;
|
||||||
|
bool pressed; /* true if pressed, false if released. */
|
||||||
|
|
||||||
|
std::string getKeyName() const; /* Get the key name */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MouseButtonEvent {
|
||||||
|
Mouse::Button button;
|
||||||
|
bool pressed; /* true if pressed, false if released. */
|
||||||
|
|
||||||
|
std::string getName() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MouseMoveEvent {
|
||||||
|
unsigned int x;
|
||||||
|
unsigned int y;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SizeEvent
|
||||||
|
{
|
||||||
|
Window *window;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
};
|
||||||
|
|
||||||
|
Type type;
|
||||||
|
union {
|
||||||
|
struct SizeEvent size;
|
||||||
|
struct KeyEvent key;
|
||||||
|
struct MouseMoveEvent mouseMove;
|
||||||
|
struct MouseButtonEvent mouseButton;
|
||||||
|
};
|
||||||
|
|
||||||
|
Event(Type type = Unknown);
|
||||||
|
|
||||||
|
std::string toString() const;
|
||||||
|
|
||||||
|
// Helper methods
|
||||||
|
|
||||||
|
static Event createSize(Window *window, int width, int height);
|
||||||
|
|
||||||
|
static Event createKey(Keyboard::Key code, bool pressed);
|
||||||
|
|
||||||
|
static Event createMouseButton(Mouse::Button button, bool pressed);
|
||||||
|
|
||||||
|
static Event createMouseMove(unsigned int x, unsigned int y);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif /* SPECTRE_SYSTEM_EVENT_H */
|
||||||
23
include/Spectre/System/EventListener.h
Normal file
23
include/Spectre/System/EventListener.h
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
|
||||||
|
#ifndef SYSTEM_EVENT_LISTENER_H
|
||||||
|
#define SYSTEM_EVENT_LISTENER_H
|
||||||
|
|
||||||
|
#include <Spectre/System/Event.h>
|
||||||
|
#include <Spectre/Input/Mouse.h>
|
||||||
|
#include <Spectre/Input/Keyboard.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
class Window;
|
||||||
|
|
||||||
|
class EventListener
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
virtual void onSizeChanged(Window* window, int width, int height);
|
||||||
|
|
||||||
|
virtual void onEvent(const Event& event);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif /* SYSTEM_EVENT_LISTENER_H */
|
||||||
|
|
@ -2,18 +2,118 @@
|
||||||
#ifndef SPECTRE_SYSTEM_FILE_H
|
#ifndef SPECTRE_SYSTEM_FILE_H
|
||||||
#define SPECTRE_SYSTEM_FILE_H
|
#define SPECTRE_SYSTEM_FILE_H
|
||||||
|
|
||||||
#include <vector>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <system_error>
|
||||||
|
|
||||||
namespace sp { namespace file
|
namespace sp {
|
||||||
|
|
||||||
|
class File
|
||||||
{
|
{
|
||||||
std::string getBasename(const std::string& path);
|
public :
|
||||||
|
|
||||||
std::string getExtension(const std::string& path);
|
enum struct Access {
|
||||||
|
READ = 1 << 0,
|
||||||
|
WRITE = 1 << 1,
|
||||||
|
READ_WRITE = READ | WRITE,
|
||||||
|
};
|
||||||
|
|
||||||
std::string getPathname(const std::string& path);
|
// NOTE: These are ignored atm. as implementation uses stdio.h
|
||||||
|
enum OpenMode {
|
||||||
|
// Only open if file exists and
|
||||||
|
// in overwrite mode if write is enabled.
|
||||||
|
DEFAULT = 0,
|
||||||
|
// Create file if it does not exist (ignored in read-only mode)
|
||||||
|
CREATE = 1 << 0,
|
||||||
|
// If file exists any write calls will
|
||||||
|
// append to the file. (ignored in read-only mode)
|
||||||
|
APPEND = 1 << 1,
|
||||||
|
// If file exists it's content are discarded
|
||||||
|
// resulting in an empty file. (ignored in read-only mode)
|
||||||
|
TRUNCATE = 1 << 2
|
||||||
|
};
|
||||||
|
|
||||||
std::vector<unsigned char> read(const std::string& path);
|
// Methods.
|
||||||
} }
|
public :
|
||||||
|
File();
|
||||||
|
|
||||||
|
// see `open()`
|
||||||
|
File(const std::string& filename,
|
||||||
|
Access access = Access::READ,
|
||||||
|
unsigned int mode = DEFAULT);
|
||||||
|
|
||||||
|
~File();
|
||||||
|
|
||||||
|
// Opens a file (default in read-only)
|
||||||
|
bool open(const std::string& filename,
|
||||||
|
Access access = Access::READ,
|
||||||
|
unsigned int mode = DEFAULT);
|
||||||
|
|
||||||
|
// Returns true if the file is open, false otherwise.
|
||||||
|
bool isOpen() const;
|
||||||
|
|
||||||
|
// Close the file.
|
||||||
|
void close();
|
||||||
|
|
||||||
|
std::string getErrorMessage() const;
|
||||||
|
|
||||||
|
// Get the current position in the file.
|
||||||
|
size_t pos();
|
||||||
|
|
||||||
|
// Set the file stream position.
|
||||||
|
// if `from_end` is true. `offset` will be applied from the end of file, otherwise from beginning.
|
||||||
|
// Returns true if the position was updated, false otherwise.
|
||||||
|
bool set(long int pos = 0, bool from_end = false);
|
||||||
|
|
||||||
|
// Move the current file stream position with `offset` bytes.
|
||||||
|
// This is equivalent to calling set(pos() + offset)
|
||||||
|
// Returns true if the position was updated, false otherwise.
|
||||||
|
bool seek(long int offset);
|
||||||
|
|
||||||
|
// Get the size of the file (in bytes)
|
||||||
|
size_t size() const;
|
||||||
|
|
||||||
|
// Read `size` data from file at the current position.
|
||||||
|
// Content is stored in `ptr` and must be alteast `size` bytes.
|
||||||
|
// Returns -1 if an error occured. Otherwice the number of bytes read is returned.
|
||||||
|
size_t read(void *ptr, size_t size);
|
||||||
|
|
||||||
|
// Read all remaining data from file at the current position. Content is stored in `buffer`.
|
||||||
|
// Returns true if exactly all data could be read from file. false otherwise.
|
||||||
|
template <typename buffer_t>
|
||||||
|
inline bool read(buffer_t& buffer)
|
||||||
|
{
|
||||||
|
size_t s = size();
|
||||||
|
buffer.resize(s);
|
||||||
|
return read((void*) &buffer[0], s) == s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read contents into str until null (\0)
|
||||||
|
size_t readString(std::string &str);
|
||||||
|
|
||||||
|
// Write data to file at the current position.
|
||||||
|
// Returns -1 if an error occured. Otherwice the number of bytes written is returned.
|
||||||
|
size_t write(const void *ptr, size_t size);
|
||||||
|
|
||||||
|
// Write data to file at the current position.
|
||||||
|
// Returns true if exactly all data could be written from `buffer`. false otherwise.
|
||||||
|
template <typename buffer_t>
|
||||||
|
inline bool write(const buffer_t& buffer)
|
||||||
|
{
|
||||||
|
return write((const void*) &buffer[0], buffer.size()) == buffer.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flush any buffered data to the file.
|
||||||
|
bool flush();
|
||||||
|
|
||||||
|
private :
|
||||||
|
|
||||||
|
FILE *m_handle;
|
||||||
|
|
||||||
|
// Error
|
||||||
|
mutable std::error_condition m_error;
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace sp
|
||||||
|
|
||||||
#endif /* SPECTRE_SYSTEM_FILE_H */
|
#endif /* SPECTRE_SYSTEM_FILE_H */
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
|
namespace log { class Writer; }
|
||||||
|
|
||||||
class Log
|
class Log
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
@ -15,17 +17,24 @@ public :
|
||||||
T_WARNING = 1 << 0,
|
T_WARNING = 1 << 0,
|
||||||
T_CRITICAL = 1 << 1,
|
T_CRITICAL = 1 << 1,
|
||||||
T_ERROR = 1 << 2,
|
T_ERROR = 1 << 2,
|
||||||
|
T_DEBUG = 1 << 3
|
||||||
};
|
};
|
||||||
|
|
||||||
static void info(const char *message, ...);
|
static void setWriter(log::Writer* writer);
|
||||||
|
|
||||||
static void warn(const char *message, ...);
|
static void info(const char *format, ...);
|
||||||
|
|
||||||
static int error(const char *message, ...);
|
static void warn(const char *format, ...);
|
||||||
|
|
||||||
|
static int error(const char *format, ...);
|
||||||
|
|
||||||
|
static void debug(const char *format, ...);
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
static void writeln(Type type, const char *fmt, va_list args);
|
static void writeln(Type type, const char *fmt, va_list args);
|
||||||
|
|
||||||
|
static log::Writer* _writer;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
32
include/Spectre/System/Log/FileWriter.h
Normal file
32
include/Spectre/System/Log/FileWriter.h
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
#ifndef SPECTRE_SYSTEM_LOG_FILEWRITER_H
|
||||||
|
#define SPECTRE_SYSTEM_LOG_FILEWRITER_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string>
|
||||||
|
#include <Spectre/System/Log/Writer.h>
|
||||||
|
|
||||||
|
namespace sp { namespace log {
|
||||||
|
|
||||||
|
class FileWriter : public Writer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FileWriter(const std::string file = "");
|
||||||
|
~FileWriter();
|
||||||
|
|
||||||
|
bool open(const std::string file);
|
||||||
|
|
||||||
|
bool close();
|
||||||
|
|
||||||
|
size_t write(const void *data, size_t len);
|
||||||
|
|
||||||
|
virtual bool flush();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
FILE *m_fd;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} } // sp::log
|
||||||
|
|
||||||
|
#endif /* SPECTRE_SYSTEM_LOG_FILEWRITER_H */
|
||||||
19
include/Spectre/System/Log/Writer.h
Normal file
19
include/Spectre/System/Log/Writer.h
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef SPECTRE_SYSTEM_LOG_WRITER_H
|
||||||
|
#define SPECTRE_SYSTEM_LOG_WRITER_H
|
||||||
|
|
||||||
|
namespace sp { namespace log {
|
||||||
|
|
||||||
|
class Writer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~Writer() {}
|
||||||
|
|
||||||
|
virtual size_t write(const void *data, size_t len) = 0;
|
||||||
|
|
||||||
|
virtual bool flush() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} } // sp::log
|
||||||
|
|
||||||
|
#endif /* SPECTRE_SYSTEM_LOG_WRITER_H */
|
||||||
|
|
@ -2,16 +2,25 @@
|
||||||
#ifndef SPECTRE_SYSTEM_MESSAGEHANDLER_H
|
#ifndef SPECTRE_SYSTEM_MESSAGEHANDLER_H
|
||||||
#define SPECTRE_SYSTEM_MESSAGEHANDLER_H
|
#define SPECTRE_SYSTEM_MESSAGEHANDLER_H
|
||||||
|
|
||||||
#include "SystemEvent.h"
|
#include <vector>
|
||||||
|
#include "EventListener.h"
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class Display;
|
class MessageHandler : public EventListener
|
||||||
|
|
||||||
class MessageHandler
|
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
virtual void onSizeChanged(Display* display, int width, int height);
|
|
||||||
|
void registerListener(EventListener *listener);
|
||||||
|
|
||||||
|
void unregisterListener(EventListener *listener);
|
||||||
|
|
||||||
|
virtual void onSizeChanged(Window* window, int width, int height);
|
||||||
|
|
||||||
|
virtual void onEvent(const Event& event);
|
||||||
|
|
||||||
|
protected :
|
||||||
|
std::vector<EventListener*> m_listeners;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -2,22 +2,29 @@
|
||||||
#ifndef SPECTRE_MESSAGE_QUEUE_H
|
#ifndef SPECTRE_MESSAGE_QUEUE_H
|
||||||
#define SPECTRE_MESSAGE_QUEUE_H
|
#define SPECTRE_MESSAGE_QUEUE_H
|
||||||
|
|
||||||
#include <Spectre/System/SystemEvent.h>
|
#include <Spectre/System/Event.h>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
|
class PlatformEventQueue;
|
||||||
|
|
||||||
class MessageQueue
|
class MessageQueue
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
void postEvent(SysEvent event);
|
MessageQueue();
|
||||||
|
~MessageQueue();
|
||||||
|
|
||||||
bool pollEvent(SysEvent& event);
|
void postEvent(Event event);
|
||||||
|
|
||||||
|
bool pollEvent(Event& event);
|
||||||
|
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
std::deque<SysEvent> m_queue;
|
std::deque<Event> m_queue;
|
||||||
|
|
||||||
|
PlatformEventQueue* m_impl;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
|
||||||
19
include/Spectre/System/Path.h
Normal file
19
include/Spectre/System/Path.h
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
|
||||||
|
#ifndef SYSTEM_PATH_H
|
||||||
|
#define SYSTEM_PATH_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
class Path
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
static std::string getBasename(const std::string& path);
|
||||||
|
|
||||||
|
static std::string getExtension(const std::string& path);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif /* SYSTEM_PATH_H */
|
||||||
27
include/Spectre/System/Stopwatch.h
Normal file
27
include/Spectre/System/Stopwatch.h
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_SYSTEM_STOPWATCH_H
|
||||||
|
#define SPECTRE_SYSTEM_STOPWATCH_H
|
||||||
|
|
||||||
|
#include <Spectre/Math/Time.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
class Stopwatch {
|
||||||
|
public :
|
||||||
|
Stopwatch();
|
||||||
|
|
||||||
|
// Restart the watch. also returns the elapsed time before
|
||||||
|
// the watch was restarted.
|
||||||
|
Time restart();
|
||||||
|
|
||||||
|
// Get the elapsed time since the watch was restarted.
|
||||||
|
Time elapsed() const;
|
||||||
|
|
||||||
|
private :
|
||||||
|
|
||||||
|
Time m_start;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif /* SPECTRE_SYSTEM_STOPWATCH_H */
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
|
|
||||||
#ifndef SYSTEM_EVENT_H
|
|
||||||
#define SYSTEM_EVENT_H
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
class Display;
|
|
||||||
|
|
||||||
struct SysEvent
|
|
||||||
{
|
|
||||||
public :
|
|
||||||
|
|
||||||
enum Type {
|
|
||||||
None,
|
|
||||||
Quit,
|
|
||||||
Size,
|
|
||||||
};
|
|
||||||
|
|
||||||
Type type;
|
|
||||||
|
|
||||||
struct Size
|
|
||||||
{
|
|
||||||
Display *display;
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
};
|
|
||||||
|
|
||||||
union {
|
|
||||||
struct Size size;
|
|
||||||
};
|
|
||||||
|
|
||||||
SysEvent(Type type = None);
|
|
||||||
|
|
||||||
// Helper methods
|
|
||||||
|
|
||||||
static SysEvent sizeEvent(Display *display, int width, int height);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
||||||
#endif /* SYSTEM_EVENT_H */
|
|
||||||
|
|
@ -16,6 +16,15 @@ public :
|
||||||
|
|
||||||
static DisplayMode getDesktopMode();
|
static DisplayMode getDesktopMode();
|
||||||
|
|
||||||
|
// Returns true if width hight and bpp are not set (eg. zero)
|
||||||
|
// useful to determine if a DisplayMode object is set or not.
|
||||||
|
// this is equal to:
|
||||||
|
// DisplayMode a;
|
||||||
|
// if (a == DisplayMode()) {
|
||||||
|
// // empty
|
||||||
|
// }
|
||||||
|
bool empty() const;
|
||||||
|
|
||||||
inline bool operator==(const DisplayMode& other)
|
inline bool operator==(const DisplayMode& other)
|
||||||
{
|
{
|
||||||
return width == other.width
|
return width == other.width
|
||||||
|
|
@ -1,24 +1,22 @@
|
||||||
|
|
||||||
#ifndef DISPLAY_GLCONTEXT_H
|
#ifndef SPECTRE_WINDOW_GLCONTEXT_H
|
||||||
#define DISPLAY_GLCONTEXT_H
|
#define SPECTRE_WINDOW_GLCONTEXT_H
|
||||||
|
|
||||||
#include <Spectre/Math/Vector2.h>
|
#include <Spectre/Math/Vector2.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
class PlatformDisplay;
|
class PlatformWindow;
|
||||||
|
|
||||||
// Platform independant interface for OpenGL Contexts.
|
// Platform independant interface for OpenGL Contexts.
|
||||||
|
|
||||||
class GLContext
|
class GLContext
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
static GLContext* create();
|
|
||||||
|
|
||||||
virtual ~GLContext();
|
virtual ~GLContext();
|
||||||
|
|
||||||
// Create a GLContext for this perticular display.
|
// Create a GLContext for this perticular window.
|
||||||
virtual bool create(const PlatformDisplay* display) = 0;
|
virtual bool create(const PlatformWindow* window) = 0;
|
||||||
|
|
||||||
virtual void destroy() = 0;
|
virtual void destroy() = 0;
|
||||||
|
|
||||||
|
|
@ -38,13 +36,10 @@ public :
|
||||||
// This is usually refered to as enabling/disabling vertical synchronization.
|
// This is usually refered to as enabling/disabling vertical synchronization.
|
||||||
virtual bool setSwapInterval(int interval) = 0;
|
virtual bool setSwapInterval(int interval) = 0;
|
||||||
|
|
||||||
// Set the size of the pixel buffer.
|
|
||||||
virtual void setSize(unsigned int width, unsigned int height) = 0;
|
|
||||||
|
|
||||||
// Swap front with back buffer and vice versa.
|
// Swap front with back buffer and vice versa.
|
||||||
virtual void swapBuffers() = 0;
|
virtual void swapBuffers() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|
||||||
#endif /* DISPLAY_GLCONTEXT_H */
|
#endif /* SPECTRE_WINDOW_GLCONTEXT_H */
|
||||||
41
include/Spectre/Window/GLWindow.h
Normal file
41
include/Spectre/Window/GLWindow.h
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_WINDOW_GLWINDOW_H
|
||||||
|
#define SPECTRE_WINDOW_GLWINDOW_H
|
||||||
|
|
||||||
|
#include <Spectre/Window/Window.h>
|
||||||
|
#include <Spectre/Window/GLContext.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
class GLContext;
|
||||||
|
|
||||||
|
// GLWindow represents a window that has an OpenGL context attached to it.
|
||||||
|
class GLWindow : public Window
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GLWindow();
|
||||||
|
virtual ~GLWindow();
|
||||||
|
|
||||||
|
virtual bool create(WindowDescription decription);
|
||||||
|
|
||||||
|
virtual void destroy();
|
||||||
|
|
||||||
|
bool activate(bool value);
|
||||||
|
|
||||||
|
// Enable/Disable Vertical Sync.
|
||||||
|
bool enableVSync(bool value);
|
||||||
|
|
||||||
|
void swapBuffers();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void onReshape(int width, int height);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
GLContext* m_context;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namepsace sp
|
||||||
|
|
||||||
|
#endif /* SPECTRE_WINDOW_GLWINDOW_H */
|
||||||
83
include/Spectre/Window/Window.h
Normal file
83
include/Spectre/Window/Window.h
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_WINDOW_WINDOW_H
|
||||||
|
#define SPECTRE_WINDOW_WINDOW_H
|
||||||
|
|
||||||
|
#include "DisplayMode.h"
|
||||||
|
#include "WindowDescription.h"
|
||||||
|
#include <Spectre/Math/Vector2.h>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
class PlatformWindow;
|
||||||
|
class GLContext;
|
||||||
|
|
||||||
|
class Window
|
||||||
|
{
|
||||||
|
friend class PlatformWindow;
|
||||||
|
public :
|
||||||
|
enum Mode {
|
||||||
|
WINDOWED = 0,
|
||||||
|
FULLSCREEN = 1,
|
||||||
|
WINDOWEDFULLSCREEN = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
public :
|
||||||
|
Window();
|
||||||
|
virtual ~Window();
|
||||||
|
|
||||||
|
virtual bool create(WindowDescription decription);
|
||||||
|
|
||||||
|
virtual void destroy();
|
||||||
|
|
||||||
|
void setSize(unsigned int width, unsigned int height);
|
||||||
|
|
||||||
|
sp::Vector2u getSize() const;
|
||||||
|
|
||||||
|
void setCaption(const std::string& title);
|
||||||
|
|
||||||
|
const std::string& getCaption() const;
|
||||||
|
|
||||||
|
void setIcon(const std::string& filename);
|
||||||
|
|
||||||
|
void setIcon(unsigned int width, unsigned int height, const uint8_t *pixels);
|
||||||
|
|
||||||
|
void setDisplayMode(const DisplayMode& mode);
|
||||||
|
|
||||||
|
const DisplayMode& getDisplayMode() const;
|
||||||
|
|
||||||
|
void setVideoMode(Mode mode);
|
||||||
|
|
||||||
|
enum Mode getVideoMode() const;
|
||||||
|
|
||||||
|
void setVisible(bool visible);
|
||||||
|
|
||||||
|
void showCursor(bool value);
|
||||||
|
|
||||||
|
void grabCursor(bool value);
|
||||||
|
|
||||||
|
protected :
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
|
virtual void onReshape(int width, int height);
|
||||||
|
|
||||||
|
protected :
|
||||||
|
enum Mode m_fmode;
|
||||||
|
|
||||||
|
// Cache window position when entering fullscreen
|
||||||
|
// So it can be restored when returning to window mode.
|
||||||
|
Vector2u m_cachePos;
|
||||||
|
|
||||||
|
WindowDescription m_description;
|
||||||
|
WindowDescription m_cacheDesc;
|
||||||
|
|
||||||
|
std::string m_caption;
|
||||||
|
|
||||||
|
PlatformWindow* m_impl;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namepsace sp
|
||||||
|
|
||||||
|
#endif /* SPECTRE_WINDOW_WINDOW_H */
|
||||||
34
include/Spectre/Window/WindowDescription.h
Normal file
34
include/Spectre/Window/WindowDescription.h
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_WINDOW_WINDOWDESCRIPTION_H
|
||||||
|
#define SPECTRE_WINDOW_WINDOWDESCRIPTION_H
|
||||||
|
|
||||||
|
#include "DisplayMode.h"
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
namespace WindowDecorate {
|
||||||
|
|
||||||
|
enum Type {
|
||||||
|
Empty = 0,
|
||||||
|
Menu = 1 << 0,
|
||||||
|
Resize = 1 << 1,
|
||||||
|
Close = 1 << 2,
|
||||||
|
Default = Menu | Resize | Close,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WindowDescription
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
WindowDescription();
|
||||||
|
WindowDescription(DisplayMode mode, unsigned decoration = WindowDecorate::Default);
|
||||||
|
|
||||||
|
public :
|
||||||
|
DisplayMode mode;
|
||||||
|
|
||||||
|
unsigned int decoration;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif /* SPECTRE_WINDOW_WINDOWDESCRIPTION_H */
|
||||||
|
|
@ -4,6 +4,13 @@
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
|
std::string core::to_string(int value)
|
||||||
|
{
|
||||||
|
char buf[32];
|
||||||
|
sprintf(buf, "%i", value);
|
||||||
|
return std::string(buf);
|
||||||
|
}
|
||||||
|
|
||||||
std::string core::to_string(unsigned int value)
|
std::string core::to_string(unsigned int value)
|
||||||
{
|
{
|
||||||
char buf[32];
|
char buf[32];
|
||||||
|
|
|
||||||
|
|
@ -1,154 +0,0 @@
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <Spectre/Display/Display.h>
|
|
||||||
#include <Spectre/Display/GLContext.h>
|
|
||||||
#include <Spectre/System/SystemEvent.h>
|
|
||||||
#include <Platform/PlatformDisplay.h>
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
#define CAPTION_DEFAULT "Spectre"
|
|
||||||
#define ICON_DEFAULT "./assets/app.ico"
|
|
||||||
|
|
||||||
Display::Display()
|
|
||||||
{
|
|
||||||
m_caption = CAPTION_DEFAULT;
|
|
||||||
m_fmode = WINDOWED;
|
|
||||||
|
|
||||||
m_context = GLContext::create();
|
|
||||||
m_impl = PlatformDisplay::make(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
Display::~Display()
|
|
||||||
{
|
|
||||||
delete m_context;
|
|
||||||
delete m_impl;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Display::create(DisplayDescription description)
|
|
||||||
{
|
|
||||||
destroy();
|
|
||||||
|
|
||||||
if (!m_impl->create(description)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_context->create(m_impl)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
init();
|
|
||||||
|
|
||||||
m_description = description;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Display::init()
|
|
||||||
{
|
|
||||||
m_impl->setCaption(m_caption);
|
|
||||||
|
|
||||||
setIcon(ICON_DEFAULT);
|
|
||||||
|
|
||||||
activate(true);
|
|
||||||
|
|
||||||
enableVSync(false);
|
|
||||||
showCursor(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Display::destroy()
|
|
||||||
{
|
|
||||||
m_context->destroy();
|
|
||||||
|
|
||||||
m_impl->destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Display::setCaption(const std::string& caption)
|
|
||||||
{
|
|
||||||
m_caption = caption;
|
|
||||||
m_impl->setCaption(m_caption);
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& Display::getCaption() const
|
|
||||||
{
|
|
||||||
return m_caption;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Display::setIcon(const std::string& filename)
|
|
||||||
{
|
|
||||||
m_impl->setIcon(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Display::setSize(unsigned int width, unsigned int height)
|
|
||||||
{
|
|
||||||
m_description.mode.width = width;
|
|
||||||
m_description.mode.height = height;
|
|
||||||
|
|
||||||
m_impl->setSize(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Display::setVideoMode(Mode mode)
|
|
||||||
{
|
|
||||||
DisplayDescription desc;
|
|
||||||
|
|
||||||
if (m_fmode == mode) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode == FULLSCREEN || mode == WINDOWEDFULLSCREEN) {
|
|
||||||
|
|
||||||
// True fullscreen
|
|
||||||
if (mode == FULLSCREEN) {
|
|
||||||
desc.mode = m_description.mode;
|
|
||||||
} else {
|
|
||||||
desc.mode = DisplayMode::getDesktopMode();
|
|
||||||
m_cacheDesc = m_description;
|
|
||||||
}
|
|
||||||
|
|
||||||
desc.decoration = DisplayDecorate::None;
|
|
||||||
} else {
|
|
||||||
desc = m_cacheDesc;
|
|
||||||
}
|
|
||||||
|
|
||||||
create(desc);
|
|
||||||
|
|
||||||
m_fmode = mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Display::Mode Display::getVideoMode() const
|
|
||||||
{
|
|
||||||
return m_fmode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Display::showCursor(bool value)
|
|
||||||
{
|
|
||||||
m_impl->showCursor(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Display::activate(bool value)
|
|
||||||
{
|
|
||||||
if (value) {
|
|
||||||
return m_context->activate();
|
|
||||||
}
|
|
||||||
return m_context->deactivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Display::enableVSync(bool value)
|
|
||||||
{
|
|
||||||
return m_context->setSwapInterval(value ? 1 : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Display::swapBuffers()
|
|
||||||
{
|
|
||||||
if (activate(true)) {
|
|
||||||
m_context->swapBuffers();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Display::onReshape(int width, int height)
|
|
||||||
{
|
|
||||||
// Resize context if the windows resizes.
|
|
||||||
m_context->setSize(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
|
|
||||||
#include <Spectre/Display/DisplayDescription.h>
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
DisplayDescription::DisplayDescription() :
|
|
||||||
mode (),
|
|
||||||
decoration (DisplayDecorate::Default)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
DisplayDescription::DisplayDescription(DisplayMode mode, unsigned decoration) :
|
|
||||||
mode (mode),
|
|
||||||
decoration (decoration)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
|
|
||||||
#include <Spectre/Display/GLContext.h>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <Platform/Win32/Win32GLContext.h>
|
|
||||||
typedef sp::Win32GLContext ContextType;
|
|
||||||
#else
|
|
||||||
#error "No GLContext implementation exists"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace sp {
|
|
||||||
|
|
||||||
GLContext* GLContext::create()
|
|
||||||
{
|
|
||||||
return new ContextType();
|
|
||||||
}
|
|
||||||
|
|
||||||
GLContext::~GLContext()
|
|
||||||
{
|
|
||||||
// Nothing to do.
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sp
|
|
||||||
|
|
@ -3,45 +3,49 @@
|
||||||
#include <Spectre/Game/GameTime.h>
|
#include <Spectre/Game/GameTime.h>
|
||||||
#include <Spectre/Game/FPSCounter.h>
|
#include <Spectre/Game/FPSCounter.h>
|
||||||
#include <Spectre/Input/InputModule.h>
|
#include <Spectre/Input/InputModule.h>
|
||||||
|
#include <Spectre/System/Log.h>
|
||||||
|
#include <Spectre/System/Log/FileWriter.h>
|
||||||
#include <Spectre/System/MessageHandler.h>
|
#include <Spectre/System/MessageHandler.h>
|
||||||
|
#include <Spectre/System/MessageQueue.h>
|
||||||
#include <Platform/PlatformMisc.h>
|
|
||||||
#include <Platform/Win32/Win32Application.h>
|
|
||||||
#include <Spectre/Game.h>
|
#include <Spectre/Game.h>
|
||||||
|
|
||||||
|
#include <Platform/PlatformApplication.h>
|
||||||
|
#include <Platform/PlatformMisc.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
Game::Game()
|
Game::Game() :
|
||||||
|
m_running(false)
|
||||||
{
|
{
|
||||||
m_platform = new Win32Application();
|
m_platform = PlatformApplication::get();
|
||||||
|
|
||||||
m_running = false;
|
|
||||||
m_graphics = new Graphics(m_platform);
|
m_graphics = new Graphics(m_platform);
|
||||||
m_input = new InputModule(&m_platform->getInput());
|
m_input = new InputModule(&m_platform->getInput());
|
||||||
|
|
||||||
m_messageHandler = new MessageHandler();
|
m_messageHandler = new MessageHandler();
|
||||||
|
|
||||||
|
// Setup log
|
||||||
|
m_log_writer = new log::FileWriter("stdout");
|
||||||
|
Log::setWriter(m_log_writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::~Game()
|
Game::~Game()
|
||||||
{
|
{
|
||||||
delete m_input;
|
delete m_input;
|
||||||
delete m_graphics;
|
delete m_graphics;
|
||||||
delete m_platform;
|
|
||||||
delete m_messageHandler;
|
delete m_messageHandler;
|
||||||
}
|
|
||||||
|
|
||||||
void Game::setup()
|
// TODO: This is abit ugly tbh.
|
||||||
{
|
m_platform->shutdown();
|
||||||
m_graphics->init();
|
|
||||||
|
|
||||||
m_graphics->setClearColor(0.0f, 0.0f, 0.0f);
|
|
||||||
|
|
||||||
init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::run()
|
void Game::run()
|
||||||
{
|
{
|
||||||
setup();
|
m_platform->init();
|
||||||
|
|
||||||
|
if (!m_graphics->init()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
gameLoop();
|
gameLoop();
|
||||||
}
|
}
|
||||||
|
|
@ -56,6 +60,9 @@ void Game::gameLoop()
|
||||||
|
|
||||||
processEvents();
|
processEvents();
|
||||||
|
|
||||||
|
// Update input.
|
||||||
|
getInput()->update();
|
||||||
|
|
||||||
if (time.beginFrame()) {
|
if (time.beginFrame()) {
|
||||||
|
|
||||||
while(time.tick()) {
|
while(time.tick()) {
|
||||||
|
|
@ -71,22 +78,22 @@ void Game::gameLoop()
|
||||||
void Game::processEvents()
|
void Game::processEvents()
|
||||||
{
|
{
|
||||||
MessageQueue& queue = m_platform->getMessageQueue();
|
MessageQueue& queue = m_platform->getMessageQueue();
|
||||||
SysEvent event;
|
Event event;
|
||||||
|
|
||||||
m_platform->update();
|
|
||||||
|
|
||||||
while(queue.pollEvent(event)) {
|
while(queue.pollEvent(event)) {
|
||||||
|
|
||||||
if (event.type == SysEvent::Quit) {
|
if (event.type == Event::Quit) {
|
||||||
exit();
|
exit();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call message handler.
|
// Call message handler.
|
||||||
|
|
||||||
if (event.type == SysEvent::Size) {
|
if (event.type == Event::Size) {
|
||||||
m_messageHandler->onSizeChanged(event.size.display, event.size.width, event.size.height);
|
m_messageHandler->onSizeChanged(event.size.window, event.size.width, event.size.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_messageHandler->onEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,4 +117,9 @@ FPSCounter& Game::getFpsCounter()
|
||||||
return m_fpsCounter;
|
return m_fpsCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MessageHandler* Game::getMessageHandler() const
|
||||||
|
{
|
||||||
|
return m_messageHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
FPSCounter::FPSCounter() :
|
FPSCounter::FPSCounter() :
|
||||||
m_fps (60.0f),
|
m_fps (60.0f)
|
||||||
m_updateRate (2000)
|
|
||||||
{
|
{
|
||||||
|
m_updateRate = Time::seconds(2);
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -16,19 +16,19 @@ void FPSCounter::addFrame()
|
||||||
m_count++;
|
m_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
float FPSCounter::getFPS() const
|
double FPSCounter::getFPS() const
|
||||||
{
|
{
|
||||||
return m_fps;
|
return m_fps;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FPSCounter::setUpdateRate(unsigned int ups)
|
void FPSCounter::setUpdateRate(unsigned int rate)
|
||||||
{
|
{
|
||||||
// Clamp to 1.
|
// Clamp to 1.
|
||||||
if (ups < 1) {
|
if (rate < 1) {
|
||||||
ups = 1;
|
rate = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_updateRate = ups * 1000;
|
m_updateRate = Time::seconds(rate);
|
||||||
|
|
||||||
// Must reset the counter.
|
// Must reset the counter.
|
||||||
reset();
|
reset();
|
||||||
|
|
@ -36,15 +36,12 @@ void FPSCounter::setUpdateRate(unsigned int ups)
|
||||||
|
|
||||||
bool FPSCounter::update()
|
bool FPSCounter::update()
|
||||||
{
|
{
|
||||||
unsigned int current = system::getMilliseconds();
|
Time elapsed = m_watch.elapsed();
|
||||||
unsigned int elapsed = current - m_time;
|
|
||||||
|
|
||||||
if (elapsed >= m_updateRate) {
|
if (elapsed >= m_updateRate) {
|
||||||
float fraction = m_count / ((float) elapsed);
|
m_fps = m_count / elapsed.seconds();
|
||||||
m_fps = fraction * 1000.f;
|
|
||||||
|
|
||||||
m_time = current;
|
reset();
|
||||||
m_count = 0;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -52,7 +49,7 @@ bool FPSCounter::update()
|
||||||
|
|
||||||
void FPSCounter::reset()
|
void FPSCounter::reset()
|
||||||
{
|
{
|
||||||
m_time = system::getMilliseconds();
|
m_watch.restart();
|
||||||
m_count = 0;
|
m_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,44 +7,44 @@ namespace sp {
|
||||||
|
|
||||||
GameTime::GameTime(unsigned long updates_per_sec)
|
GameTime::GameTime(unsigned long updates_per_sec)
|
||||||
{
|
{
|
||||||
m_acc = 0;
|
|
||||||
m_current = system::getMilliseconds();
|
|
||||||
m_lastUpdate = m_current;
|
|
||||||
setTimeStep(updates_per_sec);
|
setTimeStep(updates_per_sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
double GameTime::getTimeStep() const
|
double GameTime::getTimeStep() const
|
||||||
{
|
{
|
||||||
return m_slice;
|
return m_slice.milliseconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameTime::setTimeStep(unsigned long updates_per_sec)
|
void GameTime::setTimeStep(unsigned long updates_per_sec)
|
||||||
{
|
{
|
||||||
m_slice = (1000.0f / ((double) updates_per_sec));
|
m_slice = Time::seconds(1.0f / ((double) updates_per_sec));
|
||||||
|
m_max_acc = Time::seconds(1.0f / m_slice.seconds());
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long GameTime::getElapsed() const
|
Time GameTime::getElapsed() const
|
||||||
{
|
{
|
||||||
return m_current - m_lastUpdate;
|
return m_watch.elapsed();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameTime::beginFrame()
|
bool GameTime::beginFrame()
|
||||||
{
|
{
|
||||||
reset();
|
|
||||||
|
|
||||||
accumulateTime();
|
accumulateTime();
|
||||||
|
|
||||||
if (m_acc > m_slice) {
|
// Signal if we should tick
|
||||||
m_inLoop = true;
|
return shouldTick();
|
||||||
}
|
}
|
||||||
return m_inLoop;
|
|
||||||
|
bool GameTime::shouldTick() const
|
||||||
|
{
|
||||||
|
// if acc is larger than one slice, we have atleast one tick.
|
||||||
|
return m_acc > m_slice;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameTime::tick()
|
bool GameTime::tick()
|
||||||
{
|
{
|
||||||
if (m_acc > m_slice) {
|
if (shouldTick()) {
|
||||||
m_acc -= m_slice;
|
m_acc -= m_slice;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -53,27 +53,14 @@ bool GameTime::tick()
|
||||||
|
|
||||||
void GameTime::reset()
|
void GameTime::reset()
|
||||||
{
|
{
|
||||||
m_lastUpdate = m_current;
|
m_watch.restart();
|
||||||
m_inLoop = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameTime::accumulateTime()
|
void GameTime::accumulateTime()
|
||||||
{
|
{
|
||||||
updateTime();
|
m_acc += m_watch.restart();
|
||||||
|
if (m_acc > m_max_acc) {
|
||||||
m_acc += (double) (m_current - m_lastUpdate);
|
m_acc = m_max_acc;
|
||||||
if (m_acc > (1000.f / m_slice)) {
|
|
||||||
m_acc = 1000.f / m_slice;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameTime::updateTime()
|
|
||||||
{
|
|
||||||
m_current = system::getMilliseconds();
|
|
||||||
|
|
||||||
// Just to be safe. check so we don't get a negative interval.
|
|
||||||
if (m_current < m_lastUpdate) {
|
|
||||||
m_lastUpdate = m_current;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
68
source/GfxDriver/OpenGL/OpenGLDrv.cpp
Normal file
68
source/GfxDriver/OpenGL/OpenGLDrv.cpp
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
|
||||||
|
#include "OpenGLDrv.h"
|
||||||
|
#include <GfxDriver/OpenGL/OpenGLShaderProgram.h>
|
||||||
|
#include <Graphics/GL/gl.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
std::string OpenGLDrv::getName() const {
|
||||||
|
return "OpenGL";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string OpenGLDrv::getVersion() const {
|
||||||
|
|
||||||
|
char buf[512];
|
||||||
|
std::string prof = "Compability";
|
||||||
|
GLint flags;
|
||||||
|
|
||||||
|
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &flags);
|
||||||
|
if (flags & GL_CONTEXT_CORE_PROFILE_BIT) {
|
||||||
|
prof = "Core";
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "%s %s", prof.c_str(), glGetString(GL_VERSION));
|
||||||
|
|
||||||
|
return std::string(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string OpenGLDrv::getVendor() const
|
||||||
|
{
|
||||||
|
return std::string((char*)glGetString(GL_VENDOR));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string OpenGLDrv::getCardName() const
|
||||||
|
{
|
||||||
|
return std::string((char*)glGetString(GL_RENDERER));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenGLDrv::setViewport(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
glViewport(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenGLDrv::setClearColor(float r, float g, float b, float a)
|
||||||
|
{
|
||||||
|
glClearColor(r, g, b, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenGLDrv::clearBuffer(GfxDriver::BufferFlags flags)
|
||||||
|
{
|
||||||
|
int glFlags = 0;
|
||||||
|
|
||||||
|
if (flags == GfxDriver::CLEAR_BUFFER_BIT) {
|
||||||
|
glFlags |= GL_COLOR_BUFFER_BIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
glClear(glFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenGLDrv::clearColorBuffer()
|
||||||
|
{
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
ShaderProgram* OpenGLDrv::createShaderProgram() {
|
||||||
|
return new OpenGLShaderProgram();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
35
source/GfxDriver/OpenGL/OpenGLDrv.h
Normal file
35
source/GfxDriver/OpenGL/OpenGLDrv.h
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_GFXDRIVER_OPENGL_OPENGLDRV_H
|
||||||
|
#define SPECTRE_GFXDRIVER_OPENGL_OPENGLDRV_H
|
||||||
|
|
||||||
|
#include <Spectre/GfxDriver/GfxDriver.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
class ShaderProgram;
|
||||||
|
|
||||||
|
class OpenGLDrv : public GfxDriver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual std::string getName() const;
|
||||||
|
|
||||||
|
virtual std::string getVersion() const;
|
||||||
|
|
||||||
|
virtual std::string getVendor() const;
|
||||||
|
|
||||||
|
virtual std::string getCardName() const;
|
||||||
|
|
||||||
|
virtual void setViewport(int x, int y, int width, int height);
|
||||||
|
|
||||||
|
virtual void setClearColor(float r, float g, float b, float a);
|
||||||
|
|
||||||
|
virtual void clearBuffer(GfxDriver::BufferFlags flags);
|
||||||
|
|
||||||
|
virtual void clearColorBuffer();
|
||||||
|
|
||||||
|
virtual ShaderProgram* createShaderProgram();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif /* SPECTRE_GFXDRIVER_GFXDRIVER_H */
|
||||||
185
source/GfxDriver/OpenGL/OpenGLShaderProgram.cpp
Normal file
185
source/GfxDriver/OpenGL/OpenGLShaderProgram.cpp
Normal file
|
|
@ -0,0 +1,185 @@
|
||||||
|
|
||||||
|
#include "OpenGLShaderProgram.h"
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
OpenGLShaderProgram::OpenGLShaderProgram()
|
||||||
|
{
|
||||||
|
m_extension = "glsl";
|
||||||
|
m_id = glCreateProgram();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
OpenGLShaderProgram::~OpenGLShaderProgram()
|
||||||
|
{
|
||||||
|
if (m_id > 0) {
|
||||||
|
glDeleteProgram(m_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OpenGLShaderProgram::loadFromMemory(const std::string& source, ShaderType type)
|
||||||
|
{
|
||||||
|
const char *s = source.c_str();
|
||||||
|
|
||||||
|
GLuint shader_id = glCreateShader(type == ShaderType::Vertex
|
||||||
|
? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
|
glShaderSource(shader_id, 1, &s, NULL);
|
||||||
|
|
||||||
|
if (!compileShader(shader_id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return attachShader(shader_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OpenGLShaderProgram::link()
|
||||||
|
{
|
||||||
|
GLint status;
|
||||||
|
|
||||||
|
glLinkProgram(m_id);
|
||||||
|
|
||||||
|
// Query OpenGL for link status.
|
||||||
|
glGetProgramiv(m_id, GL_LINK_STATUS, &status);
|
||||||
|
m_linked = status == GL_TRUE;
|
||||||
|
|
||||||
|
if (!m_linked) {
|
||||||
|
m_error = fetchErrorLog();
|
||||||
|
}
|
||||||
|
return m_linked;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable this shader
|
||||||
|
// All shader operations after this call will affect this shader.
|
||||||
|
void OpenGLShaderProgram::enable() const
|
||||||
|
{
|
||||||
|
glUseProgram(m_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable this shader
|
||||||
|
// Operations will no longer affect this shader after this call.
|
||||||
|
void OpenGLShaderProgram::disable() const
|
||||||
|
{
|
||||||
|
glUseProgram(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------
|
||||||
|
// Variables.
|
||||||
|
// ---------------------
|
||||||
|
|
||||||
|
bool OpenGLShaderProgram::setMVPMatrix(const Matrix4f& matrix)
|
||||||
|
{
|
||||||
|
return setUniform("u_MVP", matrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------
|
||||||
|
// General Variables.
|
||||||
|
// ---------------------
|
||||||
|
|
||||||
|
bool OpenGLShaderProgram::setAttribute(const std::string& name, float value) const
|
||||||
|
{
|
||||||
|
int loc;
|
||||||
|
if (getAttribLoc(name, loc)) {
|
||||||
|
glVertexAttrib1f(loc, value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OpenGLShaderProgram::setAttribute(const std::string& name, const Matrix4f& matrix) const
|
||||||
|
{
|
||||||
|
int loc;
|
||||||
|
if (getAttribLoc(name, loc)) {
|
||||||
|
glVertexAttrib4fv(loc, matrix.e);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OpenGLShaderProgram::setUniform(const std::string& name, const Matrix4f& matrix) const
|
||||||
|
{
|
||||||
|
int loc;
|
||||||
|
if (getUniformLoc(name, loc)) {
|
||||||
|
glUniformMatrix4fv(loc, 1, GL_FALSE, matrix.e);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OpenGLShaderProgram::setUniform(const std::string& name, const Color& color) const
|
||||||
|
{
|
||||||
|
int loc;
|
||||||
|
if (getUniformLoc(name, loc)) {
|
||||||
|
Vector4f c = color.toRGBAf();
|
||||||
|
|
||||||
|
glUniform4f(loc, c.x, c.y, c.z, c.w);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OpenGLShaderProgram::getAttribLoc(const std::string& name, int& loc) const
|
||||||
|
{
|
||||||
|
loc = glGetAttribLocation(m_id, name.c_str());
|
||||||
|
if (loc < 0) {
|
||||||
|
m_error = "Attribute variable '" + name + "' was not found in shader.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OpenGLShaderProgram::getUniformLoc(const std::string& name, int& loc) const
|
||||||
|
{
|
||||||
|
loc = glGetUniformLocation(m_id, name.c_str());
|
||||||
|
if (loc < 0) {
|
||||||
|
m_error = std::string("Uniform variable '" + name + "' was not found in shader.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string OpenGLShaderProgram::fetchErrorLog() const
|
||||||
|
{
|
||||||
|
GLchar buf[4096] = { '\0' };
|
||||||
|
|
||||||
|
glGetProgramInfoLog(m_id, sizeof(buf), NULL, buf);
|
||||||
|
|
||||||
|
return std::string(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OpenGLShaderProgram::compileShader(GLuint id)
|
||||||
|
{
|
||||||
|
glCompileShader(id);
|
||||||
|
|
||||||
|
// Query OpenGL for status.
|
||||||
|
GLint status;
|
||||||
|
glGetShaderiv(id, GL_COMPILE_STATUS, &status);
|
||||||
|
if (status == GL_FALSE) {
|
||||||
|
GLchar buf[4096] = { '\0' };
|
||||||
|
glGetShaderInfoLog(id, sizeof(buf), NULL, buf);
|
||||||
|
m_error = std::string(buf);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OpenGLShaderProgram::attachShader(GLuint id)
|
||||||
|
{
|
||||||
|
GLenum err;
|
||||||
|
|
||||||
|
glAttachShader(m_id, id);
|
||||||
|
err = glGetError();
|
||||||
|
if (err == GL_INVALID_VALUE) {
|
||||||
|
m_error = "Invalid Value";
|
||||||
|
return false;
|
||||||
|
} else if (err == GL_INVALID_OPERATION) {
|
||||||
|
m_error = "Invalid operation";
|
||||||
|
return false;
|
||||||
|
} else if (err != GL_NO_ERROR) {
|
||||||
|
m_error = "Unkown Error";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
70
source/GfxDriver/OpenGL/OpenGLShaderProgram.h
Normal file
70
source/GfxDriver/OpenGL/OpenGLShaderProgram.h
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_GFXDRIVER_OPENGL_OPENGLSHADERPROGRAM_H
|
||||||
|
#define SPECTRE_GFXDRIVER_OPENGL_OPENGLSHADERPROGRAM_H
|
||||||
|
|
||||||
|
#include <Graphics/GL/gl.h>
|
||||||
|
#include <Spectre/GfxDriver/ShaderProgram.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
class OpenGLShaderProgram : public ShaderProgram
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OpenGLShaderProgram();
|
||||||
|
virtual ~OpenGLShaderProgram();
|
||||||
|
|
||||||
|
// Load a shader from memory.
|
||||||
|
virtual bool loadFromMemory(const std::string& source, ShaderType type);
|
||||||
|
|
||||||
|
// Link the program.
|
||||||
|
virtual bool link();
|
||||||
|
|
||||||
|
// Enable this shader
|
||||||
|
// All shader operations after this call will affect this shader.
|
||||||
|
virtual void enable() const;
|
||||||
|
|
||||||
|
// Disable this shader
|
||||||
|
// Operations will no longer affect this shader after this call.
|
||||||
|
virtual void disable() const;
|
||||||
|
|
||||||
|
// ---------------------
|
||||||
|
// Variables.
|
||||||
|
// ---------------------
|
||||||
|
|
||||||
|
virtual bool setMVPMatrix(const Matrix4f& matrix);
|
||||||
|
|
||||||
|
// ---------------------
|
||||||
|
// General Variables.
|
||||||
|
// ---------------------
|
||||||
|
|
||||||
|
virtual bool setAttribute(const std::string& name, float value) const;
|
||||||
|
|
||||||
|
virtual bool setAttribute(const std::string& name, const Matrix4f& matrix) const;
|
||||||
|
|
||||||
|
virtual bool setUniform(const std::string& name, const Matrix4f& matrix) const;
|
||||||
|
|
||||||
|
virtual bool setUniform(const std::string& name, const Color& color) const;
|
||||||
|
|
||||||
|
protected :
|
||||||
|
|
||||||
|
// Compile a shader.
|
||||||
|
bool compileShader(GLuint id);
|
||||||
|
|
||||||
|
// Attach shader to program.
|
||||||
|
bool attachShader(GLuint id);
|
||||||
|
|
||||||
|
bool getAttribLoc(const std::string& name, int& loc) const;
|
||||||
|
|
||||||
|
bool getUniformLoc(const std::string& name, int& loc) const;
|
||||||
|
|
||||||
|
std::string fetchErrorLog() const;
|
||||||
|
|
||||||
|
protected :
|
||||||
|
|
||||||
|
// Program ID
|
||||||
|
GLuint m_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif /* SPECTRE_GFXDRIVER_OPENGL_OPENGLSHADERPROGRAM_H */
|
||||||
69
source/GfxDriver/ShaderProgram.cpp
Normal file
69
source/GfxDriver/ShaderProgram.cpp
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
|
||||||
|
#include <Spectre/System/Path.h>
|
||||||
|
#include <Spectre/System/File.h>
|
||||||
|
#include <Spectre/GfxDriver/ShaderProgram.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace sp
|
||||||
|
{
|
||||||
|
|
||||||
|
ShaderProgram::~ShaderProgram()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShaderProgram::loadFromFile(const std::string& filename)
|
||||||
|
{
|
||||||
|
std::string extension = Path::getExtension(filename);
|
||||||
|
|
||||||
|
// Meta file. load real shaders.
|
||||||
|
if (extension == "shader." + m_extension) {
|
||||||
|
|
||||||
|
// FIXME: This is ugly :)
|
||||||
|
std::string base_name = filename.substr(0, filename.length() - extension.length());
|
||||||
|
|
||||||
|
// vert and frag are not optional. they must exist.
|
||||||
|
return loadFromFile(base_name + "vert." + m_extension, ShaderType::Vertex) &&
|
||||||
|
loadFromFile(base_name + "frag." + m_extension, ShaderType::Fragment);
|
||||||
|
|
||||||
|
} else if (extension == "vert." + m_extension) {
|
||||||
|
return loadFromFile(filename, ShaderType::Vertex);
|
||||||
|
} else if (extension == "frag." + m_extension) {
|
||||||
|
return loadFromFile(filename, ShaderType::Fragment);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_error = "Invalid file extension: " + extension;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShaderProgram::loadFromFile(const std::string& filename, ShaderType type)
|
||||||
|
{
|
||||||
|
std::string src;
|
||||||
|
File file;
|
||||||
|
|
||||||
|
if (!file.open(filename)) {
|
||||||
|
m_error = "Can't open file: " + filename;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load file into memory.
|
||||||
|
if (!file.read(src)) {
|
||||||
|
m_error = "Could not read file: " + filename;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return loadFromMemory(src, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool ShaderProgram::isLinked() const
|
||||||
|
{
|
||||||
|
return m_linked;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ShaderProgram::getLastError() const
|
||||||
|
{
|
||||||
|
return m_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
|
|
||||||
#include <Spectre/System/Log.h>
|
#include <Spectre/System/Log.h>
|
||||||
#include <Spectre/Graphics/OpenGL.h>
|
|
||||||
#include <Spectre/Graphics/Renderable.h>
|
#include <Spectre/Graphics/Renderable.h>
|
||||||
#include <Spectre/Graphics/RenderState.h>
|
#include <Spectre/Graphics/RenderState.h>
|
||||||
#include <Spectre/Graphics/ShaderProgram.h>
|
|
||||||
#include <Spectre/Graphics/Texture.h>
|
#include <Spectre/Graphics/Texture.h>
|
||||||
#include <Spectre/Graphics/BatchRenderer2D.h>
|
#include <Spectre/Graphics/BatchRenderer2D.h>
|
||||||
#include <Spectre/Math/Math.h>
|
#include <Spectre/Math/Math.h>
|
||||||
|
#include <GfxDriver/OpenGL/OpenGLShaderProgram.h>
|
||||||
|
#include <Graphics/GL/gl.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
@ -49,22 +49,24 @@ BatchRenderer2D::BatchRenderer2D()
|
||||||
glEnableVertexAttribArray(VertexAttribTexCoord0);
|
glEnableVertexAttribArray(VertexAttribTexCoord0);
|
||||||
glVertexAttribPointer(VertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void*)24);
|
glVertexAttribPointer(VertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void*)24);
|
||||||
|
|
||||||
m_textShader.create();
|
m_textShader = new OpenGLShaderProgram();
|
||||||
if (!m_textShader.loadFromFile("assets/shaders/text.shader.glsl")) {
|
|
||||||
std::cout << "Failed to load shader: " << m_textShader.getLastError() << std::endl;
|
if (!m_textShader->loadFromFile("assets/shaders/text.shader.glsl")) {
|
||||||
|
std::cout << "Failed to load shader: " << m_textShader->getLastError() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_textShader.link()) {
|
if (!m_textShader->link()) {
|
||||||
std::cout << "Failed to link shader: " << m_textShader.getLastError() << std::endl;
|
std::cout << "Failed to link shader: " << m_textShader->getLastError() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_spriteShader.create();
|
m_spriteShader = new OpenGLShaderProgram();
|
||||||
if (!m_spriteShader.loadFromFile("assets/shaders/standard.shader.glsl")) {
|
|
||||||
std::cout << "Failed to load shader: " << m_spriteShader.getLastError() << std::endl;
|
if (!m_spriteShader->loadFromFile("assets/shaders/standard.shader.glsl")) {
|
||||||
|
std::cout << "Failed to load shader: " << m_spriteShader->getLastError() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_spriteShader.link()) {
|
if (!m_spriteShader->link()) {
|
||||||
std::cout << "Failed to link shader: " << m_spriteShader.getLastError() << std::endl;
|
std::cout << "Failed to link shader: " << m_spriteShader->getLastError() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,6 +75,9 @@ BatchRenderer2D::~BatchRenderer2D()
|
||||||
glDeleteBuffers(1, &m_VBO);
|
glDeleteBuffers(1, &m_VBO);
|
||||||
glDeleteBuffers(1, &m_IBO);
|
glDeleteBuffers(1, &m_IBO);
|
||||||
glDeleteVertexArrays(1, &m_VAO);
|
glDeleteVertexArrays(1, &m_VAO);
|
||||||
|
|
||||||
|
delete m_textShader;
|
||||||
|
delete m_spriteShader;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BatchRenderer2D::setBatchSize(unsigned short size)
|
void BatchRenderer2D::setBatchSize(unsigned short size)
|
||||||
|
|
@ -146,13 +151,13 @@ void BatchRenderer2D::render()
|
||||||
glBindVertexArray(m_VAO);
|
glBindVertexArray(m_VAO);
|
||||||
|
|
||||||
// Set shader uniforms.
|
// Set shader uniforms.
|
||||||
m_textShader.enable();
|
m_textShader->enable();
|
||||||
m_textShader.setUniform("u_MVP", MVP);
|
m_textShader->setUniform("u_MVP", MVP);
|
||||||
m_textShader.disable();
|
m_textShader->disable();
|
||||||
|
|
||||||
m_spriteShader.enable();
|
m_spriteShader->enable();
|
||||||
m_spriteShader.setUniform("u_MVP", MVP);
|
m_spriteShader->setUniform("u_MVP", MVP);
|
||||||
m_spriteShader.disable();
|
m_spriteShader->disable();
|
||||||
|
|
||||||
prepareQueue();
|
prepareQueue();
|
||||||
|
|
||||||
|
|
@ -242,9 +247,9 @@ void BatchRenderer2D::drawBatch(Batch& batch)
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
shader = &m_textShader;
|
shader = m_textShader;
|
||||||
} else {
|
} else {
|
||||||
shader = &m_spriteShader;
|
shader = m_spriteShader;
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable shader.
|
// enable shader.
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,21 @@
|
||||||
|
|
||||||
#include <Spectre/Graphics/Texture.h>
|
#include <Spectre/Graphics/Texture.h>
|
||||||
#include <Spectre/Graphics/OpenGL.h>
|
|
||||||
#include <Spectre/Graphics/Renderable.h>
|
#include <Spectre/Graphics/Renderable.h>
|
||||||
#include <Spectre/Graphics/DefaultRenderer2D.h>
|
#include <Spectre/Graphics/DefaultRenderer2D.h>
|
||||||
|
#include <GfxDriver/OpenGL/OpenGLShaderProgram.h>
|
||||||
|
#include <Graphics/GL/gl.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
DefaultRenderer2D::DefaultRenderer2D()
|
DefaultRenderer2D::DefaultRenderer2D()
|
||||||
{
|
{
|
||||||
m_shader.create();
|
m_shader = new OpenGLShaderProgram();
|
||||||
if (!m_shader.loadFromFile("assets/shaders/standard.shader.glsl")) {
|
if (!m_shader->loadFromFile("assets/shaders/standard.shader.glsl")) {
|
||||||
std::cout << "Failed to load shader: " << m_shader.getLastError() << std::endl;
|
std::cout << "Failed to load shader: " << m_shader->getLastError() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_shader.link()) {
|
if (!m_shader->link()) {
|
||||||
std::cout << "Failed to link shader: " << m_shader.getLastError() << std::endl;
|
std::cout << "Failed to link shader: " << m_shader->getLastError() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,7 +34,7 @@ void DefaultRenderer2D::render()
|
||||||
viewMatrix = Matrix4f::Identity;
|
viewMatrix = Matrix4f::Identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_shader.enable();
|
m_shader->enable();
|
||||||
|
|
||||||
glEnableVertexAttribArray(VertexAttribPosition);
|
glEnableVertexAttribArray(VertexAttribPosition);
|
||||||
glEnableVertexAttribArray(VertexAttribColor0);
|
glEnableVertexAttribArray(VertexAttribColor0);
|
||||||
|
|
@ -48,7 +49,7 @@ void DefaultRenderer2D::render()
|
||||||
const Texture *tex = obj->getTexture();
|
const Texture *tex = obj->getTexture();
|
||||||
|
|
||||||
Matrix4f modelViewMatrix = viewMatrix * obj->getTransform().getMatrix();
|
Matrix4f modelViewMatrix = viewMatrix * obj->getTransform().getMatrix();
|
||||||
m_shader.setMVPMatrix(modelViewMatrix);
|
m_shader->setMVPMatrix(modelViewMatrix);
|
||||||
|
|
||||||
glVertexAttribPointer(VertexAttribPosition, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), data + 0);
|
glVertexAttribPointer(VertexAttribPosition, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), data + 0);
|
||||||
glVertexAttribPointer(VertexAttribColor0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), data + 8);
|
glVertexAttribPointer(VertexAttribColor0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), data + 8);
|
||||||
|
|
@ -69,7 +70,7 @@ void DefaultRenderer2D::render()
|
||||||
glDisableVertexAttribArray(VertexAttribColor0);
|
glDisableVertexAttribArray(VertexAttribColor0);
|
||||||
glDisableVertexAttribArray(VertexAttribTexCoord0);
|
glDisableVertexAttribArray(VertexAttribTexCoord0);
|
||||||
|
|
||||||
m_shader.disable();
|
m_shader->disable();
|
||||||
m_queue.clear();
|
m_queue.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,27 +5,27 @@
|
||||||
#include <Spectre/Graphics/Image.h>
|
#include <Spectre/Graphics/Image.h>
|
||||||
#include <Spectre/Graphics/Texture.h>
|
#include <Spectre/Graphics/Texture.h>
|
||||||
#include <Spectre/Math/Math.h>
|
#include <Spectre/Math/Math.h>
|
||||||
#include "Font/FreeTypeDriver.h"
|
#include "Font/Engine/FreeTypeEngine.h"
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
Font::Font() :
|
Font::Font() :
|
||||||
m_driver (new FreeTypeDriver())
|
m_engine (new FreeTypeEngine())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Font::~Font()
|
Font::~Font()
|
||||||
{
|
{
|
||||||
delete m_driver;
|
delete m_engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Font::loadFromFile(const std::string& filename)
|
bool Font::loadFromFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
if (!m_driver->loadFromFile(filename)) {
|
if (!m_engine->loadFromFile(filename)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_driver->setCharacterSize(22)) {
|
if (!m_engine->setCharacterSize(22)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ bool Font::loadFromMemory(const void *data)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Font::Glyph Font::getGlyph(unsigned int code) const
|
Glyph Font::getGlyph(unsigned int code) const
|
||||||
{
|
{
|
||||||
if (m_charset.find(code) == m_charset.end()) {
|
if (m_charset.find(code) == m_charset.end()) {
|
||||||
|
|
||||||
|
|
@ -54,13 +54,13 @@ Font::Glyph Font::getGlyph(unsigned int code) const
|
||||||
void Font::loadChar(unsigned char code) const
|
void Font::loadChar(unsigned char code) const
|
||||||
{
|
{
|
||||||
Image img;
|
Image img;
|
||||||
Font::Glyph glyph;
|
Glyph glyph;
|
||||||
|
|
||||||
if (!m_driver) {
|
if (!m_engine) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
glyph = m_driver->loadGlyph(code, img);
|
glyph = m_engine->loadGlyph(code, img);
|
||||||
|
|
||||||
if (glyph.size > vec2b(0, 0)) {
|
if (glyph.size > vec2b(0, 0)) {
|
||||||
|
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue