OpenGL Drawing Classes

xiaoxiao2021-03-06  43

Code Name: A Small VRML Viewer Using OpenGL AND MFC. Download address: http://www.vccode.com/file_show.php?id=262.

BY: Pierre Alliez Data Structure Analysis: 1. For the drawing function, define the base class COBJECT3D, implement the GLDRAW interface, and define glbuildlist.2 for the display list. To dynamically determine the class object, COBJECT3D defines the int GetType () interface. (Is it good ? Factory Necessary?)

3. Class inheritance Implement CEDGE3D, CFACE3D, CVector3D, CVERTEX3D, CMESH3D: Public COBJECT3D

4. Texture is relatively special.

Class Ctexture: Public COBJECT

Class cscenegraph3d :: carray3d m_arraytexture, gluint * m_pindextexturebinding;

step

function

Create a texture list name

CSCENEGRAPH3D texture name creation adopts the following steps

GLGENTEXTURES GLBINDTEXTURE Defines the name of the texture in the list

GLTEXIMAGE2D Bind M_Arraytexture [i]

Binding texture

In the cscenegraph3d :: GLDRAW function, first specify the texture name with GLBINDTEXTURE, then call M_ArrayObject3D [i] .GLDRAW ()

Define texture coordinates

The texture coordinates are defined in CMesh3D, using Gltexcoord2f, because there is a member class cmesh3d :: m_ptexturecoordinate, m_ptexturecoordinateIndex. Cmesh3d :: getTextureIndex ();

5 advantages

With triangles represent each face, each face has 3 Neighbor Face pointers, each Face has 6 Vertex3d, where extra easy to Subdivision. Each face has data such as colors, materials, normal, and is easy to draw. But Vertex is a pointer, in other words, Face does not change the coordinates of Vertex

There are two List of Face and Vertex in Cmesh3D, a CTRANSFORM M_TRANSFORM, and the coordinate can be rotated before drawing. M_indexTexture remains the same as the CSceneGraph3D texture.

Trace function facilitates debugging

6 shortcomings

CTexture class actually read and implemented (GL_TEXTURE_2D ,,, CTexture :: GetWidth (), CTexture :: GetHeight () ,, GL_RGB, GL_UNSIGNED_BYTE, glTexImage2D :: GetData ()) using a function interface glTexImage2D, no glDraw () Interface, so it should not be attached to the COBJECT inheritance.

Cscenegraph3d :: GlbuildList seems to have called CMESH3D :: GlbuildList, while cscenegraph3d :: GLDRAW continues to call Cmesh3d :: GLDRAW () àcmesh3d :: glbuildlist, as if you repeat.

It seems that GLBUILDLIST should not be inherited as a virtual function of the base class COBJECT3D, because it seems to have only the list of the list.

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

New Post(0)