void Rigid_body_viewer:: draw() { // parent's status text Viewer_2D::draw(); // draw walls glDisable(GL_LIGHTING); glLineWidth(1.0); glColor3f(0.5,0.5,0.5); glBegin(GL_LINE_STRIP); glVertex2f( -1.0, 1.0 ); glVertex2f( -1.0, -1.0 ); glVertex2f( 1.0, -1.0 ); glVertex2f( 1.0, 1.0 ); glVertex2f( -1.0, 1.0 ); glEnd(); // draw rigid body body_.draw(); // draw mouse spring if (mouse_spring_.active) { glLineWidth(5.0); glColor3f(1,0,0); glBegin(GL_LINES); glVertex2fv( body_.points[ mouse_spring_.particle_index ].data() ); glVertex2fv( mouse_spring_.mouse_position.data() ); glEnd(); } }
void GlassLayer::draw(Graphics* const TheGraphics, const Pnt2f& TopLeft, const Pnt2f& BottomRight, const Real32 Opacity) const { Pnt2f IntermediatePosition; Vec3f Bounds(BottomRight- TopLeft); //Setup the Blending equations properly glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glBegin(GL_TRIANGLE_FAN); glColor4f(getEdgeColor().red(),getEdgeColor().green(),getEdgeColor().blue(),getEdgeColor().alpha() * Opacity); glVertex2f(getStartPosition().x(), getEndPosition().y()); glColor4f(getCenterColor().red(),getCenterColor().green(),getCenterColor().blue(),getCenterColor().alpha() * Opacity); glVertex2fv(getStartPosition().getValues()); for(UInt32 i(0) ; i<_Segments.size(); ++i) { IntermediatePosition.setValues(_Segments[i].x() * Bounds.x(),_Segments[i].y() * Bounds.y()); glVertex2fv(IntermediatePosition.getValues()); } glVertex2fv(getEndPosition().getValues()); glEnd(); glDisable(GL_BLEND); }
void drawSpline(const Gm::Spline2& spline, Gs::Real a, Gs::Real b, std::size_t segments) { // draw curve glBegin(GL_LINE_STRIP); auto step = (b - a) / segments; for (std::size_t i = 0; i <= segments; ++i) { glColor4f(1, 1, 1, 1); // interpolate vertex auto p = spline(a); glVertex2fv(p.Ptr()); a += step; } glEnd(); // draw control points glPointSize(5.0f); glBegin(GL_POINTS); for (const auto& p : spline.GetPoints()) { glColor4f(1, 0, 0, 1); glVertex2fv(p.point.Ptr()); } glEnd(); glPointSize(1.0f); }
static void Lines(void) { GLint i,j; float v1[3],v2[3]; double start; start=Now(); for(i=0;i<repeatCount;i++) { v1[0]=10; v1[1]=10; v1[2]=10; v2[0]=20; v2[1]=20; v2[2]=10; glBegin(GL_LINES); for(j=0;j<loopCount;j++) { glVertex2fv(v1); glVertex2fv(v2); } glEnd(); } glFinish(); }
void GLUI_Rotation::iaction_draw_active_area_ortho( void ) { float radius; radius = (float)(h-22)/2.0; /*MIN((float)w/2.0, (float)h/2.0); */ /********* Draw emboss circles around arcball control *********/ int k; glLineWidth( 1.0 ); glBegin( GL_LINE_LOOP); for( k=0; k<60; k++ ) { float phi = 2*M_PI*(float)k/60.0; vec2 p( cos(phi) * (2.0 + radius), sin(phi) * (2.0 + radius)); if ( p[1] < -p[0] ) glColor3ub( 128,128,128 ); else glColor3ub( 255,255,255 ); glVertex2fv((float*)&p[0]); } glEnd(); glBegin( GL_LINE_LOOP); for( k=0; k<60; k++ ) { float phi = 2*M_PI*(float)k/60.0; vec2 p( cos(phi) * (1.0 + radius), sin(phi) * (1.0 + radius)); if ( enabled ) { if ( p[1] < -p[0] ) glColor3ub( 0,0,0); else glColor3ub( 192,192,192); } else { if ( p[1] < -p[0] ) glColor3ub( 180,180,180); else glColor3ub( 192,192,192); } glVertex2fv((float*)&p[0]); } glEnd(); }
void clip_draw_cfra(SpaceClip *sc, ARegion *ar, Scene *scene) { View2D *v2d = &ar->v2d; float xscale, yscale; float vec[2]; /* Draw a light green line to indicate current frame */ vec[0] = (float)(sc->user.framenr * scene->r.framelen); UI_ThemeColor(TH_CFRAME); glLineWidth(2.0); glBegin(GL_LINE_STRIP); vec[1] = v2d->cur.ymin; glVertex2fv(vec); vec[1] = v2d->cur.ymax; glVertex2fv(vec); glEnd(); glLineWidth(1.0); UI_view2d_view_orthoSpecial(ar, v2d, 1); /* because the frame number text is subject to the same scaling as the contents of the view */ UI_view2d_scale_get(v2d, &xscale, &yscale); glScalef(1.0f / xscale, 1.0f, 1.0f); ED_region_cache_draw_curfra_label(sc->user.framenr, (float)sc->user.framenr * xscale, 18); /* restore view transform */ glScalef(xscale, 1.0, 1.0); }
void drawBezierCurve(const Gm::BezierCurve2& curve, std::size_t segments) { // draw curve glBegin(GL_LINE_STRIP); auto t = Gs::Real(0); auto step = Gs::Real(1) / segments; for (std::size_t i = 0; i <= segments; ++i) { glColor4f(1, 1, 1, 1); // interpolate vertex auto p = curve(t); glVertex2fv(p.Ptr()); t += step; } glEnd(); // draw control points glPointSize(5.0f); glBegin(GL_POINTS); for (const auto& p : curve.controlPoints) { glColor4f(1, 1, 0, 1); glVertex2fv(p.Ptr()); } glEnd(); glPointSize(1.0f); }
/////////////////////////////////////////////////////////////////////////////// /// \brief Prints out a string using this font, beginning with the baseline /// at the origin. /// /// \param text The string to print. /// \param color The base color to modulate by the font texture. void TextureFont::print(const std::string& text, const color4& color) const { vec2 cursor; // where the current character should be drawn F32 scale_x = 1.0f / texture_.getDimensions().x; F32 scale_y = 1.0f / texture_.getDimensions().y; for (char c : text) { const TextureFontCharacter& ch = (*this)[c]; // vertices vec2 top_left(cursor + ch.character_offset); vec2 bottom_right(top_left.x + ch.texture_dimensions.x, top_left.y - ch.texture_dimensions.y); vec2 tex_top_left(ch.texture_offset); vec2 tex_bottom_right(tex_top_left + ch.texture_dimensions); tex_top_left.x *= scale_x; tex_bottom_right.x *= scale_x; tex_top_left.y *= scale_y; tex_bottom_right.y *= scale_y; cursor.x += ch.character_advance; texture_.enable(GL_MODULATE); glColor4fv(glm::value_ptr(color)); glBegin(GL_QUADS); glTexCoord2fv(glm::value_ptr(tex_top_left)); glVertex2fv(glm::value_ptr(top_left)); glTexCoord2f(tex_top_left.x, tex_bottom_right.y); glVertex2f(top_left.x, bottom_right.y); glTexCoord2fv(glm::value_ptr(tex_bottom_right)); glVertex2fv(glm::value_ptr(bottom_right)); glTexCoord2f(tex_bottom_right.x, tex_top_left.y); glVertex2f(bottom_right.x, top_left.y); glEnd(); texture_.disable(); } }
static void redrawCB(void) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); /* Perform scene rotations based on user mouse input. */ if (!mapMode) { glRotatef(angle2, 1.0f, 0.0f, 0.0f); glRotatef(angle, 0.0f, 1.0f, 0.0f); } glLightfv(GL_LIGHT0, GL_POSITION, sunDirection); if (mapMode) { /* use the normals for a sphere on a flat surface to get * the lighting as if we unwrapped a lighted sphere. */ int lat, lon; for (lat = 0; lat < LAT_GRID; lat++) { glBegin(GL_TRIANGLE_STRIP); for (lon = 0; lon <= LON_GRID; lon++) { glTexCoord2fv(uv[lat + 1][lon]); glNormal3fv(sphere[lat + 1][lon]); glVertex2fv(map[lat + 1][lon]); glTexCoord2fv(uv[lat][lon]); glNormal3fv(sphere[lat][lon]); glVertex2fv(map[lat][lon]); } glEnd(); } } else { /* draw a sphere */ int lat, lon; for (lat = 0; lat < LAT_GRID; lat++) { glBegin(GL_TRIANGLE_STRIP); for (lon = 0; lon <= LON_GRID; lon++) { glTexCoord2fv(uv[lat + 1][lon]); glNormal3fv(sphere[lat + 1][lon]); glVertex3fv(sphere[lat + 1][lon]); glTexCoord2fv(uv[lat][lon]); glNormal3fv(sphere[lat][lon]); glVertex3fv(sphere[lat][lon]); } glEnd(); } } glPopMatrix(); glutSwapBuffers(); }
void t(point2d a,point2d b,point2d c){ glBegin(GL_TRIANGLES); glVertex2fv(a); glVertex2fv(b); glVertex2fv(c); glEnd(); }
void Draw() { //Function to Draw the BEzier Curve glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0, 1.0, 0.0); glPointSize(5.0); glBegin(GL_POINTS); //Drawing the Four control points glVertex2fv(bez_pnt[0]); glColor3f(0.0, 1.0, 0.0); glVertex2fv(bez_pnt[1]); glColor3f(0.0, 1.0, 0.0); glVertex2fv(bez_pnt[2]); glColor3f(0.0, 1.0, 0.0); glVertex2fv(bez_pnt[3]); glEnd(); while(bez_t <= 1) //Parametric curve from t=0 to t=1 { i=3; while(i>0) { for(j=0;j<i;j++) { bez_pnt[j][0]=decasteljau(bez_t,bez_pnt[j][0],bez_pnt[j+1][0]); bez_pnt[j][1]=decasteljau(bez_t,bez_pnt[j][1],bez_pnt[j+1][1]); } i=i-1; } glColor3f(0.0, 0.0, 1.0); glPointSize(1.0); glBegin(GL_POINTS); //Draw the points on curve glVertex2fv(bez_pnt[0]); glEnd(); bez_t=bez_t+0.00001; //Increment t by 0.00001 } glFlush(); }
void Display (void){ float V[][2] ={ -5.,-5., -5., 5., 8., 5., 8.,-5. }; glTranslated(1.5,0,0); glRotated(45, 0, 0, 1); glTranslated(-1.5,0,0); glClear (GL_COLOR_BUFFER_BIT); glBegin (GL_POLYGON); glVertex2fv (V[0]); glVertex2fv (V[1]); glVertex2fv (V[2]); glVertex2fv (V[3]); glEnd (); glLoadIdentity(); glTranslated(6,7,0); glBegin(GL_TRIANGLES); glColor3f (1., 0., 0.); glVertex2d(2.,2.); glColor3f (0., 1., 0.); glVertex2d(5.,2.); glColor3f (0., 0., 1.); glVertex2d(3.5,5); glEnd(); glFlush (); }
void star() { GLfloat v[13][2] = { {0, 0}, {0, 0.5}, {0.1, 0.3}, {0.4, 0.3}, {0.25, 0}, {0.4, -0.3}, {0.1, -0.3}, {0, -0.5}, {-0.1, -0.3}, {-0.4, -0.3}, {-0.25, 0}, {-0.4, 0.3}, {-0.1, 0.3} }; GLfloat color[7][3] = { {1, 1, 1}, // white {1, 0, 0}, // red {1, 0, 1}, // pink {0, 0, 1}, // blue {0, 1, 1}, // light blue {0, 1, 0}, // green {1, 1, 0} // yellow }; glBegin(GL_POLYGON); glColor3fv(color[0]); glVertex2fv(v[0]); for (GLint i = 1; i <= 6; ++i) { glColor3fv(color[i]); glVertex2fv(v[2 * i - 1]); glVertex2fv(v[2 * i]); } glColor3fv(color[1]); glVertex2fv(v[1]); glEnd(); glFlush(); }
/* desenha um triângulo */ void triangulo(GLfloat *v1, GLfloat *v2, GLfloat *v3) { /* desenha um triângulo */ glVertex2fv(v1); glVertex2fv(v2); glVertex2fv(v3); }
void DebugDraw :: DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) { glColor3fv(&color.r); glBegin(GL_LINES); glVertex2fv(&p1.x); glVertex2fv(&p2.x); glEnd(); }
/* General call for drawing current frame indicator in animation editor */ void ANIM_draw_cfra(const bContext *C, View2D *v2d, short flag) { Scene *scene = CTX_data_scene(C); float vec[2]; /* Draw a light green line to indicate current frame */ vec[0] = (float)(scene->r.cfra * scene->r.framelen); UI_ThemeColor(TH_CFRAME); if (flag & DRAWCFRA_WIDE) glLineWidth(3.0); else glLineWidth(2.0); glBegin(GL_LINE_STRIP); vec[1] = v2d->cur.ymin - 500.0f; /* XXX arbitrary... want it go to bottom */ glVertex2fv(vec); vec[1] = v2d->cur.ymax; glVertex2fv(vec); glEnd(); glLineWidth(1.0); /* Draw current frame number in a little box */ if (flag & DRAWCFRA_SHOW_NUMBOX) { UI_view2d_view_orthoSpecial(CTX_wm_region(C), v2d, 1); draw_cfra_number(scene, v2d, vec[0], (flag & DRAWCFRA_UNIT_SECONDS) != 0); } }
void triangle( GLfloat *a, GLfloat *b, GLfloat *c) /* specify one triangle */ { glVertex2fv(a); glVertex2fv(b); glVertex2fv(c); }
void draw_segmentset2d(const std::vector<Vec2f>& vertices, const std::vector<Vec2i>& edges) { glBegin(GL_LINES); for(unsigned int i = 0; i < edges.size(); ++i) { glVertex2fv(vertices[edges[i][0]].v); glVertex2fv(vertices[edges[i][1]].v); } glEnd(); }
void draw_box2d(const Vec2f& origin, float width, float height) { glBegin(GL_POLYGON); glVertex2fv(origin.v); glVertex2fv((origin + Vec2f(0, height)).v); glVertex2fv((origin + Vec2f(width, height)).v); glVertex2fv((origin + Vec2f(width, 0)).v); glEnd(); }
/*draw a triangle */ void drawTriangle(float *v1, float *v2, float *v3) { glBegin(GL_TRIANGLES); glVertex2fv(v1); glVertex2fv(v2); glVertex2fv(v3); glEnd(); }
void VoronoiPolygonSite::DrawSite() { glBegin(GL_LINE_STRIP); for (int k=0; k<NumPts*2; k+=2) glVertex2fv(&(Pts[k])); glVertex2fv(Pts); glEnd(); }
/** * What this function does is on a mouse press, it sets a vector to hold a specific triangle point. * Now, there is one problem in that the window's coordinate system is different from our drawing coordinate * system. In order to draw correctly, we transform the (x,y) from window to (x',y') of our world coordinate * system. * * The way I did this was to use gluUnProject which returns the transformed coordinates. The reason I pass the y * value in as I do is because y starts at upper left and I need to ensure that y is subtracted from viewport[3] * which holds the viewHeight(yMax + yMin). The z coordinate is passed as 0.0f as we are only drawing in 2D space. * * Reference: http://www.opengl.org/discussion_boards/showthread.php/126012-converting-window-coordinates-to-world-coordinates */ void MyPanelOpenGL::mousePressEvent(QMouseEvent *event) { if (event->button() != Qt::LeftButton) return; // Get the position of where the mouse clicked and set that as triangle point lastPos = event->pos(); GLdouble x; GLdouble y; GLdouble z; GLdouble projection[16]; //var to hold the projection matrix info GLint viewport[4]; //var to hold the viewport info GLdouble modelview[16]; //var to hold the modelview info glGetDoublev( GL_PROJECTION_MATRIX, projection ); //get the projection matrix info glGetIntegerv( GL_VIEWPORT, viewport ); //get the viewport info glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); //get the modelview info gluUnProject( lastPos.x(), (float)viewport[3] - (float)lastPos.y(), 0.0f, modelview, projection, viewport, &x, &y, &z); if (currPoint == 1) { triangle_point1[0] = x; triangle_point1[1] = y; glLoadIdentity(); glTranslated(5.0, 5.0, 0.0); glColor3f(0.0f, 0.0f, 1.0f); glBegin(GL_POINT); glVertex2fv(triangle_point1); glEnd(); //emit(trianglePoint1Changed()); } else if (currPoint == 2) { triangle_point2[0] = x; triangle_point2[1] = y; glColor3f(0.0f, 0.0f, 1.0f); glBegin(GL_POINT); glVertex2fv(triangle_point2); glEnd(); //emit(trianglePoint1Changed()); } else if (currPoint == 3) { triangle_point3[0] = x; triangle_point3[1] = y; glColor3f(0.0f, 0.0f, 1.0f); glBegin(GL_POINT); glVertex2fv(triangle_point3); glEnd(); //emit(trianglePoint1Changed()); } updateGL(); }
void draw_trimesh2d(const std::vector<Vec2f>& vertices, const std::vector<Vec3ui>& tris) { glBegin(GL_TRIANGLES); for(unsigned int i = 0; i < tris.size(); ++i) { glVertex2fv(vertices[tris[i][0]].v); glVertex2fv(vertices[tris[i][1]].v); glVertex2fv(vertices[tris[i][2]].v); } glEnd(); }
// methods void Line::Render(void) const { glBegin(GL_LINES); glVertex2fv( (d[0] * trans).v ); glVertex2fv( (d[1] * trans).v ); glEnd(); }
void draw_line(const mat4 &m, const line &a, const vec4 &color) { glLoadIdentity(); glLoadMatrixf(m.m); glColor4fv(color.v); glBegin(GL_LINES); glVertex2fv(a.position.v); glVertex2fv(a.end.v); glEnd(); }
void cube_quad(const struct wc_cube_t *ptr, int n0, int n1, int n2, int n3) { glBegin(GL_POLYGON); glVertex2fv((GLfloat*)(ptr->buffer + n0)); glVertex2fv((GLfloat*)(ptr->buffer + n1)); glVertex2fv((GLfloat*)(ptr->buffer + n2)); glVertex2fv((GLfloat*)(ptr->buffer + n3)); glEnd(); }
void fdrawline(float x1, float y1, float x2, float y2) { float v[2]; glBegin(GL_LINE_STRIP); v[0] = x1; v[1] = y1; glVertex2fv(v); v[0] = x2; v[1] = y2; glVertex2fv(v); glEnd(); }
void Shape::draw(){ glColor3f(1, 1, 1); glBegin(GL_POLYGON); for (int i=0, l=vertices.size(); i<l; i++) glVertex2fv(vertices[i].data); glEnd(); glColor3f(0, .3, 1); glPointSize(5); glBegin(GL_POINTS); for (int i=0, l=vertices.size(); i<l; i++) glVertex2fv(vertices[i].data); glEnd(); }
void drawWigginsEast(void) { orderedPair wigginsEast1 = { 70.0, 282.0 }; orderedPair wigginsEast2 = { 80.0, 282.0 }; orderedPair wigginsEast3 = { 80.0, 238.0 }; orderedPair wigginsEast4 = { 70.0, 238.0 }; glBegin(GL_POLYGON); glVertex2fv(wigginsEast1); glVertex2fv(wigginsEast2); glVertex2fv(wigginsEast3); glVertex2fv(wigginsEast4); glEnd(); }
void TFGeometry2D::render() const { // TODO: get rid of intermediade mode? if (_keyPoints.size() < 2) return; glBegin(GL_TRIANGLE_FAN); glColor4ubv(_center._color.elem); glVertex2fv(_center._position.elem); for (std::vector<KeyPoint>::const_iterator it = _keyPoints.begin(); it != _keyPoints.end(); ++it) { glColor4ubv(it->_color.elem); glVertex2fv(it->_position.elem); } glEnd(); }