OSGL is an open-source project. Feel free to edit source code or give ideas - You can do this in the github or here in the DevForum.
Credits
You are not required to credit me for OSGL, it is optional. While you may edit the source as you like, please do not reupload / claim this asset as your own work(s)!
make it better
Assistant
Sure! Here’s a refined version of your contribution and credits section:
Contribution
OSGL is an open-source project, and we welcome your contributions! You’re encouraged to edit the source code and share your ideas. Feel free to participate via GitHub or on the DevForum. Your involvement is greatly appreciated!
Credits
While you do not need to credit me for using OSGL, acknowledging the original creator is always appreciated but entirely optional. You are free to modify the source code as you wish, but please refrain from reuploading or claiming the asset as your own work.
Let me know if you need any further changes!
User
make it better
OSGL, Open-Source-Graphical-Library, aims to provide a simple way for developers to read and write PixelData to EditableImages.
OSGL was originally developed as an alternative to CanvasDraw, a graphics-engine built for Roblox. Unlike CanvasDraw, OSGL attemtps to be a library solely for EditableImages alone.
OSGL is currently in some sort of "beta", with some "expected" features not being implemented / still being worked on!
Assistant
Here’s an enhanced version of your description for OSGL:
OSGL (Open-Source Graphical Library) is designed to offer developers a straightforward and efficient way to read and write PixelData to EditableImages.
Originally created as an alternative to CanvasDraw, a graphics engine specifically built for Roblox, OSGL focuses exclusively on providing a robust library for working with EditableImages.
Please note that OSGL is currently in a "beta" phase. While many features are planned, some may still be under development or yet to be implemented. Your feedback and contributions are invaluable as we continue to enhance the library!
Feel free to adjust any part of it further!
User
make it better
OSGL provides the user with a "Window" (Or known as an EditableImage) that they can draw shapes, textures, text, etc onto. Features that OSGL provide are:
Shapes
Textures, supporting a wide range of Image-Formats, (with support for videos) & sprites
Texts & custom fonts
It even comes with its own error handler!
Assistant
Here’s an improved version of your OSGL feature description:
OSGL offers users a versatile "Window," also known as an EditableImage, that allows for drawing a variety of elements including shapes, textures, and text. Key features of OSGL include:
Shapes: Easily create and manipulate various geometric shapes.
Textures: Support for a wide array of image formats, including animated textures, videos, and sprites.
Text: Access to customizable fonts and text rendering options for dynamic content.
Built-in Error Handling: OSGL comes with its own error handler to ensure a smoother development experience by catching and managing errors effectively.
With OSGL, you have the tools you need to enhance your graphical projects seamlessly!
Feel free to make adjustments if necessary!
User
fix
This library would be a great help to those who would like to make pixel-based 2D/3D games, or where storing Pixel Data is needed.
Assistant
Here’s a refined version of your sentence:
This library is an invaluable resource for developers looking to create pixel-based 2D or 3D games, as well as for projects that require efficient storage and manipulation of Pixel Data.
Let me know if you need any further modifications!
User
now this
Quick tutorial
⚠️ This tutorial assumes you have a basic understand of Luau. If you're new, you can find plenty of resources online!
You can learn more on the Docs.
The following tutorial will show you how to draw a circle to the screen.
Creating & Opening the window
Before we can start drawing on a window, we need to create one. Place the OSGL module somewhere, such as ReplicatedStorage/Packages. Create an ImageLabel in StarterGui, with its BackgroundTransparency set to 0. This ImageLabel will serve as your canvas:
[image: image|690x331]
⚠️ Lower resolutions cause blurred images! If you're rendering at a low resolution, set the ResampleMode property of your ImageLabel to Pixelated!
Also create a LocalScript in your desired place (I'm putting it in StarterPlayer/StarterPlayerScripts) with any name that fits. This script will create our window and render to it.
OSGL is split into sub-modules that do different tasks. The sub-module we're looking for is the Window class, which handles creation of windows:
code
local OSGL = require(ReplicatedStorage.Packages.OSGL)
local Window = OSGL.Window
There are 2 functions we can use to create our window, Window.from, and Window.new.
As described by the documentation, Window.From:
"Creates an OSGL window from an existing EditableImage."
And Window.new:
"Creates an OSGL window by creating a new EditableImage instance at the given place."
In this case, we don't have an EditableImage, so we use Window.new to create our window on the given :
Assistant
Here’s a polished version of your quick tutorial, enhancing clarity and readability:
Quick Tutorial
⚠️ This tutorial assumes a basic understanding of Luau. If you're new to Luau, there are plenty of resources available online!
For more detailed information, check out the Documentation. In this tutorial, we will demonstrate how to draw a circle on the screen using OSGL.
Creating & Opening the Window
Before we can begin drawing on a window, we need to create one. First, place the OSGL module in a designated location, such as ReplicatedStorage/Packages. Next, create an ImageLabel in StarterGui, ensuring its BackgroundTransparency property is set to 0. This ImageLabel will serve as our canvas:
[image: image|690x331]
⚠️ Note: Using lower resolutions may result in blurred images! If you're working with low resolutions, set the ResampleMode property of your ImageLabel to Pixelated to maintain clarity.
Additionally, create a LocalScript in your desired location (e.g., StarterPlayer/StarterPlayerScripts) and name it appropriately. This script will create our window and manage the rendering process.
OSGL consists of several sub-modules for different tasks. The sub-module we need is the Window class, which handles the creation of windows:
lua
local OSGL = require(ReplicatedStorage.Packages.OSGL)
local Window = OSGL.Window
There are two functions available for creating our window: Window.from and Window.new. According to the documentation:
Window.from: Creates an OSGL window from an existing EditableImage.
Window.new: Creates an OSGL window by initializing a new EditableImage instance at the specified location.
Since we don't have an existing EditableImage, we'll use Window.new to create our window on the designated :
User
self.windowContents = self.pixels
is there a way of doing this without table.clone
Assistant
Yes! If you want to assign the contents of self.pixels to self.windowContents without using table.clone, you can directly assign it if self.pixels is a table of simple value types (like numbers or strings). However, if self.pixels contains nested tables and you want a deep copy (where changes to one do not affect the other), you'll need to implement a custom method to copy the tables.
Here's how you can handle both scenarios:
For Shallow Copy
If self.pixels only contains simple data types (like numbers or strings), you can do this directly:
lua
self.windowContents = self.pixels
In this case, self.windowContents will reference the same table as self.pixels. Any changes to one will affect the other.
For Deep Copy
If you need to create a completely independent copy of self.pixels (i.e., a deep copy), you can create a function to do this. Here’s a simple example of a deep copy function:
lua
local function deepCopy(original)
local copy = {}
for key, value in pairs(original) do
if type(value) == "table" then
copy[key] = deepCopy(value) -- Recursively copy nested tables
else
copy[key] = value
end
end
return copy
end
self.windowContents = deepCopy(self.pixels)
Summary
If you only need a reference and you're okay with both variables pointing to the same data, use a simple assignment.
If you need an independent copy and self.pixels may contain nested tables, use a custom deep copy function.
Let me know if you have a specific use-case or further questions!
User
what would you xcall a function that enables / disables smth to skip rendering the screen if content is unchanged
Assistant
A suitable name for a function that enables or disables the functionality to skip rendering when the content hasn't changed could be something like:
SetRenderOptimization(enabled)
ToggleRenderOptimization(enabled)
EnableRenderSkipping(enabled)
SetSkipRenderingOnUnchanged(enabled)
ConfigureRenderSkipping(enabled)
These names clearly indicate that the function modifies how rendering behaves based on whether the content has changed. The use of "enabled" or "toggle" in the name conveys that the function controls whether this optimization feature is active or inactive.
Feel free to modify any of these suggestions to better fit your coding style or naming conventions!
User
make it shorter and better its like "SkipRenderOnUnchanged"
Assistant
Here are some concise suggestions that maintain clarity while keeping it short:
SkipRenderIfUnchanged
SkipUnchangedRender
ToggleSkipRender
SetSkipRender
EnableSkipRender
Any of these options would effectively convey the function's purpose in a succinct manner. Let me know if you need more suggestions!
Dataset releases
Not yet included in a published release.
ImageLabel
code
local OSGL = require(ReplicatedStorage.Packages.OSGL)
local Window = OSGL.Window
local windowUi = -- *reference to windowUi*
-- Create our window
local myWindow = Window.new(windowUi, { sizeX = 500, sizeY = 500 })
The example above creates an OSGL window, with a size of 500x500, on windowUi. You can read more about this function in the docs.
Rendering to the Window
Great, now we have our window, but now we need to render to it, but only if it hasn't been destroyed by some external script! OSGL provides a handy method, IsOpen, that returns true while the window exists.
code
while myWindow:IsOpen() do
end
IsOpen automatically yields, so there is no need to use task.wait here. We can get straight to rendering!
To render a circle, we can use the draw sub-module. This module draws shapes straight to the provided double-buffer (meaning it isn't rendered onto the screen straight away!). We also need the color module (which uses RGBA, 0 - 255) to give our window some color! We can use the default RED for our example:
code
local OSGL = require(ReplicatedStorage.Packages.OSGL)
local Window = OSGL.Window
local draw = OSGL.draw
local color = OSGL.color
local windowUi = -- *reference to windowUi*
-- Create our window
local myWindow = Window.new(windowUi, { sizeX = 500, sizeY = 500 })
-- Automatically yields for a heartbeat, so task.wait isn't needed!
while myWindow:IsOpen() do
draw.circle(myWindow, {
centerX = 250,
centerY = 250,
fillColor = color.RED,
radius = 200
-- Strokes are optional, so we don't need to
-- pass `strokeColor` and `strokeThickness`
})
end
The first argument of everything you draw should be your window. This code creates a circle at 250, 250, with a radius of 200, with a RED (255, 0, 0, 255) color.
Running this however, you may notice that nothing happens (other than a slight performance drop 😭), but this is because we don't ACTUALLY render anything to the screen, only to the buffer. We can use Windows Render method to render the contents of the buffer to the screen:
code
local OSGL = require(ReplicatedStorage.Packages.OSGL)
local Window = OSGL.Window
local draw = OSGL.draw
local color = OSGL.color
local windowUi = -- *reference to windowUi*
-- Create our window
local myWindow = Window.new(windowUi, { sizeX = 500, sizeY = 500 })
-- Automatically yields for a heartbeat, so task.wait isn't needed!
while myWindow:IsOpen() do
draw.circle(myWindow, {
centerX = 250,
centerY = 250,
fillColor = color.RED,
radius = 200
-- Strokes are optional, so we don't need to
-- pass `strokeColor` and `strokeThickness`
})
-- Renders the double-buffer to the screen
myWindow:Render()
end
[image: image|418x359]
Running this, yay, it works! You may be wondering about the performance of this however; we're constantly rendering the same pixels to the screen without changing anything, that must be inefficient, right?
Well, yes, it is. But OSGL comes with this nifty feature where it doesn't render the entire window if the buffer has the exact same contents as the window, meaning, we're actually only rendering once. Because of this, we don't need to clear the screen everysingleframe. Clearing the screen is still useful, but it is not needed in this context. The reason for the small FPS drop is because OSGL still has to draw the circle into the buffer.
ImageLabel
lua
local OSGL = require(ReplicatedStorage.Packages.OSGL)
local Window = OSGL.Window
local windowUi = -- *reference to windowUi*
-- Create our window
local myWindow = Window.new(windowUi, { sizeX = 500, sizeY = 500 })
In the example above, we created an OSGL window with a size of 500x500 on windowUi. You can find more details about this function in the documentation.
Rendering to the Window
Now that we have our window, we need to render to it—but only if it hasn't been destroyed by any external scripts! OSGL provides a convenient method called IsOpen, which returns true while the window exists:
lua
while myWindow:IsOpen() do
-- Rendering code goes here
end
IsOpen will automatically yield, so there’s no need for task.wait here. We can focus directly on rendering!
To draw a circle, we will use the draw sub-module, which allows us to render shapes directly to the provided double-buffer (meaning the rendering is not displayed on screen immediately). In addition, we need to use the color module (which accepts RGBA values in the range of 0 to 255) to set a color for our window. We'll use the default RED color for this example:
lua
local OSGL = require(ReplicatedStorage.Packages.OSGL)
local Window = OSGL.Window
local draw = OSGL.draw
local color = OSGL.color
local windowUi = -- *reference to windowUi*
-- Create our window
local myWindow = Window.new(windowUi, { sizeX = 500, sizeY = 500 })
-- Automatically yields for a heartbeat, so task.wait isn't necessary!
while myWindow:IsOpen() do
draw.circle(myWindow, {
centerX = 250,
centerY = 250,
fillColor = color.RED,
radius = 200
-- Strokes are optional; no need to provide strokeColor and strokeThickness
})
end
The first argument for every drawing function should be your window. In this code, we create a circle centered at (250, 250) with a radius of 200 in RED (255, 0, 0, 255).
After running this code, you may notice that nothing appears on the screen (aside from a slight performance drop 😭). This is because we have only rendered to the buffer, and not yet to the screen. To display the contents of the buffer, we can use the Render method of the Window class:
lua
local OSGL = require(ReplicatedStorage.Packages.OSGL)
local Window = OSGL.Window
local draw = OSGL.draw
local color = OSGL.color
local windowUi = -- *reference to windowUi*
-- Create our window
local myWindow = Window.new(windowUi, { sizeX = 500, sizeY = 500 })
-- Automatically yields for a heartbeat, so task.wait isn't necessary!
while myWindow:IsOpen() do
draw.circle(myWindow, {
centerX = 250,
centerY = 250,
fillColor = color.RED,
radius = 200
-- Strokes are optional; no need to provide strokeColor and strokeThickness
})
-- Renders the double-buffer to the screen
myWindow:Render()
end
[image: image|418x359]
Now everything should work beautifully! However, you might be concerned about performance. We're continuously rendering the same pixels to the screen without any changes—this seems inefficient, right?
Indeed, it can be. Fortunately, OSGL incorporates a smart optimization: it only renders the entire window if the buffer contents differ from the displayed window. In this case, since the contents are the same, we effectively only render once per frame. While there’s no need to clear the screen with every frame, clearing it can still be useful in certain contexts. The slight FPS drop you're experiencing is due to OSGL still having to draw the circle into the buffer.
Feel free to make any further changes to suit your style!