KJB
|
Classes | |
class | Glew |
class | Opengl_callable |
Functions | |
template<bool bgr_format> | |
float * | to_gl_array (const Image &img) |
Allocate and build a float array representing the pixel data. More... | |
void | glRotate (const kjb::Quaternion &q) |
glRotate for a kjb::Quaternion. More... | |
void | glTranslate (const kjb::Vector &p) |
glTranslate for a kjb::Vector. More... | |
void | glTranslate (const kjb::Vector3 &p) |
glTranslate for a kjb::Vector3. More... | |
void | glVertex (const Vector &p) |
glVertex for a kjb::Vector. More... | |
void | glTranslate (const kjb::Vector2 &p) |
void | glVertex (const Vector2 &p) |
void | glVertex (const Vector3 &p) |
void | glVertex (const Vector4 &p) |
void | glColor (const Vector &color) |
glColor for a kjb::Vector. More... | |
void | glColor (const kjb::PixelRGBA &color) |
void | glColor (const Vector3 &color) |
void | glColor (const Vector4 &color) |
void | glLoadMatrix (const kjb::Matrix &m) |
glLoadMatrix for a kjb::Matrix. More... | |
void | glLoadMatrix (const kjb::Matrix_d< 4, 4 > &m) |
template<class Matrix_type > | |
void | glMultMatrix_disp_ (const Matrix_type &m) |
void | glMultMatrix (const kjb::Matrix &m) |
glMultMatrix for a kjb::Matrix. More... | |
void | glMultMatrix (const Matrix_d< 4, 4 > &m) |
void | gluBuild2DMipmaps (const Image &img) |
NEEDS COMMENTING!!!. More... | |
void | glTexImage2D (const Image &img) |
Copy kjb::Image into an opengl texture. More... | |
template<class ReturnVectorType , class VectorType > | |
ReturnVectorType | gluUnProject_dispatch_ (const VectorType &vertex, double *modelview, double *projection, int *viewport) |
Vector | gluUnProject (const Vector &vertex, double *modelview, double *projection, int *viewport) |
Wraps gluUnproject using kjb::Vertex. More... | |
Vector3 | gluUnProject (const Vector2 &vertex, double *modelview, double *projection, int *viewport) |
Vector3 | gluUnProject (const Vector3 &vertex, double *modelview, double *projection, int *viewport) |
void | gluLookAt (Matrix &M, const Vector &eye, const Vector &target, const Vector &up) |
Computes a gluLookAt matrix and multiplies it by the given matrix. More... | |
template<class Matrix_type > | |
void | glOrtho_disp_ (Matrix_type &state, double left, double right, double bottom, double top, double znear, double zfar) |
template void | glOrtho_disp_ (Matrix &state, double left, double right, double bottom, double top, double znear, double zfar) |
template void | glOrtho_disp_ (Matrix_d< 4, 4 > &state, double left, double right, double bottom, double top, double znear, double zfar) |
void | glOrtho (Matrix &state, double left, double right, double bottom, double top, double znear, double zfar) |
void | glOrtho (Matrix_d< 4, 4 > &state, double left, double right, double bottom, double top, double znear, double zfar) |
void | glClearDepthBuffer () |
void | glcolormask (bool b1, bool b2, bool b3, bool b4) |
void | glEnableLineSmooth () |
void | glDisableLineSmooth () |
void | default_init_opengl (unsigned int width=100, unsigned int height=100) |
Initializes OpenGL in a standard way. More... | |
size_t | get_viewport_width () |
Get current GL viewport width. More... | |
size_t | get_viewport_height () |
Get current GL viewport height. More... | |
Image | get_framebuffer_as_image () |
Read pixels from opengl's whole back-buffer into an image. More... | |
Matrix | get_modelview_matrix () |
Returns a copy of the current modelview matrix. More... | |
Matrix | get_projection_matrix () |
Returns a copy of the current projection matrix. More... | |
Vector | project (const Vector &x) |
Computes the window coordinates of the given point using current GL state. More... | |
Vector2 | project (const Vector3 &x) |
template<class ReturnVectorType , class VectorType > | |
ReturnVectorType | unproject_dispatch_ (const VectorType &vertex) |
Vector | unproject (const Vector &vertex) |
Unproject a point from screen coordinates to world coordinates. More... | |
Vector3 | unproject (const Vector2 &vertex) |
Vector3 | unproject (const Vector3 &vertex) |
void | draw_full_screen_quad (float z) |
bool | has_stencil_buffer () |
Returns true if OpenGL version supports stencil buffer (right?). More... | |
void | set_framebuffer (const Image &img) |
Puts the contents of an image into the framebuffer. More... | |
void | set_framebuffer (const Matrix &mat) |
Puts the contents of a matrix into the framebuffer. More... | |
void | set_framebuffer (const Int_matrix &mat) |
Puts the contents of a int matrix into the framebuffer. More... | |
Image | get_framebuffer_as_image (size_t x, size_t y, size_t width, size_t height) |
Read pixels from opengl's back-buffer into an image. More... | |
void | get_buffer_as_matrix_ (size_t x, size_t y, size_t width, size_t height, GLenum format, Matrix &result) |
void | get_framebuffer_as_matrix (size_t x, size_t y, size_t width, size_t height, Matrix &result) |
void | get_depth_buffer_as_matrix (size_t x, size_t y, size_t width, size_t height, Matrix &result) |
Matrix | get_framebuffer_as_matrix (size_t x, size_t y, size_t width, size_t height) |
Matrix | get_depth_buffer_as_matrix (size_t x, size_t y, size_t width, size_t height) |
Matrix | get_framebuffer_as_matrix () |
Read pixels from opengl's whole back-buffer into a matrix. More... | |
Matrix | get_depth_buffer_as_matrix () |
Read pixels from opengl's whole (back) depth-buffer into a matrix. More... | |
Int_matrix | get_framebuffer_as_int_matrix () |
Read pixels from opengl's whole back-buffer into a int matrix. More... | |
Int_matrix | get_framebuffer_as_int_matrix (size_t x, size_t y, size_t width, size_t height) |
void | bitmap_string (const std::string &s, double x, double y, void *font=NULL) |
Draws a bitmap string at the specified location. More... | |
void | move_in_plane (kjb::Vector3 &plane_pt, const kjb::Vector2 &new_pt) |
Translate a point so it projects to a screen point. More... | |
void | get_backprojection_line (const Vector2 &pt, Vector3 &line_pt, Vector3 &line_dir) |
Get backprojection line using current opengl state. More... | |
void | render_xz_plane_grid (double xmin, double xmax, double zmin, double zmax, double csz=1.0) |
Draw a grid representing the ground plane. More... | |
void | render_xy_plane_grid (double xmin, double xmax, double ymin, double ymax, double csz=1.0) |
Draw a grid representing the ground plane. More... | |
void | glLoadMatrix (const kjb::Matrix4 &m) |
glLoadMatrix for a kjb::Matrix4. More... | |
void | glMultMatrix (const kjb::Matrix4 &m) |
glLoadMatrix for a kjb::Matrix4. More... | |
void | glOrtho (Matrix4 &state, double left, double right, double bottom, double top, double znear, double zfar) |
void | uint_to_rgb (unsigned int i, unsigned char *rgb) |
unsigned int | rgb_to_uint (unsigned char rgb[3]) |
void | kjb_opengl_debug_display_buffer () |
Pop up a window displaying the opengl color buffer. More... | |
void | generate_video_frames (const boost::function0< void > &draw, const boost::function0< void > &tick, const size_t num_frames, const std::string &frame_out_fmt) |
Variables | |
const Vector3 | WHITE (1.0, 1.0, 1.0) |
const Vector3 | BLACK (0.0, 0.0, 0.0) |
const Vector3 | RED (1.0, 0.0, 0.0) |
const Vector3 | GREEN (0.0, 1.0, 0.0) |
const Vector3 | BLUE (0.0, 0.0, 1.0) |
const Vector3 | YELLOW (1.0, 1.0, 0.0) |
const Vector3 | CYAN (0.0, 1.0, 1.0) |
const Vector3 | MAGENTA (1.0, 0.0, 1.0) |
void kjb::opengl::bitmap_string | ( | const std::string & | s, |
double | x, | ||
double | y, | ||
void * | font | ||
) |
Draws a bitmap string at the specified location.
font | Glut font (default GLUT_BITMAP_8_BY_13) |
void kjb::opengl::default_init_opengl | ( | unsigned int | width, |
unsigned int | height | ||
) |
Initializes OpenGL in a standard way.
void kjb::opengl::draw_full_screen_quad | ( | float | z = 0.0 | ) |
z | Depth of the quad. Values must be insiderange [-1, 1], otherwise the quad might not appear. |
void kjb::opengl::generate_video_frames | ( | const boost::function0< void > & | draw, |
const boost::function0< void > & | tick, | ||
const size_t | num_frames, | ||
const std::string & | frame_out_fmt | ||
) |
Generate a set of video frames using opengl. User provides two callbacks: one to render the current scene, and one to advance the scene state.
To render an offscreen buffer, simply activate/bind the buffer before calling this.
draw | Draw callback. This should paint the current scene to the current opengl colorbuffer. This reads from the backbuffer by default, so the draw method should NOT include a call to swap the front and back buffers. |
tick | "Tick" callback. Calling this should advance the scene state by one frame |
num_frames | Number of frames to generate |
frame_fmt | Printf-formatted string representing filenames to draw frames to (e.g. frame_%03d.jpg). File extension will determine the image format used |
Generate a set of video frames using opengl.
void kjb::opengl::get_backprojection_line | ( | const Vector2 & | pt, |
Vector3 & | line_pt, | ||
Vector3 & | line_dir | ||
) |
Get backprojection line using current opengl state.
Use current opengl matrix state to get the backprojection line for a given screen point
pt | Point in OpenGL screen coordinates (bottom-left origin) |
line_pt | Output. point on the backprojection line |
line_dir | Output. direction vector for backprojection line |
void kjb::opengl::get_buffer_as_matrix_ | ( | size_t | x, |
size_t | y, | ||
size_t | width, | ||
size_t | height, | ||
GLenum | format, | ||
Matrix & | result | ||
) |
Retrieve pixels from an opengl buffer. all values will be between [0,1] unless some fancy glPixelTranfer tricks are in use.
format | The format of the pixel data. Specifies which buffer will be retrieved. See glReadPixels for valid values. |
void kjb::opengl::get_depth_buffer_as_matrix | ( | size_t | x, |
size_t | y, | ||
size_t | width, | ||
size_t | height, | ||
Matrix & | result | ||
) |
Matrix kjb::opengl::get_depth_buffer_as_matrix | ( | size_t | x, |
size_t | y, | ||
size_t | width, | ||
size_t | height | ||
) |
Matrix kjb::opengl::get_depth_buffer_as_matrix | ( | ) |
Read pixels from opengl's whole (back) depth-buffer into a matrix.
Image kjb::opengl::get_framebuffer_as_image | ( | ) |
Read pixels from opengl's whole back-buffer into an image.
Image kjb::opengl::get_framebuffer_as_image | ( | size_t | x, |
size_t | y, | ||
size_t | width, | ||
size_t | height | ||
) |
Int_matrix kjb::opengl::get_framebuffer_as_int_matrix | ( | ) |
Read pixels from opengl's whole back-buffer into a int matrix.
Int_matrix kjb::opengl::get_framebuffer_as_int_matrix | ( | size_t | x, |
size_t | y, | ||
size_t | width, | ||
size_t | height | ||
) |
void kjb::opengl::get_framebuffer_as_matrix | ( | size_t | x, |
size_t | y, | ||
size_t | width, | ||
size_t | height, | ||
Matrix & | out | ||
) |
Matrix kjb::opengl::get_framebuffer_as_matrix | ( | size_t | x, |
size_t | y, | ||
size_t | width, | ||
size_t | height | ||
) |
Matrix kjb::opengl::get_framebuffer_as_matrix | ( | ) |
Read pixels from opengl's whole back-buffer into a matrix.
Matrix kjb::opengl::get_modelview_matrix | ( | ) |
Returns a copy of the current modelview matrix.
Matrix kjb::opengl::get_projection_matrix | ( | ) |
Returns a copy of the current projection matrix.
size_t kjb::opengl::get_viewport_height | ( | ) |
Get current GL viewport height.
size_t kjb::opengl::get_viewport_width | ( | ) |
Get current GL viewport width.
void kjb::opengl::glClearDepthBuffer | ( | ) |
void kjb::opengl::glColor | ( | const Vector & | color | ) |
glColor for a kjb::Vector.
void kjb::opengl::glColor | ( | const kjb::PixelRGBA & | color | ) |
void kjb::opengl::glColor | ( | const Vector3 & | color | ) |
void kjb::opengl::glColor | ( | const Vector4 & | color | ) |
void kjb::opengl::glcolormask | ( | bool | b1, |
bool | b2, | ||
bool | b3, | ||
bool | b4 | ||
) |
void kjb::opengl::glDisableLineSmooth | ( | ) |
void kjb::opengl::glEnableLineSmooth | ( | ) |
void kjb::opengl::glLoadMatrix | ( | const kjb::Matrix4 & | m | ) |
glLoadMatrix for a kjb::Matrix4.
void kjb::opengl::glLoadMatrix | ( | const Matrix & | m | ) |
glLoadMatrix for a kjb::Matrix.
void kjb::opengl::glLoadMatrix | ( | const kjb::Matrix_d< 4, 4 > & | m | ) |
void kjb::opengl::glMultMatrix | ( | const kjb::Matrix4 & | m | ) |
glLoadMatrix for a kjb::Matrix4.
void kjb::opengl::glMultMatrix | ( | const Matrix & | m | ) |
glMultMatrix for a kjb::Matrix.
void kjb::opengl::glMultMatrix | ( | const Matrix_d< 4, 4 > & | m | ) |
void kjb::opengl::glMultMatrix_disp_ | ( | const Matrix_type & | m | ) |
void kjb::opengl::glOrtho | ( | Matrix4 & | state, |
double | left, | ||
double | right, | ||
double | bottom, | ||
double | top, | ||
double | znear, | ||
double | zfar | ||
) |
right-multiply the state matrix with the equivalent of opengl's glOrtho matrix.
void kjb::opengl::glOrtho | ( | Matrix & | state, |
double | left, | ||
double | right, | ||
double | bottom, | ||
double | top, | ||
double | znear, | ||
double | zfar | ||
) |
right-multiply the state matrix with the equivalent of opengl's glOrtho matrix.
void kjb::opengl::glOrtho | ( | Matrix_d< 4, 4 > & | state, |
double | left, | ||
double | right, | ||
double | bottom, | ||
double | top, | ||
double | znear, | ||
double | zfar | ||
) |
void kjb::opengl::glOrtho_disp_ | ( | Matrix_type & | state, |
double | left, | ||
double | right, | ||
double | bottom, | ||
double | top, | ||
double | znear, | ||
double | zfar | ||
) |
Template dispatch function; do not call directly.
template void kjb::opengl::glOrtho_disp_ | ( | Matrix & | state, |
double | left, | ||
double | right, | ||
double | bottom, | ||
double | top, | ||
double | znear, | ||
double | zfar | ||
) |
template void kjb::opengl::glOrtho_disp_ | ( | Matrix_d< 4, 4 > & | state, |
double | left, | ||
double | right, | ||
double | bottom, | ||
double | top, | ||
double | znear, | ||
double | zfar | ||
) |
void kjb::opengl::glRotate | ( | const kjb::Quaternion & | q | ) |
glRotate for a kjb::Quaternion.
void kjb::opengl::glTexImage2D | ( | const Image & | img | ) |
Copy kjb::Image into an opengl texture.
void kjb::opengl::glTranslate | ( | const kjb::Vector & | p | ) |
glTranslate for a kjb::Vector.
void kjb::opengl::glTranslate | ( | const kjb::Vector3 & | p | ) |
glTranslate for a kjb::Vector3.
void kjb::opengl::glTranslate | ( | const kjb::Vector2 & | p | ) |
void kjb::opengl::gluBuild2DMipmaps | ( | const Image & | img | ) |
NEEDS COMMENTING!!!.
void kjb::opengl::gluLookAt | ( | Matrix & | M, |
const Vector & | eye, | ||
const Vector & | target, | ||
const Vector & | up | ||
) |
Computes a gluLookAt matrix and multiplies it by the given matrix.
Vector kjb::opengl::gluUnProject | ( | const Vector & | vertex, |
double * | modelview, | ||
double * | projection, | ||
int * | viewport | ||
) |
Wraps gluUnproject using kjb::Vertex.
Vector3 kjb::opengl::gluUnProject | ( | const Vector2 & | vertex, |
double * | modelview, | ||
double * | projection, | ||
int * | viewport | ||
) |
Vector3 kjb::opengl::gluUnProject | ( | const Vector3 & | vertex, |
double * | modelview, | ||
double * | projection, | ||
int * | viewport | ||
) |
ReturnVectorType kjb::opengl::gluUnProject_dispatch_ | ( | const VectorType & | vertex, |
double * | modelview, | ||
double * | projection, | ||
int * | viewport | ||
) |
void kjb::opengl::glVertex | ( | const Vector & | p | ) |
glVertex for a kjb::Vector.
void kjb::opengl::glVertex | ( | const Vector2 & | p | ) |
void kjb::opengl::glVertex | ( | const Vector3 & | p | ) |
void kjb::opengl::glVertex | ( | const Vector4 & | p | ) |
bool kjb::opengl::has_stencil_buffer | ( | ) |
Returns true if OpenGL version supports stencil buffer (right?).
void kjb::opengl::kjb_opengl_debug_display_buffer | ( | ) |
Pop up a window displaying the opengl color buffer.
This pops up a window to display the contents of the opengl color buffer during debugging.
This is intentionally in the global namespace to make it callable inside gdb using "print kjb_opengl_debug_display_buffer()".
Since it's difficult to know exactly the format of the active buffer, this simply assumes it's grayscale and reads the red component only. This should be good enough for debugging.
void kjb::opengl::move_in_plane | ( | kjb::Vector3 & | plane_pt, |
const kjb::Vector2 & | new_pt | ||
) |
Translate a point so it projects to a screen point.
Move a 3d point so that it projects to a given screen position. Point will remain in the plane parallel to the image plane (i.e. it's depth won't change). Uses the current opengl matrix and viewport state to do camera computations.
world_point | A 3D point to move, given in world coordinates. |
screen_point | A 2d cursor position where the 3d point should project to Note that cursor coordinates are relatve to bottom-left of screen, following OpenGL standard (as opposed to Glut-standard top-left) |
Vector kjb::opengl::project | ( | const Vector & | x | ) |
Computes the window coordinates of the given point using current GL state.
Vector2 kjb::opengl::project | ( | const Vector3 & | x | ) |
void kjb::opengl::render_xy_plane_grid | ( | double | xmin, |
double | xmax, | ||
double | ymin, | ||
double | ymax, | ||
double | csz = 1.0 |
||
) |
Draw a grid representing the ground plane.
This function draws the a grid on the XY-plane, extending from xmin to xmax in the X direction and from zmin to zmax in the Y direction.
xmin | How far to extend in -X. |
xmax | How far to extend in X. |
zmin | How far to extend in -Y. |
zmax | How far to extend in Y. |
csz | Size of grid cells (in world units). |
void kjb::opengl::render_xz_plane_grid | ( | double | xmin, |
double | xmax, | ||
double | zmin, | ||
double | zmax, | ||
double | csz = 1.0 |
||
) |
Draw a grid representing the ground plane.
This function draws the a grid on the XZ-plane, extending from xmin to xmax in the X direction and from zmin to zmax in the Z direction.
xmin | How far to extend in -X. |
xmax | How far to extend in X. |
zmin | How far to extend in -Z. |
zmax | How far to extend in Z. |
csz | Size of grid cells (in world units). |
|
inline |
unpack 3-element byte array into lowest 24 bits of an unsigned integer
rgb | pointer to a 3-element byte array |
void kjb::opengl::set_framebuffer | ( | const Image & | img | ) |
Puts the contents of an image into the framebuffer.
void kjb::opengl::set_framebuffer | ( | const Matrix & | mat | ) |
Puts the contents of a matrix into the framebuffer.
void kjb::opengl::set_framebuffer | ( | const Int_matrix & | mat | ) |
Puts the contents of a int matrix into the framebuffer.
The matrix is intepreted as having the RGBA values as bytes packed in each integer.
float* kjb::opengl::to_gl_array | ( | const Image & | img | ) |
Allocate and build a float array representing the pixel data.
Data will be arranged in row-major format with BGR or RGB order, with values in [0,1]. Caller is responsible for freeing the result.
This is useful for interfacing C functions like Opengl that require a pixel array as input.
bgr_format | If true, the order of channels will be blue, green, red; if false, the channel order will be red, green, blue. Most opengl implementations store textures in BGR format, so this is generally faster when loading textures. |
img | The image to convert to an array. |
|
inline |
pack the lowest 24-bits of i into a 3-element byte array.
rgb | pointer to a 3-element byte array to store result |
Vector kjb::opengl::unproject | ( | const Vector & | vertex | ) |
Unproject a point from screen coordinates to world coordinates.
This function performs all the steps of unprojecting a vertex from screen coordinates into world coordinates, including querying OpenGl for the transformation matrices and viewport, and calling gluUnproject().
Vector3 kjb::opengl::unproject | ( | const Vector2 & | vertex | ) |
Vector3 kjb::opengl::unproject | ( | const Vector3 & | vertex | ) |
ReturnVectorType kjb::opengl::unproject_dispatch_ | ( | const VectorType & | vertex | ) |
const Vector3 kjb::opengl::BLACK |
const Vector3 kjb::opengl::BLUE |
const Vector3 kjb::opengl::CYAN |
const Vector3 kjb::opengl::GREEN |
const Vector3 kjb::opengl::MAGENTA |
const Vector3 kjb::opengl::RED |
const Vector3 kjb::opengl::WHITE |
const Vector3 kjb::opengl::YELLOW |