23 #include "texture_drawer.h" 25 #include <fvcams/camera.h> 26 #include <fvutils/color/colorspaces.h> 27 #include <fvutils/color/conversions.h> 55 : __width(width), __height(height),
56 __texture_width(get_closest_power_of_two(__width)),
57 __texture_height(get_closest_power_of_two(__height))
62 __texture_initialized =
false;
72 SkelGuiTextureDrawer::get_closest_power_of_two(
unsigned int n)
81 SkelGuiTextureDrawer::init_texture()
83 glGenTextures(1, &__texture_id);
84 glBindTexture(GL_TEXTURE_2D, __texture_id);
86 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
87 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
89 memset(__texture_coords, 0,
sizeof(__texture_coords));
95 __texture_initialized =
true;
100 SkelGuiTextureDrawer::draw_rectangle(
float topLeftX,
float topLeftY,
101 float bottomRightX,
float bottomRightY)
103 GLfloat verts[8] = { topLeftX, topLeftY, topLeftX, bottomRightY,
104 bottomRightX, bottomRightY, bottomRightX, topLeftY };
105 glVertexPointer(2, GL_FLOAT, 0, verts);
106 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
114 if (!__texture_initialized) init_texture();
118 glBindTexture(GL_TEXTURE_2D, __texture_id);
123 glColor4f(0.75,0.75,0.75,1);
125 glEnable(GL_TEXTURE_2D);
126 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
127 glTexCoordPointer(2, GL_FLOAT, 0, __texture_coords);
129 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
130 glDisable(GL_TEXTURE_2D);
142 const unsigned char *rgb = rgb_buf;
143 unsigned int bytes = 0;
144 for (
unsigned int h = 0; h <
__height; ++h) {
146 for (
unsigned int w = 0; w <
__width; ++w) {
const unsigned int __texture_width
Real texture width.
Fawkes library namespace.
const unsigned int __width
Width of visible area from texture.
unsigned char * __texture
Texture buffer.
void draw()
Draw texture to screen.
void copy_rgb_to_texture(const unsigned char *rgb_buf)
Copy an RGB buffer to texture.
virtual void fill_texture()=0
Fill texture with data.
const unsigned int __texture_height
Real texture height.
SkelGuiTextureDrawer(unsigned int width, unsigned int height)
Constructor.
const unsigned int __height
Height of visible area from texture.
virtual ~SkelGuiTextureDrawer()
Destructor.