Set up OpenGL Programming Environment

Slides:



Advertisements
Similar presentations
KompoZer. This is what KompoZer will look like with a blank document open. As you can see, there are a lot of icons for beginning users. But don't be.
Advertisements

Chapter 2: Graphics Programming
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
What is OpenGL? Low level 2D and 3D Graphics Library Competitor to Direct3D (the rendering part of DirectX) Used in: CAD, virtual reality, scientific.
Fall 2007ACS-1903 BlueJ Ron McFadyen Lab 1: Using BlueJ at UofW The purpose of this lab is to give you some experience with BlueJ. Over the course of the.
by Jim X. Chen: 1.1. Professor Jim X. Chen Department of Computer Science George Mason University Fairfax, VA
Write a Simple Program with OpenGL & GLUT. Books and Web Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible.
ImageJ Tutorial.
2005 by Jim X. Chen: The OpenGL graphics system is an application Programming interface (API) to graphics hardware. WHAT.
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
2005 by Jim X. Chen: Jim X. Chen, Ph.D. Director of Computer Graphics Lab George Mason University.
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
C O M P U T E R G R A P H I C S Jie chen Computer graphic -- OpenGL Howto.
Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.
2001 by Jim X. Chen: Professor Jim X. Chen Department of Computer Science George Mason University Fairfax, VA
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
1 k Jarek Rossignac,  2008 Processing  Install Processing  Learn how to edit, run, save, export, post programs  Understand.
OpenGl Graphics Programming. Introduction OpenGL is a low-level graphics library specification. It makes available to the programmer a small set of geomteric.
Lecture 1: Introduction. Pick Your Version of GLUT OpenGL and the GLUT are available for Windows, Linux and many other Operating Systems and platforms.
Install and Setup VC++ and OpenGL Introduction to Computer Graphics and Animation (Principle of Computer Graphics) Rattapoom Waranusast.
Programming with OpenGL Part 1: Background
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
CD2012 Principles of Interactive Graphics Lecture 01 Introduction Abir Hussain (Rome: 6.33,Tel , Web:
Unit 1: Java and Eclipse The Eclipse Development Environment.
1 Chapter 12 GUI C/C++ Language Programming Wanxiang Che.
Introduction to Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
Intro to OpenGL (Version 2) Geb Thomas. Setting Up GLUT You will need GLUT for opening windows We can use the version made by Nate Robins: –
NoufNaief.net TA: Nouf Al-harbi.
Computer Graphics Lab 1 OpenGL.
1 How to Install OpenGL u Software running under Microsoft Windows makes extensive use of "dynamic link libraries." A dynamic link library (DLL) is a set.
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 6 1 Microsoft Office Access 2003 Tutorial 6 – Creating Custom Forms.
Computer Graphics and Multimedia Dr. Rajesh Siddavatam Ph.D (BITS–Pilani) Dean – Quality Assurance Professor Mail:
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics -practical- Lecture 6. (visual c++) open gl library To use open GL with VC++ we add these files:- 1)Glut.h C:\program files\ Microsoft.
Development Environment Setup
Programming with OpenGL Part 1: Background
CS380 Lab Spring Myungbae Son.
OpenCV Tutorial Part I Using OpenCV with Microsoft Visual Studio .net November 2005 Gavin S Page
Introduction to Computer CC111
Eclipse Navigation & Usage.
Computer Graphics George Mason University Jim X. Chen, Ph.D.
Programming with OpenGL Part 2: Complete Programs
Set up OpenGL Programming Environment
OpenGL and Related Libraries
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Microsoft Office Access 2003
גרפיקה ממוחשבת: מבוא ל-OpenGL
Microsoft Office Access 2003
Chapter 2 – Introduction to the Visual Studio .NET IDE
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 1: Background
Introduction to Computer Graphics with WebGL
Introduction to OpenGL
Download and Installation of code::blocks
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 1: Background
CS297 Graphics with Java and OpenGL
Wells Fargo Toolkit – CreativeBuilder Reference Guide
Programming with OpenGL Part 2: Complete Programs
The Role of Command Line Compiler (csc.exe)
Presentation transcript:

Set up OpenGL Programming Environment Professor Jim X. Chen Department of Computer Science George Mason University Fairfax, VA 22030 Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu .1.

Setting Up Working Environment for JOGL http://www.cs.gmu.edu/%7Ejchen/graphics/setup. html Installing Java Development Kit http://java.sun.com Installing JOGL https://jogl.dev.java.net/ Installing a Java IDE (Eclipse, jGRASP, or JBuilder) Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Building an Executable JAR File Set up a working directory Move all the necessary java class files into this directory, including all inheritance class files. For example, if you are to run program J1_1_Point, you should have your directory: 2008-01-07 08:31 <DIR> . 2008-01-07 08:31 <DIR> .. 2008-01-07 09:19 1,766 J1_1_Point.class 2008-01-06 18:10 2,190 J1_0_Point.class 2008-01-07 09:19 736 J1_1_Point$1.class 3 File(s) 4,692 bytes Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Building an Executable JAR File Create a text file “manifest-info.txt” in the same directory that contains the following information with a carriage return at the last line: Class-Path: gluegen-rt.jar jogl.jar Main-Class: J1_1_Point The Class-Path entry should include any jar files needed to run this program (jogl.jar and gluegen-rt.jar). When you run your program, you must make sure that these jar files are in the same directory. The Main-Class entry tells Java system which file contains your main method. Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Building an Executable JAR File Execute the following in the same directory from the command line: > "C:\myJDK\bin\jar" -cfm myexe.jar manifest-info.txt *.class This will create your jar file with the specified manifest information and all of the *.class files in this directory. Run your executable jar file: To run the file (myexe.jar), you need to put the library jar files (jogl.jar and gluegen-rt.jar) in the same directory. You may want to put all the dll files in the same directory as well if they are not installed in the system. Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Building an Executable JAR File Your directory will contain the following files as in our example: 2008-01-07 08:31 <DIR> .. 2008-01-07 09:19 1,766 J1_1_Point.class 2008-01-06 18:10 2,190 J1_0_Point.class 2008-01-07 09:19 736 J1_1_Point$1.class 2008-01-07 09:46 61 manifest-info.txt 2008-01-07 09:46 3,419 myexe.jar 2007-04-22 02:00 1,065,888 jogl.jar 2007-04-22 02:00 17,829 gluegen-rt.jar 2007-04-22 02:00 20,480 gluegen-rt.dll 2007-04-22 02:00 315,392 jogl.dll 2007-04-22 02:00 20,480 jogl_awt.dll 10 File(s) 1,448,241 bytes Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Building an Executable JAR File Now you can either double-click on the jar file in Windows interface environment or execute it on a command line with: > "C:\myJDK\bin\java" -jar myexe.jar To get additional help or learn more on this topic you may visit the following place: http://java.sun.com/docs/books/tutorial/deployment/jar/index.html You may want to include your source code in the myexe.jar as well. Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

How to setup OpenGL working environment On Windows 95, 98, NT system, or 2000 Download GLUT GUI library: http://www.xmission.com/~nate/glut.html Or http://cs.gmu.edu/~jchen/cs451/notes/glutdlls.zip to download precompiled glutdlls.zip for Windows 98-XP. 8 Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

1. OpenGL/Glut Configuration Tutorial On Visual C++ 6.0 I assume you have Microsoft Visual C++ installed to the default directory, c:\msdev (For your system, you may start ‘find’ tool to find a VC++ file like gl.h, and then determine the default directory for your system.) A. Install OpenGL and Glut Create a temporary directory and extract the glutdlls.zip there. Copy all *.h files to c:\msdev\include\gl; all *.lib files to c:\msdev\lib; and all *.dll files to c:\windows\system32. You are now ready to enter the fun and exciting world of OpenGL and Glut programming! 9 Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu B. Set OpenGL or Glut in Visual C++: First, make sure that you've included all the necessary *.h files in your program. You need <GL/glut.h> for Glut; or <GL/gl.h> and <afxwin.h>, and possibly <GL/glu.h> and/or <GL/glaux.h> for OpenGL. You need to let Visual C++ know that you want it to consult all the necessary libraries. To do this, you first need to choose Settings under the Project or Build menu item. The Settings button will appear after you compile your program once. 1010 Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu A Project Settings dialog box will now pop up. You now need to select the Link tab. Unfortunately, the Link tab may be hidden. Click the half-a-tab circled below... 1111 Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu ...and the Link page will magically appear: 1212 Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu The Object/library modules section of this page which you should be interested in is circled in red above. Scroll to the end of this line and add the necessary *.lib files to the list. There are four libraries that you might need to add: opengl32.lib, glu32.lib, glaux.lib, and glut32.lib. Since it doesn't hurt much to have extra libs listed, I suggest you add all of them. 1313 Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu C. Compile and run the following program Source code examples can be downloaded from ftp://ftp.sgi.com/opengl/opengl12.zip Or http://cs.gmu.edu/~jchen/cs451/notes/opengl12.zip /* Example 1.1.point.c: draw multiple randomly generated points */ // by Jim X. Chen; September 2000 Points.c Points 1414 Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

OpenGL/GLUT with Visual Studio .net Extract the glutdlls.zip Copy all *.h files to C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\gl\; (if gl directory is not exist, create one); all *.lib files to C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib; and all *.dll files to c:\windows\system32. 2. Start Visual Studio Under the file menu select New Project In the “New Project Window”, select “Visual C++ Projects” on the left hand side and select “Win32 console project” on the right hand side Specify name and location of the project In the “Win32 Application Wizard Window ”, select the “Application Settings”; then click “Empty Project” Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu Now the project is open; right click on the “Source Files” folder (on the right); select “Add” “Add New Item” “C++ file” Name the file, and copy whatever code to this file, and run. 2. To build and run your project, hit “F5” Point Visual Studio to the relevant GLUT files (Optional, if you put your glut under C:/my/glut/) Right click on your project name (on the right hand side) or pull down the Project menu Select “Properties” “C/C++” properties Select “General”and add the following line to “Additional Include Directories” “C:/my/glut/include” Select the “Linker” properties “General” and add the following line to “Additional Library Directories” “C:/my/glut/” Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

2. OpenGL/Glut Tutorial On Borland C++ Please visit web site for detail: http://home.clara.net/paulyg/ogl.htm http://www.gnt.net/~heiman/opengl.htm http://www.opengl.org/Coding/Coding.html 17 Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

How to setup OpenGL working environment On SGI Workstations (ST Rm228 and Graphics Lab.) The system administrator should have OpenGL library installed. Check this with your system administrator Download GLUT GUI library for SGI: Go to web site: http://reality.sgi.com/opengl/glut3/glut3.html Get GLUT documents from the same place Following the instructions to compile and configure GLUT on your system GLUT Online help: http://reality.sgi.com/opengl/spec3/spec3.html Sample code: ftp://ftp.sgi.com/opengl/opengl12.tar.Z 18 Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

How to setup OpenGL working environment On SUN Workstations (ST2 SITE Lab.) First we'll create directories for AUX and then copy AUX files from system directories. (Here we use aux GUI library) mkdir $HOME/OpenGL mkdir $HOME/OpenGL/aux mkdir $HOME/OpenGL/aux/examples mkdir $HOME/OpenGL/aux/libaux mkdir $HOME/OpenGL/aux/libtk cd /usr/openwin/share/src/GL/contrib/utils/aux cp ./aux/examples $HOME/OpenGL/aux/examples cp ./aux/libaux $HOME/OpenGL/aux/libaux cp ./aux/libtk $HOME/OpenGL/aux/libtk OR just run the following command: cp -r ~xwang1/OpenGL $HOME/OpenGL 19 Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu After that, you have your environment ready. Now you can compile and run some example program. First change to the examples directory under your account by: cd $HOME/OpenGL/aux/examples then compile an example program (movelight.c) by make movelight finnally, run ‘movelight’, and you will see the result. Reference web site: http://sun.com/software/graphics/OpenGL/ 20 Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Microsoft .NET development environment and C# C# (pronounced "C sharp") for the new Microsoft .NET development environment provides tools and services that fully exploit both computing and communications. C# is generally regarded as being a successor to C++ that incorporates and improves upon the major innovations made in the Java programming language. Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu C# OpenGL Wrapper There is not yet a version of .NET which supports OpenGL. But you may find several C# OpenGL wrappers that are freely available. Google search with the key words “C# OpenGL wrapper”. The simplest C# OpenGL wrapper will be “Colin Fahey's C# OpenGL Wrapper”. Detailed information about this wrapper may be found at http://www.colinfahey.com/opengl/csharp.htm. Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu C# OpenGL Wrapper Another open source wrapper CsGL at http://csgl.sourceforge.net/. It is recommended to use Colin Fahey's C# OpenGL Wrapper because it’s simpler and rather easier to install. If you will be using Microsoft .NET to do your project, please make sure to include the information about the type of wrapper you are using and the steps of running your project when submitting it. Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Other References on Setting up your Graphics programming environment http://www.cs.uml.edu/~hmasterm/Environments/environment.html Set up DirectX programming environment (Visual C++) 24 Copyright@2008 by Jim X. Chen: jchen (a) cs.gmu.edu

Computer Graphics Director of Computer Graphics Lab Jim X. Chen, Ph.D. Director of Computer Graphics Lab George Mason University

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu Reference Jim. X Chen and Edward J. Wegman, Foundations of 3D Graphics Programming, Springer Verlag, Second Edition, required text book. Jim. X Chen, Guide to 3D Graphics Tools, Second Edition, Springer Verlag, companion in C with a survey of graphics tools. Mason Woo, Jackie Neider, and Tom Davis, OpenGL Programming Guide, Addison Wesley. Programming examples James D. Foley, Andries van Dam, Steven K. Feiner and John F. Hughes, Computer Graphics: Principles and Practice, Addison Wesley. Detailed theory in depth. Donald Hearn and M. Pauline Baker, Computer Graphics, Printice-Hall. Easy to read textbook for undergraduates. Contains more than enough. 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu Objects and Models Objectives Introduce basic graphics concepts object, model, image, graphics library, frame buffer, scan-conversion, clipping, and anti-aliasing Set up OpenGL programming environment Understand simple OpenGL programs 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu Computer Graphics CG displays or animates real or imaginary objects from their computer-based models; Modeling creating and modifying a model image processing treats the inverse process: the analysis of images, pattern recognition, or the reconstruction of 2D or 3D objects from images. 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu Display A graphics display is a drawing area comprised of an array of fine points called pixels (picture elements). At the heart of a graphics system there is a magic pen, move at lightning speed to a specific pixel draw the pixel with a specific color — a red, green, and blue (RGB) vector value. Computer graphics is about using this pen automatically through programming. 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu Object, Model, and Image A real or imaginary object is represented in a computer as a model, and is displayed as an image. A model is an abstract description of the object’s shape (vertices) and attributes (colors), which can be used to find all the points on the object corresponding to the pixels in the drawing area. Given a model, the application program will control the pen through a graphics library to generate the corresponding image. An image is simply a 2D array of pixels. 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu Primitive and Graphics Library A graphics library provides a set of graphics commands or functions. bound in C, Java, or other programming languages on different platforms. specify primitive 2D and 3D geometric models to be digitized and displayed. Primitive models or simply primitives stand for some simple shapes (such as points, lines, and polygons) OpenGL is a graphics library; DirectX includes a graphics library Direct3D 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu OpenGL Programming OpenGL is the most widely used graphics library (GL) or application programming interface (API ) Compile and run Example J1_0_Point.java Corresponding example in C: 1.1.point.c links to all the example programs, and setting up working environments on different platforms: http://www.cs.gmu.edu/~jchen/graphics/ 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu /* draw a point */ /* Java’s supplied classes are “imported”. Here the awt (Abstract Windowing Toolkit) is imported to provide “Frame” class, which includes windowing functions */ import java.awt.*; // JOGL: OpenGL functions import net.java.games.jogl.*; 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu /* Java class definition: “extends” means “inherits”. So J1_0_Point is a subclass of Frame, and it inherits Frame’s variables and methods. “implements” means GLEventListener is an interface, which only defines methods (init(), reshape(), display(), and displaychanged()) without implementation. These methods are actually callback functions handling events. J1_0_Point will implement GLEventListener’s methods and use them for different events. */ public class J1_0_Point extends Frame implements GLEventListener { static int HEIGHT = 400, WIDTH = 400; static GL gl; //interface to OpenGL static GLCanvas canvas; // drawable in a frame …; // methods } 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu public class J1_0_Point extends Frame implements GLEventListener { … public J1_0_Point() { // constructor //1. specify a drawable: canvas GLCapabilities capabilities = new GLCapabilities(); canvas = GLDrawableFactory.getFactory().createGLCanvas(capabilities); //2. listen to the events related to canvas: reshape canvas.addGLEventListener(this); } 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu public J1_0_Point() { // constructor … //3. add the canvas to fill the Frame container add(canvas, BorderLayout.CENTER); /* In Java, a method belongs to a class object. Here the method “add” belongs to J1_0_Point’s instantiation, which is frame in “main” function. It is equivalent to use “this.add(canvas, ...)” */ //4. interface to OpenGL functions gl = canvas.getGL(); } public static void main(String[] args) { J1_0_Point frame = new J1_0_Point(); 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu public class J1_0_Point extends Frame implements GLEventListener { … public static void main(String[] args) { J1_0_Point frame = new J1_0_Point(); //5. set the size of the frame and make it visible frame.setSize(WIDTH, HEIGHT); frame.setVisible(true); } // Called once for OpenGL initialization public void init(GLDrawable drawable) { //6. specify a drawing color: red gl.glColor3f(1.0f, 0.0f, 0.0f); 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu public class J1_0_Point extends Frame implements GLE ventListener { … // Called for handling reshaped drawing area public void reshape(GLDrawable drawable, int x, int y, int width, int height) { //7. specify the drawing area (frame) coordinates gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0, width, 0, height, -1.0, 1.0); } 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu public class J1_0_Point extends Frame implements GLEventListener { … // Called for OpenGL rendering every reshape public void display(GLDrawable drawable) { //8. specify to draw a point gl.glBegin(GL.GL_POINTS); gl.glVertex2i(WIDTH/2, HEIGHT/2); gl.glEnd(); } // called if display mode or device are changed public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) { 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu /* Example 1.1.point.c: draw randomly generated points */ #include <stdlib.h> #include <GL/glut.h> #define Height 400 #define Width 400 Points 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu void display(void) { int x, y; //a. generate a random point x = rand() % Width; y = rand() % Height; //b. specify a drawing color: red glColor3f(1, 0, 0); //c. specify to draw a point glBegin(GL_POINTS); glVertex2i (x,y); glEnd(); //d. start drawing glFlush(); } 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu static void reshape(int w, int h) { //e. specify the window’s coordinates glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho(0, Width, 0, Height, -1.0, 1.0); } int main(int argc, char **argv) { //f. initialize a drawing area glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE); glutInitWindowSize(Width, Height); glutCreateWindow("Example 1.1.point.c"); //g. specify event callback functions glutReshapeFunc(reshape); glutDisplayFunc(display); glutIdleFunc(display); glutMainLoop(); 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu

HW0: due before next class Set up your programming environment, and run the first sample program that draws a point (or randomly generated points). If you failed, schedule a time to come to my office during my office hours or bring your computer to the next class. 9/17/2018 Copyright @ 2008 by Jim X. Chen: jchen@cs.gmu.edu