void display(void) { glClear (GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); glLoadIdentity (); glColor3f (1.0, 1.0, 1.0); draw_triangle (); glEnable (GL_LINE_STIPPLE); glLineStipple (1, 0xF0F0); glLoadIdentity (); glTranslatef (-20.0, 0.0, 0.0); draw_triangle (); glLineStipple (1, 0xF00F); glLoadIdentity (); glScalef (1.5, 0.5, 1.0); draw_triangle (); glLineStipple (1, 0x8888); glLoadIdentity (); glRotatef (90.0, 0.0, 0.0, 1.0); draw_triangle (); glDisable (GL_LINE_STIPPLE); glFlush (); }
/* Callback function for display. */ void display(void) { GLint a[] = {0, 0, 20}, b[] = {10, 10, 10}, c[] = {0, 0, 0}, d[] = {10, 0, 10}; glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 0.0, 0.0); draw_triangle(a, b, c); glColor3f(0.0, 1.0, 0.0); draw_triangle(a, b, d); glColor3f(0.0, 0.0, 1.0); draw_triangle(a, c, d); glColor3f(0.5, 0.5, 0.5); draw_triangle(b, c, d); glColor3f(1.0, 0.0, 0.0); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(20,0,0); glEnd(); glColor3f(0.0, 1.0, 0.0); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(0,20,0); glEnd(); glColor3f(0.0, 0.0, 1.0); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(0,0,20); glEnd(); glutSwapBuffers(); }
void Lesson_3_2::draw() { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glLoadIdentity(); glColor3f(1.0,1.0,1.0); draw_triangle(); glEnable(GL_LINE_STIPPLE); glLineStipple(1,0xF0F0); glLoadIdentity(); glTranslatef(-2.0,0.0,0.0); draw_triangle(); glLineStipple(1,0xF00F); glLoadIdentity(); glScalef(1.5,0.5,1.0); draw_triangle(); glLineStipple(1,0x8888); glLoadIdentity(); glRotatef(90.0,0.0,0.0,1.0); draw_triangle(); glDisable(GL_LINE_STIPPLE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); }
void display(UGWindow uwin) { glClear (GL_COLOR_BUFFER_BIT); glColor4f (1.0, 1.0, 1.0, 1.0); glLoadIdentity (); glColor4f (1.0, 1.0, 1.0, 1.0); draw_triangle (); /*glEnable (GL_LINE_STIPPLE);*/ /*glLineStipple (1, 0xF0F0);*/ glColor4f(1.0f, 0.f, 0.f, 1.f); glLoadIdentity (); glTranslatef (-20.0, 0.0, 0.0); draw_triangle (); /*glLineStipple (1, 0xF00F);*/ glColor4f(0.0f, 1.f, 0.f, 1.f); glLoadIdentity (); glScalef (1.5, 0.5, 1.0); draw_triangle (); /*glLineStipple (1, 0x8888);*/ glColor4f(0.0f, 0.f, 1.f, 1.f); glLoadIdentity (); glRotatef (90.0, 0.0, 0.0, 1.0); draw_triangle (); /*glDisable (GL_LINE_STIPPLE);*/ glFlush (); ugSwapBuffers(uwin); }
//draw cylinder based on two circles and multiple triangles void draw_cylinder (float baser, float topr, float h, int slices, float color[3],bool center,glm::mat4 M ) { glPushMatrix(); glMultMatrixf(&M[0][0]); if(center) glTranslatef(0,0,h/2); glTranslatef(0,0,h/2); draw_circle(topr,color); glTranslatef(0,0,-h); draw_circle(baser,color); glTranslatef(0,0,h/2); for (int i = 0; i < slices; ++i) { //sida = 360/slices draw_triangle(baser*cos(i*2*PI/slices),baser*sin(i*2*PI/slices),-h/2, baser*cos((i+1)*2*PI/slices),baser*sin((i+1)*2*PI/slices),-h/2, topr*cos(i*2*PI/slices),topr*sin(i*2*PI/slices),h/2); draw_triangle(topr*cos(i*2*PI/slices),topr*sin(i*2*PI/slices),h/2, topr*cos((i+1)*2*PI/slices),topr*sin((i+1)*2*PI/slices),h/2, baser*cos((i+1)*2*PI/slices),baser*sin((i+1)*2*PI/slices),-h/2); } //draw_triangle(base,-1,-h/2, -1,-1,-h/2, -1,1,-h/2); glPopMatrix(); }
static void draw_axes_directions() { struct Color col; col.r = 0.0; col.g = 0.5; col.b = 0.0; draw_triangle(x_axis_direction_vert, &col); draw_triangle(y_axis_direction_vert, &col); }
void draw_sort_trangle( char *filename ) { FILE *out ; Trangle *Ptr_tmp; int i,j; out = fopen( filename ,"w"); Ptr_tmp = start_node; for (i =0 ; i < trangle_number; i++ ) { Ptr_tmp = search_min_z(); draw_triangle(Ptr_tmp->node0->x,Ptr_tmp->node0->y,Ptr_tmp->node0->z, Ptr_tmp->node1->x,Ptr_tmp->node1->y,Ptr_tmp->node1->z, Ptr_tmp->node2->x,Ptr_tmp->node2->y,Ptr_tmp->node2->z); //Ptr_tmp = Ptr_tmp->next; } fprintf( out , "P3\n" ); fprintf( out , "800 600\n" ); fprintf( out , "255\n" ); for(j=0;j<600;j++) { for(i=0;i<800;i++) { fprintf(out,"%d %d %d ",screen_buffer[j][i].R,screen_buffer[j][i].G,screen_buffer[j][i].B); } } fclose(out); }
void rasterizer::draw_triangles() { const auto& desc = state_->get_desc(); if (desc.fm == fill_wireframe) { draw_lines(); } else if (desc.fm == fill_solid) { if (prim_vert_cnt_ < 3) { draw_lines(); return; } //draw_lines(); assert(prim_vert_cnt_ == 3); bool have_color = !colors_.empty(); for (size_t index = 0; index < indices_.size(); ) { const auto& v0 = wvp_[indices_[index]]; const auto& v1 = wvp_[indices_[index + 1]]; const auto& v2 = wvp_[indices_[index + 2]]; const color_rgba8* c0 = &color_rgba8::black; const color_rgba8* c1 = &color_rgba8::black; const color_rgba8* c2 = &color_rgba8::black; if (have_color) { c0 = &colors_[indices_[index]]; c1 = &colors_[indices_[index + 1]]; c2 = &colors_[indices_[index + 2]]; } draw_triangle(v0.x, v0.y, v1.x, v1.y, v2.x, v2.y, *c0, *c1, *c2); index += prim_vert_cnt_; } } }
void TestGame::engine_render() { buffer_clear(); static float rot = 0; rot += PI / 120; if (rot > 4 * PI) rot -= 4 * PI; camera_.x = (float)sin(rot) * 2.5f; camera_.y = -0.3f; camera_.z = (float)cos(rot) * 2.5f; Matrix4 viewMatrix = matrix_look_at(camera_, Vector3(0, 0, 0), vector_up()); Matrix4 projectionMatrix = matrix_perspective(0.1f, ((float)ENGINE_WIDTH) / ENGINE_HEIGHT, 0.01f, 1.0f); for (int i = 0; i < meshes_count_; i++) { Matrix4 transform = meshes_[i].world * viewMatrix * projectionMatrix; for (int j = 0; j < meshes_[i].face_count; j++) draw_triangle( project(meshes_[i].vertices[meshes_[i].faces[j].a], transform), project(meshes_[i].vertices[meshes_[i].faces[j].b], transform), project(meshes_[i].vertices[meshes_[i].faces[j].c], transform), meshes_[i].texture); } }
/*********************************** FUNCTION: draw_house ARGS: none RETURN: none DOES: helper build function; defines a hollow cube with a bottomless pyramid as rooftop ************************************/ void draw_house() { draw_triangle(vertices_house,0,1,2,RED); draw_triangle(vertices_house,0,2,3,GREEN); draw_triangle(vertices_house,0,3,4,WHITE); draw_triangle(vertices_house,0,4,1,GREY); draw_quad(vertices_house,2,1,5,6, BLUE); draw_triangle(vertices_house,2,6,3, CYAN); draw_triangle(vertices_house,3,6,7, CYAN); draw_triangle(vertices_house,3,7,8, YELLOW); draw_triangle(vertices_house,8,3,4, YELLOW); draw_triangle(vertices_house,4,8,1, MAGENTA); draw_triangle(vertices_house,1,8,5, MAGENTA); }
static void draw_bumper() { struct Color col; col.r = 0.0; col.g = 0.0; col.b = 0.0; draw_triangle(robot_measures.vert_bumper, &col); }
void draw_figure(IFS_DATA* ifs_data) { int i; for (i=0; i<ifs_data->numTriangles; ++i) { draw_triangle(ifs_data,i); } }
void ShZshapeManager::draw_shape(const char* content) { if (content == "cube") { draw_cube(); } if (content == "cylinder") { draw_cylinder(); } if (content == "pipe") { draw_pipe(); } if (content == "cone") { draw_cone(); } if (content == "circle") { draw_circle(); } if (content == "ring") { draw_ring(); } if (content == "pyramid") { draw_pyramid(); } if (content == "triangle") { draw_triangle(); } if (content == "rectangle") { draw_rectangle(); } if (content == "polygon") { draw_polygon(); } if (content == "multigonalStar") { draw_multigonalStar(); } }
/*TODO: add bottom and top face triangles*/ void draw_cube_brute() { draw_triangle(vertices_cube_brute, 4,5,1,BLUE); draw_triangle(vertices_cube_brute, 0,4,1,BLUE); draw_triangle(vertices_cube_brute, 5,6,2,CYAN); draw_triangle(vertices_cube_brute, 1,5,2,CYAN); draw_triangle(vertices_cube_brute, 3,2,6,YELLOW); draw_triangle(vertices_cube_brute, 7,3,6,YELLOW); draw_triangle(vertices_cube_brute, 0,3,7,MAGENTA); draw_triangle(vertices_cube_brute, 4,0,7,MAGENTA); }
static void draw(NVGcontext *nvg, struct gui_command_queue *queue, int width, int height) { const struct gui_command *cmd; glPushAttrib(GL_ENABLE_BIT|GL_COLOR_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glEnable(GL_SCISSOR_TEST); glEnable(GL_TEXTURE_2D); nvgBeginFrame(nvg, width, height, ((float)width/(float)height)); gui_foreach_command(cmd, queue) { switch (cmd->type) { case GUI_COMMAND_NOP: break; case GUI_COMMAND_SCISSOR: { const struct gui_command_scissor *s = gui_command(scissor, cmd); nvgScissor(nvg, s->x, s->y, s->w, s->h); } break; case GUI_COMMAND_LINE: { const struct gui_command_line *l = gui_command(line, cmd); draw_line(nvg, l->begin.x, l->begin.y, l->end.x, l->end.y, l->color); } break; case GUI_COMMAND_RECT: { const struct gui_command_rect *r = gui_command(rect, cmd); draw_rect(nvg, r->x, r->y, r->w, r->h, r->rounding, r->color); } break; case GUI_COMMAND_CIRCLE: { const struct gui_command_circle *c = gui_command(circle, cmd); draw_circle(nvg, c->x, c->y, (float)c->w / 2.0f, c->color); } break; case GUI_COMMAND_TRIANGLE: { const struct gui_command_triangle *t = gui_command(triangle, cmd); draw_triangle(nvg, t->a.x, t->a.y, t->b.x, t->b.y, t->c.x, t->c.y, t->color); } break; case GUI_COMMAND_TEXT: { const struct gui_command_text *t = gui_command(text, cmd); draw_text(nvg, t->x, t->y, t->w, t->h, t->foreground, t->background, t->string, t->length); } break; case GUI_COMMAND_IMAGE: { const struct gui_command_image *i = gui_command(image, cmd); draw_image(nvg, i->img.handle, i->x, i->y, i->w, i->h, 1); } break; case GUI_COMMAND_MAX: default: break; } } gui_command_queue_clear(queue); nvgResetScissor(nvg); nvgEndFrame(nvg); glPopAttrib(); }
int main(int argc, char* argv[]) { set_delay_time(1); create_turtle_world(); for (int n = 1; n < 73; n++) { draw_triangle(n); } return(p1world_shutdown()); }
/*TODO: add bottom and top face triangles*/ void draw_cube_brute() { draw_triangle(vertices_cube_brute, 4,5,1,BLUE); draw_triangle(vertices_cube_brute, 0,4,1,BLUE); draw_triangle(vertices_cube_brute, 5,6,2,CYAN); draw_triangle(vertices_cube_brute, 1,5,2,CYAN); draw_triangle(vertices_cube_brute, 3,2,6,YELLOW); draw_triangle(vertices_cube_brute, 7,3,6,YELLOW); draw_triangle(vertices_cube_brute, 0,3,7,MAGENTA); draw_triangle(vertices_cube_brute, 4,0,7,MAGENTA); draw_triangle(vertices_cube_brute, 1,2,3,WHITE); draw_triangle(vertices_cube_brute, 7,6,5,WHITE); //manually calculate the normals for the cube if(draw_norms){ glBegin(GL_LINES); { glVertex4f(1,1,-1,1); glVertex4f(1+1/sqrt(3),1+1/sqrt(3),-1-1/sqrt(3),1); glVertex4f(1,-1,-1,1); glVertex4f(1+1/sqrt(3),-1-1/sqrt(3),-1-1/sqrt(3),1); glVertex4d(1,-1,1,1); glVertex4f(1+1/sqrt(3),-1-1/sqrt(3),1+1/sqrt(3),1); glVertex4d(-1,-1,1,1); glVertex4f(-1-1/sqrt(3),-1-1/sqrt(3),1+1/sqrt(3),1); glVertex4d(-1,1,1,1); glVertex4f(-1-1/sqrt(3),1+1/sqrt(3),1+1/sqrt(3),1); glVertex4d(-1,1,-1,1); glVertex4f(-1-1/sqrt(3),1+1/sqrt(3),-1-1/sqrt(3),1); glVertex4d(-1,-1,-1,1); glVertex4f(-1-1/sqrt(3),-1-1/sqrt(3),-1-1/sqrt(3),1); glVertex4d(1,1,1,1); glVertex4f(1+1/sqrt(3),1+1/sqrt(3),1+1/sqrt(3),1); } glEnd(); } }
/* Renders a triangle that rotates. */ void render(GLFWwindow* window) { float ratio = prepare_view_port(window); prepare_identity_matrix(ratio); glLoadIdentity(); glRotatef((float)glfwGetTime() * 50.f, 0.f, 0.f, 1.f); draw_triangle(); // Swap the window buffer with the buffer we've drawn to. glfwSwapBuffers(window); }
//draw circle implementation (This is the correct way of drawing circles, but fps is too low) void draw_circle2 (float r,float color[3]){ glPushMatrix(); int cut =24; glColor3f(color[0],color[1],color[2]); //glScalef(r*1.414,r*1.414,0); for (int i = 0; i < cut; ++i) { draw_triangle(r*cos(i*2*PI/cut),r*sin(i*2*PI/cut),0, r*cos((i+1)*2*PI/cut),r*sin((i+1)*2*PI/cut),0, 0,0,0); } glPopMatrix(); }
YUMEALIGN16 void window::draw(std::vector<Eigen::Vector4f, Eigen::aligned_allocator<Eigen::Vector4f>> vertices) { std::vector<triangle> triangles; triangles.resize(vertices.size() / 3); for (size_t i = 0; i < vertices.size(); i += 3) { triangles[i / 3].points.resize(3); triangles[i / 3].points[0] = vertices[i + 0]; triangles[i / 3].points[1] = vertices[i + 1]; triangles[i / 3].points[2] = vertices[i + 2]; } for (auto triangle : triangles) { draw_triangle(triangle); } }
void hail_to_raster ( NIDS_image *im, NIDS_hail *h) { int i, j; if (h->severe >= 50) { for (i = 16, j = 20 ; i > 0; i--, j--) { draw_triangle(im, h->x_start, h->y_start, i, j, 3); } } else if (h->severe >= 30) { draw_triangle(im, h->x_start, h->y_start, 16, 20, 3); } else if (h->prob >= 50) { for (i = 8, j = 12 ; i > 0; i--, j--) { draw_triangle(im, h->x_start, h->y_start, i, j, 3); } } else if (h->severe >= 30) { draw_triangle(im, h->x_start, h->y_start, 8, 12, 3); } }
void display( void ) { glClear( GL_COLOR_BUFFER_BIT ); // clear the window draw_circle(0); // size = 50 draw_ellipse(50); // size = 38 draw_triangle(88); // size = 3 draw_square(91); // size = 6 draw_square(97); // size = 6 draw_square(103); // size = 6 draw_square(109); // size = 6 draw_square(115); // size = 6 draw_square(121); // size = 6 glFlush(); }
int draw(t_env *e) { draw_triangle(e); // do_the_thing(e, e->beta, 0, 0); ft_more(e, 3); // ft_more(e, 5); // ft_more(e, 11 ); int i = 5; while (i < 51) { ft_more(e, i); i+= 7; } // print_old(e); return (0); }
void test_triangles(Screen* screen) { fill_screen(screen, color_make(2, 0, 0)); Coordinate p1 = point_make(screen->window->size.width / 2, 0); Coordinate p2 = point_make(0, screen->window->size.height - 10); Coordinate p3 = point_make(screen->window->size.width, screen->window->size.height - 10); for (int i = 1; i <= 12; i++) { Triangle t = triangle_make(p1, p2, p3); draw_triangle(screen, t, color_make(i, 0, 0), THICKNESS_FILLED); p1.y += i * 2; p2.x += i * 1.5; p2.y -= i / 2; p3.x -= i * 1.5; p3.y -= i / 2; } }
void display(void) { glLoadIdentity(); gluLookAt (ex, ey, ez, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0); glScalef(dimx, dimy, dimz); glClear (GL_COLOR_BUFFER_BIT); glClear (GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(xRotation, 1, 0, 0); int pt; for(pt=0; pt<20; pt++){ draw_triangle(sommets[sindex[pt][0]], sommets[sindex[pt][1]], sommets[sindex[pt][2]]); } glPopMatrix(); glutSwapBuffers(); }
/* The main rendering callback */ static gboolean render (GtkGLArea *area, GdkGLContext *context) { glClearColor (0.5, 0.5, 0.5, 1.0); glClear (GL_COLOR_BUFFER_BIT); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); glRotatef (rotation_angles[X_AXIS], 1, 0, 0); glRotatef (rotation_angles[Y_AXIS], 0, 1, 0); glRotatef (rotation_angles[Z_AXIS], 0, 0, 1); draw_triangle (); glFlush (); return TRUE; }
static gboolean render (GtkGLArea *area, GdkGLContext *context) { if (gtk_gl_area_get_error (area) != NULL) return FALSE; /* Clear the viewport */ glClearColor (0.5, 0.5, 0.5, 1.0); glClear (GL_COLOR_BUFFER_BIT); /* Draw our object */ draw_triangle (); /* Flush the contents of the pipeline */ glFlush (); return TRUE; }
void TestRasterizationSpeed(void) { const int N = 1000; struct timeval t0, t1; double diff; //srand(123456); gettimeofday(&t0, NULL); if (draw_optimized) { for (int t = 0; t < N; t++) { draw_triangle_optimized( rand()%framebuffer_width, rand()%framebuffer_height, rand()%framebuffer_width, rand()%framebuffer_height, rand()%framebuffer_width, rand()%framebuffer_height, colors[t%6].r, colors[t%6].g, colors[t%6].b); } } else { for (int t = 0; t < N; t++) { draw_triangle( rand()%framebuffer_width, rand()%framebuffer_height, rand()%framebuffer_width, rand()%framebuffer_height, rand()%framebuffer_width, rand()%framebuffer_height, colors[t%6].r, colors[t%6].g, colors[t%6].b); } } gettimeofday(&t1, NULL); /* calculate time used */ diff = t1.tv_sec - t0.tv_sec + (t1.tv_usec - t0.tv_usec)*1.0e-6; printf("%d triangles in %.6f seconds, %.1f triangles/sec\n", N, diff, N/diff); }
END_TEST // STUB goes here START_TEST(test_draw_triangle) { char stu[2048]; char *mod = "....#\n...##\n..###\n.####\n#####\n"; int size = 5; freopen("mockoutput", "w", stdout); draw_triangle(size); read_stdout(stu, 2048); char infostr[100] = ""; if (mycompare(stu, mod, infostr)) { fail("[Task 1.5] Called draw_triangle(%d). Your output:\n%s\nReference output:\n%s\nReason: %s\n", size, stu, mod, infostr); } }
void CusefulView::OnDraw(CDC* pDC) { CusefulDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; if(pDoc->m_triShow) draw_triangle(pDoc->m_tinNet,pDoc->m_triVex,pDC); if(pDoc->m_gridShow) draw_grid(pDoc->m_grid,pDC); if(pDoc->m_shp_Show) { CRect clientRect; this->GetClientRect( &clientRect ); if ( m_pMapControl == 0 ) return ; m_pMapControl->SetViewBound( clientRect.left,clientRect.top,clientRect.Width(), clientRect.Height() ); m_pMapControl->DrawMap(); } // TODO: 在此处为本机数据添加绘制代码 }