Skip to content

Commit

Permalink
3ds: fix stupid texture error, test: add scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Cpasjuste committed Oct 25, 2018
1 parent 7497e08 commit b3ad886
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ target_compile_options(${PROJECT_NAME} PUBLIC ${FLAGS} -Wno-narrowing)
#####################
# test executable
#####################
set(PROJECT_AUTHOR "Cpasjuste")
set(VERSION_MAJOR "1")
set(VERSION_MINOR "0")
# ps vita
set(TITLE_ID "CROSS0001")
add_executable(${PROJECT_NAME}.elf test/main.cpp)
target_link_libraries(${PROJECT_NAME}.elf cross2d)

Expand Down
3 changes: 0 additions & 3 deletions Targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ if (BUILD_SWITCH)
add_custom_target(${PROJECT_NAME}_switch_release.zip
DEPENDS ${PROJECT_NAME}.nro
COMMAND rm -rf ${CMAKE_BINARY_DIR}/release/${PROJECT_NAME}
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/release/${PROJECT_NAME}/data
COMMAND cp -f ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.nro ${CMAKE_BINARY_DIR}/release/${PROJECT_NAME}/
COMMAND cd ${CMAKE_BINARY_DIR}/release && zip -r ../${PROJECT_NAME}-${VERSION_MAJOR}.${VERSION_MINOR}_switch.zip ${PROJECT_NAME}
COMMAND cd ${CMAKE_CURRENT_BINARY_DIR})
Expand All @@ -66,9 +65,7 @@ if (BUILD_3DS)
add_custom_target(${PROJECT_NAME}_3ds_release.zip
DEPENDS ${PROJECT_NAME}.3dsx
COMMAND rm -rf ${CMAKE_BINARY_DIR}/release/${PROJECT_NAME}
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/release/${PROJECT_NAME}/data
COMMAND cp -f ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.3dsx ${CMAKE_BINARY_DIR}/release/${PROJECT_NAME}/
COMMAND cp -r ${CMAKE_CURRENT_SOURCE_DIR}/data/common/* ${CMAKE_BINARY_DIR}/release/${PROJECT_NAME}/data
COMMAND cd ${CMAKE_BINARY_DIR}/release && zip -r ../${PROJECT_NAME}-${VERSION_MAJOR}.${VERSION_MINOR}_3ds.zip ${PROJECT_NAME}
COMMAND cd ${CMAKE_CURRENT_BINARY_DIR})
endif (BUILD_3DS)
4 changes: 2 additions & 2 deletions source/platforms/3ds/ctr_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ CTRTexture::CTRTexture(const std::string &path) : Texture(path) {
int src_pitch = img_w * bpp;
for (int i = 0; i < img_h; i++) {
memcpy(dst, src, (size_t) img_w * bpp);
dst += dst_pitch * bpp;
dst += dst_pitch;
src += src_pitch;
}
free(img);
Expand Down Expand Up @@ -181,7 +181,7 @@ void CTRTexture::uploadSoft() {

if (pixels) {
// TODO: add RGB565 support
int i, j, w = (int) getSize().x, h = (int) getSize().y;
int i, j, w = getTextureRect().width, h = getTextureRect().height;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
u32 coarse_y = static_cast<u32>(j & ~7);
Expand Down
21 changes: 13 additions & 8 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ using namespace c2d;
int main(int argc, char **argv) {

// create main renderer
auto *renderer = new C2DRenderer(Vector2f(1280, 720));
auto *renderer = new C2DRenderer(Vector2f(C2D_SCREEN_WIDTH, C2D_SCREEN_HEIGHT));
renderer->setClearColor(Color::Black);

// scale font and texture for different resolution (devices),
// based on 720p resolution
float scaling = renderer->getSize().y / 720.0f;

// create a rect
auto *rect = new C2DRectangle(
{renderer->getSize().x / 2, renderer->getSize().y / 2,
Expand All @@ -20,31 +24,32 @@ int main(int argc, char **argv) {
rect->setOrigin(Origin::Center);
rect->setFillColor(Color::Gray);
rect->setOutlineColor(Color::Orange);
rect->setOutlineThickness(8);
rect->setOutlineThickness(8 * scaling);

// create a texture and add it to the rect
auto *tex = new C2DTexture(renderer->getIo()->getDataPath() + "gbatemp.png");
if (tex->available) {
tex->setPosition(rect->getSize().x / 2, rect->getSize().y / 2);
tex->setScale(0.5f, 0.5f);
//tex->setScale(0.5f * scaling, 0.5f * scaling);
tex->setOrigin(Origin::Center);
rect->add(tex);
}

// create a font
auto *text = new C2DText("cross2d");
auto *text = new C2DText("libcross2d @ Cpasjuste");
text->setOutlineThickness(2);
text->setPosition(rect->getSize().x / 2, 32);
text->setOrigin(Origin::Center);
text->setPosition(rect->getSize().x - 16 * scaling, rect->getSize().y - 16 * scaling);
text->setOrigin(Origin::BottomRight);
text->setScale(scaling, scaling);
rect->add(text);

// add all this crap to the renderer
renderer->add(rect);

// add some tweening :)
auto *tweenPos = new TweenPosition(
{renderer->getSize().x / 2 - 256, rect->getPosition().y},
{renderer->getSize().x / 2 + 256, rect->getPosition().y},
{renderer->getSize().x / 2 - (256 * scaling), rect->getPosition().y},
{renderer->getSize().x / 2 + (256 * scaling), rect->getPosition().y},
4.0f, TweenLoop::PingPong);
rect->add(tweenPos);
auto *tweenRot = new TweenRotation(0, 360, 5.0f, TweenLoop::PingPong);
Expand Down

0 comments on commit b3ad886

Please sign in to comment.