generated from It-Club/RaylibTemplate-C
Initial commit
This commit is contained in:
7
src/consts.c
Normal file
7
src/consts.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "consts.h"
|
||||
|
||||
const int SCREEN_WIDTH = 320;
|
||||
const int SCREEN_HEIGHT = 240;
|
||||
|
||||
const int WIN_WIDTH = 1280;
|
||||
const int WIN_HEIGHT = 720;
|
||||
5
src/consts.h
Normal file
5
src/consts.h
Normal file
@@ -0,0 +1,5 @@
|
||||
extern const int SCREEN_WIDTH;
|
||||
extern const int SCREEN_HEIGHT;
|
||||
|
||||
extern const int WIN_WIDTH;
|
||||
extern const int WIN_HEIGHT;
|
||||
14
src/draw.c
Normal file
14
src/draw.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "draw.h"
|
||||
#include "main.h"
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
|
||||
void Draw() {
|
||||
ClearBackground(BLACK);
|
||||
DrawCircleV((Vector2){160.0f, 120.0f}, 120.0f, WHITE);
|
||||
BeginMode3D(cam);
|
||||
{
|
||||
DrawModel(cube, Vector3Zero(), 1.0f, WHITE);
|
||||
}
|
||||
EndMode3D();
|
||||
}
|
||||
1
src/draw.h
Normal file
1
src/draw.h
Normal file
@@ -0,0 +1 @@
|
||||
extern void Draw();
|
||||
86
src/main.c
Normal file
86
src/main.c
Normal file
@@ -0,0 +1,86 @@
|
||||
#include "main.h"
|
||||
#include "consts.h"
|
||||
#include "draw.h"
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
#include "update.h"
|
||||
#include <math.h>
|
||||
|
||||
#include "../data/cube.png.h"
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
static void MainLoop();
|
||||
|
||||
RenderTexture2D target;
|
||||
|
||||
Image texImg;
|
||||
Texture2D texture;
|
||||
|
||||
Camera3D cam;
|
||||
Model cube;
|
||||
|
||||
int main(void) {
|
||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
|
||||
InitWindow(WIN_WIDTH, WIN_HEIGHT, "game");
|
||||
SetTargetFPS(60);
|
||||
SetExitKey(KEY_BACKSPACE);
|
||||
|
||||
target = LoadRenderTexture(SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
SetTextureFilter(target.texture, TEXTURE_FILTER_POINT);
|
||||
|
||||
texImg = LoadImageFromMemory(".png", cube_png, cube_png_len);
|
||||
texture = LoadTextureFromImage(texImg);
|
||||
|
||||
cam = (Camera3D){0};
|
||||
cam.position = (Vector3){0.0f, 0.0f, sqrtf(3.0f)};
|
||||
cam.target = (Vector3){0.0f, 0.0f, 0.0f};
|
||||
cam.up = (Vector3){0.0f, 1.0f, 0.0f};
|
||||
cam.fovy = 60.0f;
|
||||
cam.projection = CAMERA_PERSPECTIVE;
|
||||
|
||||
cube = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f));
|
||||
cube.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = texture;
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(MainLoop, 0, 1);
|
||||
#else
|
||||
while (!WindowShouldClose())
|
||||
MainLoop();
|
||||
#endif
|
||||
CloseWindow();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void MainLoop() {
|
||||
int winWidth = GetScreenWidth(), winHeight = GetScreenHeight();
|
||||
float scale =
|
||||
MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT);
|
||||
|
||||
Update();
|
||||
|
||||
BeginTextureMode(target);
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
EndTextureMode();
|
||||
|
||||
BeginDrawing();
|
||||
{
|
||||
ClearBackground(BLACK);
|
||||
DrawTexturePro(
|
||||
target.texture,
|
||||
(Rectangle){0.0f, 0.0f, (float)SCREEN_WIDTH, (float)-SCREEN_HEIGHT},
|
||||
(Rectangle){(winWidth - ((float)SCREEN_WIDTH * scale)) * 0.5f,
|
||||
(winHeight - ((float)SCREEN_HEIGHT * scale)) * 0.5f,
|
||||
(float)SCREEN_WIDTH * scale, (float)SCREEN_HEIGHT * scale},
|
||||
(Vector2){0, 0}, 0.0f, WHITE);
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
9
src/main.h
Normal file
9
src/main.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "raylib.h"
|
||||
|
||||
extern RenderTexture2D target;
|
||||
|
||||
extern Image texImg;
|
||||
extern Texture2D texture;
|
||||
|
||||
extern Camera3D cam;
|
||||
extern Model cube;
|
||||
72
src/minshell.html
Normal file
72
src/minshell.html
Normal file
@@ -0,0 +1,72 @@
|
||||
<!doctype html>
|
||||
<html lang="en-us">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
|
||||
<style>
|
||||
body {
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
canvas.emscripten {
|
||||
border: 0px none;
|
||||
background-color: black;
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
<script type='text/javascript' src="https://cdn.jsdelivr.net/gh/eligrey/FileSaver.js/dist/FileSaver.min.js"> </script>
|
||||
<script type='text/javascript'>
|
||||
function saveFileFromMEMFSToDisk(memoryFSname, localFSname) // This can be called by C/C++ code
|
||||
{
|
||||
var isSafari = false; // Not supported, navigator.userAgent access is being restricted
|
||||
//var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
||||
var data = FS.readFile(memoryFSname);
|
||||
var blob;
|
||||
|
||||
if (isSafari) blob = new Blob([data.buffer], {type: "application/octet-stream"});
|
||||
else blob = new Blob([data.buffer], {type: "application/octet-binary"});
|
||||
|
||||
// NOTE: SaveAsDialog is a browser setting. For example, in Google Chrome,
|
||||
// in Settings/Advanced/Downloads section you have a setting:
|
||||
// 'Ask where to save each file before downloading' - which you can set true/false.
|
||||
// If you enable this setting it would always ask you and bring the SaveAsDialog
|
||||
saveAs(blob, localFSname);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<canvas class=emscripten id=canvas oncontextmenu=event.preventDefault() tabindex=-1></canvas>
|
||||
<p id="output" />
|
||||
<script>
|
||||
var Module = {
|
||||
print: (function () {
|
||||
var element = document.getElementById('output');
|
||||
if (element) element.value = ''; // clear browser cache
|
||||
return function (text) {
|
||||
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
|
||||
console.log(text);
|
||||
if (element) {
|
||||
element.value += text + "\n";
|
||||
element.scrollTop = element.scrollHeight; // focus on bottom
|
||||
}
|
||||
};
|
||||
})(),
|
||||
canvas: (function () {
|
||||
var canvas = document.getElementById('canvas');
|
||||
return canvas;
|
||||
})()
|
||||
};
|
||||
</script>
|
||||
{{{ SCRIPT }}}
|
||||
</body>
|
||||
|
||||
</html>
|
||||
11
src/update.c
Normal file
11
src/update.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "update.h"
|
||||
#include "main.h"
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
|
||||
void Update() {
|
||||
cube.transform =
|
||||
MatrixMultiply(MatrixRotateXYZ(Vector3Scale((Vector3){1.0f, 1.5f, 2.5f},
|
||||
GetFrameTime())),
|
||||
cube.transform);
|
||||
}
|
||||
1
src/update.h
Normal file
1
src/update.h
Normal file
@@ -0,0 +1 @@
|
||||
extern void Update();
|
||||
Reference in New Issue
Block a user