void collageHexagon(int n, int m, float r, float v) { for(int i = 0; i < n; i++) { pushCT(); for(int j=0; j <ceil((float) m/2); j++) { hexagon(r); translate2D(3*r,0); } popCT(); if(i%2==0) translate2D(3*r/2,v); else translate2D(-3*r/2,v); } }
void displayFunc() { /* define initial position for triangle */ GLint nVerts = 3; wcPt2D verts[3] = { { 50.0, 25.0 },{ 150.0, 25.0 },{ 100.0, 100.0 } }; /* calculate position of triangle centroid */ wcPt2D centroidPt; GLint k, xSum = 0, ySum = 0; for (k = 0; k < nVerts; k++) { xSum += verts[k].x; ySum += verts[k].y; } centroidPt.x = GLfloat(xSum) / GLfloat(nVerts); centroidPt.y = GLfloat(ySum) / GLfloat(nVerts); /* set geometric transformation parameters */ wcPt2D pivPt, fixedPt; pivPt = centroidPt; fixedPt = centroidPt; GLfloat tx = 0.0, ty = 100.0; GLfloat sx = 0.5, sy = 0.5; GLdouble theta = pi / 2.0; glClear(GL_COLOR_BUFFER_BIT); // clear display window glColor3f(0.0, 0.0, 1.0); // set initial fill coor to blue triangle(verts); // display blue triangle /* initialize composite matrix to identity */ matrix3x3SetIndentity(matComposite); // here will not copy matrix, because it sent a pointer which point to the matrix /* construc composite matrix to triangle vertices */ scale2D(sx, sy, fixedPt); rotate2D(pivPt, theta); translate2D(tx, ty); /* apply composite matrix to triangle verteices*/ transformVerts2D(nVerts, verts); glColor3f(1.0, 0.0, 0.0); // set color for transform triangle triangle(verts); // display red transformed triangle glFlush(); }
void CircleDrawer::makeDrawCalls(bool sendColors) { glEnable(GL_DEPTH_TEST); for (vector<Circle>::iterator it = circles_->begin(); it != circles_->end(); ++it) { glm::mat3 circle_transform(1.0f); circle_transform = translate2D(circle_transform, it->center); circle_transform = scale2D(circle_transform, glm::vec2(it->radius + delta_radius_)); glUniformMatrix3fv(Renderer::instance().uniformHandle("modelview"), 1, GL_FALSE, glm::value_ptr(fullTransform() * circle_transform)); if (sendColors) { glUniform4fv(Renderer::instance().uniformHandle("color"), 1, glm::value_ptr(it->color)); } glBindVertexArray(array_object_); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } glDisable(GL_DEPTH_TEST); }
void Renderer::draw() { // 2D rendering modelview glm::mat3 view(1.0f); view = translate2D(view, glm::vec2(-1.0f, -1.0f)); view = scale2D(view, glm::vec2(2.0f/aspect_, 2.0f)); view = translate2D(view, glm::vec2(-left_of_window_, 0.0f)); root_node_.setRelativeTransform(view); vector<SceneNode *> draw2D; root_node_.getSortedVisibleDescendants(&draw2D); // Draw occluders to texture. //glBindFramebuffer(GL_FRAMEBUFFER, 0); //glViewport(0,0,width_, height_); glBindFramebuffer(GL_FRAMEBUFFER, occluder_frame_buffer_); glViewport(0,0,width_/2, height_/2); glDepthMask(GL_TRUE); glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDepthMask(GL_FALSE); for (vector<SceneNode *>::iterator it = draw2D.begin(); it != draw2D.end(); ++it) { if ((*it)->isOccluder()) (*it)->drawOccluder(); } //return; //glBindFramebuffer(GL_FRAMEBUFFER, 0); //glViewport(0,0,width_, height_); glBindFramebuffer(GL_FRAMEBUFFER, shadow_frame_buffer_); glDepthMask(GL_TRUE); glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDepthMask(GL_FALSE); useProgram("shadows"); glm::vec3 transformed_light_position = view * glm::vec3(light_position_, 1.0f); glUniform2fv(uniformHandle("light_position"), 1, glm::value_ptr(transformed_light_position)); glBindTexture(GL_TEXTURE_2D, shadow_texture_); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, occluder_texture_); glBindVertexArray(quad_array_object_); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //return; glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0,0,width_, height_); glDepthMask(GL_TRUE); glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDepthMask(GL_FALSE); glEnable(GL_MULTISAMPLE); glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, shadow_texture_); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); for (vector<SceneNode *>::iterator it = draw2D.begin(); it != draw2D.end(); ++it) { if ((*it)->isVisible()) (*it)->draw(); } if (do_stencil_) { glEnable(GL_STENCIL_TEST); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glStencilFunc(GL_ALWAYS, 0, 0xFF); glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); for (vector<SceneNode *>::iterator it = draw2D.begin(); it != draw2D.end(); ++it) { if ((*it)->is3DStencil()) (*it)->draw(); } glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glStencilFunc(GL_NOTEQUAL, 0, 0xFF); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); } glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); glEnable(GL_BLEND); for (vector<Drawable *>::iterator it = draw3D_.begin(); it != draw3D_.end(); ++it) { (*it)->draw(); } glDisable(GL_BLEND); if (do_stencil_) { glDisable(GL_STENCIL_TEST); } }