GithubHelp home page GithubHelp logo

ichi-raven / opensiv3d Goto Github PK

View Code? Open in Web Editor NEW

This project forked from siv3d/opensiv3d

0.0 1.0 0.0 1.03 GB

πŸ¦– C++20 framework for creative coding

Home Page: https://siv3d.github.io/

License: MIT License

C++ 84.63% Objective-C++ 0.94% CMake 0.85% HLSL 1.04% GLSL 1.92% AngelScript 0.16% C 10.17% Objective-C 0.03% JavaScript 0.24% Metal 0.02%

opensiv3d's Introduction

OpenSiv3D

Siv3D logo

OpenSiv3D is a C++20 framework for creative coding.

v0.6.0 beta 5 (pre-release)

SDK Downloads

Platform Version Date Requirements
Windows 0.6.0 beta 5 2 September 2021 - Windows 7 SP1 / 8.1 / Windows 10 (64-bit)
- Microsoft Visual C++ 2019 16.10
- Windows 10 SDK
- Intel / AMD CPU
macOS 0.6.0 beta 5 2 September 2021 - macOS Mojave / Catalina / Big Sur
- Xcode 11.3 or newer (Big Sur requires Xcode 12.5)
- Intel CPU
- OpenGL 4.1 compatible graphics card
Linux 0.6.0 beta 5* 2 September 2021 - GCC 9.3.0
- Intel / AMD CPU
- OpenGL 4.1 compatible graphics card
Web (experimental) 0.6.0b0* August 2021 - Emscripten 2.0.22 or newer
- Browser with WebAssembly and WebGL2 support

* Some functionality may be missing or limited

Installation Guide & Documentation (v0.6.0)

v0.4.3 (stable)

Installation Guide & Documentation (v0.4.3)

SDK Downloads

Platform Version Date Requirements
Windows 0.4.3 11 April 2020 - Windows 7 SP1 / 8.1 / 10 (64-bit)
- Microsoft Visual C++ 2019 16.4
- Windows 10 SDK
macOS 0.4.3 11 April 2020 - macOS Mojave v10.14 or newer
- Xcode 11.3 or newer
- OpenGL 4.1 compatible graphics card
Linux 0.4.3* 11 April 2020 - Tested compilers: Clang 8.0.1 / GCC 9.1.0
- OpenGL 4.1 compatible graphics card

Examples (v0.6.0)

1. Hello, Siv3D!

Screenshot

# include <Siv3D.hpp>

void Main()
{
	// Set background color to sky blue
	Scene::SetBackground(ColorF{ 0.8, 0.9, 1.0 });

	// Create a new font
	const Font font{ 60 };
	
	// Create a new emoji font
	const Font emojiFont{ 60, Typeface::ColorEmoji };
	
	// Set emojiFont as a fallback
	font.addFallback(emojiFont);

	// Create a texture from an image file
	const Texture texture{ U"example/windmill.png" };

	// Create a texture from an emoji
	const Texture emoji{ U"🐈"_emoji };

	// Coordinates of the emoji
	Vec2 emojiPos{ 300, 150 };

	// Print a text
	Print << U"Push [A] key";

	while (System::Update())
	{
		// Draw a texture
		texture.draw(200, 200);

		// Put a text in the middle of the screen
		font(U"Hello, Siv3D!πŸš€").drawAt(Scene::Center(), Palette::Black);

		// Draw a texture with animated size
		emoji.resized(100 + Periodic::Sine0_1(1s) * 20).drawAt(emojiPos);

		// Draw a red transparent circle that follows the mouse cursor
		Circle{ Cursor::Pos(), 40 }.draw(ColorF{ 1, 0, 0, 0.5 });

		// When [A] key is down
		if (KeyA.down())
		{
			// Print a randomly selected text
			Print << Sample({ U"Hello!", U"こんにけは", U"δ½ ε₯½", U"μ•ˆλ…•ν•˜μ„Έμš”?" });
		}

		// When [Button] is pushed
		if (SimpleGUI::Button(U"Button", Vec2{ 640, 40 }))
		{
			// Move the coordinates to a random position in the screen
			emojiPos = RandomVec2(Scene::Rect());
		}
	}
}

2. Breakout

Screenshot

# include <Siv3D.hpp>

void Main()
{
	constexpr Size brickSize{ 40, 20 };
	
	constexpr double speed = 480.0;
	
	Vec2 ballVelocity{ 0, -speed };
	
	Circle ball{ 400, 400, 8 };

	Array<Rect> bricks;
	for (auto p : step(Size{ (Scene::Width() / brickSize.x), 5 }))
	{
		bricks << Rect{ (p.x * brickSize.x), (60 + p.y * brickSize.y), brickSize };
	}

	while (System::Update())
	{
		const Rect paddle{ Arg::center(Cursor::Pos().x, 500), 60, 10 };

		ball.moveBy(ballVelocity * Scene::DeltaTime());

		for (auto it = bricks.begin(); it != bricks.end(); ++it)
		{
			if (it->intersects(ball))
			{
				(it->bottom().intersects(ball) || it->top().intersects(ball)
					? ballVelocity.y : ballVelocity.x) *= -1;

				bricks.erase(it);
				break;
			}
		}

		if (ball.y < 0 && ballVelocity.y < 0)
		{
			ballVelocity.y *= -1;
		}

		if ((ball.x < 0 && ballVelocity.x < 0)
			|| (Scene::Width() < ball.x && 0 < ballVelocity.x))
		{
			ballVelocity.x *= -1;
		}

		if (0 < ballVelocity.y && paddle.intersects(ball))
		{
			ballVelocity = Vec2{ (ball.x - paddle.center().x) * 10, -ballVelocity.y }.setLength(speed);
		}

		for (const auto& brick : bricks)
		{
			brick.stretched(-1).draw(HSV{ brick.y - 40 });
		}

		ball.draw();
		paddle.draw();
	}
}

3. Hello, 3D world!

Screenshot

# include <Siv3D.hpp>

void Main()
{
	// Resize the window and scene to 1280x720
	Window::Resize(1280, 720);

	// Background color (remove SRGB curve for a linear workflow)
	const ColorF backgroundColor = ColorF{ 0.4, 0.6, 0.8 }.removeSRGBCurve();

	// Texture for UV check (mipmapped. treat as SRGB texture in a linear workflow)
	const Texture uvChecker{ U"example/texture/uv.png", TextureDesc::MippedSRGB };

	// Multisample RenderTexture for a linear workflow
	const MSRenderTexture renderTexture{ Scene::Size(), TextureFormat::R8G8B8A8_Unorm_SRGB, HasDepth::Yes };

	// 3D debug camera (free camera)
	// Vertical FOV: 30Β°, Eye position: (10, 16, -32)
	// Move: [W][S][A][D][E][X], View: [arrow keys]
	DebugCamera3D camera{ renderTexture.size(), 30_deg, Vec3{ 10, 16, -32 } };

	while (System::Update())
	{
		// Update a camera
		camera.update(2.0);

		// Set up a camera in the current 3D scene
		Graphics3D::SetCameraTransform(camera);

		// [3D rendering]
		{
			// Clear renderTexture with the background color,
			// then make renderTexture the render target for the current 3D scene
			const ScopedRenderTarget3D target{ renderTexture.clear(backgroundColor) };

			// Draw a floor
			Plane{ 64 }.draw(uvChecker);

			// Draw a box
			Box{ -8,2,0,4 }.draw(ColorF{ 0.8, 0.6, 0.4 }.removeSRGBCurve());

			// Draw a sphere
			Sphere{ 0,2,0,2 }.draw(ColorF{ 0.4, 0.8, 0.6 }.removeSRGBCurve());

			// Draw a cylinder
			Cylinder{ 8, 2, 0, 2, 4 }.draw(ColorF{ 0.6, 0.4, 0.8 }.removeSRGBCurve());
		}

		// [2D rendering]
		{
			// Flush 3D rendering commands before multisample resolve
			Graphics3D::Flush();

			// Multisample resolve
			renderTexture.resolve();

			// Transfer renderTexture to the current 2D scene (default scene)
			Shader::LinearToScreen(renderTexture);
		}
	}
}

opensiv3d's People

Contributors

reputeless avatar wynd2608 avatar nokotan avatar azaika avatar kurokoji avatar ebishu-0309 avatar falrnd avatar taotao54321 avatar para7 avatar agehama avatar kestrel-90r avatar sthairno avatar fuyutsubaki avatar yurkth avatar chobby avatar yasai03 avatar shirry0129 avatar luke256 avatar jin3004 avatar ryoga-exe avatar ai2playgame avatar hota1024 avatar ianck avatar lriki avatar tyanmahou avatar sivboard avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.