void CDisplayTextureDlg::OnBnClickedOk()
{
GLuint glTexture;
glTexture = LoadTexture();
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, glTexture );
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0);
glVertex2d(0.0,0.0);
glTexCoord2d(1.0,0.0);
glVertex2d(1.0,0.0);
glTexCoord2d(1.0,1.0);
glVertex2d(1.0,1.0);
glTexCoord2d(0.0,1.0);
glVertex2d(0.0,1.0);
glEnd();
SwapBuffers(m_hDeviceContext);
// CDialogEx::OnOK();
}
GLuint CDisplayTextureDlg :: LoadTexture()
{
char* pchBinBuffer = NULL;
BYTE* bData = NULL;
pchBinBuffer = new char[nWIDTH *nHEIGHT * nPIXEL];
bData = new BYTE[nWIDTH *nHEIGHT * nPIXEL ];
TCHAR tchFileName[MAX_PATH];
swprintf_s(tchFileName, _T("D:\\Bin Files\\InputData_1280_690.bin"));
FILE* pFile = NULL;
_wfopen_s(&pFile, tchFileName, _T("rb"));
if(NULL != pFile)
{
fread(bData, nWIDTH *nHEIGHT * nPIXEL , 1, pFile);
// memset( bData, 255, 1280 *690 * 3 );
fclose(pFile);
}
GLuint glTexture ;
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
// gluPerspective(30.0f,(GLfloat)640/(GLfloat)480,0.3f,200.0f);
// glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
// glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &glTexture);
glBindTexture(GL_TEXTURE_2D, glTexture);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // select modulate to mix texture with color for shading
// when texture area is small, bilinear filter the closest mipmap
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST );
// when texture area is large, bilinear filter the original
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
// the texture wraps over at the edges (repeat)
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
// gluBuild2DMipmaps( GL_TEXTURE_2D, 1, nWIDTH, nHEIGHT, GL_RGBA8, GL_UNSIGNED_BYTE, bData );
glTexImage2D(GL_TEXTURE_2D,0, 1 , nWIDTH, nHEIGHT, 0, GL_LUMINANCE , GL_UNSIGNED_BYTE, bData);
delete [] pchBinBuffer;
delete[] bData;
return glTexture;
}
void CDisplayTextureDlg::Initialize(void)
{
PIXELFORMATDESCRIPTOR pfd ;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.cColorBits = 8;
pfd.cDepthBits = 16;
pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER ;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.nVersion = 1;
CClientDC dc(this);
m_hDeviceContext = dc.GetSafeHdc();
int nPixelFormat = ChoosePixelFormat(m_hDeviceContext, &pfd);
SetPixelFormat(m_hDeviceContext,nPixelFormat, &pfd);
m_hRenderContext = wglCreateContext(m_hDeviceContext);
wglMakeCurrent(m_hDeviceContext, m_hRenderContext);
glClearColor(2.0f, 2.0f, 2.0f, 0.0f);
glClearDepth(0.0f);
OnBnClickedOk();
}