Browse Source

Split the OpenGL layer out, pt 25: updated documentation code snippets.

pull/233/head
Vladimír Vondruš 8 years ago
parent
commit
499984e82c
  1. 128
      doc/generated/primitives.cpp
  2. 126
      doc/generated/shaders.cpp
  3. 16
      doc/snippets/MagnumGL-framebuffer.cpp
  4. 674
      doc/snippets/MagnumGL.cpp
  5. 21
      doc/snippets/MagnumMeshTools.cpp
  6. 4
      doc/snippets/MagnumPlatform-custom.cpp
  7. 4
      doc/snippets/MagnumPlatform-windowless-custom.cpp
  8. 4
      doc/snippets/MagnumPlatform-windowless-thread.cpp
  9. 4
      doc/snippets/MagnumPlatform-windowless.cpp
  10. 8
      doc/snippets/MagnumPlatform.cpp
  11. 92
      doc/snippets/MagnumShaders.cpp
  12. 8
      doc/snippets/MagnumText.cpp
  13. 17
      doc/snippets/getting-started-blue.cpp
  14. 4
      doc/snippets/getting-started.cpp

128
doc/generated/primitives.cpp

@ -36,16 +36,16 @@
#error no windowless application available on this platform #error no windowless application available on this platform
#endif #endif
#include <Magnum/Buffer.h>
#include <Magnum/Framebuffer.h>
#include <Magnum/Image.h> #include <Magnum/Image.h>
#include <Magnum/Mesh.h>
#include <Magnum/PixelFormat.h> #include <Magnum/PixelFormat.h>
#include <Magnum/Renderbuffer.h> #include <Magnum/GL/Buffer.h>
#include <Magnum/RenderbufferFormat.h> #include <Magnum/GL/Framebuffer.h>
#include <Magnum/Renderer.h> #include <Magnum/GL/Mesh.h>
#include <Magnum/Texture.h> #include <Magnum/GL/Renderbuffer.h>
#include <Magnum/TextureFormat.h> #include <Magnum/GL/RenderbufferFormat.h>
#include <Magnum/GL/Renderer.h>
#include <Magnum/GL/Texture.h>
#include <Magnum/GL/TextureFormat.h>
#include <Magnum/MeshTools/Compile.h> #include <Magnum/MeshTools/Compile.h>
#include <Magnum/MeshTools/Interleave.h> #include <Magnum/MeshTools/Interleave.h>
#include <Magnum/MeshTools/Transform.h> #include <Magnum/MeshTools/Transform.h>
@ -135,56 +135,56 @@ int PrimitiveVisualizer::exec() {
std::exit(1); std::exit(1);
} }
Renderbuffer multisampleColor, multisampleDepth; GL::Renderbuffer multisampleColor, multisampleDepth;
multisampleColor.setStorageMultisample(16, RenderbufferFormat::RGBA8, ImageSize); multisampleColor.setStorageMultisample(16, GL::RenderbufferFormat::RGBA8, ImageSize);
multisampleDepth.setStorageMultisample(16, RenderbufferFormat::DepthComponent24, ImageSize); multisampleDepth.setStorageMultisample(16, GL::RenderbufferFormat::DepthComponent24, ImageSize);
Framebuffer multisampleFramebuffer{{{}, ImageSize}}; GL::Framebuffer multisampleFramebuffer{{{}, ImageSize}};
multisampleFramebuffer.attachRenderbuffer(Framebuffer::ColorAttachment{0}, multisampleColor) multisampleFramebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, multisampleColor)
.attachRenderbuffer(Framebuffer::BufferAttachment::Depth, multisampleDepth) .attachRenderbuffer(GL::Framebuffer::BufferAttachment::Depth, multisampleDepth)
.bind(); .bind();
CORRADE_INTERNAL_ASSERT(multisampleFramebuffer.checkStatus(FramebufferTarget::Draw) == Framebuffer::Status::Complete); CORRADE_INTERNAL_ASSERT(multisampleFramebuffer.checkStatus(GL::FramebufferTarget::Draw) == GL::Framebuffer::Status::Complete);
Renderbuffer color; GL::Renderbuffer color;
color.setStorage(RenderbufferFormat::RGBA8, ImageSize); color.setStorage(GL::RenderbufferFormat::RGBA8, ImageSize);
Framebuffer framebuffer{{{}, ImageSize}}; GL::Framebuffer framebuffer{{{}, ImageSize}};
framebuffer.attachRenderbuffer(Framebuffer::ColorAttachment{0}, color); framebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, color);
/* Cheating a bit and enabling only face culling instead of depth test in /* Cheating a bit and enabling only face culling instead of depth test in
order to draw the wireframe over. I couldn't get polygon offset to work order to draw the wireframe over. I couldn't get polygon offset to work
on the first try so I gave up. This will of course break with things on the first try so I gave up. This will of course break with things
like torus later. */ like torus later. */
Renderer::enable(Renderer::Feature::FaceCulling); GL::Renderer::enable(GL::Renderer::Feature::FaceCulling);
Renderer::enable(Renderer::Feature::Blending); GL::Renderer::enable(GL::Renderer::Feature::Blending);
Renderer::setBlendFunction(Renderer::BlendFunction::One, Renderer::BlendFunction::One); GL::Renderer::setBlendFunction(GL::Renderer::BlendFunction::One, GL::Renderer::BlendFunction::One);
Renderer::setClearColor(0x000000_rgbaf); GL::Renderer::setClearColor(0x000000_rgbaf);
Renderer::setLineWidth(1.5f); GL::Renderer::setLineWidth(1.5f);
{ {
Shaders::VertexColor2D shader; Shaders::VertexColor2D shader;
shader.setTransformationProjectionMatrix(Projection2D*Transformation2D); shader.setTransformationProjectionMatrix(Projection2D*Transformation2D);
for(auto fun: {&PrimitiveVisualizer::axis2D}) { for(auto fun: {&PrimitiveVisualizer::axis2D}) {
multisampleFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth); multisampleFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
std::string filename; std::string filename;
Containers::Optional<Trade::MeshData2D> data; Containers::Optional<Trade::MeshData2D> data;
std::tie(data, filename) = (this->*fun)(); std::tie(data, filename) = (this->*fun)();
/* TODO: use MeshTools::compile() once it can handle colors */ /* TODO: use MeshTools::compile() once it can handle colors */
Buffer vertices, indices; GL::Buffer vertices, indices;
vertices.setData(MeshTools::interleave(data->positions(0), data->colors(0)), BufferUsage::StaticDraw); vertices.setData(MeshTools::interleave(data->positions(0), data->colors(0)), GL::BufferUsage::StaticDraw);
indices.setData(data->indices(), BufferUsage::StaticDraw); indices.setData(data->indices(), GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, Shaders::VertexColor2D::Position{}, Shaders::VertexColor2D::Color{Shaders::VertexColor2D::Color::Components::Four}) mesh.addVertexBuffer(vertices, 0, Shaders::VertexColor2D::Position{}, Shaders::VertexColor2D::Color{Shaders::VertexColor2D::Color::Components::Four})
.setIndexBuffer(indices, 0, Mesh::IndexType::UnsignedInt) .setIndexBuffer(indices, 0, GL::MeshIndexType::UnsignedInt)
.setCount(data->indices().size()) .setCount(data->indices().size())
.setPrimitive(data->primitive()); .setPrimitive(data->primitive());
mesh.draw(shader); mesh.draw(shader);
AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), FramebufferBlit::Color); GL::AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), GL::FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA, PixelType::UnsignedByte}); Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA8Unorm});
converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename)); converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename));
} }
} }
@ -194,26 +194,26 @@ int PrimitiveVisualizer::exec() {
shader.setTransformationProjectionMatrix(Projection3D*Transformation3D); shader.setTransformationProjectionMatrix(Projection3D*Transformation3D);
for(auto fun: {&PrimitiveVisualizer::axis3D}) { for(auto fun: {&PrimitiveVisualizer::axis3D}) {
multisampleFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth); multisampleFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
std::string filename; std::string filename;
Containers::Optional<Trade::MeshData3D> data; Containers::Optional<Trade::MeshData3D> data;
std::tie(data, filename) = (this->*fun)(); std::tie(data, filename) = (this->*fun)();
/* TODO: use MeshTools::compile() once it can handle colors */ /* TODO: use MeshTools::compile() once it can handle colors */
Buffer vertices, indices; GL::Buffer vertices, indices;
vertices.setData(MeshTools::interleave(data->positions(0), data->colors(0)), BufferUsage::StaticDraw); vertices.setData(MeshTools::interleave(data->positions(0), data->colors(0)), GL::BufferUsage::StaticDraw);
indices.setData(data->indices(), BufferUsage::StaticDraw); indices.setData(data->indices(), GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, Shaders::VertexColor3D::Position{}, Shaders::VertexColor3D::Color{Shaders::VertexColor3D::Color::Components::Four}) mesh.addVertexBuffer(vertices, 0, Shaders::VertexColor3D::Position{}, Shaders::VertexColor3D::Color{Shaders::VertexColor3D::Color::Components::Four})
.setIndexBuffer(indices, 0, Mesh::IndexType::UnsignedInt) .setIndexBuffer(indices, 0, GL::MeshIndexType::UnsignedInt)
.setCount(data->indices().size()) .setCount(data->indices().size())
.setPrimitive(data->primitive()); .setPrimitive(data->primitive());
mesh.draw(shader); mesh.draw(shader);
AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), FramebufferBlit::Color); GL::AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), GL::FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA, PixelType::UnsignedByte}); Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA8Unorm});
converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename)); converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename));
} }
} }
@ -229,20 +229,20 @@ int PrimitiveVisualizer::exec() {
&PrimitiveVisualizer::line2D, &PrimitiveVisualizer::line2D,
&PrimitiveVisualizer::squareWireframe}) &PrimitiveVisualizer::squareWireframe})
{ {
multisampleFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth); multisampleFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
std::string filename; std::string filename;
Containers::Optional<Trade::MeshData2D> data; Containers::Optional<Trade::MeshData2D> data;
std::tie(data, filename) = (this->*fun)(); std::tie(data, filename) = (this->*fun)();
std::unique_ptr<Buffer> vertices, indices; std::unique_ptr<GL::Buffer> vertices, indices;
Mesh mesh{NoCreate}; GL::Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(*data, BufferUsage::StaticDraw); std::tie(mesh, vertices, indices) = MeshTools::compile(*data, GL::BufferUsage::StaticDraw);
mesh.draw(shader); mesh.draw(shader);
AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), FramebufferBlit::Color); GL::AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), GL::FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA, PixelType::UnsignedByte}); Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA8Unorm});
converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename)); converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename));
} }
} }
@ -263,20 +263,20 @@ int PrimitiveVisualizer::exec() {
&PrimitiveVisualizer::planeWireframe, &PrimitiveVisualizer::planeWireframe,
&PrimitiveVisualizer::uvSphereWireframe}) &PrimitiveVisualizer::uvSphereWireframe})
{ {
multisampleFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth); multisampleFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
std::string filename; std::string filename;
Containers::Optional<Trade::MeshData3D> data; Containers::Optional<Trade::MeshData3D> data;
std::tie(data, filename) = (this->*fun)(); std::tie(data, filename) = (this->*fun)();
std::unique_ptr<Buffer> vertices, indices; std::unique_ptr<GL::Buffer> vertices, indices;
Mesh mesh{NoCreate}; GL::Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(*data, BufferUsage::StaticDraw); std::tie(mesh, vertices, indices) = MeshTools::compile(*data, GL::BufferUsage::StaticDraw);
mesh.draw(shader); mesh.draw(shader);
AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), FramebufferBlit::Color); GL::AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), GL::FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA, PixelType::UnsignedByte}); Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA8Unorm});
converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename)); converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename));
} }
} }
@ -296,24 +296,24 @@ int PrimitiveVisualizer::exec() {
for(auto fun: {&PrimitiveVisualizer::circle2DSolid, for(auto fun: {&PrimitiveVisualizer::circle2DSolid,
&PrimitiveVisualizer::squareSolid}) &PrimitiveVisualizer::squareSolid})
{ {
multisampleFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth); multisampleFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
std::string filename; std::string filename;
Containers::Optional<Trade::MeshData2D> data; Containers::Optional<Trade::MeshData2D> data;
std::tie(data, filename) = (this->*fun)(); std::tie(data, filename) = (this->*fun)();
/* TODO: use MeshTools::compile() and MeshVisualizer2D once it exists */ /* TODO: use MeshTools::compile() and MeshVisualizer2D once it exists */
Buffer vertices; GL::Buffer vertices;
vertices.setData(data->positions(0), BufferUsage::StaticDraw); vertices.setData(data->positions(0), GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, Shaders::MeshVisualizer::Position{Shaders::MeshVisualizer::Position::Components::Two}) mesh.addVertexBuffer(vertices, 0, Shaders::MeshVisualizer::Position{Shaders::MeshVisualizer::Position::Components::Two})
.setCount(data->positions(0).size()) .setCount(data->positions(0).size())
.setPrimitive(data->primitive()); .setPrimitive(data->primitive());
mesh.draw(shader); mesh.draw(shader);
AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), FramebufferBlit::Color); GL::AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), GL::FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA, PixelType::UnsignedByte}); Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA8Unorm});
converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename)); converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename));
} }
} }
@ -344,21 +344,21 @@ int PrimitiveVisualizer::exec() {
&PrimitiveVisualizer::planeSolid, &PrimitiveVisualizer::planeSolid,
&PrimitiveVisualizer::uvSphereSolid}) &PrimitiveVisualizer::uvSphereSolid})
{ {
multisampleFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth); multisampleFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
std::string filename; std::string filename;
Containers::Optional<Trade::MeshData3D> data; Containers::Optional<Trade::MeshData3D> data;
std::tie(data, filename) = (this->*fun)(); std::tie(data, filename) = (this->*fun)();
std::unique_ptr<Buffer> vertices, indices; std::unique_ptr<GL::Buffer> vertices, indices;
Mesh mesh{NoCreate}; GL::Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(*data, BufferUsage::StaticDraw); std::tie(mesh, vertices, indices) = MeshTools::compile(*data, GL::BufferUsage::StaticDraw);
mesh.draw(phong); mesh.draw(phong);
mesh.draw(wireframe); mesh.draw(wireframe);
AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), FramebufferBlit::Color); GL::AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), GL::FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA, PixelType::UnsignedByte}); Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA8Unorm});
converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename)); converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename));
} }
} }

126
doc/generated/shaders.cpp

@ -36,16 +36,16 @@
#error no windowless application available on this platform #error no windowless application available on this platform
#endif #endif
#include <Magnum/Buffer.h>
#include <Magnum/Framebuffer.h>
#include <Magnum/Image.h> #include <Magnum/Image.h>
#include <Magnum/Mesh.h>
#include <Magnum/PixelFormat.h> #include <Magnum/PixelFormat.h>
#include <Magnum/Renderbuffer.h> #include <Magnum/GL/Buffer.h>
#include <Magnum/RenderbufferFormat.h> #include <Magnum/GL/Framebuffer.h>
#include <Magnum/Renderer.h> #include <Magnum/GL/Mesh.h>
#include <Magnum/Texture.h> #include <Magnum/GL/Renderbuffer.h>
#include <Magnum/TextureFormat.h> #include <Magnum/GL/RenderbufferFormat.h>
#include <Magnum/GL/Renderer.h>
#include <Magnum/GL/Texture.h>
#include <Magnum/GL/TextureFormat.h>
#include <Magnum/MeshTools/Compile.h> #include <Magnum/MeshTools/Compile.h>
#include <Magnum/MeshTools/Interleave.h> #include <Magnum/MeshTools/Interleave.h>
#include <Magnum/Primitives/Square.h> #include <Magnum/Primitives/Square.h>
@ -102,23 +102,23 @@ int ShaderVisualizer::exec() {
std::exit(1); std::exit(1);
} }
Renderbuffer multisampleColor, multisampleDepth; GL::Renderbuffer multisampleColor, multisampleDepth;
multisampleColor.setStorageMultisample(16, RenderbufferFormat::RGBA8, ImageSize); multisampleColor.setStorageMultisample(16, GL::RenderbufferFormat::RGBA8, ImageSize);
multisampleDepth.setStorageMultisample(16, RenderbufferFormat::DepthComponent24, ImageSize); multisampleDepth.setStorageMultisample(16, GL::RenderbufferFormat::DepthComponent24, ImageSize);
Framebuffer multisampleFramebuffer{{{}, ImageSize}}; GL::Framebuffer multisampleFramebuffer{{{}, ImageSize}};
multisampleFramebuffer.attachRenderbuffer(Framebuffer::ColorAttachment{0}, multisampleColor) multisampleFramebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, multisampleColor)
.attachRenderbuffer(Framebuffer::BufferAttachment::Depth, multisampleDepth) .attachRenderbuffer(GL::Framebuffer::BufferAttachment::Depth, multisampleDepth)
.bind(); .bind();
CORRADE_INTERNAL_ASSERT(multisampleFramebuffer.checkStatus(FramebufferTarget::Draw) == Framebuffer::Status::Complete); CORRADE_INTERNAL_ASSERT(multisampleFramebuffer.checkStatus(GL::FramebufferTarget::Draw) == GL::Framebuffer::Status::Complete);
Renderbuffer color; GL::Renderbuffer color;
color.setStorage(RenderbufferFormat::RGBA8, ImageSize); color.setStorage(GL::RenderbufferFormat::RGBA8, ImageSize);
Framebuffer framebuffer{{{}, ImageSize}}; GL::Framebuffer framebuffer{{{}, ImageSize}};
framebuffer.attachRenderbuffer(Framebuffer::ColorAttachment{0}, color); framebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, color);
Renderer::enable(Renderer::Feature::DepthTest); GL::Renderer::enable(GL::Renderer::Feature::DepthTest);
Renderer::setClearColor(0x000000_rgbaf); GL::Renderer::setClearColor(0x000000_rgbaf);
for(auto fun: {&ShaderVisualizer::phong, for(auto fun: {&ShaderVisualizer::phong,
&ShaderVisualizer::meshVisualizer, &ShaderVisualizer::meshVisualizer,
@ -126,12 +126,12 @@ int ShaderVisualizer::exec() {
&ShaderVisualizer::vertexColor, &ShaderVisualizer::vertexColor,
&ShaderVisualizer::vector, &ShaderVisualizer::vector,
&ShaderVisualizer::distanceFieldVector}) { &ShaderVisualizer::distanceFieldVector}) {
multisampleFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth); multisampleFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
std::string filename = (this->*fun)(); std::string filename = (this->*fun)();
AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), FramebufferBlit::Color); GL::AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), GL::FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA, PixelType::UnsignedByte}); Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA8Unorm});
converter->exportToFile(result, Utility::Directory::join("../", "shaders-" + filename)); converter->exportToFile(result, Utility::Directory::join("../", "shaders-" + filename));
} }
@ -148,9 +148,9 @@ namespace {
} }
std::string ShaderVisualizer::phong() { std::string ShaderVisualizer::phong() {
std::unique_ptr<Buffer> vertices, indices; std::unique_ptr<GL::Buffer> vertices, indices;
Mesh mesh{NoCreate}; GL::Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::uvSphereSolid(16, 32), BufferUsage::StaticDraw); std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::uvSphereSolid(16, 32), GL::BufferUsage::StaticDraw);
Shaders::Phong shader; Shaders::Phong shader;
shader.setAmbientColor(0x22272e_rgbf) shader.setAmbientColor(0x22272e_rgbf)
@ -167,9 +167,9 @@ std::string ShaderVisualizer::phong() {
} }
std::string ShaderVisualizer::meshVisualizer() { std::string ShaderVisualizer::meshVisualizer() {
std::unique_ptr<Buffer> vertices, indices; std::unique_ptr<GL::Buffer> vertices, indices;
Mesh mesh{NoCreate}; GL::Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::icosphereSolid(1), BufferUsage::StaticDraw); std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::icosphereSolid(1), GL::BufferUsage::StaticDraw);
const Matrix4 projection = Projection*Transformation* const Matrix4 projection = Projection*Transformation*
Matrix4::rotationZ(13.7_degf)* Matrix4::rotationZ(13.7_degf)*
@ -187,9 +187,9 @@ std::string ShaderVisualizer::meshVisualizer() {
} }
std::string ShaderVisualizer::flat() { std::string ShaderVisualizer::flat() {
std::unique_ptr<Buffer> vertices, indices; std::unique_ptr<GL::Buffer> vertices, indices;
Mesh mesh{NoCreate}; GL::Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::uvSphereSolid(16, 32), BufferUsage::StaticDraw); std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::uvSphereSolid(16, 32), GL::BufferUsage::StaticDraw);
Shaders::Flat3D shader; Shaders::Flat3D shader;
shader.setColor(BaseColor) shader.setColor(BaseColor)
@ -210,17 +210,17 @@ std::string ShaderVisualizer::vertexColor() {
for(Vector3 position: sphere.positions(0)) for(Vector3 position: sphere.positions(0))
colors.push_back(Color3::fromHsv(Math::lerp(240.0_degf, 420.0_degf, Math::max(1.0f - (position - target).length(), 0.0f)), 0.75f, 0.75f)); colors.push_back(Color3::fromHsv(Math::lerp(240.0_degf, 420.0_degf, Math::max(1.0f - (position - target).length(), 0.0f)), 0.75f, 0.75f));
Buffer vertices, indices; GL::Buffer vertices, indices;
vertices.setData(MeshTools::interleave(sphere.positions(0), colors), BufferUsage::StaticDraw); vertices.setData(MeshTools::interleave(sphere.positions(0), colors), GL::BufferUsage::StaticDraw);
indices.setData(sphere.indices(), BufferUsage::StaticDraw); indices.setData(sphere.indices(), GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.setPrimitive(MeshPrimitive::Triangles) mesh.setPrimitive(GL::MeshPrimitive::Triangles)
.setCount(sphere.indices().size()) .setCount(sphere.indices().size())
.addVertexBuffer(vertices, 0, .addVertexBuffer(vertices, 0,
Shaders::VertexColor3D::Position{}, Shaders::VertexColor3D::Position{},
Shaders::VertexColor3D::Color{Shaders::VertexColor3D::Color::Components::Three}) Shaders::VertexColor3D::Color{Shaders::VertexColor3D::Color::Components::Three})
.setIndexBuffer(indices, 0, Mesh::IndexType::UnsignedInt); .setIndexBuffer(indices, 0, GL::MeshIndexType::UnsignedInt);
Shaders::VertexColor3D shader; Shaders::VertexColor3D shader;
shader.setTransformationProjectionMatrix(Projection*Transformation); shader.setTransformationProjectionMatrix(Projection*Transformation);
@ -237,29 +237,29 @@ std::string ShaderVisualizer::vector() {
return "vector.png"; return "vector.png";
} }
Texture2D texture; GL::Texture2D texture;
texture.setMinificationFilter(Sampler::Filter::Linear) texture.setMinificationFilter(GL::SamplerFilter::Linear)
.setMagnificationFilter(Sampler::Filter::Linear) .setMagnificationFilter(GL::SamplerFilter::Linear)
.setWrapping(Sampler::Wrapping::ClampToEdge) .setWrapping(GL::SamplerWrapping::ClampToEdge)
.setStorage(1, TextureFormat::RGBA8, image->size()) .setStorage(1, GL::TextureFormat::RGBA8, image->size())
.setSubImage(0, {}, *image); .setSubImage(0, {}, *image);
Mesh mesh{NoCreate}; GL::Mesh mesh{NoCreate};
std::unique_ptr<Buffer> vertices; std::unique_ptr<GL::Buffer> vertices;
std::tie(mesh, vertices, std::ignore) = MeshTools::compile(Primitives::squareSolid(Primitives::SquareTextureCoords::Generate), BufferUsage::StaticDraw); std::tie(mesh, vertices, std::ignore) = MeshTools::compile(Primitives::squareSolid(Primitives::SquareTextureCoords::Generate), GL::BufferUsage::StaticDraw);
Shaders::Vector2D shader; Shaders::Vector2D shader;
shader.setColor(BaseColor) shader.setColor(BaseColor)
.bindVectorTexture(texture) .bindVectorTexture(texture)
.setTransformationProjectionMatrix({}); .setTransformationProjectionMatrix({});
Renderer::enable(Renderer::Feature::Blending); GL::Renderer::enable(GL::Renderer::Feature::Blending);
Renderer::setBlendFunction(Renderer::BlendFunction::One, Renderer::BlendFunction::OneMinusSourceAlpha); GL::Renderer::setBlendFunction(GL::Renderer::BlendFunction::One, GL::Renderer::BlendFunction::OneMinusSourceAlpha);
Renderer::setBlendEquation(Renderer::BlendEquation::Add, Renderer::BlendEquation::Add); GL::Renderer::setBlendEquation(GL::Renderer::BlendEquation::Add, GL::Renderer::BlendEquation::Add);
mesh.draw(shader); mesh.draw(shader);
Renderer::disable(Renderer::Feature::Blending); GL::Renderer::disable(GL::Renderer::Feature::Blending);
return "vector.png"; return "vector.png";
} }
@ -271,16 +271,16 @@ std::string ShaderVisualizer::distanceFieldVector() {
return "distancefieldvector.png"; return "distancefieldvector.png";
} }
Texture2D texture; GL::Texture2D texture;
texture.setMinificationFilter(Sampler::Filter::Linear) texture.setMinificationFilter(GL::SamplerFilter::Linear)
.setMagnificationFilter(Sampler::Filter::Linear) .setMagnificationFilter(GL::SamplerFilter::Linear)
.setWrapping(Sampler::Wrapping::ClampToEdge) .setWrapping(GL::SamplerWrapping::ClampToEdge)
.setStorage(1, TextureFormat::RGBA8, image->size()) .setStorage(1, GL::TextureFormat::RGBA8, image->size())
.setSubImage(0, {}, *image); .setSubImage(0, {}, *image);
Mesh mesh{NoCreate}; GL::Mesh mesh{NoCreate};
std::unique_ptr<Buffer> vertices; std::unique_ptr<GL::Buffer> vertices;
std::tie(mesh, vertices, std::ignore) = MeshTools::compile(Primitives::squareSolid(Primitives::SquareTextureCoords::Generate), BufferUsage::StaticDraw); std::tie(mesh, vertices, std::ignore) = MeshTools::compile(Primitives::squareSolid(Primitives::SquareTextureCoords::Generate), GL::BufferUsage::StaticDraw);
Shaders::DistanceFieldVector2D shader; Shaders::DistanceFieldVector2D shader;
shader.setColor(BaseColor) shader.setColor(BaseColor)
@ -289,13 +289,13 @@ std::string ShaderVisualizer::distanceFieldVector() {
.bindVectorTexture(texture) .bindVectorTexture(texture)
.setTransformationProjectionMatrix({}); .setTransformationProjectionMatrix({});
Renderer::enable(Renderer::Feature::Blending); GL::Renderer::enable(GL::Renderer::Feature::Blending);
Renderer::setBlendFunction(Renderer::BlendFunction::One, Renderer::BlendFunction::OneMinusSourceAlpha); GL::Renderer::setBlendFunction(GL::Renderer::BlendFunction::One, GL::Renderer::BlendFunction::OneMinusSourceAlpha);
Renderer::setBlendEquation(Renderer::BlendEquation::Add, Renderer::BlendEquation::Add); GL::Renderer::setBlendEquation(GL::Renderer::BlendEquation::Add, GL::Renderer::BlendEquation::Add);
mesh.draw(shader); mesh.draw(shader);
Renderer::disable(Renderer::Feature::Blending); GL::Renderer::disable(GL::Renderer::Feature::Blending);
return "distancefieldvector.png"; return "distancefieldvector.png";
} }

16
doc/snippets/MagnumGL-framebuffer.cpp

@ -23,8 +23,8 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#include "Magnum/DefaultFramebuffer.h" #include "Magnum/GL/DefaultFramebuffer.h"
#include "Magnum/Framebuffer.h" #include "Magnum/GL/Framebuffer.h"
#include "Magnum/Platform/Sdl2Application.h" #include "Magnum/Platform/Sdl2Application.h"
using namespace Magnum; using namespace Magnum;
@ -32,7 +32,7 @@ using namespace Magnum;
struct A: Platform::Sdl2Application { struct A: Platform::Sdl2Application {
/* [DefaultFramebuffer-usage-viewport] */ /* [DefaultFramebuffer-usage-viewport] */
void viewportEvent(const Vector2i& size) override { void viewportEvent(const Vector2i& size) override {
defaultFramebuffer.setViewport({{}, size}); GL::defaultFramebuffer.setViewport({{}, size});
// ... // ...
} }
@ -40,7 +40,7 @@ void viewportEvent(const Vector2i& size) override {
/* [DefaultFramebuffer-usage-clear] */ /* [DefaultFramebuffer-usage-clear] */
void drawEvent() override { void drawEvent() override {
defaultFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth); GL::defaultFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
// ... // ...
} }
@ -49,17 +49,17 @@ void drawEvent() override {
struct B: Platform::Sdl2Application { struct B: Platform::Sdl2Application {
Framebuffer framebuffer; GL::Framebuffer framebuffer;
/* [Framebuffer-usage-draw] */ /* [Framebuffer-usage-draw] */
void drawEvent() override { void drawEvent() override {
defaultFramebuffer.clear(FramebufferClear::Color); GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
framebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth|FramebufferClear::Stencil); framebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth|GL::FramebufferClear::Stencil);
framebuffer.bind(); framebuffer.bind();
// ... // ...
defaultFramebuffer.bind(); GL::defaultFramebuffer.bind();
// ... // ...
swapBuffers(); swapBuffers();

674
doc/snippets/MagnumGL.cpp

File diff suppressed because it is too large Load Diff

21
doc/snippets/MagnumMeshTools.cpp

@ -23,7 +23,8 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#include "Magnum/Buffer.h" #include "Magnum/GL/Buffer.h"
#include "Magnum/GL/Mesh.h"
#include "Magnum/Math/Color.h" #include "Magnum/Math/Color.h"
#include "Magnum/MeshTools/CombineIndexedArrays.h" #include "Magnum/MeshTools/CombineIndexedArrays.h"
#include "Magnum/MeshTools/CompressIndices.h" #include "Magnum/MeshTools/CompressIndices.h"
@ -59,15 +60,15 @@ std::vector<UnsignedInt> indices = MeshTools::combineIndexedArrays(
std::vector<UnsignedInt> indices; std::vector<UnsignedInt> indices;
Containers::Array<char> indexData; Containers::Array<char> indexData;
Mesh::IndexType indexType; MeshIndexType indexType;
UnsignedInt indexStart, indexEnd; UnsignedInt indexStart, indexEnd;
std::tie(indexData, indexType, indexStart, indexEnd) = std::tie(indexData, indexType, indexStart, indexEnd) =
MeshTools::compressIndices(indices); MeshTools::compressIndices(indices);
Buffer indexBuffer; GL::Buffer indexBuffer;
indexBuffer.setData(indexData, BufferUsage::StaticDraw); indexBuffer.setData(indexData, GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.setCount(indices.size()) mesh.setCount(indices.size())
.setIndexBuffer(indexBuffer, 0, indexType, indexStart, indexEnd); .setIndexBuffer(indexBuffer, 0, indexType, indexStart, indexEnd);
/* [compressIndices] */ /* [compressIndices] */
@ -95,17 +96,17 @@ std::tie(normalIndices, normals) =
{ {
struct MyShader { struct MyShader {
typedef Attribute<0, Vector3> Position; typedef GL::Attribute<0, Vector3> Position;
typedef Attribute<0, Vector2> TextureCoordinates; typedef GL::Attribute<0, Vector2> TextureCoordinates;
}; };
/* [interleave1] */ /* [interleave1] */
std::vector<Vector3> positions; std::vector<Vector3> positions;
std::vector<Vector2> textureCoordinates; std::vector<Vector2> textureCoordinates;
Buffer vertexBuffer; GL::Buffer vertexBuffer;
vertexBuffer.setData(MeshTools::interleave(positions, textureCoordinates), BufferUsage::StaticDraw); vertexBuffer.setData(MeshTools::interleave(positions, textureCoordinates), GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.setCount(positions.size()) mesh.setCount(positions.size())
.addVertexBuffer(vertexBuffer, 0, MyShader::Position{}, MyShader::TextureCoordinates{}); .addVertexBuffer(vertexBuffer, 0, MyShader::Position{}, MyShader::TextureCoordinates{});
/* [interleave1] */ /* [interleave1] */

4
doc/snippets/MagnumPlatform-custom.cpp

@ -23,7 +23,7 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#include <Magnum/Platform/Context.h> #include "Magnum/Platform/GLContext.h"
using namespace Magnum; using namespace Magnum;
@ -33,7 +33,7 @@ int main() {
{ {
/* Initialize Magnum */ /* Initialize Magnum */
Platform::Context context; Platform::GLContext context;
// Main loop ... // Main loop ...

4
doc/snippets/MagnumPlatform-windowless-custom.cpp

@ -24,7 +24,7 @@
*/ */
#include <Magnum/Platform/WindowlessEglApplication.h> #include <Magnum/Platform/WindowlessEglApplication.h>
#include <Magnum/Platform/Context.h> #include <Magnum/Platform/GLContext.h>
using namespace Magnum; using namespace Magnum;
@ -36,7 +36,7 @@ EGLContext anotherContext{};
int main(int argc, char** argv) { int main(int argc, char** argv) {
Platform::WindowlessGLContext glContext{{}}; Platform::WindowlessGLContext glContext{{}};
glContext.makeCurrent(); glContext.makeCurrent();
Platform::Context context{argc, argv}; Platform::GLContext context{argc, argv};
// Your GL code ... // Your GL code ...

4
doc/snippets/MagnumPlatform-windowless-thread.cpp

@ -25,7 +25,7 @@
#include <thread> #include <thread>
#include <Magnum/Platform/WindowlessEglApplication.h> #include <Magnum/Platform/WindowlessEglApplication.h>
#include <Magnum/Platform/Context.h> #include <Magnum/Platform/GLContext.h>
using namespace Magnum; using namespace Magnum;
@ -35,7 +35,7 @@ int main() {
std::thread worker{[&glContext]{ std::thread worker{[&glContext]{
glContext.makeCurrent(); glContext.makeCurrent();
Platform::Context context; Platform::GLContext context;
// Use Magnum here ... // Use Magnum here ...
}}; }};

4
doc/snippets/MagnumPlatform-windowless.cpp

@ -40,8 +40,8 @@ MyApplication::MyApplication(const Arguments& arguments):
Platform::WindowlessApplication{arguments} {} Platform::WindowlessApplication{arguments} {}
int MyApplication::exec() { int MyApplication::exec() {
Debug{} << "OpenGL version:" << Context::current().versionString(); Debug{} << "OpenGL version:" << GL::Context::current().versionString();
Debug{} << "OpenGL renderer:" << Context::current().rendererString(); Debug{} << "OpenGL renderer:" << GL::Context::current().rendererString();
/* Exit with success */ /* Exit with success */
return 0; return 0;

8
doc/snippets/MagnumPlatform.cpp

@ -28,7 +28,7 @@
#include <Magnum/GL/Renderer.h> #include <Magnum/GL/Renderer.h>
#include <Magnum/Math/Color.h> #include <Magnum/Math/Color.h>
#include <Magnum/Platform/Sdl2Application.h> #include <Magnum/Platform/Sdl2Application.h>
#include <Magnum/Platform/Context.h> #include <Magnum/Platform/GLContext.h>
using namespace Magnum; using namespace Magnum;
@ -43,12 +43,12 @@ class MyApplication: public Platform::Application {
MyApplication::MyApplication(const Arguments& arguments): Platform::Application{arguments} { MyApplication::MyApplication(const Arguments& arguments): Platform::Application{arguments} {
using namespace Math::Literals; using namespace Math::Literals;
/* Set clear color to dark blue */ /* Set clear color to dark blue */
Renderer::setClearColor(0x000066_rgbf); GL::Renderer::setClearColor(0x000066_rgbf);
} }
void MyApplication::drawEvent() { void MyApplication::drawEvent() {
/* Clear the window */ /* Clear the window */
defaultFramebuffer.clear(FramebufferClear::Color); GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
/* The context is double-buffered, swap buffers */ /* The context is double-buffered, swap buffers */
swapBuffers(); swapBuffers();
@ -71,7 +71,7 @@ class MyApplication: public Platform::Application {
// ... // ...
void MyApplication::viewportEvent(const Vector2i& size) { void MyApplication::viewportEvent(const Vector2i& size) {
defaultFramebuffer.setViewport({{}, size}); GL::defaultFramebuffer.setViewport({{}, size});
} }
/* [size] */ /* [size] */

92
doc/snippets/MagnumShaders.cpp

@ -25,10 +25,10 @@
#include <numeric> #include <numeric>
#include "Magnum/Buffer.h" #include "Magnum/GL/Buffer.h"
#include "Magnum/DefaultFramebuffer.h" #include "Magnum/GL/DefaultFramebuffer.h"
#include "Magnum/Mesh.h" #include "Magnum/GL/Mesh.h"
#include "Magnum/Texture.h" #include "Magnum/GL/Texture.h"
#include "Magnum/Math/Color.h" #include "Magnum/Math/Color.h"
#include "Magnum/MeshTools/Duplicate.h" #include "Magnum/MeshTools/Duplicate.h"
#include "Magnum/Shaders/DistanceFieldVector.h" #include "Magnum/Shaders/DistanceFieldVector.h"
@ -55,10 +55,10 @@ Vertex data[60]{
// ... // ...
}; };
Buffer vertices; GL::Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw); vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, mesh.addVertexBuffer(vertices, 0,
Shaders::Phong::Position{}, Shaders::Phong::Position{},
Shaders::Phong::Normal{}, Shaders::Phong::Normal{},
@ -69,7 +69,7 @@ mesh.addVertexBuffer(vertices, 0,
/* [shaders-rendering] */ /* [shaders-rendering] */
Matrix4 transformationMatrix, projectionMatrix; Matrix4 transformationMatrix, projectionMatrix;
Texture2D diffuseTexture, specularTexture; GL::Texture2D diffuseTexture, specularTexture;
Shaders::Phong shader{Shaders::Phong::Flag::DiffuseTexture}; Shaders::Phong shader{Shaders::Phong::Flag::DiffuseTexture};
shader.bindDiffuseTexture(diffuseTexture) shader.bindDiffuseTexture(diffuseTexture)
@ -93,7 +93,7 @@ Shaders::MeshVisualizer visualizerShader{Shaders::MeshVisualizer::Flag::Wirefram
visualizerShader visualizerShader
.setColor(0x2f83cc_rgbf) .setColor(0x2f83cc_rgbf)
.setWireframeColor(0xdcdcdc_rgbf) .setWireframeColor(0xdcdcdc_rgbf)
.setViewportSize(Vector2{defaultFramebuffer.viewport().size()}) .setViewportSize(Vector2{GL::defaultFramebuffer.viewport().size()})
.setTransformationProjectionMatrix(projectionMatrix*transformationMatrix); .setTransformationProjectionMatrix(projectionMatrix*transformationMatrix);
mesh.draw(visualizerShader); mesh.draw(visualizerShader);
@ -110,10 +110,10 @@ Vertex data[60]{
// ... // ...
}; };
Buffer vertices; GL::Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw); vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, mesh.addVertexBuffer(vertices, 0,
Shaders::DistanceFieldVector2D::Position{}, Shaders::DistanceFieldVector2D::Position{},
Shaders::DistanceFieldVector2D::TextureCoordinates{}) Shaders::DistanceFieldVector2D::TextureCoordinates{})
@ -123,10 +123,10 @@ mesh.addVertexBuffer(vertices, 0,
} }
{ {
Mesh mesh; GL::Mesh mesh;
/* [DistanceFieldVector-usage2] */ /* [DistanceFieldVector-usage2] */
Matrix3 transformationMatrix, projectionMatrix; Matrix3 transformationMatrix, projectionMatrix;
Texture2D texture; GL::Texture2D texture;
Shaders::DistanceFieldVector2D shader; Shaders::DistanceFieldVector2D shader;
shader.setColor(0x2f83cc_rgbf) shader.setColor(0x2f83cc_rgbf)
@ -148,10 +148,10 @@ Vertex data[60]{
//... //...
}; };
Buffer vertices; GL::Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw); vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, Shaders::Flat3D::Position{}) mesh.addVertexBuffer(vertices, 0, Shaders::Flat3D::Position{})
// ... // ...
; ;
@ -179,10 +179,10 @@ Vertex data[60]{
// ... // ...
}; };
Buffer vertices; GL::Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw); vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, mesh.addVertexBuffer(vertices, 0,
Shaders::Flat3D::Position{}, Shaders::Flat3D::Position{},
Shaders::Flat3D::TextureCoordinates{}) Shaders::Flat3D::TextureCoordinates{})
@ -192,7 +192,7 @@ mesh.addVertexBuffer(vertices, 0,
/* [Flat-usage-textured2] */ /* [Flat-usage-textured2] */
Matrix4 transformationMatrix, projectionMatrix; Matrix4 transformationMatrix, projectionMatrix;
Texture2D texture; GL::Texture2D texture;
Shaders::Flat3D shader{Shaders::Flat3D::Flag::Textured}; Shaders::Flat3D shader{Shaders::Flat3D::Flag::Textured};
shader.setTransformationProjectionMatrix(projectionMatrix*transformationMatrix) shader.setTransformationProjectionMatrix(projectionMatrix*transformationMatrix)
@ -211,10 +211,10 @@ Vertex data[60]{
// ... // ...
}; };
Buffer vertices; GL::Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw); vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, Shaders::MeshVisualizer::Position{}); mesh.addVertexBuffer(vertices, 0, Shaders::MeshVisualizer::Position{});
/* [MeshVisualizer-usage-geom1] */ /* [MeshVisualizer-usage-geom1] */
@ -225,7 +225,7 @@ Matrix4 projectionMatrix = Matrix4::perspectiveProjection(35.0_degf, 1.0f, 0.001
Shaders::MeshVisualizer shader{Shaders::MeshVisualizer::Flag::Wireframe}; Shaders::MeshVisualizer shader{Shaders::MeshVisualizer::Flag::Wireframe};
shader.setColor(0x2f83cc_rgbf) shader.setColor(0x2f83cc_rgbf)
.setWireframeColor(0xdcdcdc_rgbf) .setWireframeColor(0xdcdcdc_rgbf)
.setViewportSize(Vector2{defaultFramebuffer.viewport().size()}) .setViewportSize(Vector2{GL::defaultFramebuffer.viewport().size()})
.setTransformationProjectionMatrix(projectionMatrix*transformationMatrix); .setTransformationProjectionMatrix(projectionMatrix*transformationMatrix);
mesh.draw(shader); mesh.draw(shader);
@ -236,8 +236,8 @@ constexpr std::size_t vertexCount = Containers::arraySize(data);
Float vertexIndex[vertexCount]; Float vertexIndex[vertexCount];
std::iota(vertexIndex, vertexIndex + vertexCount, 0.0f); std::iota(vertexIndex, vertexIndex + vertexCount, 0.0f);
Buffer vertexIndices; GL::Buffer vertexIndices;
vertexIndices.setData(vertexIndex, BufferUsage::StaticDraw); vertexIndices.setData(vertexIndex, GL::BufferUsage::StaticDraw);
mesh.addVertexBuffer(vertexIndices, 0, Shaders::MeshVisualizer::VertexIndex{}); mesh.addVertexBuffer(vertexIndices, 0, Shaders::MeshVisualizer::VertexIndex{});
/* [MeshVisualizer-usage-no-geom-old1] */ /* [MeshVisualizer-usage-no-geom-old1] */
@ -245,7 +245,7 @@ mesh.addVertexBuffer(vertexIndices, 0, Shaders::MeshVisualizer::VertexIndex{});
#endif #endif
{ {
Mesh mesh; GL::Mesh mesh;
/* [MeshVisualizer-usage-no-geom-old2] */ /* [MeshVisualizer-usage-no-geom-old2] */
Matrix4 transformationMatrix, projectionMatrix; Matrix4 transformationMatrix, projectionMatrix;
@ -269,11 +269,11 @@ std::vector<Vector3> indexedPositions{
}; };
/* De-indexing the position array */ /* De-indexing the position array */
Buffer vertices; GL::Buffer vertices;
vertices.setData(MeshTools::duplicate(indices, indexedPositions), vertices.setData(MeshTools::duplicate(indices, indexedPositions),
BufferUsage::StaticDraw); GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, Shaders::MeshVisualizer::Position{}); mesh.addVertexBuffer(vertices, 0, Shaders::MeshVisualizer::Position{});
/* [MeshVisualizer-usage-no-geom] */ /* [MeshVisualizer-usage-no-geom] */
} }
@ -289,10 +289,10 @@ Vertex data[60]{
// ... // ...
}; };
Buffer vertices; GL::Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw); vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, mesh.addVertexBuffer(vertices, 0,
Shaders::Phong::Position{}, Shaders::Phong::Position{},
Shaders::Phong::Normal{}); Shaders::Phong::Normal{});
@ -325,10 +325,10 @@ Vertex data[60]{
// ... // ...
}; };
Buffer vertices; GL::Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw); vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, mesh.addVertexBuffer(vertices, 0,
Shaders::Phong::Position{}, Shaders::Phong::Position{},
Shaders::Phong::Normal{}, Shaders::Phong::Normal{},
@ -337,7 +337,7 @@ mesh.addVertexBuffer(vertices, 0,
/* [Phong-usage-texture2] */ /* [Phong-usage-texture2] */
Matrix4 transformationMatrix, projectionMatrix; Matrix4 transformationMatrix, projectionMatrix;
Texture2D diffuseTexture, specularTexture; GL::Texture2D diffuseTexture, specularTexture;
Shaders::Phong shader{Shaders::Phong::Flag::DiffuseTexture| Shaders::Phong shader{Shaders::Phong::Flag::DiffuseTexture|
Shaders::Phong::Flag::SpecularTexture}; Shaders::Phong::Flag::SpecularTexture};
@ -353,7 +353,7 @@ mesh.draw(shader);
#endif #endif
{ {
Texture2D ambientAlphaTexture, diffuseAlphaTexture; GL::Texture2D ambientAlphaTexture, diffuseAlphaTexture;
Color3 diffuseRgb, specularRgb; Color3 diffuseRgb, specularRgb;
/* [Phong-usage-alpha] */ /* [Phong-usage-alpha] */
Shaders::Phong shader{Shaders::Phong::Flag::AmbientTexture| Shaders::Phong shader{Shaders::Phong::Flag::AmbientTexture|
@ -376,10 +376,10 @@ Vertex data[60]{
// ... // ...
}; };
Buffer vertices; GL::Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw); vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, mesh.addVertexBuffer(vertices, 0,
Shaders::Vector2D::Position{}, Shaders::Vector2D::Position{},
Shaders::Vector2D::TextureCoordinates{}); Shaders::Vector2D::TextureCoordinates{});
@ -387,7 +387,7 @@ mesh.addVertexBuffer(vertices, 0,
/* [Vector-usage2] */ /* [Vector-usage2] */
Matrix3 transformationMatrix, projectionMatrix; Matrix3 transformationMatrix, projectionMatrix;
Texture2D texture; GL::Texture2D texture;
Shaders::Vector2D shader; Shaders::Vector2D shader;
shader.setColor(0x2f83cc_rgbf) shader.setColor(0x2f83cc_rgbf)
@ -408,10 +408,10 @@ Vertex data[60]{
// ... // ...
}; };
Buffer vertices; GL::Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw); vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh; GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, mesh.addVertexBuffer(vertices, 0,
Shaders::VertexColor3D::Position{}, Shaders::VertexColor3D::Position{},
Shaders::VertexColor3D::Color{Shaders::VertexColor3D::Color::Components::Three}); Shaders::VertexColor3D::Color{Shaders::VertexColor3D::Color::Components::Three});

8
doc/snippets/MagnumText.cpp

@ -66,12 +66,12 @@ font->fillGlyphCache(cache, "abcdefghijklmnopqrstuvwxyz"
"0123456789?!:;,. "); "0123456789?!:;,. ");
Shaders::Vector2D shader; Shaders::Vector2D shader;
Buffer vertexBuffer, indexBuffer; GL::Buffer vertexBuffer, indexBuffer;
Mesh mesh; GL::Mesh mesh;
/* Render the text, centered */ /* Render the text, centered */
std::tie(mesh, std::ignore) = Text::Renderer2D::render(*font, cache, 0.15f, std::tie(mesh, std::ignore) = Text::Renderer2D::render(*font, cache, 0.15f,
"Hello World!", vertexBuffer, indexBuffer, BufferUsage::StaticDraw, "Hello World!", vertexBuffer, indexBuffer, GL::BufferUsage::StaticDraw,
Text::Alignment::LineCenter); Text::Alignment::LineCenter);
/* Draw the text on the screen */ /* Draw the text on the screen */
@ -84,7 +84,7 @@ mesh.draw(shader);
/* [Renderer-usage2] */ /* [Renderer-usage2] */
/* Initialize the renderer and reserve memory for enough glyphs */ /* Initialize the renderer and reserve memory for enough glyphs */
Text::Renderer2D renderer{*font, cache, 0.15f, Text::Alignment::LineCenter}; Text::Renderer2D renderer{*font, cache, 0.15f, Text::Alignment::LineCenter};
renderer.reserve(32, BufferUsage::DynamicDraw, BufferUsage::StaticDraw); renderer.reserve(32, GL::BufferUsage::DynamicDraw, GL::BufferUsage::StaticDraw);
/* Update the text occasionally */ /* Update the text occasionally */
renderer.render("Hello World Countdown: 10"); renderer.render("Hello World Countdown: 10");

17
doc/snippets/getting-started-blue.cpp

@ -23,12 +23,12 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#include <Magnum/DefaultFramebuffer.h> #include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/Platform/Sdl2Application.h> #include <Magnum/Platform/Sdl2Application.h>
/** [0] */ /** [0] */
#include <Magnum/Context.h> #include <Magnum/GL/Context.h>
#include <Magnum/Renderer.h> #include <Magnum/GL/Renderer.h>
#include <Magnum/Version.h> #include <Magnum/GL/Version.h>
#include <Magnum/Math/Color.h> #include <Magnum/Math/Color.h>
/** [0] */ /** [0] */
@ -46,15 +46,16 @@ class MyApplication: public Platform::Application {
MyApplication::MyApplication(const Arguments& arguments): Platform::Application{arguments} { MyApplication::MyApplication(const Arguments& arguments): Platform::Application{arguments} {
using namespace Magnum::Math::Literals; using namespace Magnum::Math::Literals;
Renderer::setClearColor(0xa5c9ea_rgbf); GL::Renderer::setClearColor(0xa5c9ea_rgbf);
Debug{} << "Hello! This application is running on" << Context::current().version() Debug{} << "Hello! This application is running on"
<< "using" << Context::current().rendererString(); << GL::Context::current().version() << "using"
<< GL::Context::current().rendererString();
} }
/** [1] */ /** [1] */
void MyApplication::drawEvent() { void MyApplication::drawEvent() {
defaultFramebuffer.clear(FramebufferClear::Color); GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
// TODO: Add your drawing code here // TODO: Add your drawing code here

4
doc/snippets/getting-started.cpp

@ -24,7 +24,7 @@
*/ */
/** [0] */ /** [0] */
#include <Magnum/DefaultFramebuffer.h> #include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/Platform/Sdl2Application.h> #include <Magnum/Platform/Sdl2Application.h>
using namespace Magnum; using namespace Magnum;
@ -42,7 +42,7 @@ MyApplication::MyApplication(const Arguments& arguments): Platform::Application{
} }
void MyApplication::drawEvent() { void MyApplication::drawEvent() {
defaultFramebuffer.clear(FramebufferClear::Color); GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
// TODO: Add your drawing code here // TODO: Add your drawing code here

Loading…
Cancel
Save