Programmer’s Reference Manual for SunCore Sun Microsystems, Inc. • 2550 Garcia Avenue ° Mountain View, CA 94043 8 415-960-1300 Part rSo: 800-1165-0 i Acknowledgements The software in SunCore is an extended version of a merging of two software packages, namely LEGS and CLICS. LEGS (Library of Engineering Graphics Software) was built at Sun Microsys- tems between May 1982 and August 1982. LEGS consisted of 3-D transformations, clipping, and region fill, plus text, line, and marker output primitives for the Sun Workstation. CLICS (C Language Implementation of the Core System) was a 2-D implementation of the Core written by Mike Garrett, Drew Greenholt, and others. CLICS supported dynamic segment handling, error handling, and device independence, but lacked input primitives, 3-D capabilities, textured lines, and device independent text. CLICS was released to the public via the UNIX User’s Group (the precursor of USENIX) software distribution channel. CLICS plus LEGS became the SunCore graphics package at Sun Microsystems by November 1982, bringing the package up to output level 3C, input level 2, and dimension level 3-D, with raster extensions for polygons and bitmaps. Copyright ® 1982, 1983, 1984 by Sun Microsystems. This publication is protected by Federal Copyright Law, with all rights reserved. No part of this publication may be reproduced, stored in a retrieval system, translated, transcribed, or transmit- ted, in any form, or by any means manual, electric, electronic, electro-magnetic, mechanical, chemical, optical, or otherwise, without prior explicit written permission from Sun Microsystems. Revision History Rev Date Comments A 15 December 1982 First release of this Programmer’s Reference Manual. B 1 March 1983 Many minor corrections. Added aet_viewport_8 function to view- ing operations. Added inquire_inverae_compo8ite_matrix function to viewing operations. Added saving and restoring segments on disk to segmentation and naming. Added get_mouse_state function to input primitives. Added discussions on 3-D polygon shading parameters. C 15 May 1983 Many minor corrections. Made changes to SunCore routines to bring SunCore into strict compliance with the ACM Core specification. The following list of items is a guide: 1— Normal- ized device coordinates are now float values in the range 0.0 to 1.0. 2— initialize_view_surface takes different arguments — sur- face names were character strings, now they are pointers to the device drivers for the specified view surface. 3— routines for creat- ing and closing segments now match the Core specification. 4— the set_color_index function is replaced by the color raster extensions 8et_line_index, aet_fill_index, and aet_text_mdex. 5— the display list (pseudo display file) is now a virtual memory array of 500,000 bytes. Therefore, disk space must be available for these pages when running SunCore programs. The z-buffer is also a virtual array, hence more disk is used. 6— aet_image_transformation_type now replaces aet_aegment_type. 7— Defined constants for the aet_char_preciaion argument have changed. Revision History, continued Rev Date Comments D 1 November 1983 Many minor corrections. Changed viewsurface names to reflect use of new low-level device-interface routines and window system support. Old name sunbitmap replaced by bwldd when running program without window system, and pixwindd for use in windows. Old name suncolor replaced by cgldd. Changed initialize_view_surface — adding 2 to type argument value suppresses clearing the screen. awaitjkeyboard returns input_string null-terminated ‘after’ the newline character instead of before the newline character. Bitmap Frame-Buffer RasterOps of Appendix B replaced by pixrect operations. See Sun Window System Manual for details. Documentation for COP routines was confusing and has been clarified. Fixed all bugs reported to date. Also fixed some reported capability shortcomings. E 7 January 1984 Added new types of view surfaces. View-surface names| are now structures to support multiple windows. See appendix B for details. Low-level device-dependent routines for the color frame- buffer have been replaced by pixrect operations. See the Sun Win- dow System Programmer’s Reference Manual for details of pix- rects. SunCore now supports an interface from Pascal programs. See appendix E for details of the Pascal interface. A higher perfor- mance Core library is now available for use on machines with the hardware floating-point option. See appendix F for details. F 15 May 1985 Added set_pick function. Added additional raster (STRING preci- sion) fonts. SunCore now runs on the / dev/ cgtwo display surface. Added new appendix C — alphabetical list of C functions. Added new appendix G — list of error messages. Various bug fixes. — IV — Contents Chapter 1 Introduction 1=1 Chapter 2 Control 2-1 Chapter 3 Viewing Operations and Coordinate Transforms 3=1 Chapter 4 Segmentation and Naming 4-1 Chapter 5 Output Primitives 5-1 Chapter 0 Attributes 0-1 Chapter 7 Input Primitives 7-1 Chapter 8 Programming Examples 8-1 Appendix A Deviations from ACM SIGGRAPH Core A-l Appendix B SunCore View Surfaces B-l Appendix C Alphabetical SunCore C Function Reference C-l Appendix B Using SunCore with Fortran-77 Programs D-l Appendix E Using SunCore with Pascal Programs E-l Appendix F Higher Performance SunCore Library F-l Appendix G SunCore Error Numbers G-l — v — Contents Chapter 1 Introduction j_j_ 1.1. Overview and Terminology j.j 1.1.1. Basics of Drawing Pictures 1.3 1.2. Getting Started With SunCore 4.4 1.3. The SunCore Lint Library 1_6 1.4. The Coordinate Systems j.g 1.5. Details of Using SunCore 1_7 1.5.1. Classification of Functional Capabilities 1-7 1.5.2. Error Reporting ]_g 1.5.3. Useful Constants in the usercore.h Include File 1-9 1.6. Further Reading j_u Chapter 2 Control 2-1 2.1. Initialization and Termination 2-1 2.1.1. initial ize_core — Initialize the SunCore System 2-2 2.1.2. terminate_core — Close Down the SunCore System 2-2 2.2. Initializing and Selecting View Surfaces 2-2 2.2.1. initialize_viev_sur face — Initialize a View Surface 2-3 2.2.2. terminate_view_sur face — Close Down a View Surface 2-3 2.2.3. select_viev_sur face — Add View Surface to Selected Set 2-3 2.2.4. deselect_view_sur face — Remove View Surface from Selected Set 2-4 2.3. Batching of Updates 2-4 2.3.1. begin_batch_of_updates — Indicate Start of a Batch of Updates 2-4 2.3.2. end_batch_of_updates — Indicate End of a Batch of Updates 2-5 2.4. Frame Control 2-5 2.4.1. new_ frame — Start New Frame Action for Selected View Surfaces 2-5 2.5. Error Control 2-5 2.5.1. report_most_recent_error 2-5 2.5.2. print_error 2-5 2.6. Drag Control (SunCore Extension) 2-6 2.6.1. set_drag 2-6 — Vll — Chapter 3 Viewing Operations and Coordinate Transforms 3-1 3.1. Windows, View Volumes, and Clipping 3-1 3.2. Default Values of Viewing Operation Parameters 3-3 3.3. Setting 3D Viewing Operation Parameters 3-4 3.3.1. set_viev_reference_point — Establish Reference Point for Viewing 3-5 3.3.2. set_viev_plane_normal — Establish View Plane Normal Vector 3-6 3.3.3. set_viev_plane_distance — Establish View Plane Distance 3-6 3.3.4. set_projection — Select Projection Type 3-6 3.3.5. set_viev_up_2 — Establish 2D View Up Vector 3-7 3.3.6. set_viev_up_3 — Establish 3D View Up Vector 3-7 3.3.7. set_ndc_space_2 — Establish Size of NDC Space 3-1 3.3.8. set_ndc_space_3 — Establish Size of NDC Space 3-9 3.3.9. set_window — Establish a Window in the View Plane 3-10 3.3.10. set_viev_depth — Specify Planes for Depth Clipping 3-10 3.3.11. set_viewport_2 — Establish Limits of Two- Dimensional Viewport 3-10 3.3.12. set_viewport_3 — Establish Limits of Three- Dimensional Viewport 3-11 3.3.13. set_viewing_parameters 3-11 3.4. Viewing Control 3-12 3.4.1. set_window_c lipping — Enable Clipping in the View Plane 3-12 3.4.2. set_front_plane_c lipping — Enable Depth Clipping 3-13 3.4.3. set_back_plane_clipping — Enable Depth Clipping 3-13 3.4.4. set_output_c lipping (SunCore extension) 3-13 3.4.5. set_coordinate_system_type 3-14 3.4.6. set_world_coordinate_matrix_2 — Specify World or Modelling Transform 3-14 3.4.7. set_wor ld_coordinate_mat:rix_3 — Specify World or Modelling Transform 3-14 3.4.8. map_ndc_to_wor ld_2 — Convert NDC to World Coordinates 3-15 3.4.9. map_ndc_to_wor ld_3 — Convert NDC to World Coordinates 3-15 3.4.10. map_world_to_ndc_2 — Convert World to NDC Coordinates 3-15 3.4.11. map.wor ld_to_ndc_3 — Convert World to NDC Coordinates 3-15 3.5. Inquiring Viewing Characteristics 3-15 3.5.1. inquire_view_reference_point 3-16 3.5.2. inquire_view_plane_normal 3-16 3.5.3. inquire_viev_plans_distance 3-17 3.5.4. inquire_view_depth 3-17 3.5.5. inquir e_pro j ect ion 3-17 3.5.6. inquire_viev_up_2 347 3.5.7. inquire_viev_up_3 347 3.5.8. inquire_ndc_space_2 343 3.5.9. inquire_ndc_space_3 3 .I 8 3.5.10. inquire_viewport _2 348 3.5.11. inquire_vievport:_3 343 3.5.12. inquire_vindow 348 3.5.13. inquire_viewing_parameters 3-19 3.5.14. inquire. vorld_coordinate_matrix_2 3-19 3.5.15. inquire_vorld_coordinate_matrix_3 3-20 3.5.16. inquire_inverse_composite_matrix (SunCore Extension) 3_20 3.5.17. inquire_viewing_control_parameters 3-20 Chapter 4 Segmentation and Naming 4_1 4.1. Retained Segment Attributes 44 4.2. Retained Segment Operations 4_2 4.2.1. create_retained_segment — Create a New Segment 4-3 4.2.2. close_retained_segment — Close a Segment 4.3 4.2.3. delete_retained_segment — Delete a Retained Segment 4.3 4.2.4. rename_retained_segment — Rename a Retained Segment 4.4 4.2.5. delete_al l_retained_segmervts 4.4 4.2.6. inquire_retained_segment_sur faces 4-4 4.2.7. inquire_retained_segment_names 4.5 4.2.8. inquire_open_retained_segment 4.5 4.3. Temporary or Non-Re tained Segments 4.5 4.3.1. create_temporary_segment 4_6 4.3.2. close_temporary_segment 4-6 4.3.3. inquire_open_temporary_segment — Get Temporary Segment Status 4_6 4.4. Saving and Restoring Segments on Disk (SunCore Extension) 4-6 4.4.1. save_segment — Save Segment on Disk File (SunCore Extension) 4_6 4.4.2. restore_segment — Restore Segment from Disk File (SunCore Extension) 4.7 Chapter 5 Output Primitives 5_1 5.1. Moving the Current Position 5.4 5.1.1. move_abs _2 — Move to Absolute 2D Position 5-4 5.1.2. move_abs_3 — Move to Absolute 3D Position 5-4 5.1.3. move_rel _2 — Move to Relative 2D Position 5.4 5.1.4. move_rel_3 — Move to Relative 3D Position 5-5 5.2. Position Enquiry Functions 5.5 5.2.1. inquire_currervt_position _2 — Enquire 2D Position 5-5 — ix — 5.2.2. inquire_current_position_3 — Enquire 3D Position 5-5 5.3. Line Routines 5.5 5.3.1. line_abs_2 — Describe Line in Absolute 2D Coordinates 5-5 5.3.2. line_abs_3 — Describe Line in Absolute 3D Coordinates 5-6 5.3.3. line_rel_2 — Describe Line in Relative 2D Coordinates 5-6 5.3.4. line_rel_3 — Describe Line in Relative 3D Coordinates 5-6 5.4. Polyline Routines 5-6 5.4.1. poly line_abs_2 — Describe Line Sequence in Absolute 2D Coordinates 5.7 5.4.2. poly line_abs_3 — Describe Line Sequence in Absolute 3D Coordinates 5.7 5.4.3. poly line_rel_2 — Describe Line Sequence in Relative 2D Coordinates 5-7 5.4.4. poly line_rel_3 — Describe Line Sequence in Relative 3D Coordinates 5-8 5.5. Text Routines 5-8 5.5.1. text — Draw Character String In World Coordinates 5-8 5.6. Text Enquiry Functions 5-8 5.6.1. inquire_text_extent_2 5-9 5.6.2. inquire_text_extent_3 5-9 5.7. Marker Functions 5_g 5.7.1. marker_abs_2 — Plot Marker at Absolute 2D Coordinates 5_10 5.7.2. marker_abs_3 — Plot Marker at Absolute 3D Coordinates 5-10 5.7.3. marker_rel_2 — Plot Marker at Relative 2D Coordinates 5-10 5.7.4. marker_rel_3 — Plot Marker at Relative 3D Coordinates 5-10 5.7.5. polymarker_abs_2 — Plot Marker Sequence at Absolute 2D Coordinates 5_H 5.7.6. polymarker_abs_3 — Plot Marker Sequence at Absolute 3D Coordinates 5_H 5.7.7. polymarker_rel_2 — Plot Marker Sequence at Relative 2D Coordinates 5-1 1 5.7.8. polymarker_rel_3 — Plot Marker Sequence at Relative 3D Coordinates 5_H 5.8. Three-Dimensional Polygon Shading Parameters (SunCore Extension) 5-12 5.8.1. set_shading_parameters 5-12 5.8.2. set_light_direction — Specify Direction of Light Source 5_13 5.8.3. set_vertex_normals 5-13 5.8.4. set_vertex_indices 5-13 5.8.5. set_zbuf fer_cut 5-14 5.9. Polygon Functions (SunCore Extension) 5-14 5.9.1. polygon_abs_2 — Describe Polygon in Absolute 2D Coordinates 5-15 5.9.2. polygon_abs_3 — Describe Polygon in Absolute 3D Coordinates 5-15 — x — 5.9.3. polygon_rel _2 — Describe Polygon in Relative 2D Coordinates 5.^5 5.9.4. polygon_rel_3 — Describe Polygon in Relative 3D Coordinates 5 _j 5 5.10. Raster Primitive Functions (SunCore Extension) 5_16 5.10.1. put_raster — Raster Output Primitive 5_16 5.10.2. get_raster — Read Raster from Black/White or Color Frame Buffer 5 _lg 5.10.3. size.raster — Set Size of Raster in NDC 5_17 5.10.4. al locate_raster — Allocate Space for a Raster 5-17 5.10.5. free_raster — Free Space of a Raster 5 _lg 5.10.6. raster_to_file — Copy a Raster to a Disk Raster File 5-18 5.10.7. file_to_raster — Get a Raster from a Disk File 5 -ig Chapter 0 Attributes 6 . 1 . Primitive Static Attributes 6-1 6 . 1 . 1 . Using Texture for Color Attributes on the Monochrome Display 5.4 6.1.2. define_color_indices — Assign Colors to Indices 6-6 6.1.3. set_line_index — Select a Line Color Attribute 6-7 6.1.4. set_fill_index — Select a Polygon and Raster Color 6-7 6.1.5. set_text_index — Select a Text and Marker Color 6-8 6 . 1 . 6 . set_linewidth 6-8 6.1.7. set_linestyle 6-8 6 . 1 . 8 . set_polygon_interior_style — Select Plain or Shaded Polygons 6-8 6.1.9. set_polygon_edge_style (No Effect) 6-9 6 . 1 . 10 . set_font 6-9 6 . 1 . 11 . set_pen — Select a Device Dependent Pen 6-9 6 . 1 . 12 . set_charsize 6-9 6.1.13. set_charspace — Define Character Spacing for Output Primitives 6-10 6.1.14. set_charup_2 6-10 6.1.15. set_charup_3 6-10 6.1.16. set_charpath _2 6-10 6.1.17. set_charpath_3 6-11 6.1.18. set_charjust — Specify Text Justification (No Effect) 6-11 6.1.19. set_charprecision 6-11 6 . 1 . 20 . set_marker_symbol 6-11 6 . 1 . 21 . set_pick_id 6-12 6.1.22. set_r aster op — Select Rasterop to Display Memory (SunCore Extension) 6-12 6.1.23. set_primitive_attributes — Specify All Primitive Attributes 6-12 6.2. Inquiring Primitive Static Attribute Values 6-13 6 . 2 . 1 . inquire_color_indices 6-13 — xi — 6.2.2. inquire_line_index 6-13 6.2.3. inquire_fill_index 6-13 6.2.4. inquire_text_index 6-14 6.2.5. inquire_linewidth 6-14 6.2.6. inquir e_ 1 inesty 1 e 6-14 6.2.7. inquire_polygon_interior_style — Obtain Polygon Shading Method 6-14 6.2.8. inquire_polygon_edge_style 6-14 6.2.9. inquire_pen 6-15 6.2.10. inquire_font 6-15 6.2.11. inquire_charsize 6-15 6.2.12. inquire_charspaca 6-15 6.2.13. inquire_charup_2 6-15 6.2.14. inquire_charup_3 6-15 6.2.15. inquire_charpath_2 6-16 6.2.16. inquire_charpath_3 6-16 6.2.17. inquire_char just — Obtain Justification Attribute 6-16 6.2.18. inquire_rasterop — Obtain Current Rasterop (SunCore Extension) 6-16 6.2.19. inquire_charprecision 6-16 6.2.20. inquire_pick_id 6-16 6.2.21. inquir e_marker_symbo 1 6-17 6.2.22. inquire_primitive_attributes — Obtain All Primitive Attributes 6-17 6.3. Retained Segment Static Attributes 6-17 6.3.1. set_image_transformation_type 6-18 6.3.2. inquire_image_t:rans fonnation_'type 6-18 6.3.3. inquire_segment_image_trans format ion_type 6-18 6.4. Setting Retained Segment Dynamic Attributes 6-18 6.4.1. set_visibility 6-19 6.4.2. set_high lighting 6-19 6.4.3. set_detectability 6-20 6.4.4. set_image_tr ans 1 ate_2 6-20 6.4.5. set:_image_t:rans formation_2 6-20 6.4.6. set_image_translate_3 6-20 6.4.7. set_image_transformation_3 6-21 6.4.8. set_segmervt_visibility 6-21 6.4.9. set_segment:_highlight;ing 6-21 6.4.10. set_segment:_detectability 6-22 6.4.11. set_segment_image_translate_2 6-22 6.4.12. set_segment_image_transformation_2 6-22 6.4.13. set_segment_image_translate_3 6-23 6.4.14. set_segment_image_transformation_3 6-23 6.5. Inquiring Retained Segment Dynamic Attributes 6-24 6.5.1. inquire_visibilit:y 6-24 6.5.2. inquir e_highl i girting 6-24 — xii — 6.5.3. inquire_detect abi 1 ity 5.25 6.5.4. inquir o_ima ge_tr ans 1 at e_2 6-25 6.5.5. inquire_image_transformation_2 6-25 6.5.6. inquir e_image_tr ans 1 a t ®_3 5-25 6.5.7. inquire_image_transformation_3 6-25 6.5.8. inquire_segment_visibility 6-26 6.5.9. inquire_segment_highlighting 6-26 6.5.10. inquire_segment_detectability 6.26 6.5.11. inquire_segpment_image_translate_2 6-26 6.5.12. inquire_segment_image_transformation_2 6-27 6.5.13. inquire_segment_image_translate_3 6-27 6.5.14. inquire_segmervt_image_t:ransformation_3 6-27 Chapter 7 Input Primitives 7.1. Initializing and Terminating Input Devices 7_1 7.1.1. initial ize_device — Initialize a Specific Device 7-2 7.1.2. terminate_device — Disable a Specific Device 7-2 7.2. Device Echoing 7.3 7.2.1. set_echo — Define Type of Echo for Device 7.6 7.2.2. set_echo_group — Define Type of Echo for a Group of Devices 7.6 7.2.3. set_echo_position — Define Echo Reference Point 7-6 7.2.4. set_echo_sur face — Define View Surface for Echo 7-6 7.3. Setting Input Device Parameters 7.7 7.3.1. set_locator _2 — Initialize Locator Position 7.7 7.3.2. set_valuator — Initialize Value and Range for Valuator Device 7,7 7.3.3. set_keyboard — Initialize Keyboard Parameters 7.7 7.3.4. set_stroke — Initialize Stroke Device 7 _g 7.3.5. set_pick — Initialize Pick Device 7 _g 7.4. Reading From Input Devices 7 _g 7.4.1. await_any_button — Wait for Mouse Button 7 _g 7.4.2. avait_pick — Wait for Pick Device 7 _g 7.4.3. avait_keyboard — Wait for Input from the Keyboard 7-9 7.4.4. await_stroke _2 — Wait for User to Draw a Line 7-10 7.4.5. await_any_button_get_locator _2 — Read Locator When Button Clicked 7_10 7.4.6. avait_any_button_get_valuator — Read Valuator When Button Clicked 7 _H 7.4.7. get_mouse_state — Low Level Mouse Support (SunCore extension) 7 -\\ 7.5. Inquiring Input Status Parameters 7 _H 7.5.1. inquire_echo — Obtain Type of Echo for Device 7-12 7.5.2. inquire_echo_position — Obtain Echo Reference Point 7-12 7.5.3. inquire_echo_sur face — Obtain View Surface for Echo — xiii — 7-12 7.5.4. inquire_locator_2 — Obtain Initial Locator Position 7-12 7.5.5. inquire_valuat:or — Obtain Value and Range for Valuator Device 7-13 7.5.6. inquira_keyboard — Obtain Keyboard Parameters 7-13 7.5.7. inquire_stroke — Obtain Stroke Device Parameters 7-13 Chapter 8 Programming Examples 8-1 8.1. The Sun Workstation Factory 8-1 8.1.1. Declarations and the Main Program 8-1 8.1.2. The factory Drawing Function 8-5 8.1.3. The Workstation Drawing Function 8-6 8.1.4. The Chip Drawing Function 8-6 8.1.5. The Cloud Drawing Function 8-7 Appendix A Deviations from ACM SIGGRAPH Core A-l A.l. Unimplemented Functions A-l A. 2. Other Differences A-2 Appendix B SunCore View Surfaces B-l B. l. The vwsurf Structure B-l B.2. View Surface Types B-2 B.3. Choosing a View Surface Type within an Application Program B-3 B.3.1. Using Shell Variables to Determine the Environment B-3 B.3.2. The get_view_sur face Function B-4 B.4. Specifying a View Surface for Initialization B-10 B.4.1. View Surface Specification for Raw Devices B-10 B.4.2. View Surface Specification for Window Devices B-ll B.5. Input Considerations B-12 B. 6. Notes on Window Device View Surfaces B-13 Appendix C Alphabetical SunCore C Function Reference C-l C. l. Alphabetical List of C Interfaces C-l Appendix D Using SunCore with Fortran-77 Programs D-l D. l. Programming Tips D-l D.2. Example Program D-3 D.3. Correspondence Between C Names and FORTRAN Names D-4 D. 4. FORTRAN Interfaces to SunCore D-9 Appendix E Using SunCore with Pascal Programs E-l E. l. Programming Requirements E-l E.1.1. Routines Using View Surface Names E-2 E.l. 2. Routines Using Rasters and Colormaps E-3 E.2. Example Program El-3 E.3. Correspondence Between C Names and Pascal Names El-6 E.4. Declarations for SunCore-Pascal Interface El-12 — xiv — E.4.1. Type Declarations E-12 E.4.2. Function Declarations Appendix F Higher Performance SunCore Library Appendix G SunCore Error Numbers — xv — Tables Table 1-1 Output Capabilities 4.7 Table 1-2 Input Capabilities j.g Table 1-3 Dimension Levels Supported j.g Table 3-1 Default Values of Viewing Operation Parameters 3-3 Table 3-2 Default Values of Viewing Control Parameters 3-3 Table 3-3 World Coordinate Matrix Parameters 3-4 Table 3-4 Image Transformation Parameters 3_4 Table 3-5 Summary of Functions for Setting Viewing Control Parameters 3.5 Table 3-6 Summary of Functions for Inquiring Viewing Parameters 3-16 Table 5-1 Summary of Output Primitive Functions 5_1 Table 5-2 Useful PHONG Parameters 5.43 Table 6-1 Structure of a Fill-Index Value 6-4 Table 6-2 Texture Selection Values 6-5 Table 6-3 Useful Texture Selection Values 6-6 Table 7-1 Input Devices Supported By SunCore 7.4 Table 7-2 Echoing for Pick Device 7.3 Table 7-3 Echoing for Keyboard Device 7.3 Table 7-4 Echoing for Button Device 7.4 Table 7-5 Echoing for Stroke Device 7.4 Table 7-6 Echoing for Locator Device 7.5 Table 7-7 Echoing for Valuator Device 7.5 Table A-l Unimplemented Primitive Attribute Functions A-l Table A-2 Unimplemented Synchronous Input Functions A-l Table A-3 Unimplemented Asynchronous Input Functions A-2 Table A-4 Unimplemented Control Functions A-2 Table A-5 Unimplemented Escape Functions A-2 Table B-l Declarations of get_view_sur face in C, FORTRAN, and Pascal g_5 — xvii — Figures Figure 3-1 Components of Viewing System 3_2 Figure 5-1 Flow Diagram of Output Primitive Processing 5.4 — xix — Chapter 1 Introduction Welcome to the SunCore graphics package and its Programmer’s Reference Manual. Sun Microsystems offers a comprehensive package of engineering graphics software providing the underlying support for interactive graphics applications programs. The SunCore software is an implementation of the ACM Core graphics specification 1 , plus extensions. SunCore is imple- mented to level 3C of the ACM Core specification for output primitives, and to level 2 of the ACM Core specification for input primitives. Extensions to the Core include textured polygon fill algorithms, raster primitives, rasterop attri- butes, shaded surface polygon rendering, and hidden surface elimination. This graphics package supports both the high resolution monochrome bitmap displays and the Sun color displays. Device-dependent routines support all these displays under SunCore. NOTE that this manual is a reference manual for the SunCore graphics package. It is not a tutorial for the programmer without knowledge of graphics principles. It assumes th*at the reader is familiar with the concepts of graphics, and has some familiarity with the ACM Core specification. Those who are new to graphics should consult one of the publications listed in further reading at the end of this chapter. Where to Start If you are an applications programmer who is familiar with the ACM Core specification, but are new to SunCore, it is recommended that you read appendix A in order to become familiar with the areas where SunCore deviates from and provides extensions to the ACM Core specification. Note that SunCore supports the ACM Core output level 3C, that is, dynamic output is sup- ported, including two and three-dimensional translation, scaling, and rotation. SunCore sup- ports the ACM Core input level 2, that is, synchronous input, including the PICK device. Sun- Core supports dimension level 2, that is, three-dimensional operations. 1.1. Overview and Terminology The objective of a graphics application program is drawing pictures and text on some display device, be it an ephemeral display device such as TV monitor or terminal, or a hard copy device such as a plotter or printer. 1 As defined in Computer Graphics, the ACM S1GGRAPH Quarterly, Volume 13, #3, August 1979. Revision F of 15 May 1985 1-1 Introduction SunCore Reference Manual There is a need for a device-independent way of representing graphics images in the computer, and having a collection of software routines map the device-independent representations into the physical representations that the output device can handle. SunCore is an implementation of one of the “standard” packages of graphics software that have appeared recently. This section introduces some of the terminology of SunCore. This terminology is used throughout this manual. It is somewhat easier to describe the terminology from the point of view of the physical device working backwards to the application program, rather than starting at the software and working out to the device. There are two quite distinct points of view for looking at a system running a graphics applica- tion: ® The physical device (monitor, printer, and so on) on which the final pictures appear, and a The internal world which the programmer uses to describe the pictures, and which (because of SunCore) is independent of the physical device. A view surface is a physical surface on which the final picture appears. There are two interdependent sets of coordinate systems in use in the graphics package: World Coordinates is a coordinate system which is device-independent. The applications programmer constructs all graphical objects in terms of world coordinates. Normalized Device Coordinates (often abbreviated to NDC) is a fixed coordinate system which is independent of physical out- put devices. World coordinates are transformed to normalized device coordinates for clip- ping and other operations. Each physical output device driver then transforms from iformal- ized device coordinates to the physical device coordinates for each view surface. A viewport is a region of NDC space which the programmer selects and on which the pictures will appear. It is the job of the viewing transformations to perform the correct mapping between world coor- dinates and normalized device coordinates. A window is a region defined in world coordinates within which the images that the application program defines appear. The selection of the coordinates for the window are arbitrary the graphics package maps the window into the viewport. In two dimensions, the transformation from the window to the viewport is a relatively straight- forward process. In three dimensions, another level of complexity is introduced with the notion of a view plane which is positioned arbitrarily in world coordinates. An output primitive, or often just a primitive, is a part of a picture (such as a line or a character string). The appearance of primitives (such as solid or dotted lines) is determined by primitive attributes. A primitive attribute is a general characteristic of an output primitive, and affects the appearance of that primitive. Examples of primitive attributes are color, linestyle, and linewidth. Each output primitive may be assigned a name, called the pick-id, which is used to identify that primitive when an input operation (such as pointing at the primitive with the mouse) is applied. The Current Position is a SunCore system value that defines the current location for drawing. At startup time, the Current Position is set to the origin of the world coordinate system. Func- tions that create output primitives (move, line, and so on) can alter the Current Position. 1-2 Revision F of 15 May 1985 SunCore Reference Manual Introduction Output primitives are collected together in tegmenta. A segment defines an image which is a part of the picture on a view surface. Segments are divided into two classes, namely: temporary and retained. A retained segment has a name, and can have segment attributes associated with it. A temporary segment is nameless, and furthermore, the image that a temporary segment defines only remains visible as long as information is only being added to the view surface. As soon as a new frame action (one which repaints view surface) occurs, the temporary segment’s image disappears from the view surface. Each retained segment has one static attribute, its image transformation type. The value of this attribute can be none, translatable, or transformable. Translatable and transformable retained segments can be translated or transformed in either two or three dimensions. Segments also have dynamic attributes. The visibility and highlighting attributes control the appearance of the image. The detectability attribute determines if the segment can be detected by the pick device. Dynamic attributes for translatable and transformable segments include the segment’s image transformation. Depending on the image transformation type, the image transformation may contain translation, rotation, and scaling components. A viewing operation is an operation that maps positions in world coordinates to positions in nor- malized device coordinates. The viewing operation also determines the portion of the world coordinate space that is visible if window clipping or depth clipping is enabled. The applications program can obtain user interaction by means of input primitives, which pro- vide facilities for pointing at objects, entering data from the keyboard, and causing events. I. 1.1. Basics of Drawing Pictures The general sequence of actions that an application program goes through to create a picture on a device is this: 1. Initialize SunCore. 2. Initialize a view surface upon which the picture will be drawn. 3. Select a view surface upon which the picture will be drawn. 4. Specify the viewing operation parameters (sizes of windows in world coordinates, size of viewport, and so on). 5. Set an image transformation type. 6. Create a segment. The created segment becomes the currently open segment until it is closed. 7. Set attributes for the segment, if required. 8. Draw objects in the segment using output primitives. 9. Close the segment. 10. Repeat steps 4 through 9 as often as required, for as many segments as needed to build the picture. II. Apply image transformations (translation, scaling, and rotation) to a given segment, to achieve the required picture on the display device. 12. Deselect the view surface. Revision F of 15 May 1985 1-3 Introduction SunCore Reference Manual 13. Terminate SunCore. In providing the application programmer with the capabilities needed to draw pictures, Bun- Core breaks the interface into six functional areas: Control directs the major actions of SunCore, such as startup, shutdown, selection and deselection of view surfaces, and so on. Segments control the creation, closing, and removal of segments. Segments are then used to collect sets of: Output Functions also known as output primitives, which describe the drawing of lines and line sequences, shaded regions, text, and markers. Attributes control the way in which output primitives actually appear in the final image (solid or dotted lines, for instance). Transformations control the major appearances of pictures, such as orientation (rotation), scaling, and trans- lation. Transformations also control projection type and clipping. Input Functions handle the interaction with the user via the keyboard and the mouse. 1.2. Getting Started With SunCore This section provides a very simple example of a SunCore application program. The program draws a martini glass on the screen. This program demonstrates the use of. » Creating a temporary segment (see Segmentation and Naming), ® Moving to an absolute position (see Output Primitives), « Using the polyline drawing routines (see Output Primitives), <3 Using the absolute line drawing routines (see Output Primitives), The annotated code of glass.c is shown below, followed by the cc compiler call used to create the executable program. The first thing in the program is an include statement to get the definitions of constants: #include Then there are the definitions of the relative points for the polyline function to draw the glass: static float glassdx [] — {— 10 . 0, 9 .0, 0 . 0, — 14 . 0, 30 . 0, — 14 .0, 0 .0, 9 .0, — 10 .0}, static float glassdy[] = { 0 . 0 , 1 . 0 , 19 . 0 , 15 . 0 , 0 . 0 , — 15 .0, — 19 .0, — 1 .0,0.0}; int bwldd () ; /* Device driver name for Sun-1 Monochrome */ /* display — see appendix B for details */ struct vwsurf vwsurf = DEFAULT_VWSURF (bwldd) ; 1-4 Revision F of 15 May 1985 SunCore Reference Manual Introduction Then comes the main program with some initialization code: main () < /* First initialize the SunCore Package */ if (initialize_core (BASIC, NOINPUT, TWOD) ) exit (1) ; /* Elements of vwsurf may be set up here * / /* See Appendix B for details */ /* Then initialize the monochrome display */ if (initialize_view_sur face (&vwsur f , FALSE)) exit (2) ; /* Then we must select that view surface */ if (select_view_sur face (&vwsur f) ) exit (3) ; /* Then define the limits of the viewport */ set_viewport_2 (0 . 125 , 0.875, 0.125, 0.75); /* Then set a convenient window */ set_window (— 50 . O, 50.0, —10.0, 80.0); /* Create a temporary segment */ create_temporary_segment () ; Here is the actual code that draws the picture: move_abs_2 (0.0, 0.0); polyline_rel_2 (glassdx, move_rel_2 (— 12 . O, 33.0) line_rel_2 (24 .0, 0.0); /* Now move to our origin point * / /* And draw the outline of the glass */ glassdy, 9) ; /* Then move to draw the liquid surface /* Draw the liquid surface */ V Finally , we close things and exit the program: /* Now close the segment */ close_temporary_segment () ; /* Wait for 10 seconds .... */ sleep (10) ; /* Before closing the view surface .. deselect_view_sur face (Svwsur f) ; /* and closing down SunCore */ terminate_core () ; V Now we compile this program using the C compiler: tutor ial% cc glass. c -lcere -lsunwindow -lpixrect -lm Revision F of 15 May 1985 1-5 Introduction SunCore Reference Manual In the above example, the options: —Score selects the SunCore run-time library from / mr/lib/libcore.a , — Isumwindow selects the window system library, — Ipixrect selects the pixrect library, — Sm selects the correct math library. When the compilation is complete, the final program is in the file a. out and may be run by typ- ing its name. This is, a very simple example, using the bare minimum of SunCore’s capabilities. There are many improvements that could be made, such as adding an olive on a cocktail stick and so on. The Programming Examples section of this manual will cover other areas of the graphics pack- age. 1.3. The SunCore Lint Library SunCore provides a lint library which provides type checking beyond the capabilities of the C compiler. For example, you could use the SunCore lint library to check the martini-glass draw- ing program with command like this: tutor ial% lint glass. c — lsuncore but note that the error messages that lint generates are mostly warnings, and may not neces- sarily have any effect on the operation of the program. For a detailed explanation of lint, see the lint manual in the Programming Tools manual. 1.4. The Coordinate Systems Applications programs which draw pictures using SunCore communicate in world coordinates. World coordinates are a device-independent, two or three-dimensional, Cartesian coordinate sys- tem for describing objects. Output primitives are given to SunCore routines in World Coordi- nates (WC). However, if the world_co ordinate matrix is used, SunCore concatenates this matrix with the view transform so that output primitives are first transformed by this matrix from ‘model’ or ‘object’ coordinates to world coordinates. This means that the user can supply primitives in ‘model’ coordinates, each model or object being moved into world coordinates according to the current world_coordinate_matriz. In three dimensions, the user may choose to use right-handed or left-handed world coordinates. In a right-handed system, if (for example) the x coordinate increases to the right and the y coor- dinate increases upwards, then the z coordinate increases towards the viewer. In the correspond- ing left-handed system, the x coordinate increases to the right, the y coordinate increases upwards, and the z coordinate increases away from the viewer. The composite viewing transform is formed from the world_coordinate_matrix and the viewing parameters. SunCore routines transform the output primitives from world (or model) coordi- nates to Normalized Device Coordinates (NDC), which are a left-hand coordinate system bounded such that: 0.0