Skip to content

Commit

Permalink
Sprite being renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtrujy committed Aug 13, 2023
1 parent 4ceed78 commit f63db96
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

SUBDIRS =
SUBDIRS += alpha
SUBDIRS += atlas
SUBDIRS += basic
SUBDIRS += bigtex
SUBDIRS += coverflow
Expand Down
16 changes: 16 additions & 0 deletions examples/atlas/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ____ ___ | / _____ _____
# | __ | |___/ | |
# |___| ___| | \ __|__ | gsKit Open Source Project.
# ----------------------------------------------------------------------
# Copyright 2004 - Chris "Neovanglist" Gilbert <Neovanglist@LainOS.org>
# Licenced under Academic Free License version 2.0
# Review gsKit README & LICENSE files for further details.
#
# examples/atlas/Makefile - Makefile for "atlas" example.
#

EE_BIN = atlas.elf
EE_OBJS = atlas.o

include ../../Makefile.pref
include ../Makefile.global
88 changes: 88 additions & 0 deletions examples/atlas/atlas.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// ____ ___ | / _____ _____
// | __ | |___/ | |
// |___| ___| | \ __|__ | gsKit Open Source Project.
// ----------------------------------------------------------------------
// Copyright 2004 - Chris "Neovanglist" Gilbert <Neovanglist@LainOS.org>
// Licenced under Academic Free License version 2.0
// Review gsKit README & LICENSE files for further details.
//
// textures.c - Example demonstrating gsKit texture operation.
//

#include <stdio.h>
#include <malloc.h>

#include <gsKit.h>
#include <dmaKit.h>
#include <gsToolkit.h>
#include <gsInline.h>
#include <gsTexture.h>

int main(int argc, char *argv[])
{
GSGLOBAL *gsGlobal;
GSTEXTURE atlas;

#ifdef HAVE_LIBJPEG
GSTEXTURE Tex3;
#endif

u64 White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);

gsGlobal = gsKit_init_global();

gsGlobal->PSM = GS_PSM_CT24;
gsGlobal->PSMZ = GS_PSMZ_16S;
// gsGlobal->DoubleBuffering = GS_SETTING_OFF;
// gsGlobal->ZBuffering = GS_SETTING_OFF;

dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);

// Initialize the DMAC
dmaKit_chan_init(DMA_CHANNEL_GIF);

gsKit_init_screen(gsGlobal);

gsKit_mode_switch(gsGlobal, GS_ONESHOT);

gsKit_clear(gsGlobal, White);

gsKit_texture_png(gsGlobal, &atlas, "runner_atlas.png");
printf("Atlas Height: %i\n",atlas.Height);
printf("Atlas Width: %i\n",atlas.Width);

printf("Atlas VRAM Range = 0x%X - 0x%X\n",atlas.Vram, atlas.Vram +gsKit_texture_size(atlas.Width, atlas.Height, atlas.PSM) - 1);

gsKit_set_clamp(gsGlobal, GS_CMODE_CLAMP);

gsKit_clear(gsGlobal, White);

GSPRIMUVPOINT *verts = (GSPRIMUVPOINT*)malloc(sizeof(GSPRIMUVPOINT) * 2);
verts[0].xyz2 = vertex_to_XYZ2(gsGlobal, 0, 0, 0);
verts[0].rgbaq = color_to_RGBAQ(0x80, 0x80, 0x80, 0x80, 0);
verts[0].uv = vertex_to_UV(&atlas, 0, 0);

verts[1].xyz2 = vertex_to_XYZ2(gsGlobal, 324, 324, 0);
verts[1].rgbaq = color_to_RGBAQ(0x80, 0x80, 0x80, 0x80, 0);
verts[1].uv = vertex_to_UV(&atlas, atlas.Width, atlas.Height);

while(1)
{
gsKit_clear(gsGlobal, White);

gskit_prim_list_sprite_texture_uv_3d(gsGlobal, &atlas, 2, verts);
// gsKit_prim_sprite_texture(gsGlobal, &atlas, 0, 0, 0, 0, 324, 324, atlas.Width, atlas.Height, 0, TexCol);

gsKit_TexManager_bind(gsGlobal, &atlas);

gsKit_queue_exec(gsGlobal);
gsKit_sync_flip(gsGlobal);
gsKit_TexManager_nextFrame(gsGlobal);
}

free(verts);

return 0;
}
Binary file added examples/atlas/runner_atlas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f63db96

Please sign in to comment.