ImFusion SDK 4.3
MyCustomGlObject.cpp
#include "MyCustomGlObject.h"
#include <ImFusion/Core/GL/FixedFunctionPipeline.h>
#include <ImFusion/Core/GL/VertexBuffer.h>
#include <ImFusion/Core/Mat.h>
#include <vector>
using namespace ImFusion;
void MyCustomGlObject::draw(const GlView& view)
{
// define vertex data on the CPU
std::vector<vec3f> lineVertices{vec3f(-10.f, 10.f, 0.f), vec3f(10.f, 10.f, 0.f), vec3f(10.f, -10.f, 0.f)};
// upload vertex data to the GPU using the utility function of GL::FixedFunctionPipeline.
// Select the line rendering shader and initialize it with the GlViewState of the view passed as argument
// Set line color and width
ffp.setDefaultColor(vec4(1.0, 0.5, 0.0, 1.0));
ffp.setLineWidth(4);
// When the shader is completely configured, issue the draw call on the vertex buffer
// define vertex data
std::vector<vec3f> triangleVertices{vec3f(-10.f, 8.f, 0.f), vec3f(-10.f, -10.f, 0.f), vec3f(8.f, -10.f, 0.f)};
std::vector<vec3f> triangleColors{vec3f(1.f, 0.f, 0.f), vec3f(0.f, 1.f, 0.f), vec3f(0.f, 0.f, 1.f)};
// update the vertex buffer with the new data for the triangle
GL::FixedFunctionPipeline::makeVertexData(triangleVertices).useColors(triangleColors).assign(*vbo);
ffp.disable();
}
Convenience class for a shader implementing a basic fixed function rendering pipeline.
Definition FixedFunctionPipeline.h:99
void setDefaultColor(const vec3 &color)
Sets the default color with full opacity to use in case no per-vertex colors are specified.
void enable(const ViewState &state, ShaderSelection shaderSelection=ShaderSelection::Default, const OrderIndependentTransparency *oit=nullptr)
Enables the rendering shader and resets all state to the default settings.
void disable()
Disables the rendering shader.
static VertexData< T > makeVertexData(const std::vector< T > &vertexPositions)
Factory function to create a VertexData object without the need to explicitly specify the template ty...
@ Default
Default general purpose shader mimicking the fixed function pipeline.
Definition FixedFunctionPipeline.h:153
@ LineRendering
Special shader that supports wide and stippled lines, do not use with other geometry than lines.
Definition FixedFunctionPipeline.h:157
void setLineWidth(double lineWidth)
Sets the width of the rendered lines in px, will incorporate the GL::dpiScale().
static FixedFunctionPipeline & cachedInstance()
Definition InstanceManager.h:80
Base class for implementing OpenGL views.
Definition GlView.h:36
const GL::ViewState & state() const
Return the view state that was set during the last render() call.
Definition GlView.h:115
@ Triangles
Vertices 0, 1, and 2 form a triangle. Vertices 3, 4, and 5 form a triangle. And so on.
Definition Types.h:71
@ LineStrip
The adjacent vertices are considered lines. Thus, if you pass n vertices, you will get n-1 lines.
Definition Types.h:70
Namespace of the ImFusion SDK.
Definition Assert.h:7
Search Tab / S to search, Esc to close