/* * 3D Engine * display.h: * Based on pikuma.com 3D software renderer in C * Copyright (c) 2021 986-Studio. All rights reserved. * * Created by Manoƫl Trapier on 01/03/2021. */ #ifndef THREEDENGINE_SOURCE_INCLUDE_DISPLAY_H #define THREEDENGINE_SOURCE_INCLUDE_DISPLAY_H #include #include /*********************************************************************************************************************** * Data types **********************************************************************************************************************/ typedef uint32_t colour_t; /*********************************************************************************************************************** * Constants **********************************************************************************************************************/ #define FPS (60) #define FRAME_TARGET_TIME (1000 / FPS) /*********************************************************************************************************************** * Global variables **********************************************************************************************************************/ extern SDL_Window *window; extern SDL_Renderer *renderer; extern colour_t *frameBuffer; extern double *zBuffer; extern SDL_Texture *frameBufferTexture; extern int32_t windowWidth; extern int32_t windowHeight; extern bool doZBuffer; /*********************************************************************************************************************** * Prototypes **********************************************************************************************************************/ /* --- Window functions --- */ bool initialiseWindow(bool fullScreen); void destroyWindow(); void renderFrameBuffer(); /* --- Drawing functions --- */ void clearZBuffer(); void clearFrameBuffer(colour_t colour); void drawPixel(int32_t x, int32_t y, colour_t colour); void drawGrid(int spacing, colour_t colour); void drawRectangle(int32_t x, int32_t y, int32_t w, int32_t h, colour_t colour); void drawVLine(int32_t x, int32_t y0, int32_t y1, colour_t colour); void drawHLine(int32_t x0, int32_t y, int32_t x1, colour_t colour); void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, colour_t colour); void drawText(int32_t x, int32_t y, colour_t colour, const char *format, ...); static inline void intSwap(int *a, int *b) { int tmp = *a; *a = *b; *b = tmp; } static inline void doubleSwap(double *a, double *b) { double tmp = *a; *a = *b; *b = tmp; } #define MAKE_RGB(_r, _g, _b) ((0xFF000000) | ((_b & 0xFF) << 16) | ((_g & 0xFF) << 8) | ((_r & 0xFF))) #define MAKE_ARGB(_a, _r, _g, _b) (((_a & 0xFF) << 24) | ((_g & 0xFF) << 16) | ((_g & 0xFF) << 8) | ((_r & 0xFF))) #endif /* THREEDENGINE_SOURCE_INCLUDE_DISPLAY_H */