More render tests
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
display.c
|
display.c
|
||||||
|
screen.c
|
||||||
)
|
)
|
||||||
|
|
||||||
dusk_run_python(
|
dusk_run_python(
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "display/screen.h"
|
||||||
|
|
||||||
|
screen_t SCREEN = { 0 };
|
||||||
@@ -8,5 +8,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "dusk.h"
|
#include "dusk.h"
|
||||||
|
|
||||||
#define SCREEN_WIDTH ((int32_t)DUSK_DISPLAY_WIDTH)
|
typedef struct {
|
||||||
#define SCREEN_HEIGHT ((int32_t)DUSK_DISPLAY_HEIGHT)
|
int32_t width;
|
||||||
|
int32_t height;
|
||||||
|
} screen_t;
|
||||||
|
|
||||||
|
extern screen_t SCREEN;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
|
|||||||
errorChain(sceneInit());
|
errorChain(sceneInit());
|
||||||
|
|
||||||
consolePrint("Engine initialized");
|
consolePrint("Engine initialized");
|
||||||
sceneSet(SCENE_TYPE_FULL);
|
sceneSet(SCENE_TYPE_SPINNINGBOX);
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
|||||||
add_subdirectory(full)
|
add_subdirectory(full)
|
||||||
add_subdirectory(overworld)
|
add_subdirectory(overworld)
|
||||||
add_subdirectory(rainbownothing)
|
add_subdirectory(rainbownothing)
|
||||||
|
add_subdirectory(spinningbox)
|
||||||
add_subdirectory(white32)
|
add_subdirectory(white32)
|
||||||
@@ -41,53 +41,49 @@ static color_t hueColor(float_t t) {
|
|||||||
|
|
||||||
static rtexture_t testTex;
|
static rtexture_t testTex;
|
||||||
|
|
||||||
#define ASPECT FIXED((float_t)SCREEN_WIDTH / (float_t)SCREEN_HEIGHT)
|
#define ASPECT FIXED((float_t)SCREEN.width / (float_t)SCREEN.height)
|
||||||
#define FOV_Y FIXED(1.0472f)
|
#define FOV_Y FIXED(1.0472f)
|
||||||
|
|
||||||
#define TILEMAP_TILE_W 16
|
#define TILEMAP_TILE_W 16
|
||||||
#define TILEMAP_TILE_H 16
|
#define TILEMAP_TILE_H 16
|
||||||
/* Array-size macros use raw DUSK_DISPLAY_* (no cast) so they remain integer
|
#define TILEMAP_Y (SCREEN.height - 10)
|
||||||
* constant expressions valid for stack array declarations. */
|
#define TILEMAP_SCROLL_SPEED 20.0f
|
||||||
#define TILEMAP_CHUNK_W (DUSK_DISPLAY_WIDTH / TILEMAP_TILE_W + 4)
|
#define TILEMAP_SCROLL_RANGE 32.0f
|
||||||
#define TILEMAP_CHUNK_H (DUSK_DISPLAY_HEIGHT / TILEMAP_TILE_H + 1)
|
|
||||||
#define TILEMAP_Y (SCREEN_HEIGHT - 10)
|
|
||||||
#define TILEMAP_SCROLL_SPEED 40.0f
|
|
||||||
#define TILEMAP_SCROLL_RANGE 64.0f
|
|
||||||
|
|
||||||
static rtexture_t tilemapTileset;
|
static rtexture_t tilemapTileset;
|
||||||
static rtilemapchunk_t tilemapChunk;
|
static rtilemapchunk_t tilemapChunk;
|
||||||
|
|
||||||
static void renderTest2DQuad(void) {
|
static void renderTest2DQuad(void) {
|
||||||
renderSprite(50, 30, 192, 160, 0, testTex, COLOR_WHITE);
|
renderSprite(25, 15, 96, 80, 0, testTex, COLOR_WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void renderTest2DZOrder(void) {
|
static void renderTest2DZOrder(void) {
|
||||||
renderSprite(340, 30, 160, 160, 24000, testTex, color(100, 100, 220, 255));
|
renderSprite(170, 15, 80, 80, 12000, testTex, color(100, 100, 220, 255));
|
||||||
renderSprite(380, 60, 160, 160, 12000, testTex, color(220, 140, 60, 255));
|
renderSprite(190, 30, 80, 80, 6000, testTex, color(220, 140, 60, 255));
|
||||||
renderSprite(420, 90, 160, 160, 0, testTex, COLOR_WHITE);
|
renderSprite(210, 45, 80, 80, 0, testTex, COLOR_WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void renderTest3DQuad(void) {
|
static void renderTest3DQuad(void) {
|
||||||
float_t angle = fixedToFloat(TIME.time);
|
float_t angle = fixedToFloat(TIME.time);
|
||||||
renderQuad3D(
|
renderQuad3D(
|
||||||
-180, 0, 0,
|
-45, 0, 0,
|
||||||
(int16_t)(cosf(angle) * 60.0f), 0, (int16_t)(sinf(angle) * 60.0f),
|
(int16_t)(cosf(angle) * 30.0f), 0, (int16_t)(sinf(angle) * 30.0f),
|
||||||
0, 60, 0,
|
0, 30, 0,
|
||||||
0, testTex, COLOR_WHITE
|
0, testTex, COLOR_WHITE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void renderTest3DOverlap(void) {
|
static void renderTest3DOverlap(void) {
|
||||||
renderQuad3D(
|
renderQuad3D(
|
||||||
150, 0, -60,
|
40, 0, -30,
|
||||||
60, 0, 0,
|
30, 0, 0,
|
||||||
0, 60, 0,
|
0, 30, 0,
|
||||||
0, testTex, color(100, 100, 220, 255)
|
0, testTex, color(100, 100, 220, 255)
|
||||||
);
|
);
|
||||||
renderQuad3D(
|
renderQuad3D(
|
||||||
190, 0, 60,
|
50, 0, 30,
|
||||||
60, 0, 0,
|
30, 0, 0,
|
||||||
0, 60, 0,
|
0, 30, 0,
|
||||||
0, testTex, COLOR_WHITE
|
0, testTex, COLOR_WHITE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -114,16 +110,20 @@ errorret_t sceneFullInit(scenedata_t *data) {
|
|||||||
tilemapTileset = renderTextureCreate(32, 16, tsIdx, tsPal);
|
tilemapTileset = renderTextureCreate(32, 16, tsIdx, tsPal);
|
||||||
assertTrue(tilemapTileset != RTEXTURE_NONE, "Failed to create tilemap tileset");
|
assertTrue(tilemapTileset != RTEXTURE_NONE, "Failed to create tilemap tileset");
|
||||||
|
|
||||||
uint8_t chunkIdx[TILEMAP_CHUNK_W * TILEMAP_CHUNK_H];
|
int32_t chunkW = SCREEN.width / TILEMAP_TILE_W + 4;
|
||||||
for(int row = 0; row < TILEMAP_CHUNK_H; row++)
|
int32_t chunkH = SCREEN.height / TILEMAP_TILE_H + 1;
|
||||||
for(int col = 0; col < TILEMAP_CHUNK_W; col++)
|
uint8_t *chunkIdx = (uint8_t *)memoryAllocate((uint32_t)(chunkW * chunkH));
|
||||||
chunkIdx[row * TILEMAP_CHUNK_W + col] = (uint8_t)((col + row) % 2);
|
assertNotNull(chunkIdx, "Failed to allocate tilemap chunk indices");
|
||||||
|
for(int32_t row = 0; row < chunkH; row++)
|
||||||
|
for(int32_t col = 0; col < chunkW; col++)
|
||||||
|
chunkIdx[row * chunkW + col] = (uint8_t)((col + row) % 2);
|
||||||
tilemapChunk = renderTilemapChunkCreate(
|
tilemapChunk = renderTilemapChunkCreate(
|
||||||
TILEMAP_CHUNK_W, TILEMAP_CHUNK_H,
|
(uint16_t)chunkW, (uint16_t)chunkH,
|
||||||
TILEMAP_TILE_W, TILEMAP_TILE_H,
|
TILEMAP_TILE_W, TILEMAP_TILE_H,
|
||||||
tilemapTileset,
|
tilemapTileset,
|
||||||
chunkIdx
|
chunkIdx
|
||||||
);
|
);
|
||||||
|
memoryFree(chunkIdx);
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,7 @@ errorret_t sceneFullRender(scenedata_t *data) {
|
|||||||
renderTest2DZOrder();
|
renderTest2DZOrder();
|
||||||
|
|
||||||
renderSetProjection(FOV_Y, ASPECT, FIXED(10), FIXED(10000));
|
renderSetProjection(FOV_Y, ASPECT, FIXED(10), FIXED(10000));
|
||||||
renderSetView(0, 150, 400, 0, 0, 0);
|
renderSetView(0, 75, 200, 0, 0, 0);
|
||||||
renderTest3DQuad();
|
renderTest3DQuad();
|
||||||
renderTest3DOverlap();
|
renderTest3DOverlap();
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,13 @@ scenecallbacks_t SCENE_TYPES[SCENE_TYPE_COUNT] = {
|
|||||||
.dispose = sceneRainbowNothingDispose
|
.dispose = sceneRainbowNothingDispose
|
||||||
},
|
},
|
||||||
|
|
||||||
|
[SCENE_TYPE_SPINNINGBOX] = {
|
||||||
|
.init = sceneSpinningBoxInit,
|
||||||
|
.update = sceneSpinningBoxUpdate,
|
||||||
|
.render = sceneSpinningBoxRender,
|
||||||
|
.dispose = sceneSpinningBoxDispose
|
||||||
|
},
|
||||||
|
|
||||||
[SCENE_TYPE_WHITE32] = {
|
[SCENE_TYPE_WHITE32] = {
|
||||||
.init = sceneWhite32Init,
|
.init = sceneWhite32Init,
|
||||||
.update = sceneWhite32Update,
|
.update = sceneWhite32Update,
|
||||||
|
|||||||
@@ -10,12 +10,14 @@
|
|||||||
#include "scene/full/scenefull.h"
|
#include "scene/full/scenefull.h"
|
||||||
#include "scene/overworld/sceneoverworld.h"
|
#include "scene/overworld/sceneoverworld.h"
|
||||||
#include "scene/rainbownothing/scenerainbownothing.h"
|
#include "scene/rainbownothing/scenerainbownothing.h"
|
||||||
|
#include "scene/spinningbox/scenespinningbox.h"
|
||||||
#include "scene/white32/scenewhite32.h"
|
#include "scene/white32/scenewhite32.h"
|
||||||
|
|
||||||
typedef union scenedata_u {
|
typedef union scenedata_u {
|
||||||
scenefull_t full;
|
scenefull_t full;
|
||||||
sceneoverworld_t overworld;
|
sceneoverworld_t overworld;
|
||||||
scenerainbownothing_t rainbownothing;
|
scenerainbownothing_t rainbownothing;
|
||||||
|
scenespinningbox_t spinningbox;
|
||||||
scenewhite32_t white32;
|
scenewhite32_t white32;
|
||||||
} scenedata_t;
|
} scenedata_t;
|
||||||
|
|
||||||
@@ -33,6 +35,7 @@ typedef enum {
|
|||||||
SCENE_TYPE_FULL,
|
SCENE_TYPE_FULL,
|
||||||
SCENE_TYPE_OVERWORLD,
|
SCENE_TYPE_OVERWORLD,
|
||||||
SCENE_TYPE_RAINBOWNOTHING,
|
SCENE_TYPE_RAINBOWNOTHING,
|
||||||
|
SCENE_TYPE_SPINNINGBOX,
|
||||||
SCENE_TYPE_WHITE32,
|
SCENE_TYPE_WHITE32,
|
||||||
SCENE_TYPE_COUNT
|
SCENE_TYPE_COUNT
|
||||||
} scenetype_t;
|
} scenetype_t;
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Copyright (c) 2026 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||||
|
PUBLIC
|
||||||
|
scenespinningbox.c
|
||||||
|
)
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "scene/spinningbox/scenespinningbox.h"
|
||||||
|
#include "assert/assert.h"
|
||||||
|
#include "display/render/render.h"
|
||||||
|
#include "display/screen.h"
|
||||||
|
#include "display/color.h"
|
||||||
|
#include "time/time.h"
|
||||||
|
#include "util/fixed.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static const uint8_t BOX_INDICES[3 * 3] = {
|
||||||
|
0, 1, 2,
|
||||||
|
3, 4, 5,
|
||||||
|
6, 7, 8,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const color_t BOX_PALETTE[256] = {
|
||||||
|
[0] = { 255, 0, 0, 255 },
|
||||||
|
[1] = { 0, 255, 0, 255 },
|
||||||
|
[2] = { 0, 0, 255, 255 },
|
||||||
|
[3] = { 255, 255, 0, 255 },
|
||||||
|
[4] = { 255, 0, 255, 255 },
|
||||||
|
[5] = { 0, 255, 255, 255 },
|
||||||
|
[6] = { 255, 165, 0, 255 },
|
||||||
|
[7] = { 128, 0, 255, 255 },
|
||||||
|
[8] = { 255, 255, 255, 255 },
|
||||||
|
};
|
||||||
|
|
||||||
|
static rtexture_t spinTex;
|
||||||
|
|
||||||
|
#define ASPECT FIXED((float_t)SCREEN.width / (float_t)SCREEN.height)
|
||||||
|
#define FOV_Y FIXED(1.0472f)
|
||||||
|
|
||||||
|
errorret_t sceneSpinningBoxInit(scenedata_t *data) {
|
||||||
|
spinTex = renderTextureCreate(3, 3, BOX_INDICES, BOX_PALETTE);
|
||||||
|
assertTrue(spinTex != RTEXTURE_NONE, "Failed to create spinningbox texture");
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t sceneSpinningBoxUpdate(scenedata_t *data) {
|
||||||
|
color_t *pal = renderTextureGetPalette(spinTex);
|
||||||
|
int32_t idx = rand() % 9;
|
||||||
|
pal[idx] = color(
|
||||||
|
(uint8_t)(rand() % 256),
|
||||||
|
(uint8_t)(rand() % 256),
|
||||||
|
(uint8_t)(rand() % 256),
|
||||||
|
255
|
||||||
|
);
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t sceneSpinningBoxRender(scenedata_t *data) {
|
||||||
|
renderClear(color(16, 16, 24, 255));
|
||||||
|
|
||||||
|
renderSetProjection(FOV_Y, ASPECT, FIXED(10), FIXED(10000));
|
||||||
|
renderSetView(0, 0, 150, 0, 0, 0);
|
||||||
|
|
||||||
|
float_t angle = fixedToFloat(TIME.time);
|
||||||
|
renderQuad3D(
|
||||||
|
0, 0, 0,
|
||||||
|
(int16_t)(cosf(angle) * 40.0f), 0, (int16_t)(sinf(angle) * 40.0f),
|
||||||
|
0, 40, 0,
|
||||||
|
0, spinTex, COLOR_WHITE
|
||||||
|
);
|
||||||
|
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t sceneSpinningBoxDispose(scenedata_t *data) {
|
||||||
|
renderTextureDispose(spinTex);
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "scene/scenebase.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t _unused;
|
||||||
|
} scenespinningbox_t;
|
||||||
|
|
||||||
|
errorret_t sceneSpinningBoxInit(scenedata_t *data);
|
||||||
|
errorret_t sceneSpinningBoxUpdate(scenedata_t *data);
|
||||||
|
errorret_t sceneSpinningBoxRender(scenedata_t *data);
|
||||||
|
errorret_t sceneSpinningBoxDispose(scenedata_t *data);
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "display/displaypsp.h"
|
#include "display/displaypsp.h"
|
||||||
#include "display/render/renderpsp.h"
|
#include "display/render/renderpsp.h"
|
||||||
#include "display/display.h"
|
#include "display/display.h"
|
||||||
|
#include "display/screen.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include <pspgu.h>
|
#include <pspgu.h>
|
||||||
#include <pspgum.h>
|
#include <pspgum.h>
|
||||||
@@ -26,6 +27,8 @@ static uint32_t __attribute__((aligned(64))) displayList[0x10000];
|
|||||||
|
|
||||||
errorret_t displayPSPInit(void) {
|
errorret_t displayPSPInit(void) {
|
||||||
DISPLAY.whichBuffer = 0;
|
DISPLAY.whichBuffer = 0;
|
||||||
|
SCREEN.width = PSP_SCREEN_W;
|
||||||
|
SCREEN.height = PSP_SCREEN_H;
|
||||||
|
|
||||||
sceGuInit();
|
sceGuInit();
|
||||||
sceGuStart(GU_DIRECT, displayList);
|
sceGuStart(GU_DIRECT, displayList);
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ static void draw3DQuad(const ropquad3d_t *q) {
|
|||||||
verts[4] = (GuVert3D){u1,v1, abgr, brx,bry,brz};
|
verts[4] = (GuVert3D){u1,v1, abgr, brx,bry,brz};
|
||||||
verts[5] = (GuVert3D){u1,v0, abgr, trx,try_,trz};
|
verts[5] = (GuVert3D){u1,v0, abgr, trx,try_,trz};
|
||||||
|
|
||||||
sceGuDrawArray(
|
sceGumDrawArray(
|
||||||
GU_TRIANGLES,
|
GU_TRIANGLES,
|
||||||
GU_TEXTURE_32BITF | GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_3D,
|
GU_TEXTURE_32BITF | GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_3D,
|
||||||
6, 0, verts
|
6, 0, verts
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "display/display.h"
|
#include "display/display.h"
|
||||||
|
#include "display/screen.h"
|
||||||
#include "engine/engine.h"
|
#include "engine/engine.h"
|
||||||
#include "display/render/rendergl.h"
|
#include "display/render/rendergl.h"
|
||||||
#include "error/errorgl.h"
|
#include "error/errorgl.h"
|
||||||
@@ -57,6 +58,8 @@ errorret_t displaySDL2Flush(ropbuffer_t *buf) {
|
|||||||
|
|
||||||
int w, h;
|
int w, h;
|
||||||
SDL_GetWindowSize(DISPLAY.window, &w, &h);
|
SDL_GetWindowSize(DISPLAY.window, &w, &h);
|
||||||
|
SCREEN.width = (int32_t)w;
|
||||||
|
SCREEN.height = (int32_t)h;
|
||||||
errorChain(renderGLFlush(buf, w, h));
|
errorChain(renderGLFlush(buf, w, h));
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user