### Set loop callback and start rendering loop Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins/glfw Set a loop callback and start the rendering loop. The loop() method must be called on the thread where init() was called and will run indefinitely while the window is open. ```java CometGLFW.getWindow().setLoopCallback(() -> { //This code will execute in a loop as long as the window is open. CometGLFW.getWindow().getFramebuffer().bind(true); /*...*/ }); CometGLFW.getWindow().loop(); ``` -------------------------------- ### MinecraftFramebuffer creation example Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/crm/minecraftframebuffer Example of creating a MinecraftFramebuffer using the main render target from Minecraft.getInstance().getMainRenderTarget(), with a transparent clear color and zero clear depth and stencil. ```java MinecraftFramebuffer framebuffer = new MinecraftFramebuffer( Minecraft.getInstance().getMainRenderTarget(), new Color(0, 0, 0, 0), 0, 0 ); ``` -------------------------------- ### Static listener registration example Source: https://ferra13671-dev.gitbook.io/projects/main/megaevents-documentation/listeners Shows how to register static listeners. The methods must be marked as 'static' and registration uses the class object. ```java IEventBus eventBus = /*...*/ eventBus.register(StaticListener.class); ``` -------------------------------- ### Setup UI matrix with CRMInstance Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/crm/crminstance Sets up the UI matrix by registering a RenderHudCallback that calls setupUIProjection() (required for Minecraft ≥1.21.5) and optionally restoreUIProjection(). ```java CRMInstance instance = /*...*/ /*...*/ RenderHudCallback.EVENT.register(() -> { instance.setupUIProjection(); //Required for Minecraft versions ≥1.21.5 /*...*/ instance.restoreUIProjection(); //Optional for Minecraft versions ≥1.21.5 }); ``` -------------------------------- ### #abstractMethod directive shader example Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins Shader example for the #abstractMethod directive. The compiler adds content to the method. The method before the directive must follow the structure $type $name($params). ```glsl #version 330 core in vec4 position; void main(); #abstractMethod ``` -------------------------------- ### Build a shader library with GLShaderLibraryBuilder Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins Example of building a shader library using GLShaderLibraryBuilder. May throw LoadGLSLContentException, DoubleUniformAdditionException, or IllegalArgumentException. ```java public static final GLSLFileEntry OUTLINE_SHADER = new GLShaderLibraryBuilder<>( CometLoaders.IN_JAR ) .name("outlineShader") .library("outline-shader.glsl") .sampler("u_Texture") .uniform("textureSize", UniformType.IVEC2) .uniform("outlineSize", UniformType.INT) .build(); ``` -------------------------------- ### Include shader libraries with #include directive Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins Example shader showing how to include shader libraries using the #include directive. Library names are between < and > and separated by commas. ```glsl #version 330 core precision lowp float; uniform vec4 color; uniform vec4 outlineColor; out vec4 fragColor; //for one library #include //for multiple libraries #include void main() { outline(color, outlineColor); } ``` -------------------------------- ### Lambda listener example Source: https://ferra13671-dev.gitbook.io/projects/main/megaevents-documentation/listeners Shows how to create and register a lambda listener. The listener is stored as a LambdaListener object, which is used for registration and unregistration. ```java LambdaListener listener = new LambdaListener<>(TestEvent.class, event -> { System.out.println("TestEvent called!"); }); IEventBus eventBus = /*...*/ eventBus.register(listener); ``` -------------------------------- ### Object listener registration example Source: https://ferra13671-dev.gitbook.io/projects/main/megaevents-documentation/listeners Shows a class with object and ghost listeners, and how to register them using IEventBus.register(Object). The class contains both a default listener and a ghost listener. ```java public class ObjectListener { @EventSubscriber(event = ExampleEvent.class) public void defaultListener(ExampleEvent e) { System.out.println("Example object listener passed! " + e.count); } @EventSubscriber(event = ExampleEvent.class) public void ghostListener() { System.out.println("Example object ghost listener passed!"); } } ``` ```java IEventBus eventBus = /*...*/ eventBus.register(new ObjectListener()); ``` -------------------------------- ### Stencil example with READ Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/drawing-and-etc./stencil Example of using StencilInfo.READ to draw a cube only where the stencil mask has been filled. It sets up a GLProgram, creates a mask mesh and a cube mesh, then draws the mask with WRITE stencil, then draws the cube with READ stencil, and finally clears and disables stencil. ```java GLProgram program = GLProgram.builder( CometRenderer.getColorSnippet() ) .name("test") /*...*/ .build(); int x = 200; int y = 520; int s = 25; Mesh maskMesh = CometRenderer.createMesh(DrawMode.QUADS, VertexFormat.POSITION, mesh -> { mesh .vertex(x, y, s * 2, s * 2) .vertex(x + (s * 4), y, s * 2, s * 2) .vertex(x + (s * 2), y + (s * 2), s * 2, s) .vertex(x + s, y + (s * 3), s * 4, s * 2) .vertex(x + s, y + (s * 5), s, s) .vertex(x + (s * 4), y + (s * 5), s, s); }); Mesh cubeMesh = CometRenderer.createMesh(DrawMode.QUADS, VertexFormat.POSITION, mesh -> { mesh .vertex(x - s, y - s, s * 8, s * 8); }); /*...*/ CometRenderer.setCurrentProgram(program); CometRenderer.setStencil(StencilInfo.WRITE); CometRenderer.draw(maskMesh); CometRenderer.setStencil(StencilInfo.READ); CometRenderer.getShaderColor().setColor(new Vector4f(1f, 0f, 0f, 1f)); CometRenderer.applyShaderColorUniform(); CometRenderer.draw(cubeMesh); CometRenderer.clearStencil(0); CometRenderer.disableStencil(); ``` -------------------------------- ### GifLoader example Source: https://ferra13671-dev.gitbook.io/projects/main/gltextureutils-documentation/loaders A GifLoader implementation that simply returns the InputStream unchanged, since GLGifInfo expects an InputStream of the gif. ```java //GLGifInfo should be passed an InputStream of the gif, so this loader doesn't need to do anything. public static final GifLoader INPUT_STREAM = path -> path; ``` -------------------------------- ### Mesh build example using CometRenderer.createMesh Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/mesh-and-everything-that-goes-with-it Creates a mesh with DrawMode.QUADS and CometVertexFormats.POSITION, adding four vertices. May throw BadVertexStructureException, IllegalMeshBuilderStateException, NoSuchVertexElementException, or VertexOverflowException. ```java Mesh mesh = CometRenderer.createMesh(DrawMode.QUADS, CometVertexFormats.POSITION, builder -> { builder.vertex(200, 200, 0); builder.vertex(200, 400, 0); builder.vertex(400, 400, 0); builder.vertex(400, 200, 0); }); ``` -------------------------------- ### #inputs, #outputs, #uniforms block directives before and after Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins Before and after processing examples for the block directives #inputs, #outputs, and #uniforms. These directives add the keywords 'in', 'out', and 'uniform' respectively when converting fields. ```glsl #inputs { float input_1; vec2 input_2; mat4 input_3; }; #outputs { float output_1; vec2 output_2; mat4 output_3; }; #uniforms { float uniform_1; vec2 uniform_2; mat4 uniform_3; }; void main() { /*... } ``` ```glsl in float input_1; in vec2 input_2; in mat4 input_3; out float output_1; out vec2 output_2; out mat4 output_3; uniform float uniform_1; uniform vec2 uniform_2; uniform mat4 uniform_3; void main() { /*... } ``` -------------------------------- ### GLSL version directive example Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins Shader example for the BetterCompiler GLSL version directive. If the #version directive is missing and the program registry contains the BetterCompilerTags.GLSL_VERSION tag with GLVersion.GL46, the compiler automatically inserts '#version 460 core' into the shader. ```glsl /* If program registry contains BetterCompilerTags.GLSL_VERSION tag with GLVersion.GL46 value, '#version 460 core' will be pasted into the shader. */ in vec4 position; void main() { gl_Position = projMat * modelViewMat * position; } ``` -------------------------------- ### Build GLProgram with vertex and fragment shaders Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/glprogram/building-programs Shows the vertex and fragment shaders used in the example, followed by the Java code that builds a GLProgram with those shaders. The builder requires a name and shaders for Vertex and Fragment types; adding a uniform with a duplicate name throws DoubleUniformAdditionException, and adding a shader with a duplicate type throws DoubleShaderAdditionException. ```glsl #version 330 core in vec4 pos; in vec4 _vertexColor; in vec2 texCoords; layout(std140) uniform Projection { mat4 projMat; }; uniform mat4 modelViewMat; out vec2 texCoord; out vec4 vertexColor; void main() { gl_Position = projMat * modelViewMat * pos; texCoord = texCoords; vertexColor = _vertexColor; } ``` ```glsl #version 330 core in vec2 texCoord; in vec4 vertexColor; uniform sampler2D u_Texture; uniform vec4 shaderColor; out vec4 fragColor; void main() { fragColor = texture(u_Texture, texCoord) * shaderColor * vertexColor; } ``` ```java GLShader vertexShader = GLShader.builder(GLSLLoader.IN_JAR) .info( "vertex", "vertex.vsh", ShaderType.Vertex ) .build(); GLShader fragmentShader = GLShader.builder(GLSLLoader.IN_JAR) .info( "fragment", "fragment.vsh", ShaderType.Vertex ) .build(); GLProgram program = GLProgram.builder( /* Snippet for the global color (shaderColor) which are updated by CometRenderer itself (more on that later). */ CometRenderer.getColorSnippet() ) .name("test") .shader(vertexShader) .shader(fragmentShader) .sampler("u_Texture") .build(); ``` -------------------------------- ### Use #version auto directive Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins Example shader using #version auto. If BetterCompilerTags.GLSL_VERSION is not in the program registry, the version from CometRenderer global registry is inserted. ```glsl #version auto in vec4 position; void main() { gl_Position = projMat * modelViewMat * position; } ``` -------------------------------- ### Create and draw a ColoredRectBatch Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/crm/primitivebatches Creates a ColoredRectBatch, adds a rectangle with four corner colors, builds it, draws it, and closes it in a single chain. This is a minimal example of the PrimitiveBatches API. ```java new ColoredRectBatch() .rectSized(200, 210, 100, 100, new RectColors( RenderColor.of(1f, 1f, 1f, 1f), RenderColor.of(1f, 0f, 0f, 1f), RenderColor.of(0f, 1f, 0f, 1f), RenderColor.of(0f, 0f, 1f, 1f) )) .build() .tryDraw() .close(); ``` -------------------------------- ### TextureLoader example Source: https://ferra13671-dev.gitbook.io/projects/main/gltextureutils-documentation/loaders A TextureLoader implementation that reads an InputStream, decodes it with STBImage, and returns a GLTextureInfo. It uses Utils.readStream and Utils.tryGenerate, and selects 4 or 3 channels based on the ColorMode (RGBA or RGB). ```java public static final TextureLoader INPUT_STREAM = (path, colorMode) -> { ByteBuffer buffer = Utils.readStream(path); buffer.rewind(); AtomicReference glTextureInfo = new AtomicReference<>(null); Utils.tryGenerate(buffer, path, memoryStack -> { IntBuffer xBuffer = memoryStack.mallocInt(1); IntBuffer yBuffer = memoryStack.mallocInt(1); IntBuffer channelsBuffer = memoryStack.mallocInt(1); ByteBuffer byteBuffer = STBImage.stbi_load_from_memory(buffer, xBuffer, yBuffer, channelsBuffer, colorMode == ColorMode.RGBA ? 4 : 3); if (byteBuffer != null) glTextureInfo.set(new GLTextureInfo(byteBuffer, xBuffer.get(0), yBuffer.get(0), true)); }); return glTextureInfo.get(); }; ``` -------------------------------- ### Redirect version with BetterCompilerTags.GLSL_VERSION Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins Example shader showing version redirection. If the program registry contains BetterCompilerTags.GLSL_VERSION with GLVersion.GL46, the #version is replaced with '460 core'. ```glsl /* If program registry contains BetterCompilerTags.GLSL_VERSION tag with GLVersion.GL46 value, the version in #version will be replaced with '460 core'. */ #version 330 core in vec4 position; void main() { gl_Position = projMat * modelViewMat * position; } ``` -------------------------------- ### Prevent multiple includes with singleIncludeOnly() Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins Example of building a shader library with singleIncludeOnly() to prevent re-includes. Re-includes are ignored and a warning is written to the console. ```java public final GLSLFileEntry SHADER_COLOR = new GLShaderLibraryBuilder<>(CometLoaders.IN_JAR, CometRenderer.getColorSnippet()) .name("shaderColor") .library("assets/crm/shader-libraries/shader-color.glsl") .singleIncludeOnly() .build(); ``` -------------------------------- ### #inouts block directive before and after Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins Before and after processing examples for the #inouts block directive. It inserts two lists of fields marked with 'in' and 'out'. Fields marked with 'in' get the suffix '_in' appended, while 'out' fields keep their names. ```glsl #inouts { float param1; mat4 param2; vec4 param3; vec2 param4; atomic_uint param5; uint param6; }; void main() { param1_out = param1_in * 2; param2_out = param2_in; param3_out = param3_in.yxwz; param4_out = param4_in.yx; param5_out = param5_in; param6_out = param6_in + 10; } ``` ```glsl in float param1_in; in mat4 param2_in; in vec4 param3_in; in vec2 param4_in; in atomic_uint param5_in; in uint param6_in; out float param1; out mat4 param2; out vec4 param3; out vec2 param4; out atomic_uint param5; out uint param6; void main() { param1_out = param1_in * 2; param2_out = param2_in; param3_out = param3_in.yxwz; param4_out = param4_in.yx; param5_out = param5_in; param6_out = param6_in + 10; } ``` -------------------------------- ### Initialize CometRenderer with CometRenderer.init() Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation Call CometRenderer.init() in the thread where OpenGL was loaded before using CometRenderer. The comment in the source suggests adding // to each line if something doesn't work. ```java public static void main(String[] args) { /*...*/ CometRenderer.init(); /*...*/ } ``` -------------------------------- ### Initialize GLFW plugin and CometRenderer Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins/glfw Initialize the GLFW plugin and then CometRenderer. The GLFW plugin must be initialized before CometRenderer. Pass WindowHints, a FullScreenSwitchCombination, and a boolean for the debug context. ```java CometGLFW.init(...); CometRenderer.init(); ``` -------------------------------- ### #constant directive shader example Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins Shader example for the #constant directive. The compiler adds a value to the field before the directive and adds the 'const' keyword. The field must follow the structure $type $name. A default value can be added with . ```glsl #version 330 core in vec4 position; //constant without default value float value; #constant //constant with default value float value2; #constant void main() { gl_Position = projMat * modelViewMat * position; } ``` -------------------------------- ### Stencil example with INVERTED_READ Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/drawing-and-etc./stencil Example of using StencilInfo.INVERTED_READ to draw a cube only where the stencil mask has not been filled. It sets up a GLProgram, creates a mask mesh and a cube mesh, then draws the mask with WRITE stencil, then draws the cube with INVERTED_READ stencil, and finally clears and disables stencil. ```java GLProgram program = GLProgram.builder( CometRenderer.getColorSnippet() ) .name("test") /*...*/ .build(); int x = 200; int y = 520; int s = 25; Mesh maskMesh = CometRenderer.createMesh(DrawMode.QUADS, VertexFormat.POSITION, mesh -> { mesh .vertex(x, y, s * 2, s * 2) .vertex(x + (s * 4), y, s * 2, s * 2) .vertex(x + (s * 2), y + (s * 2), s * 2, s) .vertex(x + s, y + (s * 3), s * 4, s * 2) .vertex(x + s, y + (s * 5), s, s) .vertex(x + (s * 4), y + (s * 5), s, s); }); Mesh cubeMesh = CometRenderer.createMesh(DrawMode.QUADS, VertexFormat.POSITION, mesh -> { mesh .vertex(x - s, y - s, s * 8, s * 8); }); /*...*/ CometRenderer.setCurrentProgram(program); CometRenderer.setStencil(StencilInfo.WRITE); CometRenderer.draw(maskMesh); CometRenderer.setStencil(StencilInfo.INVERTED_READ); CometRenderer.getShaderColor().setColor(new Vector4f(1f, 0f, 0f, 1f)); CometRenderer.applyShaderColorUniform(); CometRenderer.draw(cubeMesh); CometRenderer.clearStencil(0); CometRenderer.disableStencil(); ``` -------------------------------- ### Ghost object listener example Source: https://ferra13671-dev.gitbook.io/projects/main/megaevents-documentation/listeners A method annotated with @EventSubscriber that takes no input parameters, unlike a regular object listener. ```java @EventSubscriber(event = TestEvent.class) public void onEvent() { System.out.println("TestEvent called!"); } ``` -------------------------------- ### Object listener example Source: https://ferra13671-dev.gitbook.io/projects/main/megaevents-documentation/listeners A method annotated with @EventSubscriber that accepts the event as a parameter. The method must accept only the event for which it is registered. ```java @EventSubscriber(event = TestEvent.class) public void onEvent(TestEvent event) { System.out.println("TestEvent called!"); } ``` -------------------------------- ### Get texture sampler with MinecraftEXT.getTextureSampler Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/crm/minecraftext Binds a GlTexture to a texture sampler for the current program. The textureSampler is set on sampler 0. ```java GlTexture texture = /*...*/ UnitBindable[] textureSampler = MinecraftEXT.getTextureSampler(texture); CometRenderer.getCurrentProgram().getSampler(0).setTextureSampler(textureSampler); ``` -------------------------------- ### Create CRMInstance with scale 1 Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/crm/crminstance Creates a CRMInstance with a Supplier that returns a UI scale of 1, making the UI size equal to the window size. ```java //For this CRMInstance, a scale of 1 will be used //(that is, the UI size will be equal to the window size) CRMInstance instance = new CRMInstance(() -> 1); ``` -------------------------------- ### Initialize BetterCompilerPlugin after CometRenderer Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins Call BetterCompilerPlugin.init() after CometRenderer.init() to enable the plugin. ```java CometRenderer.init(); BetterCompilerPlugin.init(); ``` -------------------------------- ### Load GLSLFileEntry with GLSLLoader.IN_JAR Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/glprogram/glslfileentry Creates a GLSLFileEntry by loading a shader from a JAR resource using GLSLLoader.IN_JAR. The entry can then be used with info(GLSLFileEntry, ShaderType) in the builder. Loading may throw LoadGLSLContentException. ```java GLSLFileEntry vertexShader = GLSLFileEntry.load("vertex", GLSLLoader.IN_JAR, "vertex.vsh"); ``` -------------------------------- ### PostEffectPipeline and ProgramPass API Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins/post-effects Documentation for the PostEffectPipeline and ProgramPass builder methods and the execute method. ```APIDOC ## [BUILDER] PostEffectPipeline.builder() ### Description Creates a new PostEffectPipelineBuilder instance for building a PostEffectPipeline. The builder can also be created via the usual constructor. ### Method builder() ### Parameters None ### Returns PostEffectPipelineBuilder - A builder instance for constructing a PostEffectPipeline. ### Example ```java PostEffectPipeline postEffect = PostEffectPipeline.builder().build(); ``` ``` ```APIDOC ## [BUILDER] PostEffectPipelineBuilder.localFrameBuffers(LocalFrameBufferInfo... frameBuffers) ### Description Adds temporary framebuffers that are created and used during the execution of the PostEffectPipeline and destroyed after use. ### Method localFrameBuffers(LocalFrameBufferInfo... frameBuffers) ### Parameters - **frameBuffers** (LocalFrameBufferInfo...) - Required - One or more LocalFrameBufferInfo objects specifying the temporary framebuffers. ### Returns PostEffectPipelineBuilder - The builder instance for chaining. ### Example ```java PostEffectPipeline postEffect = PostEffectPipeline.builder() .localFrameBuffers(new LocalFrameBufferInfo("Local Framebuffer 1", new Color(255, 255, 255).hashCode())) .build(); ``` ``` ```APIDOC ## [BUILDER] PostEffectPipelineBuilder.pass(ProgramPass programPass) ### Description Adds a ProgramPass, which is one of the rendering layers of the entire pipeline. ### Method pass(ProgramPass programPass) ### Parameters - **programPass** (ProgramPass) - Required - The ProgramPass to add as a rendering layer. ### Returns PostEffectPipelineBuilder - The builder instance for chaining. ### Example ```java ProgramPass programPass = /*...*/ PostEffectPipeline postEffect = PostEffectPipeline.builder() .localFrameBuffers(new LocalFrameBufferInfo("Local Framebuffer 1", new Color(255, 255, 255).hashCode())) .pass(programPass) .build(); ``` ``` ```APIDOC ## [BUILDER] ProgramPass.builder() ### Description Creates a new ProgramPassBuilder instance for building a ProgramPass. The builder can also be created via the usual constructor. ### Method builder() ### Parameters None ### Returns ProgramPassBuilder - A builder instance for constructing a ProgramPass. ### Example ```java ProgramPass programPass = ProgramPass.builder().build(); ``` ``` ```APIDOC ## [BUILDER] ProgramPassBuilder.input(int samplerId, String frameBufferName) ### Description Adds the input framebuffer to the sampler with a specific id, using a local framebuffer name. ### Method input(int samplerId, String frameBufferName) ### Parameters - **samplerId** (int) - Required - The sampler id to bind the framebuffer to. - **frameBufferName** (String) - Required - The name of the local framebuffer to use as input. ### Returns ProgramPassBuilder - The builder instance for chaining. ### Example ```java ProgramPass programPass = ProgramPass.builder() .input(0, "Local Framebuffer 1") .build(); ``` ``` ```APIDOC ## [BUILDER] ProgramPassBuilder.input(int samplerId, Framebuffer framebuffer) ### Description Adds the input framebuffer to the sampler with a specific id, using a Framebuffer object. ### Method input(int samplerId, Framebuffer framebuffer) ### Parameters - **samplerId** (int) - Required - The sampler id to bind the framebuffer to. - **framebuffer** (Framebuffer) - Required - The framebuffer to use as input. ### Returns ProgramPassBuilder - The builder instance for chaining. ### Example ```java Framebuffer framebuffer = /*...*/ ProgramPass programPass = ProgramPass.builder() .input(1, framebuffer) .build(); ``` ``` ```APIDOC ## [BUILDER] ProgramPassBuilder.output(String frameBufferName) ### Description Specifies the output framebuffer for ProgramPass using a local framebuffer name. ### Method output(String frameBufferName) ### Parameters - **frameBufferName** (String) - Required - The name of the local framebuffer to use as output. ### Returns ProgramPassBuilder - The builder instance for chaining. ### Example ```java ProgramPass programPass = ProgramPass.builder() .output("Local Framebuffer 1") .build(); ``` ``` ```APIDOC ## [BUILDER] ProgramPassBuilder.output(Framebuffer framebuffer) ### Description Specifies the output framebuffer for ProgramPass using a Framebuffer object. ### Method output(Framebuffer framebuffer) ### Parameters - **framebuffer** (Framebuffer) - Required - The framebuffer to use as output. ### Returns ProgramPassBuilder - The builder instance for chaining. ### Example ```java Framebuffer framebuffer2 = /*...*/ ProgramPass programPass = ProgramPass.builder() .output(framebuffer2) .build(); ``` ``` ```APIDOC ## [BUILDER] ProgramPassBuilder.program(GLProgram program) ### Description Specifies the program to be used in ProgramPass. ### Method program(GLProgram program) ### Parameters - **program** (GLProgram) - Required - The GLProgram to use. ### Returns ProgramPassBuilder - The builder instance for chaining. ### Example ```java GLProgram program = /*...*/ ProgramPass programPass = ProgramPass.builder() .program(program) .build(); ``` ``` ```APIDOC ## [BUILDER] ProgramPassBuilder.preRenderAction(Consumer preRenderAction) ### Description Specifies the action to be performed before the ProgramPass is rendered. ### Method preRenderAction(Consumer preRenderAction) ### Parameters - **preRenderAction** (Consumer) - Required - A Consumer that will be invoked before rendering. ### Returns ProgramPassBuilder - The builder instance for chaining. ### Example ```java ProgramPass programPass = ProgramPass.builder() .preRenderAction(_program -> { /*...*/ }) .build(); ``` ``` ```APIDOC ## [METHOD] PostEffectPipeline.execute(int textureWidth, int textureHeight) ### Description Executes the post-effect pipeline with the given framebuffer dimensions. The framebuffer with the specified width and height will be the final output framebuffer of the pipeline. ### Method execute(int textureWidth, int textureHeight) ### Parameters - **textureWidth** (int) - Required - The width of the framebuffer. - **textureHeight** (int) - Required - The height of the framebuffer. ### Returns void ### Example ```java Framebuffer framebuffer = /*...*/ PostEffectPipeline postEffect = /*...*/ postEffect.execute(framebuffer.textureWidth, framebuffer.textureHeight); ``` ``` -------------------------------- ### Define TestEvent Class Source: https://ferra13671-dev.gitbook.io/projects/main/megaevents-documentation/eventbus Defines a custom event class extending Event with two final fields and a constructor. This event is used in the activation example. ```java public class TestEvent extends Event { public final String arg1; public final int arg2; public TestEvent(String arg1, int arg2) { this.arg1 = arg1; this.arg2 = arg2; } } ``` -------------------------------- ### Build a GLShader with GLShader.builder Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/glprogram/building-shaders Creates a GLShader using GLShaderBuilder obtained via the builder() method. The GLSLLoader.IN_JAR parameter specifies the shader loading source. ```java GLShader shader = GLShader.builder(GLSLLoader.IN_JAR) /*...*/ .build(); ``` -------------------------------- ### GLProgram.builder().buildSnippet() Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/glprogram/building-programs Documentation for the buildSnippet() method, which builds a GLProgramSnippet from the builder. ```APIDOC ## GLProgram.builder().buildSnippet() ### Description Builds a GLProgramSnippet instead of a full GLProgram. This method is used when only a snippet is needed, allowing the same builder configuration. ### Method buildSnippet() ### Parameters Same as GLProgram.builder() - requires shaders and supports optional uniforms, samplers, and tags. ### Exceptions - **CompileProgramException** - Thrown when program compilation fails. - **CompileShaderException** - Thrown when shader compilation fails. - **DoubleShaderAdditionException** - Thrown if a shader with the same type is added twice. - **DoubleUniformAdditionException** - Thrown if a uniform with the same name is added twice. - **IllegalBuilderArgumentException** - Thrown for invalid builder arguments. - **NoSuchUniformException** - Thrown when a referenced uniform does not exist. ### Example ```java GLShader testShader = GLShader.builder(GLSLLoader.IN_JAR) .info( "testShader", "testShader.vsh", ShaderType.Fragment ) .build(); GLProgramSnippet snippet = GLProgram.builder() .shader(testShader) .uniform("testUniform", UniformType.VEC4) .buildSnippet(); ``` ``` -------------------------------- ### Build a shader with info, uniform, sampler, and tag Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/glprogram/building-shaders Builds a shader with required info() and optional uniform(), sampler(), and tag() methods. Adding a uniform with a duplicate name throws DoubleUniformAdditionException. Tags are only used during shader building and are not added to the program builder. ```java GLShader shader = GLShader.builder(GLSLLoader.IN_JAR) .info("example", "path/to/example", ShaderType.Vertex) .uniform("test", UniformType.FLOAT) .sampler("test") .tag(/*...*/) .build(); ``` -------------------------------- ### #inouts directive before processing Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins/better-compiler #inouts inserts two lists of fields marked with 'in' and 'out'. Fields marked 'in' get the suffix '_in', while 'out' fields keep their names. ```glsl #inouts { float param1; mat4 param2; vec4 param3; vec2 param4; atomic_uint param5; uint param6; }; void main() { param1_out = param1_in * 2; param2_out = param2_in; param3_out = param3_in.yxwz; param4_out = param4_in.yx; param5_out = param5_in; param6_out = param6_in + 10; } ``` -------------------------------- ### Config class with OpenGL and mesh settings Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/config Defines the Config class with settings for OpenGL version checks, mesh allocator size, and vertex/index limits. Configure these settings before CometRenderer initializes; MAX_VERTICES and MAX_INDICES are updated from CometTags after initialization. ```java @API(status = API.Status.MAINTAINED, since "1.9") public class Config { public final Setting CHECK_OPENGL_VERSION = new Setting<>(true); public final NumberSetting MINIMUM_OPENGL_VERSION = new NumberSetting<>(GLVersion.GL32.id, GLVersion.GL32.id, GLVersion.GL46.id); public final Setting COMPARE_CURRENT_AND_SHADER_OPENGL_VERSIONS = new Setting<>(true); public final NumberSetting DEFAULT_MESH_ALLOCATOR_SIZE = new NumberSetting<>(786432, 0, Integer.MAX_VALUE); public final NumberSetting MAX_VERTICES = new NumberSetting<>(0, 0, Integer.MAX_VALUE); //Sets from CometTags.MAX_VERTICES after init public final NumberSetting MAX_INDICES = new NumberSetting<>(0, 0, Integer.MAX_VALUE); //Sets from CometTags.MAX_INDICES after initVALUE); } ``` -------------------------------- ### Create TextureAtlas and get UV border Source: https://ferra13671-dev.gitbook.io/projects/main/gltextureutils-documentation/textureatlas Creates a TextureAtlas from a list of GLTexture objects and shows how to retrieve UV coordinates via getBorder() for rendering. The drawTexture method is a placeholder for the actual rendering logic. ```java GLTexture tex1 = /*...*/ GLTexture tex2 = /*...*/ TextureAtlas atlas = new TextureAtlas( "Texture atlas 1", Arrays.asList( tex1, tex2, /*...*/ ) ); void render() { TextureBorder border = atlas.getBorder(tex1); drawTexture(atlas, 0, 0, 200, 200, border.getU1(), border.getV1(), border.getU2(), border.getV2()) } void drawTexture(GlTex tex, float x, float y, float u1, float v1, float u2, float v2) { /*...*/ } ``` -------------------------------- ### Build a PostEffectPipeline Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/plugins/post-effects Creates a PostEffectPipeline using the builder pattern. The builder can be created either in the usual way or via the PostEffectPipeline.builder() method. To complete the build, call the build() method. ```java PostEffectPipeline postEffect = PostEffectPipeline.builder().build(); ``` -------------------------------- ### Fragment shader using the global shader color uniform Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/drawing-and-etc./shader-color Example fragment shader that uses the global shader color uniform to determine the final render color. The uniform is named shaderColor and is of type vec4. ```glsl #version 330 core precision lowp float; //Global color uniform uniform vec4 shaderColor; out vec4 fragColor; void main() { fragColor = shaderColor; } ``` -------------------------------- ### Create a Framebuffer with FramebufferInfo.builder() Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/drawing-and-etc./framebuffer Creates a new framebuffer instance using FramebufferImpl and FramebufferInfo.builder(). The builder allows setting the framebuffer name, dimensions, and optional depth/stencil buffers and clear values. The useDepth, useStencil, clearColor, clearDepth, and clearStencil options are optional. ```java Framebuffer framebuffer = new FramebufferImpl( FramebufferInfo.builder() .name("Framebuffer 1") .useDepth(true) //Optional .useStencil(true) //Optional .width(1920) .height(1080) .clearColor(new Color(0, 0, 0, 0)) //Optional .clearDepth(0) //Optional .clearStencil(0) //Optional .build() ); ``` -------------------------------- ### Creating a mesh with POSITION_COLOR format and elements Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/mesh-and-everything-that-goes-with-it Creates and draws a mesh with CometVertexFormats.POSITION_COLOR, adding vertices with Color elements using VertexElementType.FLOAT. ```java CometRenderer.draw(CometRenderer.createMesh(DrawMode.QUADS, CometVertexFormats.POSITION_COLOR, buffer -> { buffer.vertex(200, 200, 0).element("Color", VertexElementType.FLOAT, 1f, 1f, 1f, 1f); buffer.vertex(200, 400, 0).element("Color", VertexElementType.FLOAT, 1f, 0f, 0f, 1f); buffer.vertex(400, 400, 0).element("Color", VertexElementType.FLOAT, 0f, 1f, 0f, 1f); buffer.vertex(400, 200, 0).element("Color", VertexElementType.FLOAT, 0f, 0f, 1f, 1f); })); ``` -------------------------------- ### Set and get current program with CometRenderer Source: https://ferra13671-dev.gitbook.io/projects/main/cometrenderer-documentation/drawing-and-etc./current-program Sets a GLProgram as the current program via CometRenderer.setCurrentProgram, then retrieves it with getCurrentProgram to update a uniform before drawing a mesh. The uniform update uses getUniform("test", UniformType.INT).set(1) and the draw call is CometRenderer.draw(mesh). ```java GLProgram program = /*...*/ Mesh mesh = /*...*/ /*...*/ CometRenderer.setCurrentProgram(program); CometRenderer.getCurrentProgram().getUniform("test", UniformType.INT).set(1); //Updating the uniform for the current program CometRenderer.draw(mesh); ``` -------------------------------- ### Custom GLController implementation with logging Source: https://ferra13671-dev.gitbook.io/projects/main/gltextureutils-documentation Use this snippet to replace the default GL controller with a custom one that logs each OpenGL call. Call GLTextureSystem.setGlController() with this anonymous GLController instance. Each overridden method prints a message before delegating to the corresponding GL11 method. ```java GLTextureSystem.setGlController(new GLController() { @Override public void run(Runnable runnable) { runnable.run(); } @Override public int genTexId() { System.out.println("Call glGenTextures."); return GL11.glGenTextures(); } @Override public void deleteTexture(int id) { System.out.println("Call glDeleteTextures."); GL11.glDeleteTextures(id); } @Override public void bindTexture(int id) { System.out.println("Call glBindTexture."); GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); } @Override public void texParameter(int target, int pname, int param) { System.out.println("Call glTexParameteri."); GL11.glTexParameteri(target, pname, param); } @Override public void texParameter(int target, int pname, float param) { System.out.println("Call glTexParameterf."); GL11.glTexParameterf(target, pname, param); } @Override public void texImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, ByteBuffer pixels) { System.out.println("Call glTexImage2D."); GL11.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels); } @Override public void texSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, long pixels) { System.out.println("Call glTexSubImage2D."); GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); } @Override public void copyTexSubImage2D(int target, int level, int xOffset, int yOffset, int x, int y, int width, int height) { System.out.println("Call glcopyTexSubImage2D."); GL11.glCopyTexSubImage2D(target, level, xOffset, yOffset, x, y, width, height); } @Override public void getTexImage(int tex, int level, int externalFormat, int type, ByteBuffer pixels) { System.out.println("Call glGetTexImage"); GL11.glGetTexImage(tex, level, externalFormat, type, pixels); } @Override public void pixelStore(int pname, int param) { System.out.println("Call glPixelStorei."); GL11.glPixelStorei(pname, param); } }); ```