void MyPanelOpenGL::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslated(5.0, 5.0, 0.0); // The middle of the screen is located at (5, 5, 0), thus I translate. switch (myMode) { case rectangle: { glColor3f(1.0f, 1.0f, 0.0f); draw_rect2d(rect_width, rect_height); break; } case circle: { glColor3f(0.0f, 1.0f, 0.0f); draw_circle2d(circle_radius, circle_verticies); break; } case triangle: { draw_triangle2d(triangle_point1, triangle_point2, triangle_point3); break; } case custom: { draw_custom(); break; } } glFlush(); }
void GLWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glScalef(2, 2, 0); glTranslatef(-0.5, -0.5, 0); //grid glColor3f(0,0,0); glLineWidth(1); draw_grid2d(Vec2f(0,0), sim.dx, sim.n, sim.n); //particles glColor3f(0,0,1); for(int i=0; i < sim.particles.size(); i++){ draw_circle2d(sim.particles[i], sim.particle_radius, 20); } //velocity glColor3f(1,0,0); for(int j = 0;j < sim.n; ++j) for(int i = 0; i < sim.n; ++i) { Vec2f pos((i+0.5)*sim.dx,(j+0.5)*sim.dx); draw_arrow2d(pos, pos + 0.01f*sim.get_velocity(pos), 0.01*sim.dx); } }
/** * This is my custom function in which I will draw something fun. */ void MyPanelOpenGL::draw_custom() { // First draw the picture frame glLineWidth(3.0f); glColor3f(0.6f, 0.0f, 0.2f); glBegin(GL_LINE_LOOP); glVertex2f(-2.0f, -2.0f); glVertex2f(2.0f, -2.0f); glVertex2f(2.0f, 2.0f); glVertex2f(-2.0f, 2.0f); glEnd(); glBegin(GL_LINE_LOOP); glVertex2f(-1.8f, -1.8f); glVertex2f(1.8f, -1.8f); glVertex2f(1.8f, 1.8f); glVertex2f(-1.8f, 1.8f); glEnd(); // Draw insides - star (circle) // Inside: Draw Lines int i; float angle; glBegin(GL_LINES); for (i = 0; i < 8; i++) { angle = 3.14159 * 2 * i / 8; // 2PI * i/v glColor3f(angle, angle, angle); glVertex2f(1.0f * sin(angle), 1.0f * cos(angle)); glColor3f(angle/128, angle/128, angle/128); glVertex2f(-1.0f * sin(angle), -1.0f * cos(angle)); } glEnd(); // Inside: Draw Circles on each tip for (i = 0; i < 8; i++) { // Every time I will reset matrix and re-translate to center so that I can properly translate to end of line. glLoadIdentity(); glTranslatef(5.0f, 5.0f, 0.0f); angle = 3.14159 * 2 * i / 8; // 2PI * i/v glTranslatef(1.0f * sin(angle), 1.0f * cos(angle), 0.0f); glColor3f(0.1f, 0.0f, 1.0f); draw_circle2d(0.1f, 16); } }