mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
DS: 3D sorta works
This commit is contained in:
parent
0437d9d0cc
commit
f4ada2aa51
@ -4,13 +4,28 @@
|
|||||||
#include "Errors.h"
|
#include "Errors.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
|
#include <nds.h>
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*---------------------------------------------------------General---------------------------------------------------------*
|
*---------------------------------------------------------General---------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
void Gfx_Create(void) {
|
void Gfx_Create(void) {
|
||||||
Gfx_RestoreState();
|
Gfx_RestoreState();
|
||||||
|
|
||||||
|
videoSetMode(MODE_0_3D);
|
||||||
|
glInit();
|
||||||
|
|
||||||
|
glClearColor(0, 15, 10, 31);
|
||||||
|
glClearPolyID(63);
|
||||||
|
|
||||||
|
glClearDepth(0x7FFF);
|
||||||
|
|
||||||
|
glViewport(0, 0, 255, 191);
|
||||||
|
|
||||||
|
vramSetBankA(VRAM_A_TEXTURE);
|
||||||
|
// setup memory for textures
|
||||||
|
|
||||||
|
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_bool Gfx_TryRestoreContext(void) {
|
cc_bool Gfx_TryRestoreContext(void) {
|
||||||
@ -39,19 +54,28 @@ void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
|
|||||||
gfx_vsync = vsync;
|
gfx_vsync = vsync;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_OnWindowResize(void) { }
|
void Gfx_OnWindowResize(void) {
|
||||||
|
}
|
||||||
|
|
||||||
void Gfx_BeginFrame(void) {
|
void Gfx_BeginFrame(void) {
|
||||||
|
Platform_LogConst("FRAME");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_Clear(void) {
|
void Gfx_Clear(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_ClearCol(PackedCol color) {
|
void Gfx_ClearCol(PackedCol color) {
|
||||||
|
int R = PackedCol_R(color) >> 3;
|
||||||
|
int G = PackedCol_G(color) >> 3;
|
||||||
|
int B = PackedCol_B(color) >> 3;
|
||||||
|
glClearColor(R, G, B, 31);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_EndFrame(void) {
|
void Gfx_EndFrame(void) {
|
||||||
|
glFlush(0);
|
||||||
|
// TODO not needed?
|
||||||
|
swiWaitForVBlank();
|
||||||
|
|
||||||
if (gfx_minFrameMs) LimitFPS();
|
if (gfx_minFrameMs) LimitFPS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,6 +166,8 @@ void Gfx_CalcPerspectiveMatrix(struct Matrix* matrix, float fov, float aspect, f
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*----------------------------------------------------------Buffers--------------------------------------------------------*
|
*----------------------------------------------------------Buffers--------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
static void* gfx_vertices;
|
||||||
|
|
||||||
GfxResourceID Gfx_CreateIb2(int count, Gfx_FillIBFunc fillFunc, void* obj) {
|
GfxResourceID Gfx_CreateIb2(int count, Gfx_FillIBFunc fillFunc, void* obj) {
|
||||||
return (void*)1;
|
return (void*)1;
|
||||||
}
|
}
|
||||||
@ -151,30 +177,32 @@ void Gfx_DeleteIb(GfxResourceID* ib) { }
|
|||||||
|
|
||||||
|
|
||||||
static GfxResourceID Gfx_AllocStaticVb(VertexFormat fmt, int count) {
|
static GfxResourceID Gfx_AllocStaticVb(VertexFormat fmt, int count) {
|
||||||
return NULL;
|
return Mem_TryAlloc(count, strideSizes[fmt]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_BindVb(GfxResourceID vb) { }
|
void Gfx_BindVb(GfxResourceID vb) { gfx_vertices = vb; }
|
||||||
|
|
||||||
void Gfx_DeleteVb(GfxResourceID* vb) {
|
void Gfx_DeleteVb(GfxResourceID* vb) {
|
||||||
|
GfxResourceID data = *vb;
|
||||||
|
if (data) Mem_Free(data);
|
||||||
|
*vb = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Gfx_LockVb(GfxResourceID vb, VertexFormat fmt, int count) {
|
void* Gfx_LockVb(GfxResourceID vb, VertexFormat fmt, int count) {
|
||||||
return NULL;
|
return vb;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_UnlockVb(GfxResourceID vb) {
|
void Gfx_UnlockVb(GfxResourceID vb) { gfx_vertices = vb; }
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static GfxResourceID Gfx_AllocDynamicVb(VertexFormat fmt, int maxVertices) {
|
static GfxResourceID Gfx_AllocDynamicVb(VertexFormat fmt, int maxVertices) {
|
||||||
return NULL;
|
return Mem_TryAlloc(maxVertices, strideSizes[fmt]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_BindDynamicVb(GfxResourceID vb) { Gfx_BindVb(vb); }
|
void Gfx_BindDynamicVb(GfxResourceID vb) { Gfx_BindVb(vb); }
|
||||||
|
|
||||||
void* Gfx_LockDynamicVb(GfxResourceID vb, VertexFormat fmt, int count) {
|
void* Gfx_LockDynamicVb(GfxResourceID vb, VertexFormat fmt, int count) {
|
||||||
return NULL;
|
return vb;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_UnlockDynamicVb(GfxResourceID vb) { Gfx_UnlockVb(vb); }
|
void Gfx_UnlockDynamicVb(GfxResourceID vb) { Gfx_UnlockVb(vb); }
|
||||||
@ -210,33 +238,90 @@ void Gfx_DepthOnlyRendering(cc_bool depthOnly) { }
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*---------------------------------------------------------Matrices--------------------------------------------------------*
|
*---------------------------------------------------------Matrices--------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
static int matrix_modes[] = { GL_PROJECTION, GL_MODELVIEW, GL_TEXTURE };
|
||||||
|
static int lastMatrix;
|
||||||
|
|
||||||
void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) {
|
void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) {
|
||||||
|
if (type != lastMatrix) { lastMatrix = type; glMatrixMode(matrix_modes[type]); }
|
||||||
|
|
||||||
|
m4x4 m;
|
||||||
|
const float* src = (const float*)matrix;
|
||||||
|
|
||||||
|
for (int i = 0; i < 4 * 4; i++)
|
||||||
|
{
|
||||||
|
m.m[i] = floattof32(src[i]);
|
||||||
|
}
|
||||||
|
glLoadMatrix4x4(&m);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_LoadIdentityMatrix(MatrixType type) {
|
void Gfx_LoadIdentityMatrix(MatrixType type) {
|
||||||
|
if (type != lastMatrix) { lastMatrix = type; glMatrixMode(matrix_modes[type]); }
|
||||||
|
glLoadIdentity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct Matrix texMatrix = Matrix_IdentityValue;
|
||||||
void Gfx_EnableTextureOffset(float x, float y) {
|
void Gfx_EnableTextureOffset(float x, float y) {
|
||||||
|
texMatrix.row4.x = x; texMatrix.row4.y = y;
|
||||||
|
Gfx_LoadMatrix(2, &texMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_DisableTextureOffset(void) { }
|
void Gfx_DisableTextureOffset(void) { Gfx_LoadIdentityMatrix(2); }
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*--------------------------------------------------------Rendering--------------------------------------------------------*
|
*--------------------------------------------------------Rendering--------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
void Gfx_SetVertexFormat(VertexFormat fmt) {
|
void Gfx_SetVertexFormat(VertexFormat fmt) {
|
||||||
|
gfx_format = fmt;
|
||||||
|
gfx_stride = strideSizes[fmt];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_DrawVb_Lines(int verticesCount) {
|
void Gfx_DrawVb_Lines(int verticesCount) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void Draw_ColouredTriangles(int verticesCount, int startVertex) {
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
for (int i = 0; i < verticesCount; i++)
|
||||||
|
{
|
||||||
|
struct VertexColoured* v = (struct VertexColoured*)gfx_vertices + startVertex + i;
|
||||||
|
|
||||||
|
glColor3b(PackedCol_R(v->Col), PackedCol_G(v->Col), PackedCol_B(v->Col));
|
||||||
|
glVertex3f(v->x, v->y, v->z);
|
||||||
|
}
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Draw_TexturedTriangles(int verticesCount, int startVertex) {
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
for (int i = 0; i < verticesCount; i++)
|
||||||
|
{
|
||||||
|
struct VertexTextured* v = (struct VertexTextured*)gfx_vertices + startVertex + i;
|
||||||
|
|
||||||
|
glColor3b(PackedCol_R(v->Col), PackedCol_G(v->Col), PackedCol_B(v->Col));
|
||||||
|
glVertex3f(v->x, v->y, v->z);
|
||||||
|
//GX_TexCoord2f32(v->U, v->V);
|
||||||
|
}
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) {
|
void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) {
|
||||||
|
if (gfx_format == VERTEX_FORMAT_TEXTURED) {
|
||||||
|
Draw_TexturedTriangles(verticesCount, startVertex);
|
||||||
|
} else {
|
||||||
|
Draw_ColouredTriangles(verticesCount, startVertex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_DrawVb_IndexedTris(int verticesCount) {
|
void Gfx_DrawVb_IndexedTris(int verticesCount) {
|
||||||
|
if (gfx_format == VERTEX_FORMAT_TEXTURED) {
|
||||||
|
Draw_TexturedTriangles(verticesCount, 0);
|
||||||
|
} else {
|
||||||
|
Draw_ColouredTriangles(verticesCount, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
|
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
|
||||||
|
Draw_TexturedTriangles(verticesCount, startVertex);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -105,7 +105,8 @@ static void ProcessTouchInput(int mods) {
|
|||||||
void Window_ProcessEvents(double delta) {
|
void Window_ProcessEvents(double delta) {
|
||||||
scanKeys();
|
scanKeys();
|
||||||
|
|
||||||
int keys = keysDown();
|
int keys = keysDown() | keysHeld();
|
||||||
|
Platform_Log1("KEYS: %h", &keys);
|
||||||
HandleButtons(keys);
|
HandleButtons(keys);
|
||||||
|
|
||||||
Input_SetNonRepeatable(CCMOUSE_L, keys & KEY_TOUCH);
|
Input_SetNonRepeatable(CCMOUSE_L, keys & KEY_TOUCH);
|
||||||
@ -115,7 +116,21 @@ void Window_ProcessEvents(double delta) {
|
|||||||
void Cursor_SetPosition(int x, int y) { } // Makes no sense for PSP
|
void Cursor_SetPosition(int x, int y) { } // Makes no sense for PSP
|
||||||
void Window_EnableRawMouse(void) { Input.RawMode = true; }
|
void Window_EnableRawMouse(void) { Input.RawMode = true; }
|
||||||
void Window_DisableRawMouse(void) { Input.RawMode = false; }
|
void Window_DisableRawMouse(void) { Input.RawMode = false; }
|
||||||
void Window_UpdateRawMouse(void) { }
|
|
||||||
|
void Window_UpdateRawMouse(void) {
|
||||||
|
if (!touchActive) return;
|
||||||
|
|
||||||
|
touchPosition touch;
|
||||||
|
touchRead(&touch);
|
||||||
|
|
||||||
|
int DX = touch.px - touchBegX;
|
||||||
|
int DY = touch.py - touchBegY;
|
||||||
|
Platform_Log2("DELTA: %i, %i", &DX, &DY);
|
||||||
|
Event_RaiseRawMove(&PointerEvents.RawMoved,
|
||||||
|
touch.px - touchBegX, touch.py - touchBegY);
|
||||||
|
touchBegX = touch.px;
|
||||||
|
touchBegY = touch.py;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user