|
void | noLoop () |
| Stop the main application loop. More...
|
|
void | background (const glm::vec3 &color) |
| Set the background color. More...
|
|
|
virtual void | setup () |
| Override this method to perform setup before the main application loop. More...
|
|
virtual void | draw () |
| Override this method to draw. More...
|
|
virtual void | mouseMotion (int x, int y, int dx, int dy) |
| Override this method to respond to mouse movement. More...
|
|
virtual void | mouseDown (int button, int mods) |
| Override this method to respond to mouse press (button down) More...
|
|
virtual void | mouseUp (int button, int mods) |
| Override this method to respond to mouse press (button up) More...
|
|
virtual void | scroll (float dx, float dy) |
| Override this method to respond to scrolling the middle mouse button. More...
|
|
virtual void | keyUp (int key, int mods) |
| Override this method to respond to key presses (button up) More...
|
|
virtual void | keyDown (int key, int mods) |
| Override this method to respond to key presses (button down) More...
|
|
virtual void | resize (int width, int height) |
| Override this method to respond to window resizing. More...
|
|
|
bool | keyIsDown (int key) const |
| Query whether the given key is down @key The key to test. More...
|
|
bool | mouseIsDown (int button) const |
| Query whether the given mouse button is down. More...
|
|
glm::vec2 | mousePosition () const |
| Return the current mouse position (in screen coordinates)
|
|
float | dt () const |
| Return the amount of time since the previous frame (in seconds) More...
|
|
float | elapsedTime () const |
| Return the amount of time since the setup() was called (in seconds)
|
|
float | height () const |
| Return the window height in pixels.
|
|
float | width () const |
| Return the window width in pixels.
|
|
|
void | setWindowSize (int w, int h) |
| Set the size of the window in pixels. More...
|
|
void | setupOrthoScene (const glm::vec3 ¢er, const glm::vec3 &dim) |
| Initialize the projection and camera to fit the given dimensions and center using an orthographic projection. More...
|
|
void | setupPerspectiveScene (const glm::vec3 ¢er, const glm::vec3 &dim) |
| Initialize the projection and camera to fit the given dimensions and center using a perspective projection. More...
|
|
void | lookAt (const glm::vec3 &camPos, const glm::vec3 &camLook, const glm::vec3 &up=glm::vec3(0, 1, 0)) |
|
void | perspective (float fovRadians, float aspect, float near, float far) |
| Set the current projection to a perspective view. More...
|
|
void | ortho (float minx, float maxx, float miny, float maxy, float minz, float maxz) |
| Set the current projection to an orthographic view. More...
|
|
bool | cameraEnabled () const |
| Returns true if the camera controls are active; false otherwise. More...
|
|
void | setCameraEnabled (bool on) |
| Set whether the window's camera controls are active. More...
|
|
Manages the window and user input.
Override this class to create a custom application.
// Copyright 2020, Savvy Sine, Aline Normoyle
#include "agl/window.h"
class MyWindow : public agl::Window {
void draw() {
renderer.sphere();
}
};
int main() {
MyWindow window;
window.run();
}
virtual void agl::Window::draw |
( |
| ) |
|
|
inlineprotectedvirtual |
Override this method to draw.
// Copyright 2020, Savvy Sine, Aline Normoyle
#include "agl/window.h"
using glm::vec2;
using glm::vec3;
class MyWindow : public agl::Window {
void setup() {
renderer.setUniform("Fog.enabled", true);
renderer.setUniform("Fog.color", vec3(0.9f));
renderer.setUniform("Fog.minDist", 5.0f);
renderer.setUniform("Fog.maxDist", 9.0f);
renderer.setUniform("Material.specular", vec3(0.0));
renderer.setUniform("MainTexture.enabled", true);
renderer.setUniform("MainTexture.tile", vec2(10.0));
renderer.loadTexture("bricks", "../textures/bricks.png", 0);
renderer.texture("MainTexture.texture", "bricks");
setupPerspectiveScene(vec3(0.0), vec3(10.0));
background(vec3(0.9f));
}
void draw() {
renderer.scale(vec3(20.0f));
renderer.plane();
}
};
int main() {
MyWindow window;
window.run();
}
void agl::Window::ortho |
( |
float |
minx, |
|
|
float |
maxx, |
|
|
float |
miny, |
|
|
float |
maxy, |
|
|
float |
minz, |
|
|
float |
maxz |
|
) |
| |
|
protected |
Set the current projection to an orthographic view.
- Parameters
-
minx | The left side of the projection |
maxx | The right side of the projection |
miny | The bottom side of the projection |
maxy | The top side of the projection |
minz | The back side of the projection |
maxz | The front side of the projection |
If you are using Renderer from the Window class, you should call Window::ortho instead of this method.
An orthographic projection maintains parallel lines. All objects maintain their size regardless of distance to the camera. Only objects within the extents of the orthographic cuboid volume will be drawn.
The current shader should define the following uniform variables
uniform mat4 MVP A 4x4 matrix containing the product of projection * view * modelTransform
- See also
- setupOrthoScene(const glm::vec3&, const glm::vec3&)
void agl::Window::perspective |
( |
float |
fovRadians, |
|
|
float |
aspect, |
|
|
float |
near, |
|
|
float |
far |
|
) |
| |
|
protected |
Set the current projection to a perspective view.
- Parameters
-
fovRadians | The field of view |
aspect | The aspect ratio (width divided by height) of the screen |
near | The distance to the near plane from the camera |
far | The distance to the far plane from the camera |
If you are using Renderer from the Window class, you should call Window::perspective instead of this method.
Perspective projections foreshorten objects should that closer objects are larger than further objects. Only objects within the view volume will be drawn. For example, objects a distance further from the far plane will not be visible.
The current shader should define the following uniform variables
uniform mat4 MVP A 4x4 matrix containing the product of projection * view * modelTransform
- See also
- setupPerspectiveScene(const glm::vec3&, const glm::vec3&)
virtual void agl::Window::resize |
( |
int |
width, |
|
|
int |
height |
|
) |
| |
|
inlineprotectedvirtual |
Override this method to respond to window resizing.
- Parameters
-
width | The new window width |
height | The new window height |
// Copyright 2020, Savvy Sine, Aline Normoyle
#include "agl/window.h"
using glm::vec2;
using glm::vec3;
class MyWindow : public agl::Window {
void setup() {
setWindowSize(600, 400);
setCameraEnabled(false);
lookAt(vec3(0), vec3(0, 0, -2));
ortho(0, width(), 0, height(), -1, 1);
background(vec3(0));
renderer.loadShader("shadertoy",
"../shaders/shadertoy.vs",
"../shaders/shadertoy_raymarch_csg.fs");
}
void draw() {
renderer.beginShader("shadertoy");
renderer.setUniform("iGlobalTime", elapsedTime());
renderer.setUniform("iResolution", vec2(width(), height()));
renderer.translate(vec3(width()*0.5, height()*0.5, 0.0));
renderer.scale(vec3(width(), height(), 1.0f));
renderer.rotate(kPI/2, vec3(1, 0, 0));
renderer.plane();
renderer.endShader();
}
void resize(int width, int height) {
ortho(0, width, 0, height, -1, 1);
}
};
int main() {
MyWindow window;
window.run();
}
void agl::Window::run |
( |
| ) |
|
Opens the window and starts the main application loop.
// Copyright 2020, Savvy Sine, Aline Normoyle
#include "agl/window.h"
class MyWindow : public agl::Window {
void setup() {
setWindowSize(200, 200);
}
void draw() {
renderer.sphere();
}
};
int main() {
MyWindow window;
window.run();
}
This function should typically called from main after creating the Window object. This function invokes the user's setup() function and then repeatedly calls the user's draw() function. This function returns when the user closes the window (via the escape key or close menu button)
virtual void agl::Window::scroll |
( |
float |
dx, |
|
|
float |
dy |
|
) |
| |
|
inlineprotectedvirtual |
Override this method to respond to scrolling the middle mouse button.
- Parameters
-
dx | The change in the x direction (in scroll coordinates) |
dy | The change in the x direction (in scroll coordinates) |
// Copyright 2020, Savvy Sine, Aline Normoyle
#include "agl/window.h"
using glm::vec2;
using glm::vec3;
class MyWindow : public agl::Window {
void setup() {
renderer.setUniform("Fog.enabled", true);
renderer.setUniform("Fog.color", vec3(0.9f));
renderer.setUniform("Fog.minDist", 5.0f);
renderer.setUniform("Fog.maxDist", 9.0f);
renderer.setUniform("Material.specular", vec3(0.0));
renderer.setUniform("MainTexture.enabled", true);
renderer.setUniform("MainTexture.tile", vec2(10.0));
renderer.loadTexture("bricks", "../textures/bricks.png", 0);
renderer.texture("MainTexture.texture", "bricks");
setupPerspectiveScene(vec3(0.0), vec3(10.0));
background(vec3(0.9f));
}
void draw() {
renderer.scale(vec3(20.0f));
renderer.plane();
}
};
int main() {
MyWindow window;
window.run();
}
virtual void agl::Window::setup |
( |
| ) |
|
|
inlineprotectedvirtual |
Override this method to perform setup before the main application loop.
Use this method to load textures, load meshes, set the window size, and initialize the projection and view.
// Copyright 2020, Savvy Sine, Aline Normoyle
#include "agl/window.h"
using glm::vec2;
using glm::vec3;
class MyWindow : public agl::Window {
void setup() {
renderer.setUniform("Fog.enabled", true);
renderer.setUniform("Fog.color", vec3(0.9f));
renderer.setUniform("Fog.minDist", 5.0f);
renderer.setUniform("Fog.maxDist", 9.0f);
renderer.setUniform("Material.specular", vec3(0.0));
renderer.setUniform("MainTexture.enabled", true);
renderer.setUniform("MainTexture.tile", vec2(10.0));
renderer.loadTexture("bricks", "../textures/bricks.png", 0);
renderer.texture("MainTexture.texture", "bricks");
setupPerspectiveScene(vec3(0.0), vec3(10.0));
background(vec3(0.9f));
}
void draw() {
renderer.scale(vec3(20.0f));
renderer.plane();
}
};
int main() {
MyWindow window;
window.run();
}
- See also
- setWindowSize(int,int)
-
setupPerspectiveScene(const glm::vec3&, const glm::vec3&)
-
setupOrthoScene(const glm::vec3&, const glm::vec3&)
-
Renderer.loadTexture(const std::string&, const std::string&, int)
-
Renderer.loadCubemap(const std::string&, const std::string&, int)