How to start learning OpenGLWingser 2004.12.6 wujiai74@citiz.net
What is OpenGL: OpenGL ("Open Graphics Library") is a software interface of graphics hardware. OpenGL includes approximately 250 different functions, and programmers can use these functions to set up objects and operations to be drawn to create three-dimensional applications for interaction.
OpenGL is a standard graphics library in high-end applications such as professional graphics, scientific computing. Its major competitor is Microsoft Direct3D. OpenGL has long been in technology leadership, but Direct3D has also caught up in recent years. Currently, these two graphics APIs can be said in performance. However, OpenGL supports numerous operating systems, and Direct3D is only available on the Windows platform. So OpenGL is still very popular.
How to start learning OpenGL: You can download the official tutorial and examples in the documentation of OpenGL's official website http://www.opengl.org: The OpenGL Programming Guide, this is the famous Red Book ("Red Book")
If your English is not good, then I recommend you to read: "OpenGL Super Collection" is a quite a good Chinese tutorial. You can find it in http://www.vrforum.cn/forumdisplay.php?fid=29 "OpenGL Programming Key Guide" he is a Chinese translation of Red Book, which is an example of Red Book.
* Nate Robin example is very helpful to understand OpenGL. http://www.gamedev.net/reference/Articles/Article839.asp*The OpenGL Reference Manual (Blue Book) is not a textbook that is not suitable for beginners. * Nehe's example is not suitable for beginners, especially if there is no Win32 foundation, it is recommended to learn after a certain basis. http://nehe.gamedev.net
How to install the GLUT library: OpenGL needs to use OpenGL application toolkit: GLUT library, let's talk about how to install it
Visual C users: 1. Download Glut Library: http://www.opengl.org/Resources/libraries/glut/glutdlls37beta.zip2. Put glut32.lib in ... / Microsoft Visual Studio / VC98 / LIB directory in the ... / Microsoft Visual Studio / VC98 / INCLUDE / GL directory. X: / Windows / SystOM32 directory (Win98 users put into the x: / windows / system directory) 3. Create a console project Win32 Console Application, add hello.c and run: #include
Void Display (Void) {Glclear_bit); / * Clear All Pixels * / Glcolor3F (1.0, 1.0, 1.0); Glbegin (GL_POLYGON); / * Draw White Polygon with Corners At (0.25, 0.25, 0.0) and (0.75 , 0.75, 0.0) * / Glvertex3f (0.25, 0.25, 0.0); GlvertEX3F (0.75, 0.75, 0.0); GlvertEX3F (0.25, 0.75, 0.0); glend (); GLFLUSH () ; / * start processing buffered OpenGL routines * /} void init (void) {glClearColor (0.0, 0.0, 0.0, 0.0); / * select clearing color * / glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0); / * Initialize Viewing VALUES * /}
int main (int argc, char ** argv) {glutInit (& argc, argv);. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); / * Declare initial display mode (single buffer and RGBA) * / glutInitWindowSize (250, 250); / * Declare Initial Window Size. * / GlutinitWindowPosition (100); / * Declare Initial Window Position. * / GlutcreateWindow ("Hello"); / * Open window with "Hello" in its title bar. * / Init (); / * Call initialization routines * / glutDisplayFunc (display);. / * Register callback function to display graphics * / glutMainLoop ();.. / * Enter main loop and process events * / return 0; / * ANSI C requires main to return int DEVCPP users: 1. Download GLUT Library: http://www.cs.uofs.edu/~ MPC3/cmps370/glut-mingw-dev-c .zip2. Put the glut32.a and glut32.def in the ... / dev-cp / include / GL directory in the ... / dev-cp / lib directory. X: / Windows / SystOM32 directory (Win98 users put into the x: / windows / system directory) 3. Create a console engineering, modify the connector in the parameter parameter in the project properties Project Options, add the library or object AddLibrary or Object Add: ... / dev-cpp / lib / libglu32.a ... / DEV-CPP / lib / libglut32.a ... / dev-cpp / lib / libopENGL32.A or directly type -Lopengl32 -lglu32 -LGLUT324. Add Hello.c and run: #include
Void Display (Void) {Glclear_bit); / * Clear All Pixels * / Glcolor3F (1.0, 1.0, 1.0); Glbegin (GL_POLYGON); / * Draw White Polygon with Corners At (0.25, 0.25, 0.0) and (0.75 , 0.75, 0.0) * / Glvertex3f (0.25, 0.25, 0.0); GlvertEX3F (0.75, 0.75, 0.0); GlvertEX3F (0.25, 0.75, 0.0); glend (); GLFLUSH () ; / * Start processing buffered OpenGL Routines * /}
Void init (void) {GlclearColor (0.0, 0.0, 0.0, 0.0); / * select clearing color * / glmatrixmode (GL_Projection); GLLOADIDENTITITY (); glortho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0); / * initialize viewing values * /} int main (int argc, char ** argv) {glutInit (& argc, argv);. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); / * Declare initial display mode (single buffer and RGBA) * / glutInitWindowSize ( 250, 250); / * Declare Initial Window Size. * / GlutinitWindowPosition (100, 100); / * Declare Initial Window Position. * / GlutcreateWindow ("Hello"); / * Open window with "Hello" in its title bar. * / init (); / * Call initialization routines * / glutDisplayFunc (display);. / * Register callback function to display graphics * / glutMainLoop ();.. / * Enter main loop and process events * / return 0; / * ANSI C Requires main to return int. * /} For javaer: If you are a Java programmer, I recommend Jogl to you, the Jogl project is currently popular OpenGL Java binding, its official home page is https: // jogl. Dev.java.net The current Jogl supports OpenGL 1.5, and the vast majority of extensions, of course, if you are OpenGL master, you will know that as long as the graphics card drive support, we can call Jogl not available OpenGL extension. number. Ok, assume you have a Java compile environment, your Java SDK version is above 1.42, (you can download NetBeans.org to free NetBeans compiler)
Installation steps: 1. Release Builds 2004's Release Builds 2004 in https://jogl.dev.java.net - November 19 Downloading JOGL. Jar and Jogl-Natives-Win32.jar (not Windows users, download JOGL-NATIVES -myos.jar) 2. Install Jogl.jar to classpath3. Run the following program to get java.library.pathpublic class try {public static void main (string [] args) {system.out.println ("java.library.path");}} 4. Unzip JOGL-NATIVES-WIN32.JAR and put Jogl.dll and Joglcg.dll in any java.library.path directory 5. When you run the following program, it can run the installation of public class zaishishi {public static void main (string [] args) {system.loadLibrary ("jogl");}} 6.
Run our example hello.javaimport net.java.games.jogl. *; Import java.awt. *; Import java.awt.event. *; Public class hello {public static void main (string [] args) {Try { Frame Frame = new Frame ( "hello"); / * Open window with "hello" in its title bar * / Frame.setSize (250,250);. / * Declare initial window size * / GLCapabilities glCaps = new GLCapabilities ().; GLCanvas canvas = GLDrawableFactory.getFactory () createGLCanvas (glCaps);. canvas.addGLEventListener (new Renderer ()); frame.add (canvas); final Animator animator = new Animator (canvas); Frame.addWindowListener (new WindowAdapter () { Public void windowClosing (windowevent e) {animator.stop (); system.exit (0);}}}); frame.show (); Animator.Start ();} catch (exception e) {E.PrintStackTrace ();}}} Class Renderer implements GLEventListener {private GL gl; private GLDrawable glDrawable; public void init (GLDrawable drawable) {this.gl = drawable.getGL (); this.glDrawable = drawable; drawable.setGL (new DebugGL (drawable.getGL ()); Gl.glclearColor (0.0F, 0.0F, 0.0F, 0.0F); / * select clearing color * / gl.glmatrixmode (gl.gl_projection); gl.glloadident (); gl.glorTho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0); / * Initialize Viewing Values * /} Public Void Display (GL.GLCLEAR (GL.GL_COLOR_Buffer_bit); / * CLEAR All Pixels * / gl.glloadIndIndity ();