Once you've drawn something to graphics resource, it won't mean much unless you display it on the screen or save it to a file.
In this section, we'll cover how to output the rendered image to the screen.
To make use of 2D graphics in a running program, you'll need a screen to display the graphics data you've drawn.
For this, you can use functions from the "GUI" library to create a display window.
To create a window, use the "newWindow" function from the GUI library.
- Function Format -Arguments:
When you call this function, a window will be created and its assigned component ID will be returned as an int. A component ID is a unique identifier assigned to any GUI component.
To display the contents of graphics data within a window, youfll need to create a GUI component called an **image label**. This can be done using the "newImageLabel" function.
- Function Format -Arguments:
This function returns the component ID of the image label that is created.
To reflect changes in your GUI, you need to repaint the affected components.
If you change the contents of the graphics resource, for example, the GUI components that display it -- such as image labels or windows -- will not update automatically. You must explicitly request a repaint to update the screen.
To do this, use the paintComponent function.
- Function Format -Arguments:
Whenever you finish drawing 2D graphics, make sure to call this function to update the screen properly.
import Graphics;
import Graphics2D;
import GUI;
// Create graphics resource
int graphicsID = newGraphics( );
// Create a renderer
int rendererID = newGraphics2DRenderer( 800, 600, graphicsID );
// Create a window (800x600) titled "Hello, 2DCG!"
int windowID = newWindow( 0, 0, 800, 600, " Hello , 2DCG ! " );
// Create an image label to show the graphics resource
int labelID = newImageLabel( 0, 0, 800, 600, graphicsID );
// Mount the image label onto the window
mountComponent( labelID, windowID );
// Paint the GUI components
paintComponent( labelID );
paintComponent( windowID );
Sample.vcssl
When you run this program, a window titled "Hello, 2DCG!" with a size of 800~600 will appear. The window will display the graphics content, but since nothing has been drawn yet, the screen will just show a blank area.