5 Opengl Programming in Java: JOGL
Total Page:16
File Type:pdf, Size:1020Kb
Guide to Graphics Software Tools Jim X. Chen With contributions by Chunyang Chen, Nanyang Yu, Yanlin Luo, Yanling Liu and Zhigeng Pan Guide to Graphics Software Tools Second edition Jim X. Chen Computer Graphics Laboratory George Mason University Mailstop 4A5 Fairfax, VA 22030 USA [email protected] ISBN: 978-1-84800-900-4 e-ISBN: 978-1-84800-901-1 DOI 10.1007/978-1-84800-901-1 British Library Cataloguing in Publication Data A catalogue record for this book is available from the British Library Library of Congress Control Number: 2008937209 © Springer-Verlag London Limited 2002, 2008 Apart from any fair dealing for the purposes of research or private study, or criticism or review, as permitted under the Copyright, Designs and Patents Act 1988, this publication may only be reproduced, stored or transmitted, in any form or by any means, with the prior permission in writing of the publishers, or in the case of reprographic reproduction in accordance with the terms of licences issued by the Copyright Licensing Agency. Enquiries concerning reproduction outside those terms should be sent to the publishers. The use of registered names, trademarks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant laws and regulations and therefore free for general use. The publisher makes no representation, express or implied, with regard to the accuracy of the information contained in this book and cannot accept any legal responsibility or liability for any errors or omissions that may be made. Printed on acid-free paper Springer Science+Business Media springer.com Preface Many scientists in different disciplines realize the power of graphics, but are also bewildered by the complex implementations of a graphics system and numerous graphics tools. More often than not, they choose the wrong software tools and end up with unsatisfactory results. Hopefully, if we know how a graphics system works and what basic functions many graphics tools provide, we can understand and employ some graphics tools without spending much precious time on learning all the details that may not be applicable, and we can become graphics experts through such a shortcut. Overview This book aims to be a shortcut to graphics theory, programming, tools, and applications. It covers all graphics basics and several advanced topics without including some unnecessary implementation details in graphics applications. It categorizes current graphics tools according to their applications and provides many weblinks to important resources on the Internet. The purpose is to provide an exhaustive list of graphics tools with their major applications and functions. The reference list may contain some inaccuracies, since new tools are constantly emerging vi Preface and old tools become obsolete. By explaining and categorizing these graphics tools and their primary applications, we hope to provide learners and researchers with different means and application areas in computer graphics, and help them understand and use visualization, modeling, animation, simulation, virtual reality, and many online resources. Organization and Features First, the book concisely introduces graphics theory and programming. It serves as a basis for better understanding the components in the later chapters of the book which categorizes popular 3D graphics tools and explains their applications and functions. We have compiled a list of 293 different 3D graphics tools. Both graphics theory and programming are covered succinctly. A top-down approach is used to lead the audience into programming and applications up front. The theory provides a high-level understanding of all basic graphics principles without some detailed low-level implementations. The emphasis is on understanding graphics and using OpenGL or Direct3D instead of implementing a graphics system. The contents of the book are integrated with the sample programs, which are specifically designed for learning. Chapter 1 introduces OpenGL and basic graphics concepts including object, model, image, framebuffer, scan-conversion, clipping, and anti-aliasing. Chapter 2 discusses transformation theory, viewing theory, and OpenGL programming in detail. 3D models, hidden-surface removal, and collision detection are also covered. Chapter 3 overviews color in hardware, eye characteristics, gamma correction, interpolation, OpenGL lighting, and surface shading models. The emphasis is on OpenGL lighting. Chapter 4 surveys OpenGL blending, image rendering, and texture mapping, including advanced texture image applications such as bump mapping, and light mapping. Chapter 5 is the first of the chapters which can be used independently. It introduces OpenGL programming in Java: JOGL, and provides a basis for advanced graphics programming on the Java platform. Chapter 6 discusses existing 3D model functions in GLUT and GLU libraries. It also covers theories and programming of basic cubic curves and bi-cubic curved surfaces. Chapter 7 introduces GPUs and their parallel programming with vertex and pixel (fragment) shaders. It features Cg programming vii with JOGL on the Java platform. Chapter 8 introduces scene graph structure and Java3D programming basics. Chapter 9 introduces the OpenGL Shading Language (GLSL), and discusses vertex and pixel programming on the C/C++ platform in OpenGL using GLSL. Some innovative shader-based applications such as depth buffer, post-image processing, and fog are discussed here. Chapter 10 introduces basic Direct3D 10 graphics principles and shader programming with examples. Chapters 7, 9, and 10 more or less cover vertex and pixel programming, but with three different shading languages: Cg in JOGL on the Java platform, GLSL in OpenGL on the C/C++ platform, and HLSL on Microsoft’s Direct3D platform. Chapter 11 wraps up basic computer graphics principles and programming with some advanced concepts and methods for advanced courses. In Part II, 293 different graphics tools are listed in Appendix B with Chapters 12 to 18 introducing the basic concepts and categories of the tools. Low-level graphics libraries, visualization, modeling and rendering, animation and simulation, virtual reality, Web3D tools and networked environments, and finally 3D file format converters are covered in their respective chapters. For each tool listed in Appendix B, we include information on its platforms, prices, vendor or supplier, applications, and Web resources. The list of tools is a reference for scientific researchers as well as advanced computer graphics learners and programmers. The tools are indexed according to their alphabetic order in the Table of Contents and their application categories in Appendix B. Appendix A includes some basic mathematics for the 3D graphics used in this book. The following Web address contains all the updates and additional information, including how to set up the programming environment, sample program sources, and accompanying Microsoft PowerPoint course notes for learners and instructors as well: http://www.cs.gmu.edu/~jchen/graphics/ Audience The book is intended for a very wide range of readers, including scientists in different disciplines, undergraduates in Computer Science, and Ph.D. students and advanced researchers who are interested in learning and using computer graphics. viii Preface Chapters 1 through 4 are suitable for a one-semester graphics course or self-learning. These chapters should be covered in order. Prerequisites for this part are good C programming skills and basic knowledge of linear algebra and trigonometry. Chapters 5 to 11 are independent introductions suitable for additional advanced graphics courses. The end section of the book, especially the list of tools in the Appendix B, is mainly a reference or informational toolkit for computational engineers, computer programmers, and graphics researchers. No prerequisite knowledge is needed for this. Acknowledgments Dr. Chunyang Chen and Nanyang Yu provided support and guidance for the book. Dr. Yanlin Luo edited Appendix B on software tools. Dr. Tianshu Zhou authored Chapter 9 on OpenGL Shading Language (GLSL). Dr. Yanling Liu wrote Chapter 10 about Direct3D programming and High Level Shading Language (HLSL). Dr. Zhigeng Pan provided support. My friend Denise O’Toole helped with editing and proofreading the book. Without her support, this book would not be possible to be finished on schedule and with quality. Some of my former students in CS 451, CS 652, CS 752, and INFT 852 at George Mason University contributed to the graphics software reviews. I acknowledge the anonymous reviewers and the whole production team at Springer Verlag. Their precious comments, editings, and help have significantly improved the quality and value of the book. Jim Xiong Chen With contributions by Chunyang Chen, Nanyang Yu, Yanlin Luo, Yanling Liu, and Zhigeng Pan August 2008 Contents Preface - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - v Chapter 1 Objects and Models 1.1 Graphics Models and Libraries - - - - - - - - - - - - 1 1.2 OpenGL Programming - - - - - - - - - - - - - - - - 2 Understanding Example 1.1 3 1.3 Frame Buffer, Scan-conversion, and Clipping - - - - - 5 Scan-converting Lines 6 Scan-converting Circles and Other Curves 11 Scan-converting Triangles and Polygons 11 Scan-converting Characters 16 Clipping 16 1.4 Attributes and Antialiasing - - - - - - - - - - - - - - 17 Area Sampling 17 Antialiasing a Line with Weighted Area Sampling 18 1.5 Double-buffering for Animation - - - - -