|
GrooveStomp's 3D Software Renderer
0.1.0
|
#include <string.h>#include <stdio.h>#include "SDL2/SDL.h"#include "math.h"#include "graphics.h"#include "texture.h"#include "color.h"
Classes | |
| struct | graphics |
| Graphics state. More... | |
Functions | |
| void | swap_generic (void *v1, void *v2, size_t size) |
| A mostly generic implementation of swap. More... | |
| struct graphics * | GraphicsInit (char *title, int width, int height, int scale) |
| Creates and initializes a new graphics object isntance. More... | |
| void | GraphicsDeinit (struct graphics *g) |
| De-initializes and frees memory for the given graphics object. More... | |
| void | GraphicsBegin (struct graphics *graphics) |
| Initializes the graphics subsystem for drawing routines. More... | |
| void | GraphicsEnd (struct graphics *graphics) |
| Prepares the graphics subsystem for presentation, then presents. More... | |
| void | GraphicsClearScreen (struct graphics *graphics, unsigned int color) |
| Sets all pixels in the screen to the given color. More... | |
| void | PutPixelScaled (struct graphics *graphics, int x, int y, unsigned int color) |
| Scale the pixel being drawn. More... | |
| void | PutPixel (struct graphics *graphics, int x, int y, unsigned int color) |
| Put a pixel into the graphics buffer. More... | |
| void | GraphicsDrawLine (struct graphics *graphics, int x1, int y1, int x2, int y2, unsigned int color) |
| Draws a line from (x1,y1) to (x2,y2) More... | |
| void | GraphicsTriangleTextured (struct graphics *graphics, struct triangle tri, struct texture *texture) |
| Draw a textured triangle with the given set of x and y coordinates. More... | |
| void | GraphicsTriangleWireframe (struct graphics *graphics, struct triangle triangle, unsigned int color) |
| Draw a triangle with the given set of x and y coordinates. More... | |
| void | TriangleSolidDrawLine (struct graphics *graphics, int xmin, int xmax, int y, unsigned int color) |
| Used internally by GraphicsTriangleSolid() | |
| void | GraphicsTriangleSolid (struct graphics *graphics, struct triangle triangle, unsigned int color) |
| Draw a triangle with the given set of x and y coordinates. More... | |
| void GraphicsBegin | ( | struct graphics * | graphics | ) |
Initializes the graphics subsystem for drawing routines.
Internally locks streaming texture for direct manipulation.
| [in,out] | graphics | Graphics state to be manipulated |
| void GraphicsClearScreen | ( | struct graphics * | graphics, |
| unsigned int | color | ||
| ) |
Sets all pixels in the screen to the given color.
| [in,out] | graphics | Graphics state to be manipulated |
| [in] | color | 32-bit color with 8-bits per component: (R,G,B,A) |
| void GraphicsDeinit | ( | struct graphics * | graphics | ) |
De-initializes and frees memory for the given graphics object.
| [in,out] | graphics | The initialized opcode object to be cleaned and reclaimed |
| void GraphicsDrawLine | ( | struct graphics * | graphics, |
| int | x1, | ||
| int | y1, | ||
| int | x2, | ||
| int | y2, | ||
| unsigned int | color | ||
| ) |
Draws a line from (x1,y1) to (x2,y2)
Used by GraphicsTriangleWireframe() and GraphicsTriangleSolid()
| [in,out] | graphics | Graphics state to be manipulated |
| [in] | x1 | horizontal position of the line start. |
| [in] | y1 | vertical position of the line start. |
| [in] | x2 | horizontal position of the line end. |
| [in] | y2 | vertical position of the line end. |
| [in] | color | color to render the line with. |
| void GraphicsEnd | ( | struct graphics * | graphics | ) |
Prepares the graphics subsystem for presentation, then presents.
Internally unlocks streaming texture then calls presentation routines.
| [in,out] | graphics | Graphics state to be manipulated. |
| struct graphics* GraphicsInit | ( | char * | title, |
| int | width, | ||
| int | height, | ||
| int | scale | ||
| ) |
Creates and initializes a new graphics object isntance.
Scale can be specified as a non-negative number. This value is used to multiply both the width and the height and the pixel size of any drawing operations.
For example, specifying a scale of 2 would multiply the width by 2, the height by 2, and every pixel would be 2x2; so the total scale factor ends up being scale^2
| [in] | title | The title displayed in the window titlebar |
| [in] | width | Width of the display area of the window, in pixels |
| [in] | height | Height of the display are of the window, in pixels |
| [in] | scale | Size and rendering scale, natural number multiple |
| void GraphicsTriangleSolid | ( | struct graphics * | graphics, |
| struct triangle | triangle, | ||
| unsigned int | color | ||
| ) |
Draw a triangle with the given set of x and y coordinates.
Fills the specified polygon with the given color.
| [in,out] | graphics | Graphics state to be changed |
| [in] | triangle | The triangle to draw |
| [in] | color | What color the solid triangle should be rendered with |
| void GraphicsTriangleTextured | ( | struct graphics * | graphics, |
| struct triangle | tri, | ||
| struct texture * | texture | ||
| ) |
Draw a textured triangle with the given set of x and y coordinates.
Fills the specified polygon with the given texture.
| [in,out] | graphics | Graphics state to be changed |
| [in] | tri | The triangle to draw |
| [in] | texture | What texture to sample while drawing the solid triangle |
| void GraphicsTriangleWireframe | ( | struct graphics * | graphics, |
| struct triangle | triangle, | ||
| unsigned int | color | ||
| ) |
Draw a triangle with the given set of x and y coordinates.
Only draws the lines, doesn't fill the polygon.
| [in,out] | graphics | Graphics state to be changed |
| [in] | triangle | The triangle to draw |
| [in] | color | What color the wireframe should be rendered with |
| void PutPixel | ( | struct graphics * | graphics, |
| int | x, | ||
| int | y, | ||
| unsigned int | color | ||
| ) |
Put a pixel into the graphics buffer.
| [in,out] | graphics | Graphics state to be manipulated |
| [in] | x | horizontal position in display buffer (assuming no scaling) |
| [in] | y | vertical position in display buffer (assuming no scaling) |
| [in] | color | Color to put into display buffer |
| void PutPixelScaled | ( | struct graphics * | graphics, |
| int | x, | ||
| int | y, | ||
| unsigned int | color | ||
| ) |
Scale the pixel being drawn.
This renders the given pixel, scaled as per graphics->scale.
When the graphics state is initialized, a width and height are specified.
Internally the graphics state multiplies both of these values by the scale and stores a buffer of the resulting size. This function allows us to treat the resulting scaled buffer as if it were the original size requested.
| [in,out] | graphics | Graphics state to be manipulated |
| [in] | x | horizontal position in display buffer (assuming no scaling) |
| [in] | y | vertical position in display buffer (assuming no scaling) |
| [in] | color | Color to put into display buffer |
| void swap_generic | ( | void * | v1, |
| void * | v2, | ||
| size_t | size | ||
| ) |
A mostly generic implementation of swap.
Both v1 and v2 must point to data that is the same size, as specified in the size parameter.
| [in,out] | v1 | first value |
| [in,out] | v2 | second value |
| [in] | size | v1 and v2 must each be this size |
1.8.13