Home > Software engineering >  MFC using OpenGL depth can't display picture after test
MFC using OpenGL depth can't display picture after test

Time:09-22

MFC using OpenGL depth, according to the testing image cannot glEnable (GL_DEPTH_TEST), can display properly after comments, wrote a few cases are the same problem, the HTML code is as follows, hope of bigwigs doubt,
Unsigned Tex;
Unsigned tex2;
Unsigned tex3;


Unsigned Gluint_make (float width, float height, const void * data) {
GlEnable (GL_TEXTURE_2D);
Unsigned texID;//create a texture handle
GlGenTextures (1, & amp; TexID);//create a few texture, what place in
GlBindTexture (GL_TEXTURE_2D texID);//bind texture
GlTexParameteri (GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER, GL_LINEAR);//model the changes of the texture of the scaling algorithm
GlTexParameteri (GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GlTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
Return texID;

}

Unsigned LodeFreeImage (const char * File_Name) {
//get file format
FREE_IMAGE_FORMAT FM=FreeImage_GetFileType (File_Name, 0);
If (FM==FIF_UNKNOWN) {
Return 0;//do not support the format of the
}
//load the picture
FIBITMAP * dib=FreeImage_Load (FM, File_Name, 0);
//get image pixel format
FREE_IMAGE_COLOR_TYPE type=FreeImage_GetColorType (dib);
//make dib format for 32 bit RGBA unified format, destroyed the original dib
Temp=dib FIBITMAP *;
Dib=FreeImage_ConvertTo32Bits (dib);
FreeImage_Unload (temp);
//get photo color data values
BYTE * pixels=(BYTE *) FreeImage_GetBits (dib);
//get photo wide high
Float width=FreeImage_GetWidth (dib);
Float height=FreeImage_GetHeight (dib);
//the image color data from the BGRA to RGBA
for (int i=0; i BYTE temp=pixels [I];
Pixels [I]=pixels [I + 2];
Pixels [I + 2)=temp;
}
Unsigned rec=Gluint_make (width, height, pixels);
FreeImage_Unload (dib);
Return the rec.
}
Void onInitGL () {
Tex=LodeFreeImage (" images/1. JPG ");
Tex2=LodeFreeImage (" Image/2. JPG ");
Tex3=LodeFreeImage (" Image/3. JPG ");
}

//CMFC_TextureView map
Void CMFC_TextureView: : ontouch * pDC (CDC)
{
CMFC_TextureDoc * pDoc=GetDocument ();
ASSERT_VALID (pDoc);
if (! PDoc)
return;


//TODO: here is the machine data add rendering code
GL_Context1 context;
The context. The setup (m_hWnd, * pDC);
The RECT the RECT.
: : GetClientRect (m_hWnd, & amp; The rect);
Double _width=the rect. Right - the rect. Left;
Double _height=the rect. Bottom - the rect. Top;

GlMatrixMode (GL_PROJECTION);
GlLoadIdentity ();
GluPerspective (60, double (_width)/double (_height), 0.1, 1000);

Struct point_ {
Float x, y, z;
Float, u, v.
};
Point_ rectangle []={
{1.0 f, 1.0 f, f 1.0, 0.3 f, 0.3 f},
{1.0 f to 1.0 f, f, 1.0 0.5 f, 0.3 f},
F {1.0, 1.0 f, f, 1.0 0.5 f, 0.8 f},
F {1.0, 1.0 f, f 1.0, 0.3 f, 0.8 f},

F {1.0, 1.0, f to 1.0 f, 0, 0},
F {1.0, 1.0, f to 1.0 f, 1, 0},
F {1.0, 1.0, f to 1.0 f, 1, 1},
F {1.0, 1.0, f to 1.0 f, 0, 1},

F {1.0, 1.0, f to 1.0 f, 0, 0},
F {1.0, 1.0 f, f 1.0, 1, 0},
F {1.0, 1.0 f, f 1.0, 1, 1},
F {1.0, 1.0, f to 1.0 f, 0, 1},

F {1.0, 1.0, f to 1.0 f, 0, 0},
F {1.0, 1.0, f to 1.0 f, 1, 0},
{1.0 f to 1.0 f, 1.0 f, 1, 1},
{1.0 f, 1.0 f, f 1.0, 0, 1},

F {1.0, 1.0, f to 1.0 f, 0, 0},
F {1.0, 1.0, f to 1.0 f, 1, 0},
F {1.0, 1.0 f, f 1.0, 1, 1},
{1.0 f to 1.0 f, f 1.0, 0, 1},

F {1.0, 1.0, f to 1.0 f, 0, 0},
{1.0 f, 1.0 f, f 1.0, 1, 0},
F {1.0, 1.0 f, f 1.0, 1, 1},
F {1.0, 1.0, f to 1.0 f, 0, 1},
};

OnInitGL ();
GlMatrixMode (GL_MODELVIEW);
GlDepthFunc (GL_LEQUAL);
//glEnable (GL_DEPTH_TEST);
GlBindTexture (GL_TEXTURE_2D, Tex);//bind texture
GlEnable (GL_TEXTURE_2D);
GlEnableClientState (GL_TEXTURE_COORD_ARRAY);//enabled texture

GlEnableClientState (GL_VERTEX_ARRAY);
GlVertexPointer (3, GL_FLOAT, sizeof (point_), & amp; A rectangle [0]. X);
GlTexCoordPointer (2, GL_FLOAT, sizeof (point_), & amp; A rectangle [0]. U);


GlLoadIdentity ();
GlTranslatef (3, 3, - 10);
GlDrawArrays (GL_QUADS, 0, 24);

The context. SwapBuffer ();

}
//CMFC_TextureView message handler

Void CMFC_TextureView: : OnPaint ()
{
CPaintDC dc (this);//device context for painting
//TODO: add message handler code here
Ontouch (& amp; Dc);
//no message calls for drawing the CView: : OnPaint ()
}

CodePudding user response:

Problem has been resolved

CodePudding user response:

You are not clear the depth buffer?

CodePudding user response:

In InitGL () or similar initialize OpenGL place, there will be a glEnable (GL_DEPTH_TEST);
Is enabled, the OpenGL will check, when I was in the drawing in front of the current pixel is there any other pixels, if the other pixels in the way it is, that it would not be drawn, that is to say, OpenGL only draw a layer of the front, the
https://blog.csdn.net/sz76211822/article/details/57407130
  • Related