NeHe OpenGL lession 2, neheopengllession

Source: Internet
Author: User

NeHe OpenGL lession 2, neheopengllession

# Include <GLUT/GLUT. h> # include <OpenGL/OpenGL. h> # include <stdio. h> # include <stdlib. h> # include <unistd. h> // Header file for sleeping/* ASCII code for the escape key. */# define ESCAPE 27/* The number of our GLUT window */int window;/* A general OpenGL initialization function. sets all of the initial parameters. * // * We call this right after our OpenGL window is created. */void initGL (int width, int height) {glClearColor (0.0f, 0.0f, 0.0f, 0.0f); // This will clear the background oclor to blackglClearDepth (1.0 ); // Enable clearing of the depth buffer glDepthFunc (GL_LESS); // The type depth test to doglEnable (GL_DEPTH_TEST); // Enables depth testingglShadeModel (GL_SMOOTH ); // Enables smooth color shadingglMatrixMode (GL_PROJECTION); glLoadIdentity (); // Reset the projection matrix // Calculate the aspect ratio of the windowgluPerspective (45.0f, (GLfloat) width/(GLfloat) height, 0.1f, 1001_f); glMatrixMode (GL_MODELVIEW);}/* The function called when our window is resized (which shouldn't happend, because we're re fullscreen) */void resizeGLScene (int width, int height) {if (height = 0) // Prevent A devide by zero if the window is too smallheight = 1; glViewport (0, 0, width, height); // Reset teh current viewport and perspective transformationglMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective (45.0f, (GLfloat) width/(GLfloat) height, 0.1f, 1001_f); glMatrixMode (GL_MODELVIEW);}/* The main drawing function. */void drawGLScene () {glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the screen and the depth. glLoadIdentity (); // Reset the viewglTranslatef (-1.5f, 0.0f,-6.0f); // Move left 1.5 units and into the screen 6.0 // Draw a triangleglBegin (GL_POLYGON ); glVertex3f (0.0f, 1.0f, 0.0f); // TopglVertex3f (1.0f,-1.0f, 0.0f); // Bottom RightglVertex3f (-1.0f,-1.0f, 0.0f ); // Bottom LeftglEnd (); // We're doen with the polygonglTranslatef (3.0f, 0.0f, 0.0f); // Move Right 3 units (Move the following quadrilateral to the Right) // Draw a square (quadrilateral) glBegin (GL_QUADS); // Start drawing a polygon (4 sided) glVertex3f (-1.0f, 1.0f, 0.0f); // top leftglVertex3f (1.0f, 1.0f, 1.0f, 0.0f); // top rightglVertex3f (1.0f,-1.0f, 0.0f); // bottom rightglVertex3f (-1.0f,-1.0f, 0.0f); // Bottom leftglEnd (); // done with the polygon // swap buffers to display, since we're doouble buffered. gluswapbuffers ();}/* the function claled whever a key is pressed. */void keyPressed (unsigned char key, int x, int y) {/* avoid thrashing this procedure * // * If escape is pressed. kill everything. */if (key = ESCAPE) {/* shut down our window */FIG (window);/* exit teh program... normal termination. */exit (0) ;}} int main (int argc, char ** argv) {gluinit (& argc, argv);/* Select type of Display mode: double bufferRGBA colorAlpha components supportedDepth buffer */gluinitdisplaymode (FIG);/* get a 640x480 window */FIG (640,480 ); /* the window starts at the upper left corner of teh screen */FIG (0, 0 ); /* Open a window */window = fig ("Jeff molew.s GL Code Tutorial .. neHe '99 ");/* Register the function to do all our OpenGL drwing. */FIG (& drawGLScene);/* GO fullscreen. this is the soonest we cocould possibly go fullscreen. * // glufullscreen ();/* Even if there are no events, redraw our gl scene. */glutIdleFunc (& drawGLScene);/* Register the function called when our window is resized. */maid (& resizeGLScene);/* Register teh function claled when the keyboard is pressed. */FIG (& keyPressed);/* Initialzie our window */initGL (640,480);/* Start event processing engine */FIG (); return 0 ;}



Mac OS X running command:

$: Clang-o lession lession2.c-Wno-deprecated-framework OpenGL-framework GLUT


$:./Lession






OpenGL, DirectX

Learning is done in parallel. You cannot do it in this way. If you want to learn a game, you can:
C, c ++ syntax level, 1-2 months
Data structure, 1-2 weeks; algorithm design more than 4 years
More than one year of Design Model

---------
After a good c ++ background (at least understand its memory model) and master several common design patterns,
Learning windows programming, or you will never understand the various mfc frameworks !!! There is no reason to say that, because some design of the windows Programming Mechanism knows what it means. If you don't know it, you will always think about it. Isn't that a waste of time?
After learning some details about win32 programming, it is easy to understand the mfc. At this time, <in-depth analysis of mfc> combined with multiple tracking and debugging, we should be able to master the introduction of mfc to a framework. The more time you spend, the faster your software architecture capabilities will naturally increase.

During the learning period of mfc, you can start opengl, and then start with the red book, and then use other example books. Later I read the second version of 3d game engine, and a developer named ogre wrote it as an engine book.

It may take a year. However, if you come in this order, your foundation will be quite reliable and it will be easy to do anything.

If you want to learn dx, you need to win the essence of com.
----------------
A skillful book is useless in the early stage. It will take effect only after you have accumulated some experience. Learning is actually a parallel process. The effect is much better. Like algorithm design, you can spare some time every day.

We recommend some materials for learning OpenGL.

First, let's take a look at the red treasure book of OpenGL, the sixth edition of the basic OpenGL programming guide. There is no better book than this book in the basic part. Then, let's take a look at the source code such as nehe's OpenGL tutorial.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.