PrOGL
processing open-gl interface
Loading...
Searching...
No Matches
Renderer.pde
Go to the documentation of this file.
1// renderer.pde
2// samantha jane
3// takes a shader and a surface and renders
4//------------------------------------------------------------------------------
5
6/**
7 * PrOGL renderer.
8 * A self contained surface renderer.
9 */
10class Renderer {
11
12 Shader sh; /**< shader object */
13 PGraphics surface; /**< surface to render to */
14 PVector pos; /**< position within the window */
15 int w; /**< width to render the surface as */
16 int h; /**< height to render the surface as */
17
18 /**
19 * Renderer Constructor without Uniforms.
20 * This constructs the internal Shader object with only the default uniforms
21 * time, resolution, and mouse.
22 *
23 * @param path relative path to shader file
24 * @param w width of surface in pixels
25 * @param h height of surface in pixels
26 */
27 Renderer(String path, int w, int h) {
28 this.sh = new Shader(path, w, h);
29 this.surface = createGraphics(w, h, P2D);
30 this.pos = new PVector(0, 0);
31 this.w = w;
32 this.h = h;
33 }
34 /**
35 * Renderer Constructor with Uniform.
36 * This constructs the internal Shader object with the default uniforms
37 * along with whatever we add.
38 *
39 * @param path relative path to shader file
40 * @param w width of surface in pixels
41 * @param h height of surface in pixels
42 * @param uniform uniform object to initialize with shader
43 */
44 Renderer(String path, int w, int h, Uniform uniform) {
45 this.sh = new Shader(path, w, h, uniform);
46 this.surface = createGraphics(w, h, P2D);
47 this.pos = new PVector(0, 0);
48 this.w = w;
49 this.h = h;
50 }
51 /**
52 * Renderer Constructor with Uniforms.
53 * This constructs the internal Shader object with default uniforms
54 * and a list of other user defined Uniforms.
55 *
56 * @param path relative path to shader file
57 * @param w width of surface in pixels
58 * @param h height of surface in pixels
59 * @param uniforms an ArrayList of uniform objects to initialize
60 */
61 Renderer(String path, int w, int h, ArrayList<Uniform> uniforms) {
62 this.sh = new Shader(path, w, h, uniforms);
63 this.surface = createGraphics(w, h, P2D);
64 this.pos = new PVector(0, 0);
65 this.w = w;
66 this.h = h;
67 }
68
69 /**
70 * renders the shader and then draws it to the surface.
71 */
72 void render() {
73 update();
74 surface.beginDraw();
75 surface.shader(sh.program);
76 surface.rect(0, 0, surface.width, surface.height);
77 surface.endDraw();
78 image(surface, pos.x, pos.y);
79 }
80
81 /**
82 * attempts to update all updatable internal Uniforms.
83 */
84 void update() {
86 }
87
88 /**
89 * print Renderer class data for debugging purposes.
90 */
91 void print() {
92 println("Renderer:");
93 println("- shader : " + sh);
94 println("- surface : " + surface);
95 println("- dim(w,h) : " + w +", " + h);
96 println("- pos(x,y) : " + pos.x + ", " + pos.y);
97 println("----------------");
98 }
99}
PrOGL renderer.
Definition Renderer.pde:10
PGraphics surface
surface to render to
Definition Renderer.pde:13
Renderer(String path, int w, int h, ArrayList< Uniform > uniforms)
Renderer Constructor with Uniforms.
Definition Renderer.pde:61
PVector pos
position within the window
Definition Renderer.pde:14
Renderer(String path, int w, int h, Uniform uniform)
Renderer Constructor with Uniform.
Definition Renderer.pde:44
int h
height to render the surface as
Definition Renderer.pde:16
Shader sh
shader object
Definition Renderer.pde:12
void update()
attempts to update all updatable internal Uniforms.
Definition Renderer.pde:84
int w
width to render the surface as
Definition Renderer.pde:15
Renderer(String path, int w, int h)
Renderer Constructor without Uniforms.
Definition Renderer.pde:27
void render()
renders the shader and then draws it to the surface.
Definition Renderer.pde:72
void print()
print Renderer class data for debugging purposes.
Definition Renderer.pde:91
Shader object organizes a list of uniforms and a compiled PShader.
Definition Shader.pde:21
void update_uniforms()
update uniforms with an update function.
Definition Shader.pde:138
PShader program
OpenGL program binding.
Definition Shader.pde:22
organizes information for a single Uniform, including its underlying data type and update behavior.
Definition Uniform.pde:27