OpenGL OpenGL Extensions

xiaoxiao2021-03-06  70

OpenGL Extensions is one of the highlights of OpenGL. The update of the graphics card has brought more, more dazzling, so that we can use hardware's excellent play to draw a stunned 3D picture. With OpenGL expansion mechanism, any new features provided by any hardware vendor can be used by our OpenGL program. (I have to mention OpenGL's most powerful opponent Direct3D, Direct3D update mechanism is implemented by upgrading the DirectX SDK development package, which brings a lot of trouble to our learning, we have to face the version upgrade All kinds of problems, at this point, OpenGL's advantage is obvious). Before using OpenGL Extensions, you must check if your graphics card support this extension, only to ensure your graphics card support this extension feature, can be used with confidence. Such work can be done by some tools, such as GLVIEW. OpenGL expansion mechanism is not complicated, but there are still some people who have made many useful work, simplifying the steps we use OpenGL extension, so that we use OpenGL extensions as convenient as OpenGL API comes. This is more famous about Glext and Glew, here I mainly introduce GleW.glew's full name "OpenGL Extension Wrangler Library" .Glew mainly helps C / C to complete two cumbersome tasks: 1) Initialization and use expansion; 2) Write a portable procedure. About GLEW more detailed information and Glew, you can check the website: http://glew.sourceforge.net/. With the above preparatory knowledge, we can use some new features in our procedures. The following uses arb_multitext as an example, talk about the specific operation: Preparation: Hardware condition: A graphics card supporting arb_multitext (how to do? Either upgrade The graphics card is driven, either change new graphics card :) Software Condition: glut3.7.6 - http://www.xmission.com/~nate/glut.html Glew1.2.4 - http: //glew.sourceforge.net/ Specific steps: 1. Ensure that GLUT and GLEW have been installed correctly. 2. Contains header files and connect library files: #include #include // Note, Glew.h must be placed in the front connection library file: OpenGL32.lib Glu32.lib Glut32.lib Glew32.lib3.glut and Glew initialization, Glew must be initialized after setting the render context, that is, when you call GLUTCREATEWINDOW (), you can initially Glew, the relevant code is as follows: int _tmain (int Arg, _Tchar * argv []) {glutinit (& argc, argv); glutcreateWindow ("Multitexture"; GlutinitWindowsize (500, 500); glutinitWindowPosition (0,0); glutinitdisplaymode (glut_single | glut_rgba);

GLUTDISPLAYFUNC (Display); glutreshapefunc (myreshape);

Glenum err = glewinit (); if (err! = Glew_ok) {std :: cout << "error:" << GlewGeterrorString (Err); Return 1;} myinit (); glutmainLoop (); return 0;} 4. In the initialization phase of the program, create Texture Objects, enable the rendering phase to switch between different textures: void myinit () {Glshademodel (GL_FLAT); GLGENTEXTURES (1, & floor); glbindtexture (GL_Texture_2D, floor); loadingBMPFF ("Floor .bmp "); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glGenTextures (1, & light); glBindTexture (GL_TEXTURE_2D, light); LoadBMPff ( "lightmap.bmp"); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);.} 5 in the actual rendering phase, the calling function glActiveTextureARB extension () provided by the current operation specifies a texture unit which, before the next call glActiveTextureARB all apply to currently selected function Texture unit. Specific code: void display () {glclear (GL_COLOR_BUFFER_BIT);

GLACTIVETEXTUREARB (GL_TEXTURE0_ARB); GLENABLE (GL_TEXTURE_2D); GLTEXENVF (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); GLBINDTEXTURE (GL_Texture_2D, FLOOR);

GLACTIVETEXTUREARB (GL_TEXTURE1_ARB); GLENABLE (GL_TEXTURE_2D); GLTEXENVF (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); GLBINDTEXTURE (GL_Texture_2D, Light);

Glpushmatrix (); glbegin (gl_quads); GLMULTITEXCOORD2FARB (GL_TEXTURE0_ARB, 0.0F, 0.0F); GlmultiteXcoord2farb (GL_Texture1_arb, 0.0F, 0.0F); GlvertEX2F (-1.0, -1.0);

Glmultitexcoord2farb (GL_Texture0_arb, 0.0F, 1.0F); GLMULTITEXCOORD2FARB (GL_TEXTURE1_ARB, 0.0F, 1.0F); GlvertEX2F (-1.0, 1.0);

glMultiTexCoord2fARB (GL_TEXTURE0_ARB, 1.0f, 1.0f); glMultiTexCoord2fARB (GL_TEXTURE1_ARB, 1.0f, 1.0f); glVertex2f (1.0,1.0); glMultiTexCoord2fARB (GL_TEXTURE0_ARB, 1.0f, 0.0f); glMultiTexCoord2fARB (GL_TEXTURE1_ARB, 1.0f, 0.0f) GlvertEX2F (1.0, -1.0); glend ();

GLPOPMAMATRIX ();

Glflush ();} In this rendering code, two texture units are specified. The two texture units commonly used (actually the result of the texture pattern pixel value) is rendered to a rectangular object. Due to the two texture patterns, one is a normal texture, one is LightMap, rendering effect is like Light Mapping effect, this technology has been widely used in the game, such as the famous quake. Reference: 1.Http: // Glew.SourceForge.Net2.http: //www.gamedev.net/reference/Articles/Article1929.asp3.http://www.opengl.org/resources/tutorials/sig99/advanced99/notes/node61.html --- -------------------------- Committed to multimedia technology, becoming ideological software engineers ------------- ----------- This article is my original creation, if you want to reprint, please contact your own, or indicate. Welcome everyone to make valuable comments on the content of the article, and I hope that everyone will point out the mistakes in the text, so I can correct it in time. My contact: QQ: 7578420email: jerrydong@tom.com ------------------------------------- -------------------------------------------------- -

转载请注明原文地址:https://www.9cbs.com/read-110122.html

New Post(0)