[ Previous | Next | Contents | Glossary | Home | Search ]
GL3.2 Version 4.1 for AIX: Programming Concepts

Defining an Object

Create and name objects with the makeobj subroutine. When you call the makeobj subroutine, the system defines an object. Its object parameter is a signed 32-bit integer, which is the object's numeric identifier.

When the makeobj subroutine executes, the system enters the object's numeric identifier into a symbol table and allocates memory for its list of drawing routines. This opens a new, empty object to which you can add drawing routines. When you open an object for editing, drawing routines are not executed and drawn on the screen, but are added to the list until the closeobj subroutine is called.

Thus, a graphical object is a list of primitive drawing routines to be executed. Drawing the display list consists of executing each routine in the listed order. There is no flow control, such as looping, iteration, or condition tests (except for the bbox2 subroutine).

Note: Not all Graphics Library routines can be put in a display list. A general rule is to include drawing routines and not to include routines that return values. If you have a question about a particular subroutine, check that entry in "Choosing the Right GL Subroutine".

makeobj Subroutine

The makeobj subroutine creates a graphical object. It takes one parameter, a signed 32-bit integer that is associated with the object. If the object parameter is the number of an existing object, the contents of that object are deleted.

When the makeobj subroutine executes, the object number is entered into a symbol table and memory is allocated for a display list. Subsequent graphics routines are compiled into the display list instead of executing. The syntax is as follows:

void makeobj(Int32 object)

closeobj Subroutine

The closeobj subroutine terminates the object definition and closes the open object. All the routines in the graphical object between the makeobj and closeobj subroutines are part of the object definition.

The following fragment shows the object definition of a simple shape, as illustrated in the following figure.

makeobj(sphere=genobj);
for (phi=0; phi≤PI; phi=PI/9){
     for (theta=0; theta≤2*PI; theta+=PI/18){
          x=sin(theta) * cos(phi);
          y=sin(theta) * sin(phi);
          z=cos(theta);
          if (theta==0)move (x,y,z);
          else draw (x,y,z);
    }
}
closeobj();


If you specify a numeric identifier that is already in use, the system replaces the existing object definition with the new one. To ensure your object's numeric identifier is unique, use the isobj and genobj subroutines.

isobj Subroutine

The isobj subroutine tests whether there is an existing object with a given numeric identifier. Its object parameter specifies the desired numeric identifier. The isobj subroutine returns TRUE if an object exists with the specified numeric identifier, and FALSE if none exists. The syntax is as follows:

Int32 isobj(Int32 object)

genobj Subroutine

Use the genobj subroutine to generate a unique numeric identifier. It does not generate current numeric identifiers. This subroutine is useful in naming objects when it is impossible to anticipate what the current numeric identifier will be when the routine is called. The syntax is as follows:

Int32 genobj()

delobj Subroutine

The delobj subroutine deletes an object. It frees all memory storage associated with the object. The numeric identifier is undefined until it is reused to create a new object. The system ignores calls to deleted or undefined objects. The syntax is as follows:

void delobj(Int32 object)

[ Previous | Next | Contents | Glossary | Home | Search ]