tutorial 1 and 2
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
TARGET := tutorial_01.elf
|
||||
ENGINEDIR := ../../engine
|
||||
|
||||
#The Directories, Source, Includes, Objects, Binary and Resources
|
||||
SRCDIR := src
|
||||
INCDIR := inc
|
||||
BUILDDIR := obj
|
||||
TARGETDIR := bin
|
||||
RESDIR := res
|
||||
SRCEXT := cpp
|
||||
VSMEXT := vsm
|
||||
VCLEXT := vcl
|
||||
VCLPPEXT := vclpp
|
||||
DEPEXT := d
|
||||
OBJEXT := o
|
||||
|
||||
#Flags, Libraries and Includes
|
||||
CFLAGS :=
|
||||
LIB :=
|
||||
LIBDIRS :=
|
||||
INC := -I$(INCDIR)
|
||||
INCDEP := -I$(INCDIR)
|
||||
|
||||
include ../Makefile.tutorials-base
|
||||
@@ -0,0 +1,4 @@
|
||||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
# _____ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licensed under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tyra>
|
||||
#include <memory.h>
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
class Tutorial02 : public Game {
|
||||
public:
|
||||
Tutorial02(Engine* engine);
|
||||
~Tutorial02();
|
||||
|
||||
void init();
|
||||
void loop();
|
||||
|
||||
private:
|
||||
void loadTexture();
|
||||
void loadSprite();
|
||||
|
||||
Engine* engine;
|
||||
|
||||
Sprite sprite;
|
||||
Texture* texture;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
@@ -0,0 +1,4 @@
|
||||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
||||
@@ -0,0 +1,4 @@
|
||||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
||||
@@ -0,0 +1,4 @@
|
||||
$ConfigFile = Join-Path $PSScriptRoot '../../windows-pcsx2.ps1'
|
||||
. $ConfigFile
|
||||
|
||||
RunPCSX2
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
# _____ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licensed under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include "engine.hpp"
|
||||
#include "tutorial_02.hpp"
|
||||
|
||||
/**
|
||||
* In this tutorial we will learn how to:
|
||||
* - Load png file and create texture from it
|
||||
* - Create sprite class
|
||||
* - Clear screen and render sprite
|
||||
*/
|
||||
|
||||
int main() {
|
||||
Tyra::Engine engine;
|
||||
Tyra::Tutorial02 game(&engine);
|
||||
engine.run(&game);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
# _____ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
# Licensed under Apache License 2.0
|
||||
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
*/
|
||||
|
||||
#include <tyra>
|
||||
#include "tutorial_02.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
Tutorial02::Tutorial02(Engine* t_engine) : engine(t_engine) {
|
||||
texture = nullptr;
|
||||
}
|
||||
|
||||
Tutorial02::~Tutorial02() {
|
||||
if (texture != nullptr) {
|
||||
engine->renderer.core.texture.repository.free(texture);
|
||||
}
|
||||
}
|
||||
|
||||
void Tutorial02::init() {
|
||||
engine->renderer.setClearScreenColor(Color(32.0F, 32.0F, 32.0F));
|
||||
|
||||
loadSprite();
|
||||
loadTexture();
|
||||
}
|
||||
|
||||
void Tutorial02::loop() {
|
||||
auto& renderer = engine->renderer;
|
||||
|
||||
renderer.beginFrame();
|
||||
renderer.renderer2D.render(sprite);
|
||||
renderer.endFrame();
|
||||
}
|
||||
|
||||
void Tutorial02::loadSprite() {
|
||||
const auto& screenSettings = engine->renderer.core.getSettings();
|
||||
|
||||
sprite.mode = SpriteMode::MODE_STRETCH;
|
||||
sprite.size = Vec2(256.0F, 128.0F);
|
||||
sprite.position =
|
||||
Vec2(screenSettings.getWidth() / 2.0F - sprite.size.x / 2.0F,
|
||||
screenSettings.getHeight() / 2.0F - sprite.size.y / 2.0F);
|
||||
|
||||
TYRA_LOG("Sprite created!");
|
||||
}
|
||||
|
||||
void Tutorial02::loadTexture() {
|
||||
auto& renderer = engine->renderer;
|
||||
auto& rendererCore = renderer.core;
|
||||
auto& textureRepository = rendererCore.texture.repository;
|
||||
|
||||
auto filepath = FileUtils::fromCwd("tyra.png");
|
||||
texture = textureRepository.add(filepath);
|
||||
|
||||
texture->addLink(sprite.id);
|
||||
|
||||
TYRA_LOG("Texture loaded!");
|
||||
}
|
||||
|
||||
} // namespace Tyra
|
||||
Reference in New Issue
Block a user