libc8
CHIP-8 utility library
Loading...
Searching...
No Matches
graphics_sdl2.c File Reference
#include "../graphics.h"
#include <SDL2/SDL.h>
#include <stdint.h>

Macros

#define RGB_R(i)   ((i >> 12) & 0xFF)
 
#define RGB_G(i)   ((i >> 8) & 0xFF)
 
#define RGB_B(i)   (i & 0xFF)
 

Functions

void c8_deinit_graphics (void)
 Deinitialize the graphics library.
 
uint8_t c8_init_graphics (void)
 Initialize the graphics library.
 
void c8_render (c8_display_t *display, int *colors)
 Render graphics.
 
int c8_tick (int *key)
 Process keypresses and delay based on clockspeed.
 

Detailed Description

Note
NOT EXPORTED

SDL2 graphics implementation. When SDL2 is defined, overrides weak graphics utility function definitions in graphics.c.

Macro Definition Documentation

◆ RGB_B

#define RGB_B (   i)    (i & 0xFF)

◆ RGB_G

#define RGB_G (   i)    ((i >> 8) & 0xFF)

◆ RGB_R

#define RGB_R (   i)    ((i >> 12) & 0xFF)

Function Documentation

◆ c8_deinit_graphics()

void c8_deinit_graphics ( void  )

Deinitialize the graphics library.

Deinitialize graphics system.

◆ c8_init_graphics()

uint8_t c8_init_graphics ( void  )

Initialize the graphics library.

Initialize graphics system.

Returns
1 if successful, 0 otherwise.

◆ c8_render()

void c8_render ( c8_display_t display,
int *  colors 
)

Render graphics.

Render the given display to the SDL2 window.

Parameters
displaydisplay_t to render
colorscolors to render

◆ c8_tick()

int c8_tick ( int *  key)

Process keypresses and delay based on clockspeed.

Grab current keypresses and delay execution to match clockspeed.

If a relevant key is pressed or released (see keyMap in this file), this function will update key accordingly.

Parameters
keypointer to int arr of keys
Returns
-2 if quitting, -1 if no key was pressed/released, else returns value of key pressed/released.