void drawFullScreenRect(RenderingContext & rc){ GET_GL_ERROR(); static Geometry::Matrix4x4f projectionMatrix(Geometry::Matrix4x4f::orthographicProjection(-1, 1, -1, 1, -1, 1)); static Geometry::Matrix4x4f modelViewMatrix; static Util::Reference<Mesh> mesh; if(mesh.isNull()) { VertexDescription vertexDescription; vertexDescription.appendPosition3D(); vertexDescription.appendTexCoord(); MeshUtils::MeshBuilder mb(vertexDescription); mb.position(Geometry::Vec3f(-1,-1,0)); mb.texCoord0(Geometry::Vec2f(0,0)); uint32_t a = mb.addVertex(); mb.position(Geometry::Vec3f(1,-1,0)); mb.texCoord0(Geometry::Vec2f(1,0)); uint32_t b = mb.addVertex(); mb.position(Geometry::Vec3f(-1,1,0)); mb.texCoord0(Geometry::Vec2f(0,1)); uint32_t c = mb.addVertex(); mb.position(Geometry::Vec3f(1,1,0)); mb.texCoord0(Geometry::Vec2f(1,1)); uint32_t d = mb.addVertex(); mb.addTriangle(a, b, c); mb.addTriangle(c, b, d); mesh = mb.buildMesh(); } rc.pushMatrix_cameraToClipping(); rc.setMatrix_cameraToClipping(projectionMatrix); rc.pushMatrix_modelToCamera(); rc.setMatrix_modelToCamera(modelViewMatrix); rc.displayMesh(mesh.get()); rc.popMatrix_modelToCamera(); rc.popMatrix_cameraToClipping(); GET_GL_ERROR(); }
void drawQuad(RenderingContext & rc, const Geometry::Vec3 & lowerLeft, const Geometry::Vec3 & lowerRight, const Geometry::Vec3 & upperRight, const Geometry::Vec3 & upperLeft) { static Util::Reference<Mesh> mesh; if (mesh.isNull()) { VertexDescription vertexDescription; vertexDescription.appendPosition3D(); vertexDescription.appendNormalFloat(); vertexDescription.appendTexCoord(); mesh = new Mesh(vertexDescription, 4, 6); MeshIndexData & id = mesh->openIndexData(); uint32_t * indices = id.data(); indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 0; indices[4] = 2; indices[5] = 3; id.updateIndexRange(); id.markAsChanged(); } const Geometry::Vec3 edgeA = lowerRight - lowerLeft; const Geometry::Vec3 edgeB = upperLeft - lowerLeft; Geometry::Vec3 normal = edgeA.cross(edgeB); normal.normalize(); MeshVertexData & vd = mesh->openVertexData(); float * vertices = reinterpret_cast<float *> (vd.data()); // Lower left *vertices++ = lowerLeft.getX(); *vertices++ = lowerLeft.getY(); *vertices++ = lowerLeft.getZ(); *vertices++ = normal.getX(); *vertices++ = normal.getY(); *vertices++ = normal.getZ(); *vertices++ = 0.0f; *vertices++ = 0.0f; // Lower right *vertices++ = lowerRight.getX(); *vertices++ = lowerRight.getY(); *vertices++ = lowerRight.getZ(); *vertices++ = normal.getX(); *vertices++ = normal.getY(); *vertices++ = normal.getZ(); *vertices++ = 1.0f; *vertices++ = 0.0f; // Upper right *vertices++ = upperRight.getX(); *vertices++ = upperRight.getY(); *vertices++ = upperRight.getZ(); *vertices++ = normal.getX(); *vertices++ = normal.getY(); *vertices++ = normal.getZ(); *vertices++ = 1.0f; *vertices++ = 1.0f; // Upper left *vertices++ = upperLeft.getX(); *vertices++ = upperLeft.getY(); *vertices++ = upperLeft.getZ(); *vertices++ = normal.getX(); *vertices++ = normal.getY(); *vertices++ = normal.getZ(); *vertices++ = 0.0f; *vertices++ = 1.0f; vd.updateBoundingBox(); vd.markAsChanged(); rc.displayMesh(mesh.get()); }