squish
13
blooblib.sln
|
@ -5,6 +5,11 @@ VisualStudioVersion = 17.8.34330.188
|
|||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "blooblib", "blooblib\blooblib.vcxproj", "{CF7A4698-9135-4200-9E68-B8D4F53275D7}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test\test.vcxproj", "{243F1CBC-1E8B-4A9D-836A-1B616B805558}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{CF7A4698-9135-4200-9E68-B8D4F53275D7} = {CF7A4698-9135-4200-9E68-B8D4F53275D7}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
|
@ -21,6 +26,14 @@ Global
|
|||
{CF7A4698-9135-4200-9E68-B8D4F53275D7}.Release|x64.Build.0 = Release|x64
|
||||
{CF7A4698-9135-4200-9E68-B8D4F53275D7}.Release|x86.ActiveCfg = Release|Win32
|
||||
{CF7A4698-9135-4200-9E68-B8D4F53275D7}.Release|x86.Build.0 = Release|Win32
|
||||
{243F1CBC-1E8B-4A9D-836A-1B616B805558}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{243F1CBC-1E8B-4A9D-836A-1B616B805558}.Debug|x64.Build.0 = Debug|x64
|
||||
{243F1CBC-1E8B-4A9D-836A-1B616B805558}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{243F1CBC-1E8B-4A9D-836A-1B616B805558}.Debug|x86.Build.0 = Debug|Win32
|
||||
{243F1CBC-1E8B-4A9D-836A-1B616B805558}.Release|x64.ActiveCfg = Release|x64
|
||||
{243F1CBC-1E8B-4A9D-836A-1B616B805558}.Release|x64.Build.0 = Release|x64
|
||||
{243F1CBC-1E8B-4A9D-836A-1B616B805558}.Release|x86.ActiveCfg = Release|Win32
|
||||
{243F1CBC-1E8B-4A9D-836A-1B616B805558}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -19,13 +19,16 @@
|
|||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\draw\draw_text.cpp" />
|
||||
<ClCompile Include="src\font.cpp" />
|
||||
<ClCompile Include="src\draw\draw_image.cpp" />
|
||||
<ClCompile Include="src\tileset.cpp" />
|
||||
<ClCompile Include="src\image.cpp" />
|
||||
<ClCompile Include="src\game.cpp" />
|
||||
<ClCompile Include="src\main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="include\bloob.h" />
|
||||
<ClInclude Include="include\font.h" />
|
||||
<ClInclude Include="include\game.h" />
|
||||
<ClInclude Include="include\image.h" />
|
||||
<ClInclude Include="include\rect.h" />
|
||||
|
@ -34,6 +37,9 @@
|
|||
<ClInclude Include="include\vec2.h" />
|
||||
<ClInclude Include="src\stb_image.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="fontconvert.bat" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
|
@ -56,13 +62,13 @@
|
|||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
|
|
|
@ -15,9 +15,6 @@
|
|||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\game.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -27,6 +24,15 @@
|
|||
<ClCompile Include="src\tileset.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\draw\draw_image.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\font.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\draw\draw_text.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="include\game.h">
|
||||
|
@ -53,5 +59,13 @@
|
|||
<ClInclude Include="src\stb_image.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\font.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="fontconvert.bat">
|
||||
<Filter>Source Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1 @@
|
|||
magick convert +antialias -font @%1.ttf -pointsize 16 caption:" !""#$%%%%&,()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_'abcdefghijklmnopqrstuvwxyz{|}~" -flatten %1.png
|
|
@ -1,8 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "font.h"
|
||||
#include "game.h"
|
||||
#include "image.h"
|
||||
#include "rect.h"
|
||||
#include "settings.h"
|
||||
#include "tileset.h"
|
||||
#include "vec2.h"
|
||||
|
||||
const double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286;
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
struct image;
|
||||
|
||||
struct font {
|
||||
font(image const& image, bool proportional);
|
||||
font(std::string const& path, bool proportional);
|
||||
|
||||
image const& operator[](char ch) const;
|
||||
private:
|
||||
std::map<char, image> _glyphs;
|
||||
};
|
|
@ -2,6 +2,7 @@
|
|||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "font.h"
|
||||
#include "rect.h"
|
||||
#include "vec2.h"
|
||||
|
||||
|
@ -11,6 +12,7 @@ struct image {
|
|||
image(vec2i size);
|
||||
image(vec2i size, color* data);
|
||||
image(std::string path);
|
||||
image(image const& other);
|
||||
~image();
|
||||
//static image_from_pointer()
|
||||
|
||||
|
@ -18,13 +20,18 @@ struct image {
|
|||
recti const& bounds() const;
|
||||
|
||||
color* raw_pointer() const;
|
||||
color get(vec2i pos) const;
|
||||
|
||||
void clear(color color);
|
||||
|
||||
void draw(image const& image, vec2i pos);
|
||||
void draw(image const& image, vec2i pos, recti src_rect);
|
||||
void draw(image const& image, vec2i pos, color color);
|
||||
void draw(image const& image, vec2i pos, color color, recti src_rect);
|
||||
void draw_upscaled(image const& image);
|
||||
|
||||
|
||||
void draw(std::string const& str, vec2i pos, font const& font, color color);
|
||||
void draw(std::string const& str, vec2i pos, font const& font, color color1, color color2);
|
||||
private:
|
||||
bool _borrowed_pointer; //to know if to free or not
|
||||
color* _data; //not a vector so can wrap sdl surfaces
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include "vec2.h"
|
||||
|
||||
struct tileset {
|
||||
tileset(image const&, vec2i tile_size);
|
||||
tileset(image const& image, vec2i tile_size);
|
||||
tileset(std::string path, vec2i tile_size);
|
||||
|
||||
image& operator[](int index);
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
#include "image.h"
|
||||
|
||||
void image::draw(image const& image, vec2i pos) {
|
||||
draw(image, pos, image.bounds());
|
||||
}
|
||||
|
||||
void image::draw(image const& image, vec2i pos, recti src_rect) {
|
||||
src_rect = recti::intersection(src_rect, image.bounds());
|
||||
auto crop = recti::intersection(bounds(), recti(pos, image.bounds().size));
|
||||
crop = recti::intersection(crop, recti(crop.pos, src_rect.size));
|
||||
auto src_off = crop.pos - pos + src_rect.pos;
|
||||
auto start = crop.pos;
|
||||
auto end = crop.pos2();
|
||||
for(int y = start.y; y <= end.y; ++y) {
|
||||
for(int x = start.x; x <= end.x; ++x) {
|
||||
auto color = image._data[
|
||||
x - start.x + src_off.x + (y - start.y + src_off.y) * image._bounds.size.x
|
||||
];
|
||||
if(color & 0xff000000)
|
||||
_data[x + y * _bounds.size.x] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void image::draw(image const& image, vec2i pos, color color) {
|
||||
draw(image, pos, color, image.bounds());
|
||||
}
|
||||
|
||||
void image::draw(image const& image, vec2i pos, color color, recti src_rect) {
|
||||
color |= 0xff000000;
|
||||
src_rect = recti::intersection(src_rect, image.bounds());
|
||||
auto crop = recti::intersection(bounds(), recti(pos, image.bounds().size));
|
||||
crop = recti::intersection(crop, recti(crop.pos, src_rect.size));
|
||||
auto src_off = crop.pos - pos + src_rect.pos;
|
||||
auto start = crop.pos;
|
||||
auto end = crop.pos2();
|
||||
for(int y = start.y; y <= end.y; ++y) {
|
||||
for(int x = start.x; x <= end.x; ++x) {
|
||||
auto color_src = image._data[
|
||||
x - start.x + src_off.x + (y - start.y + src_off.y) * image._bounds.size.x
|
||||
];
|
||||
if(color_src & 0xff000000)
|
||||
_data[x + y * _bounds.size.x] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void image::draw_upscaled(image const& image) {
|
||||
auto ratio = _bounds.size / image._bounds.size;
|
||||
auto scale = std::min(ratio.x, ratio.y);
|
||||
switch(scale) {
|
||||
case 3:
|
||||
#pragma omp parallel for
|
||||
for(int y = 0; y < image._bounds.size.y; ++y) {
|
||||
for(int x = 0; x < image._bounds.size.x; ++x) {
|
||||
auto color = image._data[x + y * image._bounds.size.x];
|
||||
auto color2 = (color & 0xfefefe) >> 1;
|
||||
_data[x * 3 + 0 + (y * 3 + 0) * _bounds.size.x] = color;
|
||||
_data[x * 3 + 1 + (y * 3 + 0) * _bounds.size.x] = color;
|
||||
_data[x * 3 + 2 + (y * 3 + 0) * _bounds.size.x] = color2;
|
||||
_data[x * 3 + 0 + (y * 3 + 1) * _bounds.size.x] = color;
|
||||
_data[x * 3 + 1 + (y * 3 + 1) * _bounds.size.x] = color;
|
||||
_data[x * 3 + 2 + (y * 3 + 1) * _bounds.size.x] = color2;
|
||||
_data[x * 3 + 0 + (y * 3 + 2) * _bounds.size.x] = color2;
|
||||
_data[x * 3 + 1 + (y * 3 + 2) * _bounds.size.x] = color2;
|
||||
_data[x * 3 + 2 + (y * 3 + 2) * _bounds.size.x] = color2;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
#pragma omp parallel for
|
||||
for(int y = 0; y < image._bounds.size.y; ++y) {
|
||||
for(int x = 0; x < image._bounds.size.x; ++x) {
|
||||
auto color = image._data[x + y * image._bounds.size.x];
|
||||
for(int sy = 0; sy < scale; ++sy) {
|
||||
for(int sx = 0; sx < scale; ++sx) {
|
||||
_data[(x * scale + sx) + (y * scale + sy) * _bounds.size.x] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
#include "image.h"
|
||||
|
||||
void image::draw(std::string const& str, vec2i pos, font const& font, color color) {
|
||||
for(auto ch = str.begin(); ch != str.end(); ++ch) {
|
||||
draw(font[*ch], pos, color);
|
||||
pos.x += font[*ch].size().x;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<vec2i> shadow_offsets{
|
||||
vec2i(-1, 0),
|
||||
vec2i( 1, 0),
|
||||
vec2i( 0, -1),
|
||||
vec2i( 0, 1),
|
||||
|
||||
vec2i(-1, -1),
|
||||
vec2i(-1, 1),
|
||||
vec2i( 1, -1),
|
||||
vec2i( 1, 1),
|
||||
|
||||
vec2i( 0, 2),
|
||||
vec2i(-1, 2),
|
||||
vec2i( 1, 2)
|
||||
};
|
||||
|
||||
void image::draw(std::string const& str, vec2i pos, font const& font, color color1, color color2) {
|
||||
for(auto so = shadow_offsets.begin(); so != shadow_offsets.end(); ++so)
|
||||
draw(str, pos + *so, font, color2);
|
||||
draw(str, pos, font, color1);
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
#include "font.h"
|
||||
|
||||
#include "image.h"
|
||||
|
||||
font::font(image const& image, bool proportional) {
|
||||
if(!proportional)
|
||||
throw std::runtime_error("not yet implemented");
|
||||
|
||||
auto x = 0;
|
||||
std::vector<int> slices;
|
||||
for(int i = 0; i < image.size().x; ++i) {
|
||||
if(image.get(vec2i(i, 0)) & 0xff000000)
|
||||
slices.push_back(i);
|
||||
}
|
||||
int count = slices.size();
|
||||
slices.push_back(image.size().x);
|
||||
auto height = image.size().y;
|
||||
|
||||
auto charset = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'abcdefghijklmnopqrstuvwxyz{|}~";
|
||||
for(int i = 0; i < count; ++i) {
|
||||
auto r = recti(vec2i(slices[i], 1), vec2i(slices[i + 1] - slices[i], height - 1));
|
||||
//auto img = ::image(r.size);
|
||||
auto ch = charset[i];
|
||||
_glyphs.emplace(ch, r.size);
|
||||
_glyphs.at(ch).clear(0);
|
||||
_glyphs.at(ch).draw(image, vec2i::zero, r);
|
||||
}
|
||||
}
|
||||
|
||||
font::font(std::string const& path, bool proportional) :
|
||||
font(image(path), proportional) { }
|
||||
|
||||
image const& font::operator[](char ch) const {
|
||||
if(_glyphs.contains(ch))
|
||||
return _glyphs.at(ch);
|
||||
else
|
||||
return _glyphs.at(' ');
|
||||
}
|
|
@ -56,6 +56,10 @@ void game::run() {
|
|||
auto last_second = std::chrono::steady_clock::now();
|
||||
auto frames_since_last_second = 0;
|
||||
|
||||
std::chrono::duration<int32_t, std::nano> second(1000000000ll);
|
||||
auto frame_duration = second / settings.target_fps;
|
||||
auto last_frame = last_second;
|
||||
|
||||
auto running = true;
|
||||
while(running) {
|
||||
MSG msg;
|
||||
|
@ -76,6 +80,7 @@ void game::run() {
|
|||
last_second += std::chrono::seconds(1);
|
||||
}
|
||||
|
||||
if(now - last_frame >= frame_duration) {
|
||||
update();
|
||||
render(screen);
|
||||
window_image.draw_upscaled(screen);
|
||||
|
@ -88,11 +93,24 @@ void game::run() {
|
|||
bi.biCompression = BI_RGB;
|
||||
|
||||
auto dc = GetDC(window);
|
||||
SetDIBitsToDevice(dc, 0, 0, window_image.size().x, window_image.size().y, 0, 0, 0, window_image.size().y, window_image.raw_pointer(),
|
||||
(BITMAPINFO*)&bi, DIB_RGB_COLORS);
|
||||
SetDIBitsToDevice(
|
||||
dc,
|
||||
0,
|
||||
0,
|
||||
window_image.size().x,
|
||||
window_image.size().y,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
window_image.size().y,
|
||||
window_image.raw_pointer(),
|
||||
(BITMAPINFO*)&bi,
|
||||
DIB_RGB_COLORS
|
||||
);
|
||||
ReleaseDC(window, dc);
|
||||
++frames_since_last_second;
|
||||
|
||||
last_frame += frame_duration;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
#include "image.h"
|
||||
#include <bit>
|
||||
#include <iostream>
|
||||
//#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STBI_ONLY_PNG
|
||||
#include "stb_image.h"
|
||||
|
@ -12,27 +7,40 @@ image::image(vec2i size) :
|
|||
_borrowed_pointer(false),
|
||||
_data(new color[size.size()]),
|
||||
_bounds(vec2i::zero, size)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
image::image(vec2i size, color* data) :
|
||||
_borrowed_pointer(true),
|
||||
_data(data),
|
||||
_bounds(vec2i::zero, size) {
|
||||
}
|
||||
_bounds(vec2i::zero, size)
|
||||
{}
|
||||
|
||||
image::image(std::string path) : _borrowed_pointer(false) {
|
||||
int w, h, n;
|
||||
_data = reinterpret_cast<color*>(stbi_load(path.c_str(), &w, &h, &n, 0));
|
||||
auto data = reinterpret_cast<color*>(stbi_load(path.c_str(), &w, &h, &n, 0));
|
||||
_data = new color[w * h];
|
||||
for(int i = 0; i < w*h; ++i) {
|
||||
_data[i] = _data[i] & 0xff000000 | (_data[i] & 0x00ff0000) >> 16 | (_data[i] & 0x0000ff00) | (_data[i] & 0x000000ff) << 16;
|
||||
_data[i] = data[i];
|
||||
_data[i] = (data[i] & 0xff000000u) |
|
||||
((data[i] & 0x00ff0000u) >> 16) |
|
||||
(data[i] & 0x0000ff00u) |
|
||||
((data[i] & 0x000000ffu) << 16);
|
||||
}
|
||||
stbi_image_free(data);
|
||||
_bounds = recti(vec2i::zero, vec2i(w, h));
|
||||
}
|
||||
|
||||
image::image(image const& other) :
|
||||
_borrowed_pointer(false),
|
||||
_data(new color[other.size().size()]),
|
||||
_bounds(other.bounds())
|
||||
{
|
||||
std::memcpy(_data, other._data, size().size() * 4);
|
||||
}
|
||||
|
||||
image::~image() {
|
||||
if(!_borrowed_pointer)
|
||||
delete _data;
|
||||
if(!_borrowed_pointer && _data)
|
||||
delete[] _data;
|
||||
}
|
||||
|
||||
vec2i const& image::size() const {
|
||||
|
@ -47,62 +55,13 @@ color* image::raw_pointer() const {
|
|||
return _data;
|
||||
}
|
||||
|
||||
color image::get(vec2i pos) const {
|
||||
return _data[pos.x + pos.y * _bounds.size.x];
|
||||
}
|
||||
|
||||
void image::clear(color color) {
|
||||
std::fill(_data, _data + size().size() - 1, color);
|
||||
std::fill(_data, _data + size().size(), color);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void image::draw(image const& image, vec2i pos) {
|
||||
auto crop = recti::intersection(bounds(), recti(pos, image.bounds().size));
|
||||
auto src_off = crop.pos - pos;
|
||||
auto start = crop.pos;
|
||||
auto end = crop.pos2();
|
||||
for(int y = start.y; y <= end.y; ++y) {
|
||||
for(int x = start.x; x <= end.x; ++x) {
|
||||
auto color = image._data[x - start.x + src_off.x + (y - start.y + src_off.y) * image._bounds.size.x];
|
||||
if(color & 0xff000000)
|
||||
_data[x + y * _bounds.size.x] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void image::draw(image const& image, vec2i pos, recti src_rect) {
|
||||
}
|
||||
|
||||
void image::draw_upscaled(image const& image) {
|
||||
auto ratio = _bounds.size / image._bounds.size;
|
||||
auto scale = std::min(ratio.x, ratio.y);
|
||||
switch(scale) {
|
||||
case 3:
|
||||
#pragma omp parallel for
|
||||
for(int y = 0; y < image._bounds.size.y; ++y) {
|
||||
for(int x = 0; x < image._bounds.size.x; ++x) {
|
||||
auto color = image._data[x + y * image._bounds.size.x];
|
||||
auto color2 = (color & 0xfefefe) >> 1;
|
||||
_data[x * 3 + 0 + (y * 3 + 0) * _bounds.size.x] = color;
|
||||
_data[x * 3 + 1 + (y * 3 + 0) * _bounds.size.x] = color;
|
||||
_data[x * 3 + 2 + (y * 3 + 0) * _bounds.size.x] = color2;
|
||||
_data[x * 3 + 0 + (y * 3 + 1) * _bounds.size.x] = color;
|
||||
_data[x * 3 + 1 + (y * 3 + 1) * _bounds.size.x] = color;
|
||||
_data[x * 3 + 2 + (y * 3 + 1) * _bounds.size.x] = color2;
|
||||
_data[x * 3 + 0 + (y * 3 + 2) * _bounds.size.x] = color2;
|
||||
_data[x * 3 + 1 + (y * 3 + 2) * _bounds.size.x] = color2;
|
||||
_data[x * 3 + 2 + (y * 3 + 2) * _bounds.size.x] = color2;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
#pragma omp parallel for
|
||||
for(int y = 0; y < image._bounds.size.y; ++y) {
|
||||
for(int x = 0; x < image._bounds.size.x; ++x) {
|
||||
auto color = image._data[x + y * image._bounds.size.x];
|
||||
for(int sy = 0; sy < scale; ++sy) {
|
||||
for(int sx = 0; sx < scale; ++sx) {
|
||||
_data[(x * scale + sx) + (y * scale + sy) * _bounds.size.x] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
#include <iostream>
|
||||
#include "bloob.h"
|
||||
|
||||
struct my_game : game {
|
||||
my_game();
|
||||
void init(settings& settings);
|
||||
void update();
|
||||
void render(image& target);
|
||||
|
||||
image img;
|
||||
double time;
|
||||
};
|
||||
|
||||
my_game::my_game() :
|
||||
img("test.png"),
|
||||
time(0.0)
|
||||
{}
|
||||
|
||||
void my_game::init(settings& settings) {
|
||||
}
|
||||
|
||||
void my_game::update() {
|
||||
time += 1.0 / 60.0;
|
||||
}
|
||||
|
||||
void my_game::render(image& target) {
|
||||
target.clear(0xffdddd);
|
||||
auto pos = vec2i(std::sin(time*TAU/100), std::cos(time*TAU/100));
|
||||
std::cout << pos << std::endl;
|
||||
target.draw(img, vec2i(320, 180) + pos);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
my_game game;
|
||||
game.run();
|
||||
return 0;
|
||||
}
|
|
@ -1,6 +1,15 @@
|
|||
#include "tileset.h"
|
||||
|
||||
tileset::tileset(image const&, vec2i tile_size) {
|
||||
tileset::tileset(image const& image, vec2i tile_size) {
|
||||
auto tile_count = image.size() / tile_size;
|
||||
for(int y = 0; y < tile_count.y; ++y) {
|
||||
for(int x = 0; x < tile_count.x; ++x) {
|
||||
auto tile = ::image(tile_size);
|
||||
tile.clear(0);
|
||||
tile.draw(image, vec2i::zero, recti(tile_size * vec2i(x, y), tile_size));
|
||||
_tiles.push_back(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tileset::tileset(std::string path, vec2i tile_size) :
|
||||
|
|
Before Width: | Height: | Size: 900 KiB |
Before Width: | Height: | Size: 675 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 1.2 KiB |
|
@ -0,0 +1,44 @@
|
|||
#include <iostream>
|
||||
#include "bloob.h"
|
||||
|
||||
struct my_game : game {
|
||||
my_game();
|
||||
void init(settings& settings);
|
||||
void update();
|
||||
void render(image& target);
|
||||
|
||||
image img;
|
||||
tileset tileset;
|
||||
font font;
|
||||
double time;
|
||||
};
|
||||
|
||||
my_game::my_game() :
|
||||
img("test.png"),
|
||||
tileset("font.png", vec2i(8, 14)),
|
||||
font("habbo.png", true),
|
||||
time(0.0) {
|
||||
}
|
||||
|
||||
void my_game::init(settings& settings) {
|
||||
settings.target_fps = 60;
|
||||
}
|
||||
|
||||
void my_game::update() {
|
||||
time += 1.0 / 60.0;
|
||||
}
|
||||
|
||||
void my_game::render(image& target) {
|
||||
target.clear(0xffdddd);
|
||||
auto pos = vec2i(std::sin(time * TAU / 4) * 100, std::cos(time * TAU / 4) * 100);
|
||||
//target.draw(img, vec2i(320, 180) + pos, recti(vec2i(8, 14), vec2i(8 * 4, 14 * 4)));
|
||||
//target.draw(img, vec2i(320, 180) + pos);
|
||||
//target.draw(tileset[0xda], vec2i(320, 180) + pos, 0xff00ff);
|
||||
target.draw("hello world!", vec2i(320, 180) + pos, font, 0xffffff, 0);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
my_game game;
|
||||
game.run();
|
||||
return 0;
|
||||
}
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
|
@ -0,0 +1,144 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{243f1cbc-1e8b-4a9d-836a-1b616b805558}</ProjectGuid>
|
||||
<RootNamespace>test</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)blooblib\include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)blooblib\include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)blooblib\include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)blooblib\include</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="test.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\blooblib\blooblib.vcxproj">
|
||||
<Project>{cf7a4698-9135-4200-9e68-b8d4f53275d7}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="test.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|