dynamic_rectangle.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00027 #include "renderstack/dynamic_rectangle.hpp"
00028 #include "renderstack/rs_gl.h"
00029
00030 namespace renderstack {
00031
00032 dynamic_rectangle::dynamic_rectangle()
00033 {
00034
00035 {
00036 vertex_attribute position(vertex_attribute_usage_position, GL_FLOAT, 0, 3);
00037
00038 vertex_buffer()->vertex_format().append(position);
00039 }
00040
00041
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 }
00052
00053
00054
00055 void dynamic_rectangle::update(
00056 float x0,
00057 float y0,
00058 float x1,
00059 float y1
00060 )
00061 {
00062
00063
00064
00065
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
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
00085
00086
00087
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
00104 vertex_buffer->end_edit(index);
00105 index_buffer->end_edit(vertex_index);
00106 }
00107
00108 }
00109