PDA

View Full Version : CPaintDC dc make Texture disable the texture



qubotong
05-25-2015, 10:15 PM
Hi everyone,

I create a child CWnd on an Dialogue and write the paint function as following:

void COpenGLView::OnPaint()
{
CPaintDC dc(this); // device context for painting
//CPaintDc dc effect the texture!!! but without using it, the GetOpenFileName will not useful

// TODO: Add your message handler code here
// Do not call CWnd::OnPaint() for painting messages


wglMakeCurrent(hdc, hglrc);
//CPaintDC dc(this); // device context for painting

// TODO: Add your message handler code here
glClearColor(1.0, 1.0, 1.0, 1.0); // background for rendering color coding and lighting

glDisable(GL_BLEND);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

glViewport(0, 0, win_width, win_height);

glOrtho(-1.0, 1.0, -1.0, 1.0, 0.0, 40.0);
//DrawColorBox();

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, win_width, win_height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixelsBuffer);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // this multiplies texture with lighting color

glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3d(-1.0, -1.0, 0.0);
glTexCoord2f(0.0, 1.0); glVertex3d(-1.0, 1.0, 0.0);
glTexCoord2f(1.0, 1.0); glVertex3d(1.0, 1.0, 0.0);
glTexCoord2f(1.0, 0.0); glVertex3d(1.0, -1.0, 0.0);
glEnd();

SwapBuffers(hdc);
glFinish();


}

The problem is when using the CPaintDC dc(this); the texture will no more useful, does anybody know the reason. I have to use it because I called a GetOpenFileName in the Dialogue, and without using it, I found this function will behavior wired like some non-empty folder will show as empty. Does anybody know why these happens?