23 #include "texture_drawer.h" 26 #include <fvcams/camera.h> 27 #include <fvutils/color/colorspaces.h> 28 #include <fvutils/color/conversions.h> 36 using namespace firevision;
58 texture_width_(get_closest_power_of_two(width_)),
59 texture_height_(get_closest_power_of_two(height_)),
60 texture_raii_(malloc(texture_width_ * texture_height_ * 3))
62 texture_ = (
unsigned char *)*texture_raii_;
65 texture_initialized_ =
false;
74 SkelGuiTextureDrawer::get_closest_power_of_two(
unsigned int n)
84 SkelGuiTextureDrawer::init_texture()
86 glGenTextures(1, &texture_id_);
87 glBindTexture(GL_TEXTURE_2D, texture_id_);
89 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
90 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
92 memset(texture_coords_, 0,
sizeof(texture_coords_));
98 texture_initialized_ =
true;
102 SkelGuiTextureDrawer::draw_rectangle(
float topLeftX,
108 topLeftX, topLeftY, topLeftX, bottomRightY, bottomRightX, bottomRightY, bottomRightX, topLeftY};
109 glVertexPointer(2, GL_FLOAT, 0, verts);
110 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
118 if (!texture_initialized_)
123 glBindTexture(GL_TEXTURE_2D, texture_id_);
124 glTexImage2D(GL_TEXTURE_2D,
135 glColor4f(0.75, 0.75, 0.75, 1);
137 glEnable(GL_TEXTURE_2D);
138 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
139 glTexCoordPointer(2, GL_FLOAT, 0, texture_coords_);
141 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
142 glDisable(GL_TEXTURE_2D);
154 const unsigned char *rgb = rgb_buf;
155 for (
unsigned int h = 0; h <
height_; ++h) {
157 for (
unsigned int w = 0; w <
width_; ++w) {
const unsigned int height_
Height of visible area from texture.
const unsigned int width_
Width of visible area from texture.
Fawkes library namespace.
void draw()
Draw texture to screen.
void copy_rgb_to_texture(const unsigned char *rgb_buf)
Copy an RGB buffer to texture.
const unsigned int texture_height_
Real texture height.
unsigned char * texture_
Texture buffer.
const unsigned int texture_width_
Real texture width.
virtual void fill_texture()=0
Fill texture with data.
SkelGuiTextureDrawer(unsigned int width, unsigned int height)
Constructor.
virtual ~SkelGuiTextureDrawer()
Destructor.