void GLWindow::draw() { // prevent nested calls to draw from creating infinite loops // Also prevents threads from creating invalid data // This is not atomic, so not perfect, but it should do the job for now if (isDrawing) return; isDrawing = true; // Set up fonts for drawing text float fColBack[4]; glGetFloatv( GL_COLOR_CLEAR_VALUE, fColBack ); gl_color( FL_BLACK ); gl_font(labelfont(), labelsize()); if (currentUI != 0) { gl_color( currentUI->fontColor() ); currentUI->draw(); } else { glClear(GL_COLOR_BUFFER_BIT); } // We're done, so allow other calls into this method. isDrawing = false; }
void ftgl_draw_char(struct font_descriptor *self, hwrbitmap dest, struct pgpair *position, hwrcolor col, int ch, struct pgquad *clip, s16 lgop, s16 angle) { struct ftgl_glyph *g; int advance; if (ch > NUM_GLYPHS) return; g = &DATA->font->glyphs[ch]; gl_lgop(PG_LGOP_ALPHA); glEnable(GL_TEXTURE_2D); gl_color(col); /* Rotate and scale in a matrix */ glPushMatrix(); glTranslatef(position->x, position->y,0); glScalef(DATA->scale,DATA->scale,DATA->scale); glRotatef(angle,0,0,-1); glTranslatef(g->x,g->y,0); if (g->texture != gl_global.current_texture) { glBindTexture(GL_TEXTURE_2D, g->texture); gl_global.current_texture = g->texture; } glBegin(GL_QUADS); glTexCoord2f(g->tx1,g->ty1); glVertex2f(0,0); glTexCoord2f(g->tx2,g->ty1); glVertex2f(g->w,0); glTexCoord2f(g->tx2,g->ty2); glVertex2f(g->w,g->h); glTexCoord2f(g->tx1,g->ty2); glVertex2f(0,g->h); glEnd(); advance = g->advance * DATA->scale + 0.5; switch (angle) { case 0: position->x += advance; break; case 90: position->y -= advance; break; case 180: position->x -= advance; break; case 270: position->y += advance; break; } /* Clean up */ glPopMatrix(); glDisable(GL_TEXTURE_2D); gl_lgop(PG_LGOP_NONE); }
virtual void do_draw_overlay( const ui::paint_event_t& event) const { RAMEN_ASSERT( node()->composition()); move2d_node_t::matrix3_type lm( param_->matrix_at_frame( node()->composition()->frame(), node()->aspect_ratio())); Imath::V2f p = get_absolute_value<Imath::V2f>( param_->center_param()); p = p * lm; p.x *= node()->aspect_ratio(); gl_line_width( default_line_width()); manipulators::draw_xy_axes( p, 70 / event.pixel_scale, 70 / event.pixel_scale, get_value<float>( param_->rotate_param()), event.aspect_ratio / node()->aspect_ratio(), ui::palette_t::instance().color("x_axis"), ui::palette_t::instance().color("y_axis"), event.pixel_scale); manipulators::draw_cross( p, 3 / event.pixel_scale, 3 / event.pixel_scale, default_color(), event.pixel_scale); manipulators::draw_ellipse( p, 7 / event.pixel_scale, 7 / event.pixel_scale, Imath::Color3c( 255, 255, 255), 20); // draw the boundary move2d_node_t::matrix3_type gm( node()->global_matrix()); gm *= move2d_node_t::matrix3_type().setScale( move2d_node_t::vector2_type( node()->aspect_ratio(), 1)); Imath::Box2i bbox( node()->format()); ++bbox.max.x; ++bbox.max.y; float offset = manipulators::shadow_offset( event.pixel_scale); gl_line_width( manipulator_t::default_line_width()); gl_point_size( manipulator_t::default_control_point_size()); // shadow gl_color3ub( 0, 0, 0); gl_begin( GL_LINE_LOOP); manipulators::gl_transformed_box( bbox, gm, offset); gl_end(); // color gl_color( manipulator_t::default_color()); gl_begin( GL_LINE_LOOP); manipulators::gl_transformed_box( bbox, gm); gl_end(); }
void quad_manipulator_t::do_draw_overlay( const ui::paint_event_t& event) const { boost::array<Imath::V2f, 4> dst_pts; get_corners( dst_pts, event.aspect_ratio); gl_line_width( default_line_width()); gl_point_size( default_control_point_size()); // shadow float off = manipulators::shadow_offset( event.pixel_scale); gl_color3ub( 0, 0, 0); gl_begin( GL_LINE_LOOP); for( int i = 0; i < 4; ++i) gl_vertex2f( dst_pts[i].x + off, dst_pts[i].y + off); gl_end(); gl_begin( GL_POINTS); for( int i = 0; i < 4; ++i) gl_vertex2f( dst_pts[i].x + off, dst_pts[i].y + off); gl_end(); // color gl_color( default_color()); gl_begin( GL_LINE_LOOP); for( int i = 0; i < 4; ++i) gl_vertex2f( dst_pts[i].x, dst_pts[i].y); gl_end(); // draw corners gl_begin( GL_POINTS); for( int i = 0; i < 4; ++i) { if( i != picked_corner_) gl_vertex2f( dst_pts[i].x, dst_pts[i].y); } gl_end(); for( int i = 0; i < 4; ++i) { if( i == picked_corner_) manipulators::draw_small_box( dst_pts[i], 3 / event.pixel_scale); } }
void shape_window::draw_overlay() { // the valid() property may be used to avoid reinitializing your // GL transformation for each redraw: if (!valid()) { valid(1); glLoadIdentity(); glViewport(0,0,w(),h()); } // draw an amazing graphic: gl_color(FL_RED); glBegin(GL_LINE_LOOP); for (int i=0; i<overlay_sides; i++) { double ang = i*2*M_PI/overlay_sides; glVertex3f(cos(ang),sin(ang),0); } glEnd(); glEnd(); gl_font(FL_HELVETICA, 12); gl_draw("overlay text", .1, .6); }
void shape_window::draw() { // the valid() property may be used to avoid reinitializing your // GL transformation for each redraw: if (!valid()) { valid(1); glLoadIdentity(); glViewport(0,0,w(),h()); } glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); for (int i=0; i<sides; i++) { double ang = i*2*M_PI/sides; glColor3f(float(i)/sides,float(i)/sides,float(i)/sides); glVertex3f(cos(ang),sin(ang),0); } glEnd(); gl_color(FL_WHITE); gl_font(FL_HELVETICA, 12); gl_draw("text", .1, .5); }
void gl_grop_handler(struct groprender *r, struct gropnode *n) { struct glbitmap *glb; GLfloat vector[4]; switch (n->type) { case PG_GROP_GL_BINDTEXTURE: if (!iserror(rdhandle((void**)&glb,PG_TYPE_BITMAP,-1,n->param[0])) && glb) gl_bind_texture(glb); break; case PG_GROP_GL_ENABLE: glEnable(n->param[0]); break; case PG_GROP_GL_DISABLE: glDisable(n->param[0]); break; case PG_GROP_GL_DEPTHFUNC: glDepthFunc(n->param[0]); break; case PG_GROP_GL_SHADEMODEL: glShadeModel(n->param[0]); break; case PG_GROP_GL_MATRIXMODE: glMatrixMode(n->param[0]); break; case PG_GROP_GL_LOADIDENTITY: glLoadIdentity(); break; case PG_GROP_GL_PUSHMATRIX: glPushMatrix(); break; case PG_GROP_GL_POPMATRIX: glPopMatrix(); break; case PG_GROP_GL_TRANSLATEF: glTranslatef(UNFIX(n->param[0]), UNFIX(n->param[1]), UNFIX(n->param[2])); break; case PG_GROP_GL_ROTATEF: glRotatef(UNFIX16(n->r.x,n->r.y), UNFIX(n->param[0]), UNFIX(n->param[1]), UNFIX(n->param[2])); break; case PG_GROP_GL_SCALEF: glScalef(UNFIX(n->param[0]), UNFIX(n->param[1]), UNFIX(n->param[2])); break; case PG_GROP_GL_BEGIN: glBegin(n->param[0]); break; case PG_GROP_GL_TEXCOORD2F: glTexCoord2f(UNFIX(n->param[0]), UNFIX(n->param[1])); break; case PG_GROP_GL_VERTEX3F: glVertex3f(UNFIX(n->param[0]), UNFIX(n->param[1]), UNFIX(n->param[2])); break; case PG_GROP_GL_END: glEnd(); break; case PG_GROP_GL_HINT: glHint(n->param[0],n->param[1]); break; case PG_GROP_GL_NORMAL3F: glNormal3f(UNFIX(n->param[0]), UNFIX(n->param[1]), UNFIX(n->param[2])); break; case PG_GROP_GL_LIGHTFV: vector[0] = UNFIX(n->param[0]); vector[1] = UNFIX(n->param[1]); vector[2] = UNFIX(n->param[2]); vector[3] = UNFIX16(n->r.w,n->r.h); glLightfv(n->r.x,n->r.y,(const GLfloat *)&vector); break; case PG_GROP_GL_MATERIALFV: vector[0] = UNFIX(n->param[0]); vector[1] = UNFIX(n->param[1]); vector[2] = UNFIX(n->param[2]); vector[3] = UNFIX16(n->r.w,n->r.h); glMaterialfv(n->r.x,n->r.y,(const GLfloat *)&vector); break; case PG_GROP_GL_TEXGENFV: vector[0] = UNFIX(n->param[0]); vector[1] = UNFIX(n->param[1]); vector[2] = UNFIX(n->param[2]); vector[3] = UNFIX16(n->r.w,n->r.h); glTexGenfv(n->r.x,n->r.y,(const GLfloat *)&vector); break; case PG_GROP_GL_TEXGENI: glTexGeni(n->param[0], n->param[1], n->param[2]); break; case PG_GROP_GL_MATERIALI: glMateriali(n->param[0], n->param[1], n->param[2]); break; case PG_GROP_GL_MATRIX_PIXELCOORD: gl_matrix_pixelcoord(); break; case PG_GROP_GL_COLOR: gl_color(n->param[0]); break; case PG_GROP_GL_BLENDFUNC: glBlendFunc(n->param[0],n->param[1]); break; case PG_GROP_GL_FEEDBACK: gl_feedback(n->r.x, n->r.y, n->r.w, n->r.h, r->lgop, n->param[0], n->param[1], (n->param[2]>>16) & 0xFFFF, (n->param[2] & 0xFFFF)); break; case PG_GROP_GL_TEXPARAMETERI: glTexParameteri(n->param[0],n->param[1],n->param[2]); break; } }