- Add Count<> to AssetManager - Initialize pCode in Shader - Rename linearAllocator to LinearAllocator - Add Construct and destroy to linear allocator - Add Shader unloader (fixes atexit crash i guess) -
89 lines
2.1 KiB
Plaintext
89 lines
2.1 KiB
Plaintext
#include <amethyst.hpp>
|
|
|
|
typedef struct {
|
|
float pos[3];
|
|
float color[4];
|
|
} Vertex;
|
|
|
|
static const Vertex vertex_list[] = {
|
|
{{200.0f, 200.0f, 0.5f}, {1.0f, 0.0f, 0.0f, 1.0f}},
|
|
{{100.0f, 40.0f, 0.5f}, {0.0f, 1.0f, 0.0f, 1.0f}},
|
|
{{300.0f, 40.0f, 0.5f}, {0.0f, 0.0f, 1.0f, 1.0f}},
|
|
};
|
|
|
|
#define vertex_list_count (sizeof(vertex_list) / sizeof(vertex_list[0]))
|
|
|
|
static int uLoc_projection;
|
|
|
|
Amy::AssetMgr* Assets = nullptr;
|
|
|
|
static void* vbo_data;
|
|
|
|
extern "C" {
|
|
static void sceneInit(void) {
|
|
Assets->AutoLoad("shader", "romfs:/shaders/shader2d.shbin");
|
|
Assets->Get<Amy::C3D::Shader>("shader")->Input(GPU_FLOAT, 3);
|
|
Assets->Get<Amy::C3D::Shader>("shader")->Input(GPU_FLOAT, 4);
|
|
uLoc_projection = Assets->Get<Amy::C3D::Shader>("shader")->loc("projecttion");
|
|
|
|
vbo_data = linearAlloc(sizeof(vertex_list));
|
|
memcpy(vbo_data, vertex_list, sizeof(vertex_list));
|
|
|
|
// Configure buffers
|
|
C3D_BufInfo* bufInfo = C3D_GetBufInfo();
|
|
BufInfo_Init(bufInfo);
|
|
BufInfo_Add(bufInfo, vbo_data, sizeof(Vertex), 2, 0x10);
|
|
|
|
// Configure the first fragment shading substage to just pass through the
|
|
// vertex color See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml
|
|
// for more insight
|
|
C3D_TexEnv* env = C3D_GetTexEnv(0);
|
|
C3D_TexEnvInit(env);
|
|
C3D_TexEnvSrc(env, C3D_Both, GPU_PRIMARY_COLOR);
|
|
C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE);
|
|
}
|
|
}
|
|
static void sceneRender(void) {
|
|
Assets->Get<Amy::C3D::Shader>("shader")->Use();
|
|
Assets->Get<Amy::C3D::Shader>("shader")->SetMat4(
|
|
uLoc_projection, Amy::mat4::ortho(0, 400, 240, 0, 1, -1));
|
|
|
|
Amy::C3D::DrawArrays(0, vertex_list_count);
|
|
}
|
|
|
|
static void sceneExit(void) {
|
|
// Free the VBO
|
|
linearFree(vbo_data);
|
|
|
|
Assets->Remove("shader");
|
|
}
|
|
|
|
int main() {
|
|
Amy::RegisterCxxExceptionHandler();
|
|
Amy::Ctr::Init();
|
|
Amy::C3D::Init();
|
|
auto Top = Amy::C3D::CreateScreen(GFX_TOP);
|
|
Assets = new Amy::AssetMgr();
|
|
|
|
sceneInit();
|
|
|
|
while (aptMainLoop()) {
|
|
hidScanInput();
|
|
|
|
u32 kDown = hidKeysDown();
|
|
if (kDown & KEY_START) break;
|
|
|
|
Amy::C3D::StartFrame();
|
|
Top->Clear();
|
|
Top->Use();
|
|
sceneRender();
|
|
Amy::C3D::EndFrame();
|
|
}
|
|
|
|
sceneExit();
|
|
|
|
C3D_Fini();
|
|
gfxExit();
|
|
romfsExit();
|
|
return 0;
|
|
} |