add tutorial 2 comments
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
------------ Tyra's v2.0 roadmap to publish on GitHub ------------
|
------------ Tyra's v2.0 roadmap to publish on GitHub ------------
|
||||||
|
|
||||||
- [Tutorials] 2. 2D - explain beginFrame(), endFrame()
|
|
||||||
|
|
||||||
- [Tutorials] 3. Minecraft cube - explain this pipeline, and explain that there are many 3D pipelines
|
- [Tutorials] 3. Minecraft cube - explain this pipeline, and explain that there are many 3D pipelines
|
||||||
|
|
||||||
- [Tutorials] 4. Mesh rendering - explain staticPipeline, render .obj file via Mesh class, explain that this is high-level
|
- [Tutorials] 4. Mesh rendering - explain staticPipeline, render .obj file via Mesh class, explain that this is high-level
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ class Renderer {
|
|||||||
core.setClearScreenColor(color);
|
core.setClearScreenColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextureRepository& getTextureRepository() { return core.texture.repository; }
|
||||||
|
|
||||||
void setFrameLimit(const bool& onoff) { core.setFrameLimit(onoff); }
|
void setFrameLimit(const bool& onoff) { core.setFrameLimit(onoff); }
|
||||||
|
|
||||||
/** Update view frustum for frustum culling. 3D support - off */
|
/** Update view frustum for frustum culling. 3D support - off */
|
||||||
|
|||||||
@@ -14,11 +14,17 @@
|
|||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
|
|
||||||
Tutorial02::Tutorial02(Engine* t_engine) : engine(t_engine) {
|
Tutorial02::Tutorial02(Engine* t_engine) : engine(t_engine) {
|
||||||
|
/** Lets set default value, to prevent nullptr bugs */
|
||||||
texture = nullptr;
|
texture = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tutorial02::~Tutorial02() {
|
Tutorial02::~Tutorial02() {
|
||||||
if (texture != nullptr) {
|
if (texture != nullptr) {
|
||||||
|
/**
|
||||||
|
* free() function in texture repository is
|
||||||
|
* removing texture from repository and calling
|
||||||
|
* texture destructor
|
||||||
|
*/
|
||||||
engine->renderer.core.texture.repository.free(texture);
|
engine->renderer.core.texture.repository.free(texture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,8 +39,13 @@ void Tutorial02::init() {
|
|||||||
void Tutorial02::loop() {
|
void Tutorial02::loop() {
|
||||||
auto& renderer = engine->renderer;
|
auto& renderer = engine->renderer;
|
||||||
|
|
||||||
|
/** Begin frame will clear our screen. */
|
||||||
renderer.beginFrame();
|
renderer.beginFrame();
|
||||||
|
|
||||||
|
/** Render sprite. */
|
||||||
renderer.renderer2D.render(sprite);
|
renderer.renderer2D.render(sprite);
|
||||||
|
|
||||||
|
/** End frame will perform vsync. */
|
||||||
renderer.endFrame();
|
renderer.endFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +53,11 @@ void Tutorial02::loadSprite() {
|
|||||||
const auto& screenSettings = engine->renderer.core.getSettings();
|
const auto& screenSettings = engine->renderer.core.getSettings();
|
||||||
|
|
||||||
sprite.mode = SpriteMode::MODE_STRETCH;
|
sprite.mode = SpriteMode::MODE_STRETCH;
|
||||||
|
|
||||||
|
/** Let's scale it down */
|
||||||
sprite.size = Vec2(256.0F, 128.0F);
|
sprite.size = Vec2(256.0F, 128.0F);
|
||||||
|
|
||||||
|
/** Set it in screen center */
|
||||||
sprite.position =
|
sprite.position =
|
||||||
Vec2(screenSettings.getWidth() / 2.0F - sprite.size.x / 2.0F,
|
Vec2(screenSettings.getWidth() / 2.0F - sprite.size.x / 2.0F,
|
||||||
screenSettings.getHeight() / 2.0F - sprite.size.y / 2.0F);
|
screenSettings.getHeight() / 2.0F - sprite.size.y / 2.0F);
|
||||||
@@ -51,13 +66,51 @@ void Tutorial02::loadSprite() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Tutorial02::loadTexture() {
|
void Tutorial02::loadTexture() {
|
||||||
|
/**
|
||||||
|
* Renderer has high layer functions,
|
||||||
|
* which allows to render:
|
||||||
|
* - Sprite (2D)
|
||||||
|
* - Mesh (3D)
|
||||||
|
*
|
||||||
|
* It uses ONLY low layer functions which are in renderer.core
|
||||||
|
*/
|
||||||
auto& renderer = engine->renderer;
|
auto& renderer = engine->renderer;
|
||||||
auto& rendererCore = renderer.core;
|
|
||||||
auto& textureRepository = rendererCore.texture.repository;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TextureRepository is a repository of textures.
|
||||||
|
* It is a singleton class, with all game textures.
|
||||||
|
* We are linking these textures with sprite's (2D) and mesh (3D) materials.
|
||||||
|
*/
|
||||||
|
auto& textureRepository = renderer.getTextureRepository();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Texture is stored in "res" directory.
|
||||||
|
* Content of "res" directory is automatically copied into
|
||||||
|
* "bin" directory, which contains our final game.
|
||||||
|
*
|
||||||
|
* File utils automatically add's device prefix to the path,
|
||||||
|
* based on current working directory.
|
||||||
|
*
|
||||||
|
* In PS2 world:
|
||||||
|
* - USB has a "mass:" prefix
|
||||||
|
* - Our PC in PS2Link has a "host:" prefix
|
||||||
|
* - Our PC in PCSX2 has a "host:" prefix
|
||||||
|
*/
|
||||||
auto filepath = FileUtils::fromCwd("tyra.png");
|
auto filepath = FileUtils::fromCwd("tyra.png");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tyra supports following PNG formats:
|
||||||
|
* 32bpp (RGBA)
|
||||||
|
* 24bpp (RGB)
|
||||||
|
* 8bpp, palletized (RGBA)
|
||||||
|
* 4bpp, palletized (RGBA)
|
||||||
|
*
|
||||||
|
* 8bpp and 4bpp are the fastest.
|
||||||
|
* All of these formats can be easily exported via GIMP.
|
||||||
|
*/
|
||||||
texture = textureRepository.add(filepath);
|
texture = textureRepository.add(filepath);
|
||||||
|
|
||||||
|
/** Let's assign this texture to sprite. */
|
||||||
texture->addLink(sprite.id);
|
texture->addLink(sprite.id);
|
||||||
|
|
||||||
TYRA_LOG("Texture loaded!");
|
TYRA_LOG("Texture loaded!");
|
||||||
|
|||||||
Reference in New Issue
Block a user