Template
mirror of
https://gitlab.com/raylibtemplates/rt.git
synced 2026-08-12 09:59:09 -04:00
Initial Commit
This commit is contained in:
+76
@@ -0,0 +1,76 @@
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
|
||||
#include "../data/cube.png.h"
|
||||
|
||||
#define SCREEN_WIDTH (320)
|
||||
#define SCREEN_HEIGHT (240)
|
||||
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
int main(void) {
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE |
|
||||
FLAG_WINDOW_MAXIMIZED | FLAG_VSYNC_HINT);
|
||||
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "game");
|
||||
SetWindowMinSize(320, 240);
|
||||
SetTargetFPS(60);
|
||||
|
||||
RenderTexture2D target = LoadRenderTexture(SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
SetTextureFilter(target.texture, TEXTURE_FILTER_POINT);
|
||||
|
||||
Image image =
|
||||
LoadImageFromMemory(".png", assets_cube_png, assets_cube_png_len);
|
||||
|
||||
Texture2D texture = LoadTextureFromImage(image);
|
||||
|
||||
Camera camera = {0};
|
||||
camera.position = (Vector3){0.0f, 0.0f, 5.0f};
|
||||
camera.target = (Vector3){0.0f, 0.0f, 0.0f};
|
||||
camera.up = (Vector3){0.0f, 1.0f, 0.0f};
|
||||
camera.fovy = 60.0f;
|
||||
camera.projection = CAMERA_PERSPECTIVE;
|
||||
|
||||
Model cube = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f));
|
||||
cube.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = texture;
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
|
||||
float scale = MIN((float)GetScreenWidth() / SCREEN_WIDTH,
|
||||
(float)GetScreenHeight() / SCREEN_HEIGHT);
|
||||
|
||||
BeginTextureMode(target);
|
||||
{
|
||||
ClearBackground(BLACK);
|
||||
BeginMode3D(camera);
|
||||
{
|
||||
cube.transform =
|
||||
MatrixMultiply(MatrixRotateXYZ(Vector3Scale(
|
||||
(Vector3){1.0f, 1.5f, 2.5f}, GetFrameTime())),
|
||||
cube.transform);
|
||||
DrawModel(cube, Vector3Zero(), 1.0f, WHITE);
|
||||
}
|
||||
EndMode3D();
|
||||
}
|
||||
EndTextureMode();
|
||||
|
||||
BeginDrawing();
|
||||
{
|
||||
ClearBackground(BLACK);
|
||||
DrawTexturePro(
|
||||
target.texture,
|
||||
(Rectangle){0.0f, 0.0f, (float)target.texture.width,
|
||||
(float)-target.texture.height},
|
||||
(Rectangle){
|
||||
(GetScreenWidth() - ((float)SCREEN_WIDTH * scale)) * 0.5f,
|
||||
(GetScreenHeight() - ((float)SCREEN_HEIGHT * scale)) * 0.5f,
|
||||
(float)SCREEN_WIDTH * scale, (float)SCREEN_HEIGHT * scale},
|
||||
(Vector2){0, 0}, 0.0f, WHITE);
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
CloseWindow();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user