Graphics in a graphics window

As with text buffer windows, the main tool for placing PNG and JPEG images into a graphics window is glk_image_draw(). This time it takes these four arguments:

1) The name of the window the image should be placed in (gg_mapwin, for example)

2) The image to be placed there (but see the discussion that follows the list of arguments)

3 and 4) The coordinates of where you want the top left corner of the image to go. The third argument is how many pixels from the left edge of the window it should go, and the fourth argument is how many pixels from the top edge of the window it should go, so if you want the image to nestle up against these edges, put 0 for both of these. (Why would you ever want to put images anywhere but 0,0? Maybe you first want to put in an picture of a nice decorative border, and load in smaller images inside the border, perhaps at 10,10.) Don't worry about the image overflowing the right or bottom edges of the window -- any excess will be snipped.

The tricky part is the second argument. When you put images in a text buffer window, they become just another part of the stream that the program sends to that window, so when a restore or an undo changes where the player is in the game, the library handles the images automatically. This is not the case if you're dropping your images into a separate window. Here's an example. Let's say you have a game with a fixed graphics window where you put a picture of the room the player is in. And let's say you choose to do this by directly inserting the picture you want to display when the player moves into the room. So if the kitchen is south of the dining room, you might have a block of code in the dining room object that looks like this:

   s_to [;
      if (gg_picwin) { ! testing to see if the window exists
         glk_image_draw(gg_picwin, Kitchen_pic, 0, 0);

This will, indeed, cause the picture of the kitchen to appear in the appropriate window when the player character enters the kitchen. But what if the player decides to restore or undo back to the point where she was in the dining room? In the story window, she'll have returned to the dining room -- but the graphics window will still be showing a picture of the kitchen! The library does not update graphics windows automatically. You have to do it yourself.

Next section: Graphics window handling
Or return to the table of contents