Start 3D rendering

This commit is contained in:
Miloslav Ciz 2023-09-16 20:35:01 +02:00
parent 6e068eff2b
commit edcde03fa3
3 changed files with 74 additions and 0 deletions

4
game.h
View file

@ -113,6 +113,8 @@ void LCR_gameInit(void)
{ {
for (int i = 0; i < LCR_KEYS_TOTAL; ++i) for (int i = 0; i < LCR_KEYS_TOTAL; ++i)
_LCR_keyStates[i] = 0; _LCR_keyStates[i] = 0;
LCR_rendererInit();
} }
void LCR_gameEnd(void) void LCR_gameEnd(void)
@ -136,6 +138,8 @@ for (int i = 0; i < LCR_EFFECTIVE_RESOLUTION_X; ++i)
LCR_drawBackground(200 + aaa / 10); LCR_drawBackground(200 + aaa / 10);
LCR_drawSkyStrip(200 + aaa / 10,aaa / 30); LCR_drawSkyStrip(200 + aaa / 10,aaa / 30);
LCR_render();
aaa = (aaa + 1) % 10000; aaa = (aaa + 1) % 10000;

View file

@ -1,11 +1,70 @@
#ifndef _LCR_RENDERER_H #ifndef _LCR_RENDERER_H
#define _LCR_RENDERER_H #define _LCR_RENDERER_H
#define S3L_RESOLUTION_X LCR_SETTING_RESOLUTION_X
#define S3L_RESOLUTION_Y LCR_SETTING_RESOLUTION_Y
#define S3L_PIXEL_FUNCTION LCR_pixelFunc3D
#include "small3dlib.h"
struct LCR_Renderer struct LCR_Renderer
{ {
// TODO // TODO
}; };
S3L_Scene LCR_scene3D;
S3L_Model3D LCR_models3D[3]; // TODO
S3L_Unit LCR_vertices3D[LCR_SETTING_MAX_VERTICES * 3];
S3L_Index LCR_triangles3D[LCR_SETTING_MAX_TRIANGLES * 3];
void LCR_pixelFunc3D(S3L_PixelInfo *pixel)
{
LCR_drawPixelSafe(pixel->x,pixel->y,0xff00);
}
/** Builds an internal 3D model of the currently loaded map. Returns 1 on
success, otherwise 0 (e.g. not enough space). */
uint8_t LCR_buildMapModel(void)
{
// TODO
LCR_vertices3D[0] = -400;
LCR_vertices3D[1] = -100;
LCR_vertices3D[2] = 1000;
LCR_vertices3D[3] = 400;
LCR_vertices3D[4] = -100;
LCR_vertices3D[5] = 1000;
LCR_vertices3D[6] = 0;
LCR_vertices3D[7] = 400;
LCR_vertices3D[8] = 1000;
LCR_triangles3D[0] = 0;
LCR_triangles3D[1] = 1;
LCR_triangles3D[2] = 2;
return 1;
}
uint8_t LCR_rendererInit(void)
{
if (!LCR_buildMapModel())
return 0;
S3L_model3DInit(LCR_vertices3D,3,LCR_triangles3D,1,LCR_models3D);
S3L_sceneInit(LCR_models3D,1,&LCR_scene3D);
return 1;
}
void LCR_render(void)
{
S3L_newFrame();
S3L_drawScene(LCR_scene3D);
}
void LCR_drawBackground(int verticalOffset) void LCR_drawBackground(int verticalOffset)
{ {
uint16_t color = LCR_skyImages[LCR_skyImages[256] & 0x00ff] ; // TODO uint16_t color = LCR_skyImages[LCR_skyImages[256] & 0x00ff] ; // TODO

View file

@ -13,6 +13,17 @@
#define LCR_SETTING_RESOLUTION_SUBDIVIDE 1 #define LCR_SETTING_RESOLUTION_SUBDIVIDE 1
#endif #endif
#ifndef LCR_SETTING_MAX_VERTICES
/** Maximum number of vertices for 3D rendering. Lower number will decrease
RAM usage but will prevent larger maps from being loaded. */
#define LCR_SETTING_MAX_VERTICES 10000
#endif
#ifndef LCR_SETTING_MAX_TRIANGLES
/** Like LCR_SETTING_MAX_VERTICES but for the number of triangles. */
#define LCR_SETTING_MAX_TRIANGLES 10000
#endif
#ifndef LCR_SETTING_SKY_SIZE #ifndef LCR_SETTING_SKY_SIZE
/** Size of sky texture pixel, 0 turns off sky rendering. */ /** Size of sky texture pixel, 0 turns off sky rendering. */
#define LCR_SETTING_SKY_SIZE \ #define LCR_SETTING_SKY_SIZE \