Fixed dolphin rendering.

This commit is contained in:
2026-03-29 18:42:59 -05:00
parent 6d7fbd3926
commit ef5febdde3
6 changed files with 81 additions and 9 deletions

View File

@@ -195,13 +195,16 @@ function sceneRender()
view = cameraGetViewMatrix(camera)
shaderSetMatrix(SHADER_UNLIT, SHADER_UNLIT_VIEW, view)
-- textDraw(10, 10, "Hello World\nHow are you?")
shaderSetTexture(SHADER_UNLIT, SHADER_UNLIT_TEXTURE, nil)
spriteBatchPush(
x, y,
x + 32, y + 32,
colorWhite()
)
spriteBatchFlush()
textDraw(10, 10, "Hello World\nHow are you?", colorRed())
spriteBatchFlush()
-- Update mouse position
-- if INPUT_POINTER then
@@ -258,5 +261,4 @@ function sceneRender()
-- )
-- end
-- end
spriteBatchFlush()
end

View File

@@ -37,7 +37,7 @@ void cameraInitOrthographic(camera_t *camera) {
camera->orthographic.right = SCREEN.width;
camera->orthographic.top = 0.0f;
camera->orthographic.bottom = SCREEN.height;
camera->nearClip = -1.0f;
camera->nearClip = 0.1f;
camera->farClip = 1.0f;
camera->viewType = CAMERA_VIEW_TYPE_2D;

View File

@@ -23,6 +23,24 @@
#include "script/module/display/moduleshader.h"
display_t DISPLAY = { 0 };
mesh_t mesh;
meshvertex_t vertices[3] = {
{
.color = { 255, 0, 0, 255 },
.uv = { 0.0f, 0.0f },
.pos = { 0.0f, 0.5f, 0.0f }
},
{
.color = { 0, 255, 0, 255 },
.uv = { 0.5f, 1.0f },
.pos = { -0.5f, -0.5f, 0.0f }
},
{
.color = { 0, 0, 255, 255 },
.uv = { 1.0f, 0.0f },
.pos = { 0.5f, -0.5f, 0.0f }
}
};
errorret_t displayInit(void) {
memoryZero(&DISPLAY, sizeof(DISPLAY));
@@ -50,6 +68,9 @@ errorret_t displayInit(void) {
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, mat));
errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, NULL));
errorChain(meshInit(&mesh, MESH_PRIMITIVE_TYPE_TRIANGLES, 3, vertices));
errorOk();
}
@@ -69,7 +90,26 @@ errorret_t displayUpdate(void) {
SCREEN.background
);
errorChain(sceneRender());
camera_t cam;
cameraInitOrthographic(&cam);
cam.orthographic.right = SCREEN.width;
cam.orthographic.top = SCREEN.height;
cam.orthographic.left = 0;
cam.orthographic.bottom = 0;
mat4 mat;
cameraGetProjectionMatrix(&cam, mat);
errorChain(shaderBind(&SHADER_UNLIT));
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, mat));
cameraGetViewMatrix(&cam, mat);
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_VIEW, mat));
glm_mat4_identity(mat);
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, mat));
textDraw(32, 32, "Hello World", COLOR_WHITE, &DEFAULT_FONT_TILESET, &DEFAULT_FONT_TEXTURE);
spriteBatchFlush();
// errorChain(sceneRender());
// Render UI
// uiRender();

View File

@@ -90,5 +90,31 @@ int moduleShaderSetMatrix(lua_State *l) {
int moduleShaderSetTexture(lua_State *l) {
assertNotNull(l, "Lua state cannot be NULL.");
shader_t *shader = (shader_t *)lua_touserdata(l, 1);
assertNotNull(shader, "Shader pointer cannot be NULL.");
const char_t *uniformName = luaL_checkstring(l, 2);
assertStrLenMin(uniformName, 1, "Uniform name cannot be empty.");
texture_t *texture;
// Texture can be Nil or a pointer, if not nil it must be a texture pointer.
if(lua_isnil(l, 3)) {
texture = NULL;
} else if(lua_isuserdata(l, 3)) {
texture = (texture_t *)lua_touserdata(l, 3);
assertNotNull(texture, "Texture pointer cannot be NULL.");
} else {
luaL_error(l, "Third argument must be a texture_mt userdata or nil.");
return 0;
}
errorret_t ret = shaderSetTexture(shader, uniformName, texture);
if(ret.code != ERROR_OK) {
luaL_error(l, "Failed to set shader texture: %s", ret.state->message);
errorCatch(errorPrint(ret));
return 0;
}
return 0;
}

View File

@@ -11,6 +11,10 @@
void cameraPushMatrixDolphin(camera_t *camera) {
assertNotNull(camera, "Camera cannot be null");
assertTrue(
camera->nearClip > 0.0f,
"Camera near clip must be greater than 0 for Dolphin"
);
Mtx44 guProjection;
Mtx guView;

View File

@@ -60,15 +60,15 @@ errorret_t shaderSetMatrixDolphin(
if(stringCompare(name, SHADER_UNLIT_PROJECTION) == 0) {
shader->dirtyMatrix |= SHADER_DOLPHIN_DIRTY_PROJ;
glm_mat4_ucopy(mat, shader->proj);
glm_mat4_copy(mat, shader->proj);
} else if(stringCompare(name, SHADER_UNLIT_VIEW) == 0) {
shader->dirtyMatrix |= SHADER_DOLPHIN_DIRTY_VIEW;
glm_mat4_ucopy(mat, shader->view);
glm_mat4_copy(mat, shader->view);
} else if(stringCompare(name, SHADER_UNLIT_MODEL) == 0) {
shader->dirtyMatrix |= SHADER_DOLPHIN_DIRTY_MODEL;
glm_mat4_ucopy(mat, shader->model);
glm_mat4_copy(mat, shader->model);
} else {
assertUnreachable("Cannot use a custom matrix on dolphin.");
@@ -107,7 +107,7 @@ errorret_t shaderSetTextureDolphin(
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0);
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
// GX_SetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_CLEAR);
GX_SetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_CLEAR);
GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
errorOk();