renderstack::dynamic_rectangle Class Reference

mesh for 2D rectangle that can resize

#include <dynamic_rectangle.hpp>

Inherits renderstack::mesh.

Public Member Functions

 dynamic_rectangle ()
void update (float x0, float y0, float x1, float y1)

Detailed Description

Definition at line 36 of file dynamic_rectangle.hpp.


Constructor & Destructor Documentation

renderstack::dynamic_rectangle::dynamic_rectangle (  ) 

Definition at line 32 of file dynamic_rectangle.cpp.

00033 {
00034     /*  Setup vertex format  */ 
00035     {
00036         vertex_attribute position(vertex_attribute_usage_position, GL_FLOAT, 0, 3);
00037 
00038         vertex_buffer()->vertex_format().append(position);
00039     }
00040 
00041     /*  Initialize buffers  */ 
00042     mesh::find_or_create_index_buffer(
00043         mesh_mode_edge_lines,
00044         GL_ELEMENT_ARRAY_BUFFER, 
00045         GL_STATIC_DRAW, 
00046         GL_UNSIGNED_INT, 
00047         GL_LINES
00048     );
00049 
00050     update(0.0f, 0.0f, 1.0f, 1.0f);
00051 }


Member Function Documentation

void renderstack::dynamic_rectangle::update ( float  x0,
float  y0,
float  x1,
float  y1 
)

Definition at line 55 of file dynamic_rectangle.cpp.

00061 {
00062     /*    2    3     0.. 3  corners     */ 
00063     /*                                  */ 
00064     /*                                  */ 
00065     /*    0    1                        */ 
00066 
00067     int vertex_index = 0;
00068     int index        = 0;
00069 
00070     buffer *vertex_buffer = mesh::vertex_buffer();
00071     buffer *index_buffer  = mesh::index_buffer(mesh_mode_edge_lines);
00072 
00073     vertex_buffer->begin_edit();
00074     index_buffer->begin_edit();
00075 
00076     /*  Vertices  */ 
00077     {
00078         vertex_buffer->set_index(index++); vertex_buffer->put_position(x0, y0, 0.0f);
00079         vertex_buffer->set_index(index++); vertex_buffer->put_position(x1, y0, 0.0f);
00080         vertex_buffer->set_index(index++); vertex_buffer->put_position(x0, y1, 0.0f);
00081         vertex_buffer->set_index(index++); vertex_buffer->put_position(x1, y1, 0.0f);
00082     }
00083 
00084     /*  Lines  */ 
00085     /*  Notice that you need to match end points for the lines  */ 
00086     /*  with start point of other line in order to get all      */ 
00087     /*  cornerpixels rasterized.                                */ 
00088     {
00089         index_buffer->set_index(vertex_index);
00090         index_buffer->line(0, 1);
00091         vertex_index += 2;
00092         index_buffer->set_index(vertex_index);
00093         index_buffer->line(1, 3);
00094         vertex_index += 2;
00095         index_buffer->set_index(vertex_index);
00096         index_buffer->line(3, 2);
00097         vertex_index += 2;
00098         index_buffer->set_index(vertex_index);
00099         index_buffer->line(2, 0);
00100         vertex_index += 2;
00101     }
00102 
00103     /*  Done  */ 
00104     vertex_buffer->end_edit(index);
00105     index_buffer->end_edit(vertex_index);
00106 }


The documentation for this class was generated from the following files:
Generated on Sun Apr 11 12:23:11 2010 for RenderStack by  doxygen 1.6.3