In 2D graphics (2DCG), the basic workflow typically involves manipulating a renderer (drawing engine) to modify image data. This section introduces these two essential concepts.
This section introduces these two essential concepts.
To work with 2D graphics in VCSSL, you need to understand two core components: the graphics resource, which holds the drawing contents, and the renderer, which performs the drawing operations. Don't worry -- it's simpler than it sounds.
In the real world, to draw a picture, you need things like paper to draw on and pens to draw with. In programming, it's similar -- you need a structure to hold and modify the drawing contents, such as an image, buffer, or graphics context (the exact term depends on the language or environment).
In VCSSL, all of these elements are bundled together into a single concept called a graphics resource.
You can think of it like a ready-to-use sheet of drawing paper that already comes with all the tools you need.
A renderer (drawing engine) is the tool used to perform advanced drawing operations on graphics resource. While it's technically possible to draw directly on graphics resource, using a renderer allows for more sophisticated rendering techniques.
You can think of the renderer as "the person doing the drawing." Just like in the real world, there are artists who specialize in 2D art and others who specialize in 3D.
Similarly, VCSSL provides separate renderers for 2DCG and 3DCG.
Let's start by creating the graphics data on which we'll draw. Use the "newGraphics" function from the Graphics library for this.
- Function Format -When called without any arguments, this function allocates an empty region in memory to store drawing contents, and returns a **graphics resource ID** -- a unique identifier assigned to the graphics resource.
The graphics resource created with "newGraphics" starts out blank.
To draw 2D graphics on it, you'll need to create a 2D renderer (drawing engine) using the "newGraphics2DRenderer" function.
- Function Format -Arguments:
Now let's actually create a renderer. Write and run the following program:
import Graphics;
import Graphics2D;
// Create graphics resource
int graphicsID = newGraphics( );
// Create a 2D renderer
int rendererID = newGraphics2DRenderer( 800, 600, graphicsID );
Sample.vcssl
When you run this program, the graphics data and renderer will be initialized, but nothing will appear on the screen just yet. That's because we haven't created a display screen to show the graphics data.
Let's move on to preparing the display in the next section.