Coder Social home page Coder Social logo

aabduvak / fdf Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 2.27 MB

This project is about representing a landscape as a 3D object in which all surfaces are outlined in lines.

License: GNU General Public License v3.0

Makefile 4.42% C 64.59% Roff 14.16% Objective-C 16.83%
42 42cursus fdf graphics minilibx 42school 42istanbul

fdf's Introduction

🧰 42 Project: FDF

GitHub code size in bytes Number of lines of code Code language count GitHub top language GitHub last commit

Objective

In this project you will discover the basics of graphic programming, and in particular how to place points in space, how to join them with segments and most importantly how to observe the scene from a particular viewpoint. You will also discover your first graphic library: miniLibX. This library was developedninternally and includes the minimum necessary to open a window, light a pixel and deal with events linked to this window: keyboard and mouse. This project also introduces you to “events” programming. Don’t forget to watch the e-learning videos!

Skills

  • Graphics
  • Imperative programming
  • Algorithms & AI
  • Rigor

My grade

MiniLibx

MiniLibx is an in house graphics library for students at 42 to cry and curse over. The documentation is pretty limited, the provided library is out of date, but that is all part of the learning process.

The Minilibx library provided on the project page of 42, will not work on macOS Sierra or newer, but fortunately, you will find an updated one here. This is also a treasure trove of information and I recommend you spend more time there than you do here.

The minimum code to get started with MiniLibx is the following:

#include <mlx.h>
int main(void)
{
  void *mlx;
  void *window;
  
  mlx = mlx_init();
  window = mlx_new_window(mlx, 1000, 1000, "Title");
  
  mlx_loop(mlx);
  return (0);
}

And to compile the above code, you can use the following:

gcc -Wall -Wextra -Werror -I minilibx -L minilibx -lmlx -framework OpenGL -framework AppKit main.c

Bresenham's Line Algorithm

For fdf, we will be given a number of points to draw our wireframes from, but we will eventually need to draw lines between these points. While algorithms such as Wu's algorithm are also frequently used in modern computer graphics (thanks to it's support of antialiasing), the speed and simplicity of Bresenham's line algorithm means that it is still important today. It is commonly used to draw line primitives in a bitmap image (e.g. on a computer screen), as it uses only integer addition, subtraction and bit shifting, all of which are very cheap operations in standard computer architectures. It is one of the earliest algorithms developed in the field of computer graphics and thanks to it's simplicity, it is often implemented in either the firmware or the graphics hardware of modern graphics cards.

Below is a C implementation of Bresenham's Line Algorithm. Note that this will NOT pass the 42 Norminette, but making the changes should be simple enough!

// Instead of swaps in the initialisation, use error 
// calculation for both directions x and y simultaneously 
void line(int x0, int y0, int x1, int y1) {
 
  int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
  int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1; 
  int err = (dx>dy ? dx : -dy)/2, e2;
 
  for(;;){
    setPixel(x0,y0);
    if (x0==x1 && y0==y1) break;
    e2 = err;
    if (e2 >-dx) { err -= dy; x0 += sx; }
    if (e2 < dy) { err += dx; y0 += sy; }
  }
}

References:

Hex Colors

The colors provided in some of the maps for fdf are in Hexadecimal. The below link can provide a very quick and rudimentary understanding of how hex-colors work.

Reference:

Screenshots

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.