mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2025-06-06 15:54:47 +00:00
Added CosmicGL.
This commit is contained in:
parent
9a30b7f1a0
commit
1cbc72e57b
@ -15,7 +15,7 @@ Features in development include:
|
||||
- Fully-functional AHCI support
|
||||
- ~~VBE support~~ 32-bit color VBE graphics
|
||||
- A new GUI framework in 32-bit color
|
||||
- [Gr2](https://github.com/TempleProgramming/Gr2)
|
||||
- CosmicGL renderer
|
||||
- Compiler optimizations for speed improvements
|
||||
- SSE2+ instruction support in compiler and assembler
|
||||
- Network card drivers and a networking stack
|
||||
|
BIN
Zenith-latest-2021-06-25-21_34_44.iso → Zenith-latest-2021-06-26-04_03_37.iso
Executable file → Normal file
BIN
Zenith-latest-2021-06-25-21_34_44.iso → Zenith-latest-2021-06-26-04_03_37.iso
Executable file → Normal file
Binary file not shown.
BIN
src/Home/CosmicGLDemos/DrawBSP/DOOM1.WAD
Normal file
BIN
src/Home/CosmicGLDemos/DrawBSP/DOOM1.WAD
Normal file
Binary file not shown.
83
src/Home/CosmicGLDemos/DrawBSP/DrawBSP.CC
Normal file
83
src/Home/CosmicGLDemos/DrawBSP/DrawBSP.CC
Normal file
@ -0,0 +1,83 @@
|
||||
/* This demo renders a BSP. Put DOOM1.WAD in the directory to try this. */
|
||||
|
||||
Cd(__DIR__);;
|
||||
|
||||
"\n\n\n\n"; // Seperate from annoying warnings
|
||||
|
||||
I64 wWC = 90; // Window width in columns
|
||||
I64 wHC = 90; // Window height in rows
|
||||
I64 wW = wWC * 8;
|
||||
I64 wH = wHC * 8;
|
||||
I64 wXC = 1; // Window x in columns
|
||||
I64 wYC = 2; // Window y in rows
|
||||
I64 wX = wXC * 8;
|
||||
I64 wY = wYC * 8;
|
||||
|
||||
SettingsPush;
|
||||
WinHorz(wXC, wXC + wWC - 1);
|
||||
WinVert(wYC, wYC + wHC - 1);
|
||||
DocClear;
|
||||
|
||||
// Prepare framebuffer
|
||||
CTex2D frameBuf;
|
||||
Tex2DInit(&frameBuf, TEX2D_RAW, wW, wH);
|
||||
Tex2DColorFill(&frameBuf, gr_palette[WHITE]);
|
||||
|
||||
// Load BSP and render
|
||||
CWAD doom1;
|
||||
WADLoad(&doom1, "DOOM1.WAD");
|
||||
|
||||
CDoomMap map;
|
||||
DoomMapLoad(&map, &doom1, "E1M1");
|
||||
|
||||
// Sprite loading
|
||||
CTex2D sprite;
|
||||
Tex2DLoadWADSprite(&sprite, &doom1, "POSSF2F8");
|
||||
|
||||
WADFree(&doom1);
|
||||
|
||||
CBGR24 cRed;
|
||||
cRed.r = 255; cRed.b = cRed.g = 0;
|
||||
|
||||
I64 i, a, b, c, d;
|
||||
for (i = 0; i < map.nLines; i++)
|
||||
{
|
||||
a = map.lines[i].v1->x >> 32;
|
||||
b = map.lines[i].v1->y >> 32;
|
||||
c = map.lines[i].v2->x >> 32;
|
||||
d = map.lines[i].v2->y >> 32;
|
||||
|
||||
a /= 8;
|
||||
b /= 8;
|
||||
c /= 8;
|
||||
d /= 8;
|
||||
|
||||
a += 200;
|
||||
b += 650;
|
||||
c += 200;
|
||||
d += 650;
|
||||
|
||||
if (a < 0 || b < 0 || c < 0 || d < 0 ||
|
||||
a >= wW || b >= wH || c >= wW || d >= wH)
|
||||
{
|
||||
// One coordinate outside window
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawLine(&frameBuf, a, b, c, d, cRed);
|
||||
}
|
||||
}
|
||||
|
||||
DrawTexture(&frameBuf, &sprite, 200, 200, TRUE);
|
||||
|
||||
while (CharScan() == 0)
|
||||
{
|
||||
Tex2DDebugDisp(&frameBuf, wX, wY);
|
||||
Sleep(1);
|
||||
}
|
||||
|
||||
DoomMapFree(&doom1);
|
||||
Tex2DFree(&sprite);
|
||||
Tex2DFree(&framebuf);
|
||||
SettingsPop;
|
||||
Exit;
|
53
src/Home/CosmicGLDemos/DrawPrimitives/DrawPrimitives.CC
Normal file
53
src/Home/CosmicGLDemos/DrawPrimitives/DrawPrimitives.CC
Normal file
@ -0,0 +1,53 @@
|
||||
/* This demo shows how to draw primitives to textures. */
|
||||
|
||||
Cd(__DIR__);;
|
||||
|
||||
I64 wWC = 64; // Window width in columns (512px)
|
||||
I64 wHC = 48; // Window height in rows (384px)
|
||||
I64 wW = wWC * 8;
|
||||
I64 wH = wHC * 8;
|
||||
I64 wXC = 1; // Window x in columns
|
||||
I64 wYC = 2; // Window y in rows
|
||||
I64 wX = wXC * 8;
|
||||
I64 wY = wYC * 8;
|
||||
|
||||
SettingsPush;
|
||||
WinHorz(wXC, wXC + wWC - 1);
|
||||
WinVert(wYC, wYC + wHC - 1);
|
||||
DocClear;
|
||||
|
||||
// Prepare framebuffer
|
||||
CTex2D frameBuf;
|
||||
Tex2DInit(&frameBuf, TEX2D_RAW, wW, wH);
|
||||
Tex2DColorFill(&frameBuf, gr_palette[WHITE]);
|
||||
|
||||
// Draw Rectangles
|
||||
DrawRectFill(&frameBuf, 32, 32, 128, 96, gr_palette[CYAN]);
|
||||
|
||||
DrawRectVertGradient(&frameBuf, 64, 128, 96, 256, gr_palette[CYAN],
|
||||
gr_palette[BLUE]);
|
||||
|
||||
// Gradient's starting transition points can also be modified:
|
||||
DrawRectVertGradient(&frameBuf, 160, 32, 224, 96, gr_palette[BLACK],
|
||||
gr_palette[WHITE], 0.65, 0.7);
|
||||
|
||||
DrawRectOutline(&frameBuf, 55, 300, 75, 310, gr_palette[LTGRAY]);
|
||||
|
||||
// You can also define a second color for adding button-like shading
|
||||
DrawRectSoftOutline(&frameBuf, 100, 200, 130, 210, gr_palette[LTGRAY],
|
||||
gr_palette[DKGRAY]);
|
||||
|
||||
// Drawing text
|
||||
DrawChar(&frameBuf, 48, 48, '!', gr_palette[WHITE]);
|
||||
DrawString(&frameBuf, 16, 104, "When I wrote this, God said:
|
||||
calls singing moist days excellence.", gr_palette[GREEN]);
|
||||
|
||||
while (CharScan() == 0)
|
||||
{
|
||||
Tex2DDebugDisp(&frameBuf, wX, wY);
|
||||
Sleep(1);
|
||||
}
|
||||
|
||||
Tex2DFree(&frameBuf);
|
||||
SettingsPop;
|
||||
Exit;
|
BIN
src/Home/CosmicGLDemos/ModelLoading/KingTerry.wad
Normal file
BIN
src/Home/CosmicGLDemos/ModelLoading/KingTerry.wad
Normal file
Binary file not shown.
247
src/Home/CosmicGLDemos/ModelLoading/TerryTruth.CC
Normal file
247
src/Home/CosmicGLDemos/ModelLoading/TerryTruth.CC
Normal file
@ -0,0 +1,247 @@
|
||||
/* This demo shows how to load a custom model (created based on the .obj format
|
||||
using a converstion script). It uses WAD textures rather than BMP textures
|
||||
unlike most of the other demos. The model is not transformed in any way and
|
||||
is rendered directly, so scaling the window will also scale the resulting
|
||||
render. */
|
||||
|
||||
Cd(__DIR__);;
|
||||
|
||||
I64 wWC = 80; // Window width in columns (Drop to under 80 for 640x480 displays)
|
||||
I64 wHC = 45; // Window height in rows (Drop to under 60 for 640x480 displays)
|
||||
I64 wW = wWC * 8;
|
||||
I64 wH = wHC * 8;
|
||||
I64 wXC = 1; // Window x in columns
|
||||
I64 wYC = 2; // Window y in rows
|
||||
I64 wX = wXC * 8;
|
||||
I64 wY = (wYC + 0) * 8;
|
||||
|
||||
SettingsPush;
|
||||
WinHorz(wXC, wXC + wWC - 1);
|
||||
WinVert(wYC, wYC + wHC - 1);
|
||||
DocClear;
|
||||
|
||||
// Framebuffer Initialization
|
||||
CTex2D frameBuf;
|
||||
CTex2D depthBuf;
|
||||
|
||||
Tex2DInit(&frameBuf, TEX2D_RAW, wW, wH);
|
||||
Tex2DInit(&depthBuf, TEX2D_DEPTH, wW, wH);
|
||||
|
||||
// Colors
|
||||
CBGR24 cBlack;
|
||||
cBlack.r = 0; cBlack.g = 0; cBlack.b = 0;
|
||||
CBGR24 cRed;
|
||||
cRed.r = 255; cRed.g = 20; cRed.b = 20;
|
||||
CBGR24 cWhite;
|
||||
cWhite.r = 255; cWhite.g = 255; cWhite.b = 255;
|
||||
|
||||
Tex2DColorFill(&frameBuf, cBlack);
|
||||
|
||||
// Texture Intitalization
|
||||
CWAD wad;
|
||||
WADLoad(&wad, "KingTerry.wad");
|
||||
|
||||
CTex2D TexRevelation;
|
||||
Tex2DLoadWAD(&TexRevelation, &wad, "Revelation");
|
||||
|
||||
CTex2D TexKingTerrySkin;
|
||||
Tex2DLoadWAD(&TexKingTerrySkin, &wad, "KingTerry_Skin");
|
||||
|
||||
CTex2D TexKingTerryBody;
|
||||
Tex2DLoadWAD(&TexKingTerryBody, &wad, "KingTerry_Body");
|
||||
|
||||
CTex2D TexNebula;
|
||||
Tex2DLoadWAD(&TexNebula, &wad, "Nebula");
|
||||
|
||||
WADFree(&wad);
|
||||
|
||||
// Generate our own page texture
|
||||
CTex2D TexPages;
|
||||
Tex2DInit(&TexPages, TEX2D_RAW, 256, 256);
|
||||
Tex2DColorFill(&TexPages, cWhite);
|
||||
DrawString(&TexPages, 16, 20, "I should fix", cBlack);
|
||||
DrawString(&TexPages, 16, 35, "the UVs on this", cBlack);
|
||||
DrawString(&TexPages, 16, 50, "book model.", cBlack);
|
||||
|
||||
class CMat
|
||||
{
|
||||
U8 name[32];
|
||||
U32 nOffset; // Offset to first triangle
|
||||
U32 nTris; // Number of triangles
|
||||
};
|
||||
|
||||
class CZMHeader
|
||||
{
|
||||
I32 nMats; // Number of materials
|
||||
U32 nTriOffset; // Triangle array offset
|
||||
U32 nVertOffset; // Vertex array offset
|
||||
U32 nUVOffset; // UV array offset
|
||||
U32 nNormOffset; // Normal array offset
|
||||
};
|
||||
|
||||
class CZMTri
|
||||
{
|
||||
U32 iV1; // Vertices
|
||||
U32 iV2;
|
||||
U32 iV3;
|
||||
U32 iN1; // Normals
|
||||
U32 iN2;
|
||||
U32 iN3;
|
||||
U32 iT1; // UVs
|
||||
U32 iT2;
|
||||
U32 iT3;
|
||||
};
|
||||
|
||||
class CZModel
|
||||
{
|
||||
CMat *mat;
|
||||
CZMTri *tri;
|
||||
CVec3 *vert;
|
||||
CVec2 *uv;
|
||||
CVec3 *norm;
|
||||
};
|
||||
|
||||
class UniformTex
|
||||
{
|
||||
I64 mat; // Material index of model to render
|
||||
CTex2D *tex;
|
||||
};
|
||||
|
||||
class UniformCol
|
||||
{
|
||||
I64 mat;
|
||||
CBGR24 col;
|
||||
};
|
||||
|
||||
// Load model
|
||||
U8 *MdlHandle = FileRead("TerryTruth.ZM");
|
||||
CZMHeader *header = MdlHandle;
|
||||
CZModel MdlTerry;
|
||||
|
||||
MdlTerry.mat = MdlHandle + 20;
|
||||
MdlTerry.tri = MdlHandle + header->nTriOffset;
|
||||
MdlTerry.vert = MdlHandle + header->nVertOffset;
|
||||
MdlTerry.uv = MdlHandle + header->nUVOffset;
|
||||
MdlTerry.norm = MdlHandle + header->nNormOffset;
|
||||
|
||||
// Prepare uniforms (unchanging parameters) to feed into shader
|
||||
|
||||
// Book cover is red
|
||||
UniformCol UniCover;
|
||||
UniCover.col.r = 150;
|
||||
UniCover.col.g = 0;
|
||||
UniCover.col.b = 0;
|
||||
UniCover.mat = 0;
|
||||
|
||||
// Skin uses skin texture
|
||||
UniformTex UniKingTerry_Skin;
|
||||
UniKingTerry_Skin.tex = &TexKingTerrySkin;
|
||||
UniKingTerry_Skin.mat = 1;
|
||||
|
||||
// Body uses body texture
|
||||
UniformTex UniKingTerry_Body;
|
||||
UniKingTerry_Body.tex = &TexKingTerryBody;
|
||||
UniKingTerry_Body.mat = 2;
|
||||
|
||||
// Hat is black (dark gray)
|
||||
UniformCol UniHat;
|
||||
UniHat.col.r = 20;
|
||||
UniHat.col.g = 20;
|
||||
UniHat.col.b = 20;
|
||||
UniHat.mat = 3;
|
||||
|
||||
// Pages uses WAD texture
|
||||
UniformTex UniPages;
|
||||
UniPages.tex = &TexPages; // Set this to &TexRevelation for original.
|
||||
UniPages.mat = 4;
|
||||
|
||||
// Nebula uses WAD texture
|
||||
UniformTex UniNebula;
|
||||
UniNebula.tex = &TexNebula;
|
||||
UniNebula.mat = 5;
|
||||
|
||||
// Generate a texure and color shader
|
||||
CShader ShdTex, ShdCol;
|
||||
ShdTex.vertValues = MAlloc(2 * sizeof(I64));
|
||||
ShdTex.vertValues[0] = SHD_CVEC2; // UV
|
||||
ShdTex.vertValues[1] = SHD_CVEC3; // Normal
|
||||
|
||||
ShdCol.vertValues = MAlloc(2 * sizeof(I64));
|
||||
ShdCol.vertValues[0] = SHD_CVEC2; // UV
|
||||
ShdCol.vertValues[1] = SHD_CVEC3; // Normal
|
||||
|
||||
ShdTex.nVertValues = 2;
|
||||
ShdCol.nVertValues = 2;
|
||||
|
||||
U0 vShaderTex(CTri *tri, F64 *vertOutBuf, U8 *mdlPtr, U8 *uniforms, I64 iTri, I64 nTris)
|
||||
{
|
||||
CZModel *mdl = mdlPtr;
|
||||
UniformTex *uni = uniforms;
|
||||
|
||||
nTris++; // So I don't have to see the unused warning.
|
||||
|
||||
I64 t = mdl->mat[uni->mat].nOffset + iTri; // Triangle index in triangle array
|
||||
|
||||
// Copy model directly into the triangle, I won't even transform for this demo.
|
||||
MemCopy(&tri->p[0], &mdl->vert[mdl->tri[t].iV1 - 1], sizeof(CVec3));
|
||||
MemCopy(&tri->p[1], &mdl->vert[mdl->tri[t].iV2 - 1], sizeof(CVec3));
|
||||
MemCopy(&tri->p[2], &mdl->vert[mdl->tri[t].iV3 - 1], sizeof(CVec3));
|
||||
|
||||
tri->p[0].z = -1 * tri->p[0].z;
|
||||
tri->p[1].z = -1 * tri->p[1].z;
|
||||
tri->p[2].z = -1 * tri->p[2].z;
|
||||
|
||||
// Copy uv and normals into vertOutBuf to be interpolated for the vertex shader.
|
||||
MemCopy(&vertOutBuf[0], &mdl->uv[mdl->tri[t].iT1 - 1], sizeof(CVec2));
|
||||
MemCopy(&vertOutBuf[2], &mdl->norm[mdl->tri[t].iN1 - 1], sizeof(CVec3));
|
||||
MemCopy(&vertOutBuf[5], &mdl->uv[mdl->tri[t].iT2 - 1], sizeof(CVec2));
|
||||
MemCopy(&vertOutBuf[7], &mdl->norm[mdl->tri[t].iN2 - 1], sizeof(CVec3));
|
||||
MemCopy(&vertOutBuf[10], &mdl->uv[mdl->tri[t].iT3 - 1], sizeof(CVec2));
|
||||
MemCopy(&vertOutBuf[12], &mdl->norm[mdl->tri[t].iN3 - 1], sizeof(CVec3));
|
||||
}
|
||||
|
||||
U0 fShaderTex(CBGR24 *color, F64 *fragInBuf, U8 *uniforms)
|
||||
{
|
||||
UniformTex *uni = uniforms;
|
||||
Tex2DSampleNorm(color, uni->tex, fragInBuf[0], 1.0-fragInBuf[1]);
|
||||
// Debug, display normals
|
||||
// color->r=fragInBuf[2]*255.0; color->g=fragInBuf[3]*255.0; color->b=fragInBuf[4]*255.0;
|
||||
}
|
||||
|
||||
U0 fShaderCol(CBGR24 *color, F64 *fragInBuf, U8 *uniforms)
|
||||
{
|
||||
UniformCol *uni = uniforms;
|
||||
color->r = uni->col.r;
|
||||
color->g = uni->col.g;
|
||||
color->b = uni->col.b;
|
||||
}
|
||||
|
||||
ShdTex.FragShd = &fShaderTex;
|
||||
ShdTex.VertShd = &vShaderTex;
|
||||
ShdCol.FragShd = &fShaderCol;
|
||||
ShdCol.VertShd = &vShaderTex;
|
||||
|
||||
Tex2DDepthReset(&depthBuf);
|
||||
RenderTris(&ShdCol, &frameBuf, &depthBuf, &MdlTerry, &UniCover, MdlTerry.mat[0].nTris);
|
||||
RenderTris(&ShdTex, &frameBuf, &depthBuf, &MdlTerry, &UniKingTerry_Skin, MdlTerry.mat[1].nTris);
|
||||
RenderTris(&ShdTex, &frameBuf, &depthBuf, &MdlTerry, &UniKingTerry_Body, MdlTerry.mat[2].nTris);
|
||||
RenderTris(&ShdCol, &frameBuf, &depthBuf, &MdlTerry, &UniHat, MdlTerry.mat[3].nTris);
|
||||
RenderTris(&ShdTex, &frameBuf, &depthBuf, &MdlTerry, &UniPages, MdlTerry.mat[4].nTris);
|
||||
RenderTris(&ShdTex, &frameBuf, $ER$&depthBuf, &MdlTerry, &UniNebula, MdlTerry.mat[5].nTris);
|
||||
|
||||
while (CharScan() == 0)
|
||||
{
|
||||
Tex2DDebugDisp(&frameBuf, wX, wY);
|
||||
Sleep(1);
|
||||
}
|
||||
|
||||
Tex2DFree(&frameBuf);
|
||||
Tex2DFree(&depthBuf);
|
||||
Tex2DFree(&TexPages);
|
||||
Tex2DFree(&TexRevelation);
|
||||
Tex2DFree(&TexKingTerrySkin);
|
||||
Tex2DFree(&TexKingTerryBody);
|
||||
Tex2DFree(&TexNebula);
|
||||
|
||||
SettingsPop;
|
||||
Exit;
|
BIN
src/Home/CosmicGLDemos/ModelLoading/TerryTruth.ZM
Normal file
BIN
src/Home/CosmicGLDemos/ModelLoading/TerryTruth.ZM
Normal file
Binary file not shown.
30
src/Home/CosmicGLDemos/TextureLoading/RenderTextures.CC
Normal file
30
src/Home/CosmicGLDemos/TextureLoading/RenderTextures.CC
Normal file
@ -0,0 +1,30 @@
|
||||
/* This demo shows how to initialize, import, and render textures. */
|
||||
|
||||
Cd(__DIR__);;
|
||||
|
||||
I64 wWC = 32; // Window width in columns (256px)
|
||||
I64 wHC = 32; // Window height in rows (256px)
|
||||
I64 wW = wWC * 8;
|
||||
I64 wH = wHC * 8;
|
||||
I64 wXC = 1; // Window x in columns
|
||||
I64 wYC = 2; // Window y in rows
|
||||
I64 wX = wXC * 8;
|
||||
I64 wY = wYC * 8;
|
||||
|
||||
SettingsPush;
|
||||
WinHorz(wXC, wXC + wWC - 1);
|
||||
WinVert(wYC, wYC + wHC - 1);
|
||||
DocClear;
|
||||
|
||||
CTex2D texture;
|
||||
Tex2DLoadBMP(&texture, "SaintTerry.bmp");
|
||||
|
||||
while (CharScan() == 0)
|
||||
{
|
||||
Tex2DDebugDisp(&texture, wX, wY);
|
||||
Sleep(1);
|
||||
}
|
||||
|
||||
Tex2DFree(&texture);
|
||||
SettingsPop;
|
||||
Exit;
|
BIN
src/Home/CosmicGLDemos/TextureLoading/SaintTerry.bmp
Normal file
BIN
src/Home/CosmicGLDemos/TextureLoading/SaintTerry.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 192 KiB |
BIN
src/Home/CosmicGLDemos/TexturedTriangle/MrGod.bmp
Normal file
BIN
src/Home/CosmicGLDemos/TexturedTriangle/MrGod.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 192 KiB |
119
src/Home/CosmicGLDemos/TexturedTriangle/UVMappedShader.CC
Normal file
119
src/Home/CosmicGLDemos/TexturedTriangle/UVMappedShader.CC
Normal file
@ -0,0 +1,119 @@
|
||||
/* This demo shows how to create a custom model format, import a texture, and
|
||||
program a shader to render a triangle. */
|
||||
|
||||
Cd(__DIR__);;
|
||||
|
||||
I64 wWC = 32; // Window width in columns (512px)
|
||||
I64 wHC = 32; // Window height in rows (512px)
|
||||
I64 wW = wWC * 8;
|
||||
I64 wH = wHC * 8;
|
||||
I64 wXC = 1; // Window x in columns
|
||||
I64 wYC = 2; // Window y in rows
|
||||
I64 wX = wXC * 8;
|
||||
I64 wY = (wYC + 4) * 8;
|
||||
|
||||
SettingsPush;
|
||||
WinHorz(wXC, wXC + wWC - 1);
|
||||
WinVert(wYC, wYC + wHC + 3);
|
||||
DocClear;
|
||||
|
||||
// Framebuffer Initialization
|
||||
CTex2D frameBuf;
|
||||
CTex2D depthBuf;
|
||||
|
||||
Tex2DInit(&frameBuf, TEX2D_RAW, wW, wH);
|
||||
Tex2DInit(&depthBuf, TEX2D_DEPTH, wW, wH);
|
||||
|
||||
// Clear framebuffer texture with black background
|
||||
CBGR24 cBlack;
|
||||
cBlack.r = 0; cBlack.g = 0; cBlack.b = 0;
|
||||
Tex2DColorFill(&frameBuf, cBlack);
|
||||
|
||||
// Importing BMP texture
|
||||
CTex2D texture;
|
||||
Tex2DLoadBMP(&texture, "MrGod.bmp");
|
||||
|
||||
// Create custom model format that is quite straightforward
|
||||
class MDL
|
||||
{
|
||||
I64 nTris;
|
||||
CTri *tri;
|
||||
CVec2 *uv;
|
||||
};
|
||||
|
||||
// Load it with a texture mapped triangle.
|
||||
MDL model;
|
||||
model.nTris = 1;
|
||||
model.tri = MAlloc(sizeof(CTri));
|
||||
model.tri[0].p[0].x = 0.0;
|
||||
model.tri[0].p[0].y = 0.8;
|
||||
model.tri[0].p[0].z = 0.0;
|
||||
model.tri[0].p[1].x = -0.8;
|
||||
model.tri[0].p[1].y = -0.4;
|
||||
model.tri[0].p[1].z = 0.0;
|
||||
model.tri[0].p[2].x = 0.8;
|
||||
model.tri[0].p[2].y = -0.4;
|
||||
model.tri[0].p[2].z = 0.0;
|
||||
model.uv = MAlloc(sizeof(CVec2)*3);
|
||||
// UVs commonly use coordinates of 0.0-1.0, although you can use direct pixel
|
||||
// coordinates if you use the pixel coordinate sampler in the shader.
|
||||
model.uv[0].x = 0.5;
|
||||
model.uv[0].y = 0.0898;
|
||||
model.uv[1].x = 0.07421875;
|
||||
model.uv[1].y = 0.73046875;
|
||||
model.uv[2].x = 0.9375;
|
||||
model.uv[2].y = 0.7305;
|
||||
|
||||
// In this example a class is not needed for the uniforms (unchanging
|
||||
// parameters), we only feed the pointer for the texture we want to sample.
|
||||
// to the shader.
|
||||
|
||||
// Generate a shader. Each vertex has a UV coordinate (coordinate that
|
||||
// maps to the texture), so we only need to pass one CVEC2 attribute
|
||||
// from the vertex shader to the fragment shader.
|
||||
CShader shd, shdB;
|
||||
shd.vertValues = MAlloc(sizeof(I64));
|
||||
shd.vertValues[0] = SHD_CVEC2; // UV coordinate
|
||||
shd.nVertValues = 1;
|
||||
|
||||
// The vertex shader gives the normalized device coordinates (screen coordinates
|
||||
// from -1.0 to 1.0) of each vertex of a specified triangle. Normally you would
|
||||
// do translations and perspective transforms, but here our model is already in
|
||||
// NDC. It also passes the UV coordinates of each vertex to the vertOutBuf to
|
||||
// be interpolated for the fragment shader.
|
||||
U0 vShader(CTri *tri, F64 *vertOutBuf, U8 *mdlPtr, U8 *uniforms, I64 iTri, I64 nTris)
|
||||
{
|
||||
MDL *mdl = mdlPtr;
|
||||
MemCopy(tri, &mdl->tri[iTri], sizeof(CTri));
|
||||
MemCopy(vertOutBuf, &mdl->uv[iTri*3], sizeof(CVec2)*3);
|
||||
}
|
||||
|
||||
// The fragment shader calculates what color an individual fragment (pixel)
|
||||
// should be. Here we use the interpolated UV coordinate from the fragInBuf to
|
||||
// sample the color from the texture.
|
||||
U0 fShader(CBGR24 *color, F64 *fragInBuf, U8 *uniforms)
|
||||
{
|
||||
// We will pass in the texture pointer through the uniform later
|
||||
// when we render.
|
||||
Tex2DSampleNorm(color, uniforms, fragInBuf[0], fragInBuf[1]);
|
||||
}
|
||||
|
||||
// Attach vertex and fragment shader
|
||||
shd.FragShd = &fShader;
|
||||
shd.VertShd = &vShader;
|
||||
|
||||
while (CharScan() == 0)
|
||||
{
|
||||
// Where &texture is you would usually feed in a pointer to uniforms,
|
||||
// however since the texture is the only value the shader needs,
|
||||
// we simply pass in that pointer.
|
||||
RenderTris(&shd, &frameBuf, &depthBuf, &model, &texture, 1);
|
||||
Tex2DDebugDisp(&frameBuf, wX, wY);
|
||||
Sleep(1);
|
||||
}
|
||||
|
||||
Tex2DFree(&frameBuf);
|
||||
Tex2DFree(&depthBuf);
|
||||
Tex2DFree(&texture);
|
||||
SettingsPop;
|
||||
Exit;
|
10
src/Home/Registry.CC
Normal file
10
src/Home/Registry.CC
Normal file
@ -0,0 +1,10 @@
|
||||
$TR,"Zenith"$
|
||||
$ID,2$$TR,"SysMessageFlags"$
|
||||
$ID,2$sys_message_flags[0]=0;
|
||||
$ID,-2$$TR,"SysRegVer"$
|
||||
$ID,2$registry_version=2.010;
|
||||
$ID,-2$$ID,-2$$TR,"Once"$
|
||||
$ID,2$$TR,"Zenith"$
|
||||
$ID,2$$ID,-2$$TR,"User"$
|
||||
$ID,2$$ID,-2$$ID,-2$$TR,"AutoComplete"$
|
||||
$ID,2$ac.col=98;ac.row=23;$ID,-2$
|
247
src/Zenith/CosmicGL/Docs/CosmicGLOverview.DD
Normal file
247
src/Zenith/CosmicGL/Docs/CosmicGLOverview.DD
Normal file
@ -0,0 +1,247 @@
|
||||
|
||||
$FG,5$Using this Library$FG$
|
||||
$HL,1$#include "MakeCosmicGL"$HL,0$
|
||||
$FG,2$Simply include MakeCosmicGL.CC located at the root of this repository in your
|
||||
project. The #include's beneath each title in the documentation are to help
|
||||
you find where these functions/classes are implemented.
|
||||
|
||||
$FG,5$Creating/Freeing Textures and Framebuffers$FG$
|
||||
$HL,1$#include "Texture"
|
||||
$HL,0$
|
||||
$FG,2$CTex2D is used for both textures and framebuffers:$FG$
|
||||
|
||||
$HL,1$U0 Tex2DInit(CTex2D *tex, I64 type, I64 w, I64 h);
|
||||
U0 Tex2DFree(CTex2D *tex);$HL,0$
|
||||
|
||||
$FG,2$Where $FG$$FG,9$type$FG$ $FG,2$can be:$FG$
|
||||
$FG,3$
|
||||
TEX2D_RAW$FG$ $FG,2$CBGR24 format$FG$
|
||||
$FG,3$TEX2D_DEPTH$FG$ $FG,2$F64 format$FG$
|
||||
$FG,3$TEX2D_WAD$FG$ $FG,2$WAD/BMP 8-bit 256-CBGR24 palette compression$FG$
|
||||
|
||||
$FG,2$Textures must be made for the frame and depth buffer, which can later be drawn
|
||||
to a window after the image is rendered onto them. Textures that you intend to
|
||||
use as render targets such as framebuffers can not be compressed:$FG$
|
||||
|
||||
$HL,1$CTex2D frameBuf, depthBuf;
|
||||
Tex2DInit(&frameBuf, TEX2D_RAW, 640, 480);
|
||||
Tex2DInit(&depthBuf, TEX2D_DEPTH, 640, 480);$HL,0$
|
||||
|
||||
$FG,5$Loading/Clearing Textures$FG$
|
||||
$FG,2$Tex2DInit merely allocates space, you can then clear the textures with the
|
||||
following:$FG$
|
||||
|
||||
$HL,1$U0 Tex2DColorFill(CTex2D *tex, CBGR24 color);
|
||||
U0 Tex2DDepthReset(CTex2D *tex);
|
||||
U0 Tex2DLoadWAD(CTex2D *tex, CWAD *wad, U8 *texName);
|
||||
$HL,0$
|
||||
$FG,5$Sampling Textures$FG$
|
||||
$FG,2$To sample a texture location (such as when texture mapping in a fragment
|
||||
shader), the following are available:$FG$
|
||||
|
||||
$HL,1$U0 Tex2DSampleNorm(CBGR24 *col, CTex2D *tex, F64 u, F64 v);$HL,0$ $FG,2$Samples with normalized 0.0-1.0 uv coordinates.$FG$
|
||||
$HL,1$U0 Tex2DSampleCoord(CBGR24 *col, CTex2D *tex, I64 u, I64 v);$HL,0$ $FG,2$Samples with raw pixel uv coordinates.$FG$
|
||||
|
||||
$FG,5$Displaying Textures$FG$
|
||||
$FG,2$All texture types can be rendered to the OS framebuffer. Textures and
|
||||
non-color data (depth) are rendered in grayscale.$FG$
|
||||
|
||||
$HL,1$U0 Tex2DDebugDisp(CTex2D *tex, I64 x, I64 y);$HL,0$ $FG,2$Copies directly to OS display buffer rather than window, will be replaced.$FG$
|
||||
|
||||
$FG,5$Loading Textures From Common Formats$FG$
|
||||
$HL,1$#include "TextureImport"
|
||||
$HL,0$
|
||||
$FG,5$WAD Textures$FG$
|
||||
$FG,2$WAD files were a common method of storing textures in early game engines,
|
||||
popularized by the DOOM/Quake/GldSrc engines. Textures are compressed with
|
||||
8-bit color pointing to a 256 24-bit color palette. See the WAD section to
|
||||
learn how to load the CWAD object to pass to this function.
|
||||
|
||||
$FG,2$Example WAD loading:$FG$
|
||||
$HL,1$
|
||||
CWAD wad;
|
||||
CTex2D tex;
|
||||
WADLoad(&wad, "Assets/Textures/HALFLIFE.WAD");
|
||||
Tex2DLoadWAD(&tex, &wad, "!waterblue");$HL,1$$HL,0$ $FG,2$The loader will initialize the texture.$FG$
|
||||
WADFree(&wad);
|
||||
$HL,0$
|
||||
$FG,5$BMP Images$FG$
|
||||
$FG,2$BMP images are an extremely simple format to read. You can load 24-bit uncompressed
|
||||
BMPs like so:$FG$
|
||||
|
||||
$HL,1$CTex2D tex;
|
||||
Tex2DLoadBMP(&tex, "SaintTerry.bmp");$HL,0$ $FG,2$The loader will initialize the texture.$FG$
|
||||
|
||||
$FG,5$Loading and Reading WAD Files$FG$
|
||||
$HL,1$#include "WAD/WADTypes"
|
||||
#include "WAD/WAD"$HL,0$
|
||||
$FG,2$WAD files are a general purpose format for storing a flat hierarchy of
|
||||
directories called "lumps." They were first used by the DOOM engine to hold
|
||||
game assets, however they have been used by subsequent engines such as Quake
|
||||
and GldSrc to hold textures. The general purpose WAD manipulation functions
|
||||
below can be used to access all WAD formats, although some functionality from
|
||||
other functions may be limited to specific WAD types.$FG$
|
||||
$HL,1$
|
||||
U0 WADLoad(CWAD *wad, U8 *fname);
|
||||
U0 WADFree(CWAD *wad);
|
||||
$HL,0$
|
||||
$FG,2$WAD types:$FG$$FG,3$
|
||||
WAD_TYPE_HL
|
||||
WAD_TYPE_DOOM
|
||||
$FG$
|
||||
$FG,5$Lumps$FG$
|
||||
$FG,2$These are named directories with no hierarchy. The format for lumps is slightly
|
||||
different for DOOM and Quake/Half-Life WADs, so a CWADFileLump union is available
|
||||
to pass general purpose lump pointers.
|
||||
|
||||
Lump classes:$FG$
|
||||
$HL,1$class CWADFileLumpDoom;
|
||||
class CWADFileLumpHL;
|
||||
class CWADFileLump;$HL,0$
|
||||
|
||||
$FG,2$CWADFileLump can be "interpreted" as either with:$FG$
|
||||
CWADFileLump.doom
|
||||
CWADFileLump.hl
|
||||
|
||||
$FG,2$CWAD has an internal hash file for fast lump reading. To find a lump by name, use:$FG$
|
||||
|
||||
$HL,1$I64 WADFindLump(CWAD *wad, U8 *name, CWADFileLump **lump=NULL);$HL,0$
|
||||
|
||||
$FG,2$It returns the lump index, or -1 if not found. **lump can be optionally used to get
|
||||
the handle to the target lump.$FG$
|
||||
|
||||
$FG,5$Shaders$FG$
|
||||
$HL,1$#include "Shader"
|
||||
$HL,0$
|
||||
$FG,2$Shaders are functions that calculate the vertex positions of each triangle in
|
||||
NDC (normalized device coordinates), and then calculate the color of each
|
||||
individual fragment (pixel) within the triangles. You can use any model format
|
||||
you like, as you get to decide what vertex coordinates are returned for each
|
||||
triangle. $FG$
|
||||
|
||||
$FG,5$Uniforms$FG$
|
||||
$FG,2$Uniforms are unchanging values that will be used by the shader for every
|
||||
triangle in the model. These are often values like transformation matrices,
|
||||
texture pointers, or any other material parameters you need. You can provide a
|
||||
pointer to your uniforms to use in the shader.$FG$
|
||||
|
||||
$FG,5$Vertex to Fragment Vertex Attributes$FG$
|
||||
$FG,2$The vertex shader returns not only the coordinates of the vertices for each
|
||||
triangle, but also other attributes such as UV coordinates, normals, colors,
|
||||
etc. Every time the fragment shader is called, the interpolated attributes
|
||||
for that frag (pixel) are given to the shader.)
|
||||
|
||||
$FG,2$You can choose the structure of the F64 array of attributes to be interpolated
|
||||
by setting the nVertValues and *vertValues from CShader:$FG$
|
||||
$HL,1$
|
||||
CShader shd;
|
||||
shd.nVertValues = 2; $FG,2$In this example, the vertex shader will pass two attributes.$FG$
|
||||
shd.vertValues = MAlloc(2 * sizeof(I64));
|
||||
shd.vertValues[0] = SHD_CVEC2; $FG,2$For passing UV coordinate to fragment shader.$FG$
|
||||
shd.vertValues[1] = SHD_CVEC3;$HL,0$ $FG,2$For passing normal to fragment shader.$FG$
|
||||
|
||||
$FG,2$Where the vertValues can be of type:$FG$
|
||||
$FG,3$
|
||||
SHD_F64
|
||||
SHD_CVEC2
|
||||
SHD_CVEC3
|
||||
SHD_CVEC4
|
||||
SHD_CMat4
|
||||
$FG$
|
||||
$FG,5$Vertex Shader$FG$
|
||||
$FG,2$The purpose of the vertex shader is to calculate each triangle's vertex
|
||||
coordinates in NDC (noramalized device coordinates). The renderer will "plot"
|
||||
or rasterize these coordinates to the specified render target texture.
|
||||
Fragments outside of the -1:1 range will not be rendered (as they are
|
||||
off-texture). $FG$
|
||||
|
||||
$SP,"NDC Coordinates:",BI=1$
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$HL,1$U0 (*VertShd)(CTri *tri, F64 *vertOutBuf,, U8 *mdlPtr, U8 *uniforms, I64 iTri, i64 nTris);$HL,0$
|
||||
|
||||
$FG,3$*tri$FG$ $FG,2$OUTPUT: Final triangle coordinates in NDC$FG$
|
||||
$FG,3$*mdlPtr$FG$ $FG,2$INPUT: Pointer to model data.$FG$
|
||||
$FG,3$*vertOutBuf$FG$ $FG,2$OUTPUT: Array of attributes to be interpolated for the frag shader. In order of: [V0 Attr, V1 Attr, V2 Attr] $FG$
|
||||
$FG,3$*uniforms$FG$ $FG,2$INPUT: Pointer to uniforms.$FG$
|
||||
$FG,3$iTri$FG$ $FG,2$INPUT: Current triangle.$FG$
|
||||
$FG,3$nTris$FG$ $FG,2$INPUT: Total number of triangles in model.$FG$
|
||||
|
||||
$FG,2$Example of creating and attaching a vertex shader to a CShader:$FG$
|
||||
|
||||
$HL,1$CShader shd;
|
||||
U0 vShader(CTri *tri, F64 *vertOutBuf, U8 *mdlPtr, U8 *uniforms, I64 iTri, I64 nTris)
|
||||
{
|
||||
// Set *tri with the iTri from mdlPtr.
|
||||
}
|
||||
shd.VertShd = &vShader;$HL,0$
|
||||
|
||||
$FG,5$Fragment Shader$FG$
|
||||
$FG,2$The fragment shader returns the CBGR24 color for a particular fragment (pixel).
|
||||
It takes uniforms as well as interpolated values from the vertex shader to
|
||||
calculate each frag's color.
|
||||
|
||||
For example, each vertex of a triangle may have a UV coordinate pointing to the
|
||||
part of the texture it maps to. The three UV coordinate attributes from the
|
||||
vertex shader will be interpolated into one UV coordinate sent to the fragment
|
||||
shader. The fragment shader can then sample that pixel color from the texture
|
||||
included in the uniforms and return that color. Fragment shaders can be used
|
||||
for all sorts of purposes, including rendering lighting, shadows, warping,
|
||||
color filtering, etc.$FG$
|
||||
|
||||
$HL,1$U0 (*FragShd)(CBGR24 *color, F64 *fragInBuf, U8 *uniforms);$HL,0$
|
||||
|
||||
$FG,2$Fragment shaders can be created and attached in the same way as vertex shaders:$FG$
|
||||
|
||||
$HL,1$CShader shd;
|
||||
U0 fShader(CBGR24 *color, F64 *fragInBuf, U8 *uniforms)
|
||||
{
|
||||
// Set *color using interpolated F64's from fragInBuf and uniforms
|
||||
}
|
||||
shd.FragShd = &fShader;$HL,0$
|
||||
|
||||
|
||||
|
||||
$FG,5$Rendering$FG$
|
||||
$HL,1$#include "Math"
|
||||
#include "Rasterize"
|
||||
$HL,0$
|
||||
$FG,2$After models, textures, and shaders are initialized, you can render with these
|
||||
functions. Currently only triangles can be rendered, however support for all
|
||||
sprite primitives will be added for performance and ease of use (saves the
|
||||
steps of rendering textured triangles to draw 2D primitives like in GPU
|
||||
libraries).$FG$
|
||||
$HL,1$
|
||||
U0 RenderTris(CShader *shd, CTex2D *frameBuf, CTex2D *depthBuf, U8 *mdl, U8 *uniforms, I64 nTris);
|
||||
$HL,0$
|
||||
|
||||
|