Bosses to help me take a look at why draw not to come out ah, don't know when there's problem, bothering me for a day, hope bosses stay to help me look at the problem,
struct BEZIER_PATCH//bezier surface structure
{
Point_3D anchors [4] [4].//control point coordinates
GLuint dlBPatch;//store display list address
GLuint texture;//store map texture
} m_Mybezier;//store to draw bezier curved surface data
class Point_3D
{
Public:
Point_3D ();
Point_3D (double x, double y, double z);
Double (x) const;
Double (y) const;
Double z () const;
Point_3D operator + (const Point_3D & amp; A);
Point_3D operator * (double c);
Private:
Double m_x, m_y m_z;
};
void GLWidget: : initializeGL ()
{
//initializeOpenGLFunctions ();//enabled texture mapping
A=new QPixmap QPixmap * ();
if(! A - & gt; Load (" G:/WorkSpace/Qt/My3D_4/asd. BMP "))
{
QDebug (" picture not load success ");
}
M_Mybezier. Texture=bindTexture (* a);
M_Mybezier. DlBPatch=genBezier ();
GlEnable (GL_TEXTURE_2D);//enable 2 d texture
GlClearColor (0.1 f, f, 0.1 0.4 f, 0.1 f);//background
GlShadeModel (GL_SMOOTH);//to enable smooth shadow
GlClearDepth (1.0);
//set the depth bufferGlEnable (GL_DEPTH_TEST);//enabled depth test
GlEnable (GL_CULL_FACE);//to open out
GlDepthFunc (GL_LEQUAL);//the type of depth test
GlHint (GL_PERSPECTIVE_CORRECTION_HINT GL_NICEST);//tell the system to modify the perspective
}
Point_3D GLWidget: : Bernstein (float u, Point_3D * p)
{
Point_3D a=p (u, 3) [0] * pow.
Point_3D b=p [1] * (3 * pow (u, 2) * (1 - u));
Point_3D c=p [2] * (3 * u * pow (1 - u, 2));
Point_3D d=p [3] * pow (1 - u, 3);
Point_3D r=a + b + c + d;
return r;
}
GLuint GLWidget: : genBezier ()
{
GLuint drawlist=glGenLists (1);//allocate a space of the display list
Point_3D temp [4].
//according to the fine fraction of each curve, the corresponding allocated memory
Point_3D * last=(Point_3D *) malloc (sizeof (Point_3D) * (m_Divs + 1));
If (m_Mybezier dlBPatch!=0)//if the display list, delete the
{
GlDeleteLists (m_Mybezier dlBPatch, 1);
}
\ [0]=m_Mybezier. Anchors [0] [3].//get four control points in the u direction
Temp. [1]=m_Mybezier anchors [1] [3].
Temp. [2]=m_Mybezier anchors [2] [3].
Temp. [3]=m_Mybezier anchors [3] [3].
For (int v=0; V<=m_Divs; V++)//according to the fine fraction, create the split point parameter
{
Float p y=((float) v)/((float) m_Divs);
The last [v]=Bernstein (py, temp);//using Bernstein function is obtained by dividing point coordinates
}
GlNewList (drawlist, GL_COMPILE);//draw a new display list
GlBindTexture (GL_TEXTURE_2D, m_Mybezier. Texture);//bind texture
For (int u=1; U<=m_Divs; U++)
{
Float px=(float) (u)/((float) m_Divs);//calculates the parameters of breakdown point on the v direction
Float pxold=((float) u - 1.0 f)/((float) m_Divs);//on the breakdown point in the direction of a v parameter
\ [0]=Bernstein (px, m_Mybezier anchors [0]).//calculate each segment point v direction bezier surface control points on
Temp [1]=Bernstein (px, m_Mybezier anchors [1]).
\ [2]=Bernstein (px, m_Mybezier anchors [2]).
\ [3]=Bernstein (px, m_Mybezier anchors [3]).
GlBegin (GL_TRIANGLE_STRIP);//draw the triangle strip
For (int v=0; V<=m_Divs; V++)
{
Float p y=((float) v)/((float) m_Divs);//order map in the direction of the u
GlTexCoord2f (pxold, py);//set the texture coordinates and draw a vertex
GlVertex3d (last [v]. (x), the last [v] y (), the last [v]. Z ());
The last [v]=Bernstein (py, temp);//calculate the next vertex
GlTexCoord2f (px, py);//set the texture coordinates and draw new vertex
GlVertex3d (last [v]. (x), the last [v] y (), the last [v]. Z ());
}
GlEnd ();//end of triangle strip map
}
GlEndList ();//display list drawing end
Free (last);//release the allocated memory
Return the drawlist;//return to create the display of the list
}
Void GLWidget: : initBezier ()
{
M_Mybezier. Anchors [0] [0]=Point_3D (0.75, 0.75, 0.50);
M_Mybezier. Anchors [0] [1]=Point_3D (0.25, 0.75, 0.00);
M_Mybezier. Anchors [0] [2]=Point_3D (0.25, 0.75, 0.00);
M_Mybezier. Anchors [0] [3]=Point_3D (0.75, 0.75, 0.50);
M_Mybezier. Anchors [1] [0]=Point_3D (0.75, 0.25, 0.75);
M_Mybezier. Anchors [1] [1]=Point_3D (0.25, 0.25, 0.50);
M_Mybezier. Anchors [1] [2]=Point_3D (0.25, 0.25, 0.50);
M_Mybezier. Anchors [1] [3]=Point_3D (0.75, 0.25, 0.75);
M_Mybezier. Anchors [2] [0]=Point_3D (0.75, 0.25, 0.00);
M_Mybezier. Anchors [2] [1]=Point_3D (0.25, 0.25, 0.50);
M_Mybezier. Anchors [2], [2]=Point_3D (0.25, 0.25, 0.50);
M_Mybezier. Anchors [2] [3]=Point_3D (0.75, 0.25, 0.00);
M_Mybezier. Anchors [3] [0]=Point_3D (0.75, 0.75, 0.50);
M_Mybezier. Anchors [3] [1]=Point_3D (0.25, 0.75, 1.00);
M_Mybezier. Anchors [3], [2]=Point_3D (0.25, 0.75, 1.00);
M_Mybezier. Anchors [3] [3]=Point_3D (0.75, 0.75, 0.50);
M_Mybezier. DlBPatch=0;//the default display list of 0
}
Void GLWidget: : paintGL ()
{
GlClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//clear screen and depth buffer
GlLoadIdentity ();//reset the model view matrix
GlTranslatef (0.0 f, f, 0.2-3.0 f);
GlRotatef (1.0 75.0 f, f, f 0.0, 0.0 f);
GlRotatef (m_Rot, 0.0 f, f, 0.0 1.0 f);//z axis rotate
GlCallList (m_Mybezier dlBPatch);//call the display list, draw bezier surface
GlDisable (GL_TEXTURE_2D);//disable texture map
GlColor3f (0.0 1.0 f, 0.0 f, f);//set the color to red
for (int i=0; I<4. I++)//draw a horizontal line
{
GlBegin (GL_LINE_STRIP);
for (int j=0; J<4. J++)
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull