added 2d png support

This commit is contained in:
h4570
2020-12-01 17:26:10 +01:00
parent 3841487388
commit 510199164c
17 changed files with 317 additions and 80 deletions
+1
View File
@@ -1,6 +1,7 @@
.vscode/ .vscode/
*.[Bb][Mm][Pp] *.[Bb][Mm][Pp]
*.[Pp][Nn][Gg]
*.[Oo][Bb][Jj] *.[Oo][Bb][Jj]
*.[Ww][Aa][Vv] *.[Ww][Aa][Vv]
*.[Dd][Ff][Ff] *.[Dd][Ff][Ff]
+1
View File
@@ -32,6 +32,7 @@ public:
~Point(); ~Point();
void set(const float &t_x, const float &t_y); void set(const float &t_x, const float &t_y);
void rotate(const float &t_angle, const float &t_x, const float &t_y);
void set(const Point &v); void set(const Point &v);
const void print() const; const void print() const;
}; };
+47 -10
View File
@@ -17,6 +17,13 @@
#include "./texture_link.hpp" #include "./texture_link.hpp"
#include "../include/utils/debug.hpp" #include "../include/utils/debug.hpp"
#include <vector> #include <vector>
#include <gs_psm.h>
enum TextureType
{
TEX_TYPE_RGB = GS_PSM_24, // BMP
TEX_TYPE_RGBA = GS_PSM_32 // PNG
};
/** /**
* Class which contains texture data. * Class which contains texture data.
@@ -46,15 +53,17 @@ public:
const u8 &getHeight() const { return height; }; const u8 &getHeight() const { return height; };
const TextureType &getType() const { return _type; };
u32 getTextureLinksCount() const { return static_cast<u32>(texLinks.size()); }; u32 getTextureLinksCount() const { return static_cast<u32>(texLinks.size()); };
texwrap_t *getWrapSettings() { return &wrapSettings; }; texwrap_t *getWrapSettings() { return &wrapSettings; };
/** /**
* Returns always width * width * 3. * Returns always width * width * 3/4.
* 3 because of RGB * 3 for RGB, 4 for RGBA.
*/ */
u32 getDataSize() const { return width * height * 3; }; u32 getDataSize() const { return _type == TEX_TYPE_RGB ? width * height * 3 : width * height * 4; };
/** /**
* Texture data, used by renderer. * Texture data, used by renderer.
@@ -83,6 +92,12 @@ public:
return -1; return -1;
}; };
/**
* Returns index of link.
* -1 if not found.
*/
inline const s32 getIndexOfLink(const u32 &t_spriteId) const { return getIndexOfLink(t_spriteId, 0); };
// ---- // ----
// Setters // Setters
// ---- // ----
@@ -92,7 +107,7 @@ public:
* Do not call this method unless you know what you do. * Do not call this method unless you know what you do.
* Should be called by data loader. * Should be called by data loader.
*/ */
void setSize(const u8 &t_width, const u8 &t_height); void setSize(const u8 &t_width, const u8 &t_height, const TextureType &t_type);
/** /**
* Do not call this method unless you know what you do. * Do not call this method unless you know what you do.
@@ -101,8 +116,8 @@ public:
void setHeight(const u8 &t_val) { height = t_val; } void setHeight(const u8 &t_val) { height = t_val; }
/** /**
* Set texture name. * Do not call this method unless you know what you do.
* Should be the file name without extension * Should be called by data loader.
*/ */
void setData(const u32 &t_index, const unsigned char &t_val) { data[t_index] = t_val; } void setData(const u32 &t_index, const unsigned char &t_val) { data[t_index] = t_val; }
@@ -119,9 +134,12 @@ public:
// Other // Other
// ---- // ----
/** Assign texture to mesh and mesh material */ /** Assign texture to mesh and mesh material. */
void addLink(const u32 &t_meshId, const u32 &t_materialId); void addLink(const u32 &t_meshId, const u32 &t_materialId);
/** Assign texture to sprite. */
void addLink(const u32 &t_spriteId);
const u8 &isNameSet() const { return _isNameSet; }; const u8 &isNameSet() const { return _isNameSet; };
const u8 &isSizeSet() const { return _isSizeSet; }; const u8 &isSizeSet() const { return _isSizeSet; };
@@ -135,13 +153,31 @@ public:
return false; return false;
}; };
void removeLink(const u32 &t_index) { texLinks.erase(texLinks.begin() + t_index); } const u8 isLinkedWith(const u32 &t_spriteId) const
{
s32 index = getIndexOfLink(t_spriteId);
if (index != -1)
return true;
else
return false;
};
void removeLink(const u32 &t_meshId, const u32 &t_materialId) void removeLinkByIndex(const u32 &t_index) { texLinks.erase(texLinks.begin() + t_index); }
void removeLinkBySprite(const u32 &t_spriteId)
{
s32 index = getIndexOfLink(t_spriteId);
if (index != -1)
removeLinkByIndex(index);
else
PRINT_ERR("Cant remove link, because it was not found!");
}
void removeLinkByMesh(const u32 &t_meshId, const u32 &t_materialId)
{ {
s32 index = getIndexOfLink(t_meshId, t_materialId); s32 index = getIndexOfLink(t_meshId, t_materialId);
if (index != -1) if (index != -1)
removeLink(index); removeLinkByIndex(index);
else else
PRINT_ERR("Cant remove link, because it was not found!"); PRINT_ERR("Cant remove link, because it was not found!");
} }
@@ -150,6 +186,7 @@ private:
void setDefaultWrapSettings(); void setDefaultWrapSettings();
texwrap_t wrapSettings; texwrap_t wrapSettings;
char *name; char *name;
TextureType _type;
std::vector<TextureLink> texLinks; std::vector<TextureLink> texLinks;
u32 id; u32 id;
u8 width, height, _isNameSet, _isSizeSet; u8 width, height, _isNameSet, _isSizeSet;
+67
View File
@@ -0,0 +1,67 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2020, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#ifndef _TYRA_SPRITE_
#define _TYRA_SPRITE_
#include <models/math/point.hpp>
#include <draw_types.h>
#include <draw_buffers.h>
/**
* Class which have contain 2D image data.
*/
class Sprite
{
public:
Sprite();
~Sprite();
Point position, size;
float scale;
color_t color;
clutbuffer_t clut;
// ----
// Getters
// ----
/** Auto generated unique Id. */
inline const u32 &getId() const { return id; };
// ----
// Setters
// ----
// ----
// Other
// ----
/** Flip texture horizontally. */
inline void flipHorizontally(const u8 &t_set) { _flipH = t_set; };
/** Flip texture vertically. */
inline void flipVertically(const u8 &t_set) { _flipV = t_set; };
/** Check if texture is vertically flipped. */
inline const u8 &isFlippedVertically() const { return _flipV; };
/** Check if texture is horizontally flipped. */
inline const u8 &isFlippedHorizontally() const { return _flipH; };
private:
u32 id;
u8 _isSizeSet, _flipH, _flipV;
void setDefaultColor();
void setDefaultLODAndClut();
};
#endif
+4 -1
View File
@@ -15,7 +15,10 @@
struct TextureLink struct TextureLink
{ {
u32 meshId, materialId; /** Mesh id or sprite id */
u32 meshId;
/** Mesh material id or 0 if is sprite */
u32 materialId;
}; };
#endif #endif
+5 -4
View File
@@ -17,6 +17,7 @@
#include "gif_sender.hpp" #include "gif_sender.hpp"
#include "vif_sender.hpp" #include "vif_sender.hpp"
#include "../models/math/plane.hpp" #include "../models/math/plane.hpp"
#include "../models/sprite.hpp"
#include "../models/screen_settings.hpp" #include "../models/screen_settings.hpp"
#include "../models/render_data.hpp" #include "../models/render_data.hpp"
#include "./texture_repository.hpp" #include "./texture_repository.hpp"
@@ -39,6 +40,8 @@ public:
/// --- Draw: PATH3 /// --- Draw: PATH3
void draw(Sprite &t_sprite);
/** /**
* Draw many meshes with lighting information. * Draw many meshes with lighting information.
* Slowest way of rendering (PATH 3, using EE and GIF). * Slowest way of rendering (PATH 3, using EE and GIF).
@@ -103,14 +106,12 @@ public:
TextureRepository *getTextureRepository() { return &textureRepo; }; TextureRepository *getTextureRepository() { return &textureRepo; };
void drawRectangle();
private: private:
void changeTexture(const Mesh &t_mesh, u32 t_materialId); void changeTexture(MeshTexture *t_tex);
u32 lastTextureId; u32 lastTextureId;
texbuffer_t textureBuffer; texbuffer_t textureBuffer;
u8 isTextureVRAMAllocated, isVSyncEnabled; u8 isTextureVRAMAllocated, isVSyncEnabled;
void allocateTextureBuffer(u16 t_width, u16 t_height); void allocateTextureBuffer(MeshTexture *t_texture);
void deallocateTextureBuffer(); void deallocateTextureBuffer();
void flipBuffers(); void flipBuffers();
void beginFrameIfNeeded(); void beginFrameIfNeeded();
@@ -17,6 +17,13 @@
#include "../models/mesh.hpp" #include "../models/mesh.hpp"
#include "../models/mesh_frame.hpp" #include "../models/mesh_frame.hpp"
#include "../loaders/bmp_loader.hpp" #include "../loaders/bmp_loader.hpp"
#include "../loaders/png_loader.hpp"
enum TextureFormat
{
BMP,
PNG
};
/** Class responsible for intializing draw env, textures and buffers */ /** Class responsible for intializing draw env, textures and buffers */
class TextureRepository class TextureRepository
@@ -35,6 +42,18 @@ public:
u32 getTexturesCount() const { return static_cast<u32>(textures.size()); }; u32 getTexturesCount() const { return static_cast<u32>(textures.size()); };
/**
* Returns single texture.
* NULL if not found.
*/
MeshTexture *getBySprite(const u32 &t_spriteId)
{
for (u32 i = 0; i < textures.size(); i++)
if (textures[i]->isLinkedWith(t_spriteId))
return textures[i];
return NULL;
}
/** /**
* Returns single texture. * Returns single texture.
* NULL if not found. * NULL if not found.
@@ -79,20 +98,22 @@ public:
// Other // Other
// ---- // ----
/** Add unlinked texture. /**
* NOTICE: BMP (RGB 888 24bit, without color information) is suppored only! * Add unlinked texture.
* @param t_subfolder Relative path. Ex.: "textures/" * @param t_subfolder Relative path. Ex.: "textures/"
* @param t_name Filename without extension. Ex.: "water" * @param t_name Filename without extension. Ex.: "water"
* * @param t_format if you want to use BMP, be sure that you have
* BMP with RGB 888 24bit, without color information.
*/ */
MeshTexture *add(char *t_subfolder, char *t_name); MeshTexture *add(char *t_subfolder, char *t_name, TextureFormat t_format);
/** /**
* Add linked textures in given subpath for mesh material names. * Add linked textures in given subpath for mesh material names.
* NOTICE: BMP (RGB 888 24bit, without color information) is suppored only! * @param t_path Relative path where textures should be searched.
* @param t_path Relative path where textures should be searched * @param t_format if you want to use BMP, be sure that you have
* BMP with RGB 888 24bit, without color information.
*/ */
void addByMesh(char *t_path, Mesh &mesh); void addByMesh(char *t_path, Mesh &mesh, TextureFormat t_format);
/** /**
* Remove texture from repository. * Remove texture from repository.
@@ -115,7 +136,8 @@ public:
private: private:
std::vector<MeshTexture *> textures; std::vector<MeshTexture *> textures;
BmpLoader loader; BmpLoader bmpLoader;
PngLoader pngLoader;
}; };
#endif #endif
+1 -3
View File
@@ -50,10 +50,8 @@ void BmpLoader::load(MeshTexture &o_texture, char *t_subfolder, char *t_name, ch
u32 width = (u32)header[18]; u32 width = (u32)header[18];
u32 height = (u32)header[22]; u32 height = (u32)header[22];
o_texture.setSize(width, height); o_texture.setSize(width, height, TEX_TYPE_RGB);
printf("BMPLoader - width: %d | height: %d\n", width, height); printf("BMPLoader - width: %d | height: %d\n", width, height);
if (width > 128 || height > 128)
PRINT_ERR("Given texture is big for PS2. Please strict to 128x128 max");
u64 rowPadded = (width * 3 + 3) & (~3); u64 rowPadded = (width * 3 + 3) & (~3);
+16
View File
@@ -9,6 +9,7 @@
*/ */
#include "../../include/models/math/point.hpp" #include "../../include/models/math/point.hpp"
#include "../../include/utils/math.hpp"
#include <stdio.h> #include <stdio.h>
@@ -55,6 +56,21 @@ void Point::set(const Point &v)
y = v.y; y = v.y;
} }
void Point::rotate(const float &t_angle, const float &t_x, const float &t_y)
{
float s = Math::sin(t_angle);
float c = Math::cos(t_angle);
x -= t_x;
y -= t_y;
float xnew = x * c - y * s;
float ynew = x * s + y * c;
x = xnew + t_x;
y = ynew + t_y;
}
const void Point::print() const const void Point::print() const
{ {
printf("Point(%f, %f)\n", x, y); printf("Point(%f, %f)\n", x, y);
+12 -1
View File
@@ -39,15 +39,18 @@ MeshTexture::~MeshTexture()
// Methods // Methods
// ---- // ----
void MeshTexture::setSize(const u8 &t_width, const u8 &t_height) void MeshTexture::setSize(const u8 &t_width, const u8 &t_height, const TextureType &t_type)
{ {
if (_isSizeSet) if (_isSizeSet)
{ {
PRINT_ERR("Can't set size, because was already set!"); PRINT_ERR("Can't set size, because was already set!");
return; return;
} }
if (t_width > 256 || t_height > 256)
PRINT_ERR("Given texture can be too big for PS2. Please strict to 256x256 max. Prefer 128x128.");
width = t_width; width = t_width;
height = t_height; height = t_height;
_type = t_type;
data = new unsigned char[getDataSize()]; data = new unsigned char[getDataSize()];
_isSizeSet = true; _isSizeSet = true;
} }
@@ -86,3 +89,11 @@ void MeshTexture::addLink(const u32 &t_meshId, const u32 &t_materialId)
link.meshId = t_meshId; link.meshId = t_meshId;
texLinks.push_back(link); texLinks.push_back(link);
} }
void MeshTexture::addLink(const u32 &t_spriteId)
{
TextureLink link;
link.materialId = 0;
link.meshId = t_spriteId;
texLinks.push_back(link);
}
+55
View File
@@ -0,0 +1,55 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2020, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#include "../include/models/sprite.hpp"
#include "../include/utils/debug.hpp"
#include "../include/utils/string.hpp"
#include <cstdlib>
// ----
// Constructors/Destructors
// ----
Sprite::Sprite()
{
id = rand() % 1000000;
_isSizeSet = false;
_flipH = false;
_flipV = false;
scale = 1.0F;
setDefaultColor();
setDefaultLODAndClut();
}
Sprite::~Sprite() {}
// ----
// Methods
// ----
/** Set's default object color + no transparency */
void Sprite::setDefaultColor()
{
color.r = 0x80;
color.g = 0x80;
color.b = 0x80;
color.a = 0x80;
color.q = 0.0F;
}
/** Sets texture level of details settings and CLUT settings */
void Sprite::setDefaultLODAndClut()
{
clut.storage_mode = CLUT_STORAGE_MODE1;
clut.start = 0;
clut.psm = 0;
clut.load_method = CLUT_NO_LOAD;
clut.address = 0;
}
+39 -37
View File
@@ -59,16 +59,16 @@ Renderer::~Renderer() {}
// ---- // ----
/** Configure and allocate vRAM for texture buffer */ /** Configure and allocate vRAM for texture buffer */
void Renderer::allocateTextureBuffer(u16 t_width, u16 t_height) void Renderer::allocateTextureBuffer(MeshTexture *t_texture)
{ {
textureBuffer.width = t_width; textureBuffer.width = t_texture->getWidth();
textureBuffer.psm = GS_PSM_24; textureBuffer.psm = t_texture->getType();
textureBuffer.address = graph_vram_allocate(t_width, t_height, GS_PSM_24, GRAPH_ALIGN_BLOCK); textureBuffer.info.components = textureBuffer.psm == TEX_TYPE_RGBA ? TEXTURE_COMPONENTS_RGBA : TEXTURE_COMPONENTS_RGB;
textureBuffer.address = graph_vram_allocate(t_texture->getWidth(), t_texture->getHeight(), textureBuffer.psm, GRAPH_ALIGN_BLOCK);
if (textureBuffer.address <= 1) if (textureBuffer.address <= 1)
PRINT_ERR("Texture buffer allocation error. No memory!"); PRINT_ERR("Texture buffer allocation error. No memory!");
textureBuffer.info.width = draw_log2(t_width); textureBuffer.info.width = draw_log2(t_texture->getWidth());
textureBuffer.info.height = draw_log2(t_height); textureBuffer.info.height = draw_log2(t_texture->getHeight());
textureBuffer.info.components = TEXTURE_COMPONENTS_RGB;
textureBuffer.info.function = TEXTURE_FUNCTION_MODULATE; textureBuffer.info.function = TEXTURE_FUNCTION_MODULATE;
isTextureVRAMAllocated = true; isTextureVRAMAllocated = true;
} }
@@ -83,47 +83,47 @@ void Renderer::deallocateTextureBuffer()
} }
} }
void Renderer::changeTexture(const Mesh &t_mesh, u32 t_materialId) void Renderer::changeTexture(MeshTexture *t_tex)
{ {
if (t_tex != NULL)
MeshTexture *tex = textureRepo.getByMesh(t_mesh.getId(), t_materialId);
if (tex != NULL)
{ {
if (tex->getId() != lastTextureId) if (t_tex->getId() != lastTextureId)
{ {
lastTextureId = tex->getId(); lastTextureId = t_tex->getId();
deallocateTextureBuffer(); deallocateTextureBuffer();
allocateTextureBuffer(tex->getWidth(), tex->getHeight()); allocateTextureBuffer(t_tex);
GifSender::sendTexture(*tex, &textureBuffer); GifSender::sendTexture(*t_tex, &textureBuffer);
} }
} }
else else
PRINT_ERR("Texture was not found in texture repository!"); PRINT_ERR("Texture was not found in texture repository!");
} }
void Renderer::drawRectangle() void Renderer::draw(Sprite &t_sprite)
{ {
texrect_t rect;
rect.t0.s = t_sprite.isFlippedHorizontally() ? 128.0F : 0.0F;
rect.t0.t = t_sprite.isFlippedVertically() ? 128.0F : 0.0F;
rect.t1.s = t_sprite.isFlippedHorizontally() ? 0.0F : 128.0F;
rect.t1.t = t_sprite.isFlippedVertically() ? 0.0F : 128.0F;
rect.color.r = t_sprite.color.r;
rect.color.g = t_sprite.color.g;
rect.color.b = t_sprite.color.b;
rect.color.a = t_sprite.color.a;
rect.color.q = 0;
rect.v0.x = t_sprite.position.x;
rect.v0.y = t_sprite.position.y;
rect.v0.z = (u32)-1;
rect.v1.x = (t_sprite.size.x * t_sprite.scale) + t_sprite.position.x;
rect.v1.y = (t_sprite.size.y * t_sprite.scale) + t_sprite.position.y;
rect.v1.z = (u32)-1;
beginFrameIfNeeded(); beginFrameIfNeeded();
packet2_t *packet2 = packet2_create(20, P2_TYPE_NORMAL, P2_MODE_NORMAL, 0); changeTexture(textureRepo.getBySprite(t_sprite.getId()));
packet2_t *packet2 = packet2_create(12, P2_TYPE_NORMAL, P2_MODE_NORMAL, 0);
packet2_update(packet2, draw_primitive_xyoffset(packet2->next, 0, 2048, 2048)); packet2_update(packet2, draw_primitive_xyoffset(packet2->next, 0, 2048, 2048));
packet2_utils_gif_add_set(packet2, 1);
int loop0 = 10; packet2_utils_gs_add_texbuff_clut(packet2, &textureBuffer, &t_sprite.clut);
packet2_update(packet2, draw_rect_textured(packet2->next, 0, &rect));
packet2_add_s64(packet2, GIF_SET_TAG(4, 0, 0, 0, GIF_FLG_PACKED, 1));
packet2_add_s64(packet2, GIF_REG_AD);
packet2_add_s64(packet2, GIF_SET_PRIM(6, 0, 0, 0, 0, 0, 0, 0, 0));
packet2_add_s64(packet2, GIF_REG_PRIM);
packet2_add_s64(packet2, GIF_SET_RGBAQ((loop0 * 10), 0, 255 - (loop0 * 10), 0x80, 0x3F800000));
packet2_add_s64(packet2, GIF_REG_RGBAQ);
packet2_add_s64(packet2, GIF_SET_XYZ(((loop0 * 20) << 4) + (2048 << 4), ((loop0 * 10) << 4) + (2048 << 4), -128));
packet2_add_s64(packet2, GIF_REG_XYZ2);
packet2_add_s64(packet2, GIF_SET_XYZ((((loop0 * 20) + 100) << 4) + (2048 << 4), (((loop0 * 10) + 100) << 4) + (2048 << 4), -128));
packet2_add_s64(packet2, GIF_REG_XYZ2);
packet2_update(packet2, packet2_update(packet2,
draw_primitive_xyoffset( draw_primitive_xyoffset(
packet2->next, packet2->next,
@@ -211,7 +211,8 @@ void Renderer::drawByPath3(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
{ {
if (t_mesh.shouldBeFrustumCulled && !t_mesh.getMaterial(i).isInFrustum(renderData.frustumPlanes, t_mesh.position)) if (t_mesh.shouldBeFrustumCulled && !t_mesh.getMaterial(i).isInFrustum(renderData.frustumPlanes, t_mesh.position))
return; return;
changeTexture(t_mesh, t_mesh.getMaterial(i).getId()); MeshTexture *tex = textureRepo.getByMesh(t_mesh.getId(), t_mesh.getMaterial(i).getId());
changeTexture(tex);
gifSender->initPacket(context); gifSender->initPacket(context);
u32 vertCount = t_mesh.getMaterial(i).getFacesCount(); u32 vertCount = t_mesh.getMaterial(i).getFacesCount();
VECTOR *vertices = new VECTOR[vertCount]; VECTOR *vertices = new VECTOR[vertCount];
@@ -258,7 +259,8 @@ void Renderer::draw(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
VECTOR __attribute__((aligned(16))) vertices[vertCount]; VECTOR __attribute__((aligned(16))) vertices[vertCount];
VECTOR __attribute__((aligned(16))) normals[vertCount]; VECTOR __attribute__((aligned(16))) normals[vertCount];
VECTOR __attribute__((aligned(16))) coordinates[vertCount]; VECTOR __attribute__((aligned(16))) coordinates[vertCount];
changeTexture(t_mesh, t_mesh.getMaterial(i).getId()); MeshTexture *tex = textureRepo.getByMesh(t_mesh.getId(), t_mesh.getMaterial(i).getId());
changeTexture(tex);
vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, rotatedCamera); vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, rotatedCamera);
vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer); vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer);
} }
+10 -4
View File
@@ -35,21 +35,27 @@ TextureRepository::~TextureRepository()
// Methods // Methods
// ---- // ----
MeshTexture *TextureRepository::add(char *t_subfolder, char *t_name) MeshTexture *TextureRepository::add(char *t_subfolder, char *t_name, TextureFormat t_format)
{ {
MeshTexture *texture = new MeshTexture(); MeshTexture *texture = new MeshTexture();
loader.load(*texture, t_subfolder, t_name, ".bmp"); if (t_format == BMP)
bmpLoader.load(*texture, t_subfolder, t_name, ".bmp");
else
pngLoader.load(*texture, t_subfolder, t_name, ".png");
texture->setName(t_name); texture->setName(t_name);
textures.push_back(texture); textures.push_back(texture);
return texture; return texture;
} }
void TextureRepository::addByMesh(char *t_path, Mesh &mesh) void TextureRepository::addByMesh(char *t_path, Mesh &mesh, TextureFormat t_format)
{ {
for (u32 i = 0; i < mesh.getMaterialsCount(); i++) for (u32 i = 0; i < mesh.getMaterialsCount(); i++)
{ {
MeshTexture *texture = new MeshTexture(); MeshTexture *texture = new MeshTexture();
loader.load(*texture, t_path, mesh.getMaterial(i).getName(), ".bmp"); if (t_format == BMP)
bmpLoader.load(*texture, t_path, mesh.getMaterial(i).getName(), ".bmp");
else
pngLoader.load(*texture, t_path, mesh.getMaterial(i).getName(), ".png");
texture->setName(mesh.getMaterial(i).getName()); texture->setName(mesh.getMaterial(i).getName());
texture->addLink(mesh.getId(), mesh.getMaterial(i).getId()); texture->addLink(mesh.getId(), mesh.getMaterial(i).getId());
textures.push_back(texture); textures.push_back(texture);
+7 -2
View File
@@ -8,6 +8,7 @@ EE_OBJS = \
../../engine/models/mesh_frame.o \ ../../engine/models/mesh_frame.o \
../../engine/models/mesh_material.o \ ../../engine/models/mesh_material.o \
../../engine/models/mesh.o \ ../../engine/models/mesh.o \
../../engine/models/sprite.o \
../../engine/models/mesh_texture.o \ ../../engine/models/mesh_texture.o \
../../engine/modules/audio.o \ ../../engine/modules/audio.o \
../../engine/modules/camera_base.o \ ../../engine/modules/camera_base.o \
@@ -25,6 +26,7 @@ EE_OBJS = \
../../engine/loaders/dff_loader.o \ ../../engine/loaders/dff_loader.o \
../../engine/loaders/md2_loader.o \ ../../engine/loaders/md2_loader.o \
../../engine/loaders/obj_loader.o \ ../../engine/loaders/obj_loader.o \
../../engine/loaders/png_loader.o \
../../engine/vu1_progs/draw3D.o \ ../../engine/vu1_progs/draw3D.o \
../../engine/engine.o \ ../../engine/engine.o \
camera.o \ camera.o \
@@ -32,8 +34,11 @@ EE_OBJS = \
ari.o \ ari.o \
main.o main.o
EE_LIBS = -ldraw -lgraph -lmath3d -lpacket -ldma -lpacket2 -lpad -laudsrv -lc -lstdc++ EE_LIBS = -ldraw -lgraph -lmath3d -lpacket -ldma -lpacket2 -lpad -laudsrv -lc -lstdc++ -lpng -lz
EE_INCS := -I./../../engine/include $(EE_INCS) EE_INCS := -I./../../engine/include -I$(PS2SDK)/ports/include $(EE_INCS)
EE_LDFLAGS := -L$(PS2SDK)/ports/lib $(EE_LDFLAGS)
EE_CFLAGS := -DHAVE_LIBPNG -DHAVE_ZLIB $(EE_CFLAGS)
EE_CXXFLAGS := -DHAVE_LIBPNG -DHAVE_ZLIB $(EE_CXXFLAGS)
EE_DVP = dvp-as EE_DVP = dvp-as
EE_VCL = vcl EE_VCL = vcl
+11 -7
View File
@@ -48,6 +48,10 @@ void Ari::onInit()
island.shouldBeBackfaceCulled = true; island.shouldBeBackfaceCulled = true;
island.shouldBeFrustumCulled = false; island.shouldBeFrustumCulled = false;
fist.size.set(100.0F, 100.0F);
MeshTexture *fistTex = texRepo->add("2d/", "fist", PNG);
fistTex->addLink(fist.getId());
islandAddons.loadDff("sunnyisl/", "sunnyisl3", 0.1F, false); islandAddons.loadDff("sunnyisl/", "sunnyisl3", 0.1F, false);
islandAddons.shouldBeBackfaceCulled = true; islandAddons.shouldBeBackfaceCulled = true;
islandAddons.rotation.x = -1.6F; islandAddons.rotation.x = -1.6F;
@@ -58,7 +62,7 @@ void Ari::onInit()
waterFloors[0].loadObj("water/", "water", 5.0F, false); waterFloors[0].loadObj("water/", "water", 5.0F, false);
waterFloors[0].position.set(0.0F, 8.0F, 0.0F); waterFloors[0].position.set(0.0F, 8.0F, 0.0F);
texRepo->addByMesh("water/", waterFloors[0]); texRepo->addByMesh("water/", waterFloors[0], BMP);
for (u8 i = 0; i < WATER_TILES_COUNT; i++) for (u8 i = 0; i < WATER_TILES_COUNT; i++)
{ {
spirals[i].x = 1.0F; spirals[i].x = 1.0F;
@@ -74,11 +78,11 @@ void Ari::onInit()
->addLink(waterFloors[i].getId(), waterFloors[i].getMaterial(0).getId()); ->addLink(waterFloors[i].getId(), waterFloors[i].getMaterial(0).getId());
} }
texRepo->addByMesh("sunnyisl/", island); texRepo->addByMesh("sunnyisl/", island, BMP);
texRepo->addByMesh("sunnyisl/", islandAddons); texRepo->addByMesh("sunnyisl/", islandAddons, BMP);
texRepo->addByMesh("skybox/", skybox); texRepo->addByMesh("skybox/", skybox, BMP);
texRepo->addByMesh("ari/", player.mesh); texRepo->addByMesh("ari/", player.mesh, BMP);
engine->audio.playSong(); // engine->audio.playSong();
} }
void Ari::initBulb() void Ari::initBulb()
@@ -98,8 +102,8 @@ void Ari::onUpdate()
if (engine->pad.isCircleClicked) if (engine->pad.isCircleClicked)
engine->audio.playADPCM(adpcm2); engine->audio.playADPCM(adpcm2);
camera.update(engine->pad, player.mesh); camera.update(engine->pad, player.mesh);
engine->renderer->drawRectangle();
engine->renderer->draw(skybox); engine->renderer->draw(skybox);
engine->renderer->draw(fist);
engine->renderer->draw(island); engine->renderer->draw(island);
engine->renderer->draw(islandAddons); engine->renderer->draw(islandAddons);
engine->renderer->draw(player.mesh); engine->renderer->draw(player.mesh);
+2
View File
@@ -17,6 +17,7 @@
#include <engine.hpp> #include <engine.hpp>
#include "objects/player.hpp" #include "objects/player.hpp"
#include <models/light_bulb.hpp> #include <models/light_bulb.hpp>
#include <models/sprite.hpp>
#include <modules/texture_repository.hpp> #include <modules/texture_repository.hpp>
#include "./camera.hpp" #include "./camera.hpp"
@@ -39,6 +40,7 @@ private:
Player player; Player player;
Mesh island, islandAddons, skybox; Mesh island, islandAddons, skybox;
Mesh *waterFloors; Mesh *waterFloors;
Sprite fist;
audsrv_adpcm_t *adpcm1, *adpcm2; audsrv_adpcm_t *adpcm1, *adpcm2;
Point *spirals; Point *spirals;
Camera camera; Camera camera;
+9 -3
View File
@@ -8,6 +8,7 @@ EE_OBJS = \
../../engine/models/mesh_frame.o \ ../../engine/models/mesh_frame.o \
../../engine/models/mesh_material.o \ ../../engine/models/mesh_material.o \
../../engine/models/mesh.o \ ../../engine/models/mesh.o \
../../engine/models/sprite.o \
../../engine/models/mesh_texture.o \ ../../engine/models/mesh_texture.o \
../../engine/modules/audio.o \ ../../engine/modules/audio.o \
../../engine/modules/camera_base.o \ ../../engine/modules/camera_base.o \
@@ -25,6 +26,7 @@ EE_OBJS = \
../../engine/loaders/dff_loader.o \ ../../engine/loaders/dff_loader.o \
../../engine/loaders/md2_loader.o \ ../../engine/loaders/md2_loader.o \
../../engine/loaders/obj_loader.o \ ../../engine/loaders/obj_loader.o \
../../engine/loaders/png_loader.o \
../../engine/vu1_progs/draw3D.o \ ../../engine/vu1_progs/draw3D.o \
../../engine/engine.o \ ../../engine/engine.o \
managers/light_manager.o \ managers/light_manager.o \
@@ -36,10 +38,14 @@ EE_OBJS = \
floors.o \ floors.o \
main.o main.o
EE_LIBS = -ldraw -lgraph -lmath3d -lpacket -ldma -lpad -lpacket2 -laudsrv -lc -lstdc++ EE_LIBS = -ldraw -lgraph -lmath3d -lpacket -ldma -lpacket2 -lpad -laudsrv -lc -lstdc++ -lpng -lz
EE_INCS := -I./../../engine/include $(EE_INCS) EE_INCS := -I./../../engine/include -I$(PS2SDK)/ports/include $(EE_INCS)
EE_LDFLAGS := -L$(PS2SDK)/ports/lib $(EE_LDFLAGS)
EE_CFLAGS := -DHAVE_LIBPNG -DHAVE_ZLIB $(EE_CFLAGS)
EE_CXXFLAGS := -DHAVE_LIBPNG -DHAVE_ZLIB $(EE_CXXFLAGS)
EE_DVP = dvp-as EE_DVP = dvp-as
EE_VCL = openvcl EE_VCL = vcl
all: $(EE_BIN) all: $(EE_BIN)
$(EE_STRIP) --strip-all $(EE_BIN) $(EE_STRIP) --strip-all $(EE_BIN)