Convert Figma logo to code with AI

jdah logominecraft-weekend

Minecraft, but I made it in 48 hours.

3,943
429
3,943
39

Top Related Projects

10,380

A simple Minecraft clone written in C using modern OpenGL (shaders).

An implementation of OpenGL 3.x-ish in clean C

I challenged myself to see if I could create a voxel game (Minecraft-like) in just one week using C++ and OpenGL, and here is the result

10,589

Minetest is an open source voxel game-creation platform with easy modding and game creation

Code repository of all OpenGL chapters from the book and its accompanying website https://learnopengl.com

Quick Overview

Minecraft-weekend is a project that recreates a basic version of Minecraft in C using modern OpenGL (core profile). It was developed over a weekend as a challenge and serves as an educational resource for those interested in game development and graphics programming.

Pros

  • Demonstrates how to create a voxel-based game engine from scratch
  • Uses modern OpenGL techniques, providing a good learning resource for graphics programming
  • Compact codebase that can be studied and understood relatively quickly
  • Includes basic Minecraft-like features such as world generation and block manipulation

Cons

  • Limited feature set compared to the full Minecraft game
  • May require some graphics programming knowledge to fully understand and modify
  • Not actively maintained or updated
  • Performance may not be optimized for large-scale worlds or complex scenes

Code Examples

// Example of chunk generation
void chunk_generate(chunk_t *chunk) {
    for (int x = 0; x < CHUNK_SIZE; x++) {
        for (int z = 0; z < CHUNK_SIZE; z++) {
            int height = noise2d(chunk->position.x * CHUNK_SIZE + x, chunk->position.z * CHUNK_SIZE + z) * 32 + 64;
            for (int y = 0; y < CHUNK_SIZE; y++) {
                int real_y = chunk->position.y * CHUNK_SIZE + y;
                if (real_y < height) {
                    chunk_set_block(chunk, (ivec3s) {{ x, y, z }}, BLOCK_GRASS);
                }
            }
        }
    }
}

This code snippet demonstrates how chunks are generated using noise functions to create terrain.

// Example of rendering a chunk
void chunk_render(chunk_t *chunk) {
    if (!chunk->mesh.vao) {
        return;
    }

    mat4s model = glms_translate(glms_mat4_identity(), chunk->position);
    shader_set_mat4(&chunk_shader, "model", model);
    glBindVertexArray(chunk->mesh.vao);
    glDrawArrays(GL_TRIANGLES, 0, chunk->mesh.vertex_count);
}

This code shows how chunks are rendered using OpenGL, applying transformations and drawing the mesh.

// Example of player movement
void player_move(player_t *player, vec3s direction) {
    player->velocity = glms_vec3_add(player->velocity, glms_vec3_scale(direction, PLAYER_SPEED));
    player->position = glms_vec3_add(player->position, player->velocity);
    player->velocity = glms_vec3_scale(player->velocity, PLAYER_FRICTION);
}

This snippet illustrates how player movement is handled, updating position and velocity.

Getting Started

To get started with minecraft-weekend:

  1. Clone the repository: git clone https://github.com/jdah/minecraft-weekend.git
  2. Install dependencies (OpenGL, GLFW, CGLM)
  3. Build the project: make
  4. Run the executable: ./minecraft

Note that you may need to adjust the Makefile or use CMake depending on your system configuration.

Competitor Comparisons

10,380

A simple Minecraft clone written in C using modern OpenGL (shaders).

Pros of Craft

  • Written in C, potentially offering better performance
  • More mature project with a larger community and more contributions
  • Includes multiplayer functionality out of the box

Cons of Craft

  • Less faithful to original Minecraft aesthetics and mechanics
  • More complex codebase, potentially harder for beginners to understand
  • Lacks some advanced features present in Minecraft-Weekend

Code Comparison

Craft (terrain generation):

for (int x = 0; x < size; x++) {
    for (int z = 0; z < size; z++) {
        float f = simplex2(x * 0.01, z * 0.01, 4, 0.5, 2);
        int h = (f + 1) / 2 * 32 + 16;
        for (int y = 0; y < h; y++) {
            set_block(x, y, z, 1);
        }
    }
}

Minecraft-Weekend (terrain generation):

for (int x = 0; x < CHUNK_SIZE; x++) {
    for (int z = 0; z < CHUNK_SIZE; z++) {
        float height = noise2d(x + chunk->x * CHUNK_SIZE, z + chunk->z * CHUNK_SIZE);
        int y = (int)(height * CHUNK_SIZE);
        for (int i = 0; i < y; i++) {
            chunk_set_block(chunk, x, i, z, BLOCK_GRASS);
        }
    }
}

Both projects use similar approaches for terrain generation, utilizing noise functions to create natural-looking landscapes. However, Minecraft-Weekend's implementation appears more closely aligned with Minecraft's chunk-based system.

An implementation of OpenGL 3.x-ish in clean C

Pros of PortableGL

  • More focused on providing a portable graphics library, making it potentially more versatile for different projects
  • Simpler codebase, easier to understand and modify for specific needs
  • Lighter weight, with fewer dependencies and a smaller overall footprint

Cons of PortableGL

  • Less feature-rich compared to Minecraft-weekend's game-specific implementation
  • May require more work to implement complex 3D rendering and game mechanics
  • Lacks the specific Minecraft-like voxel rendering optimizations

Code Comparison

PortableGL:

void gl_draw_triangle(GLContext *c, GLVertex *v0, GLVertex *v1, GLVertex *v2)
{
    // Triangle drawing implementation
}

Minecraft-weekend:

void chunk_render(Chunk *chunk, Camera *camera)
{
    // Chunk rendering implementation
}

The code snippets show the difference in focus between the two projects. PortableGL provides low-level graphics primitives, while Minecraft-weekend implements game-specific rendering functions.

I challenged myself to see if I could create a voxel game (Minecraft-like) in just one week using C++ and OpenGL, and here is the result

Pros of MineCraft-One-Week-Challenge

  • Uses C++ and SFML, which may be more familiar to some developers
  • Includes a basic GUI system for menus and HUD elements
  • Implements more advanced features like biomes and structures

Cons of MineCraft-One-Week-Challenge

  • Less optimized rendering and chunk loading compared to minecraft-weekend
  • Lacks some of the polish and refinement found in minecraft-weekend
  • Does not include multiplayer functionality

Code Comparison

MineCraft-One-Week-Challenge (C++):

void Chunk::makeMesh()
{
    m_mesh.reset(new Mesh);
    for (int y = 0; y < CHUNK_SIZE; ++y)
        for (int x = 0; x < CHUNK_SIZE; ++x)
            for (int z = 0; z < CHUNK_SIZE; ++z)
                addBlockToMesh(x, y, z);
}

minecraft-weekend (C):

void chunk_render(chunk_t *chunk) {
    for (int y = 0; y < CHUNK_H; y++) {
        for (int x = 0; x < CHUNK_W; x++) {
            for (int z = 0; z < CHUNK_D; z++) {
                block_render(chunk, x, y, z);
            }
        }
    }
}

Both projects use similar approaches for chunk rendering, iterating through blocks and adding them to the mesh. However, minecraft-weekend's implementation is in C, while MineCraft-One-Week-Challenge uses C++ with object-oriented principles.

10,589

Minetest is an open source voxel game-creation platform with easy modding and game creation

Pros of Minetest

  • More mature and feature-rich project with a larger community
  • Modular architecture allowing for extensive modding and customization
  • Cross-platform support (Windows, macOS, Linux, Android, FreeBSD)

Cons of Minetest

  • Less faithful recreation of Minecraft's original aesthetics and mechanics
  • Steeper learning curve for new players due to its modular nature
  • Potentially overwhelming number of mods and options for casual players

Code Comparison

Minecraft-weekend (C):

void world_set_block(World* self, ivec3s pos, Block block) {
    if (!WORLD_CONTAINS(pos)) {
        return;
    }
    self->blocks[pos.x][pos.y][pos.z] = block;
    world_set_dirty(self, pos);
}

Minetest (C++):

void Map::setNode(v3s16 p, const MapNode &n)
{
    MapBlock *block = getBlockNoCreateNoEx(p);
    if (block == NULL)
        return;
    block->setNode(p, n);
}

Both projects use similar approaches for setting blocks/nodes in the world, with Minetest's implementation being more object-oriented due to its use of C++.

Code repository of all OpenGL chapters from the book and its accompanying website https://learnopengl.com

Pros of LearnOpenGL

  • Comprehensive OpenGL tutorial series covering a wide range of topics
  • Well-structured learning path for beginners to advanced users
  • Extensive documentation and explanations for each concept

Cons of LearnOpenGL

  • Focuses solely on OpenGL, lacking game-specific implementations
  • May require additional resources for game development concepts
  • Less hands-on experience with a complete game project

Code Comparison

LearnOpenGL:

glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);

minecraft-weekend:

glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

Summary

LearnOpenGL provides a comprehensive OpenGL learning experience with detailed explanations and a structured approach. However, it lacks game-specific implementations and hands-on experience with a complete game project. minecraft-weekend offers a more focused approach to building a Minecraft-like game, providing practical experience in game development using OpenGL. The code comparison shows similarities in OpenGL usage, with minor differences in syntax and organization.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Minecraft, but I made it in 48 hours*

* I've actually updated it since - see this commit for the 48 hour version.

screenshot

Features:

  • Infinite, procedurally generated world
  • Infinite height/depth
  • Day/night cycle
  • Biomes
  • ECS-driven player and entities with full collision and movement
  • Full RGB lighting
  • Full transparency + translucency support
  • Sprite blocks (flowers)
  • Animated blocks (water + lava)
  • Distance fog
  • A whole lot of different block types
  • More

Building

Unix-like

$ git clone --recurse-submodules https://github.com/jdah/minecraft-weekend.git
$ make

The following static libraries under lib/ must be built before the main project can be built:

  • GLAD lib/glad/src/glad.o
  • CGLM lib/cglm/.libs/libcglm.a
  • GLFW lib/glfw/src/libglfw3.a
  • libnoise lib/noise/libnoise.a

All of the above have their own Makefile under their respective subdirectory and can be built with $ make libs. If libraries are not found, ensure that submodules have been cloned.

The game binary, once built with $ make, can be found in ./bin/.

Be sure to run with $ ./bin/game out of the root directory of the repository. If you are getting "cannot open file" errors (such as "cannot find ./res/shaders/*.vs"), this is the issue.

Windows

good luck 🤷‍♂️ probably try building under WSL and using an X environment to pass graphics through.