PDA

View Full Version : Windws clears my window white! How to stop it? Please help!!!



TB-Rex
08-20-2000, 08:21 AM
After I update my screen windows clear the window with a white color. Why? And how can I stop this ****?

Thanks!

frogger
08-20-2000, 08:39 AM
you have to set the glClearColor

with

glClearColor(0,0,0,0); (black) (rgba)

then when you call glClear
it will clear with black (or whatever color you put in)

TB-Rex
08-20-2000, 09:09 AM
No! It is not an OpenGL problem. The glClear(...); routines are OK in my code but windows clear the display! (I am sure)

DFrey
08-20-2000, 10:26 AM
Are you using MFC?

TB-Rex
08-20-2000, 11:11 AM
yes I use MFC in a widowed single document mode. Why?

DFrey
08-20-2000, 11:53 AM
You need to be sure, that the window was made with the proper style. And you need to be careful how you handle the paint event.
I've never used the document-view MFC model together with OpenGL, I know there is something you have to do to stop that clearing however. Search this board or the beginner's board for MFC and I'm sure you'll find the solution.

update: here is a link to a thread on this subject http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/000658.html

[This message has been edited by DFrey (edited 08-20-2000).]

NewROmancer
08-20-2000, 08:44 PM
Call Invaldiate(false);
When you repaint the client area of the window you first set the background and afterwards you paint your Ogl scene. So you have to repaint all the scene without deleting the bvackground. If you want I send you the code I have for a MFC created window
(this is for other thread here) that doesn't have this effect. Where I call invalidate with false change the parameter with true and look what it happens.


// OglWin.cpp : implementation file
//

#include "stdafx.h"
#include "Terrain.h"
#include "OglWin.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// COglWin

HDC hDC=NULL; // Private GDI Device Context
HGLRC hRC=NULL; // Permanent Rendering Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application

WNDCLASS wc; // Windows Class Structure

COglWin::COglWin()
{

}

COglWin::~COglWin()
{
}


BEGIN_MESSAGE_MAP(COglWin, CWnd)
//{{AFX_MSG_MAP(COglWin)
ON_WM_SHOWWINDOW()
ON_WM_PAINT()
ON_WM_ACTIVATE()
ON_WM_CREATE()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// COglWin message handlers

BOOL COglWin::PreCreateWindow(CREATESTRUCT& cs)
{
cs.lpszClass = AfxRegisterWndClass(CS_OWNDC);
//cs.style=CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
return CWnd::PreCreateWindow(cs);
}

void COglWin::OnShowWindow(BOOL bShow, UINT nStatus)
{
CWnd::OnShowWindow(bShow, nStatus);
}

void COglWin::OnPaint()
{
CPaintDC dc(this); // device context for painting
Invalidate(false);
DrawScene();
}

void COglWin::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CWnd::OnActivate(nState, pWndOther, bMinimized);


}

BOOL COglWin::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class

return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}

int COglWin::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
Init(); // initialize OpenGL
return 0;
}

BOOL COglWin::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
//CRect rect;
//CBrush m_brush;
//m_brush.CreateSolidBrush(0x00FFFFFF);
//GetClientRect(rect);
//pDC->FillRect(&rect,&m_brush);
DrawScene();
return CWnd::OnEraseBkgnd(pDC);
}

void COglWin::Init()
{
PIXELFORMATDESCRIPTOR pfd;
int n;
HGLRC hrc;
GLfloat fMaxObjSize, fAspect;
GLfloat fNearPlane, fFarPlane;

m_pDC = new CClientDC(this);

ASSERT(m_pDC != NULL);

if (!bSetupPixelFormat())
return;

n = ::GetPixelFormat(m_pDC->GetSafeHdc());
: http://www.opengl.org/discussion_boards/ubb/biggrin.gifescribePixelFormat(m_pDC->GetSafeHdc(), n, sizeof(pfd), &pfd);

//CreateRGBPalette();

hrc = wglCreateContext(m_pDC->GetSafeHdc());
wglMakeCurrent(m_pDC->GetSafeHdc(), hrc);

GetClientRect(&m_oldRect);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);

if (m_oldRect.bottom)
fAspect = (GLfloat)m_oldRect.right/m_oldRect.bottom;
else // don't divide by zero, not that we should ever run into that...
fAspect = 1.0f;

fNearPlane = 3.0f;
fFarPlane = 7.0f;
fMaxObjSize = 3.0f;
m_fRadius = fNearPlane + fMaxObjSize / 2.0f;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, fAspect, fNearPlane, fFarPlane);
glMatrixMode(GL_MODELVIEW);

}

BOOL COglWin::bSetupPixelFormat()
{
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
int pixelformat;

if ( (pixelformat = ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd)) == 0 )
{
MessageBox("ChoosePixelFormat failed");
return FALSE;
}

if (SetPixelFormat(m_pDC->GetSafeHdc(), pixelformat, &pfd) == FALSE)
{
MessageBox("SetPixelFormat failed");
return FALSE;
}

return TRUE;
}

void COglWin: http://www.opengl.org/discussion_boards/ubb/biggrin.gifrawScene(void)
{
static BOOL bBusy = FALSE;
static GLfloat wAngleY = 10.0f;
static GLfloat wAngleX = 1.0f;
static GLfloat wAngleZ = 5.0f;

if(bBusy)
return;
bBusy = TRUE;

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();

/*glBegin(GL_LINES);
for(int i=0;i<11;i++)
{
glColor3f(1.0f, 0.0f, 1.0f);
glVertex3f((i-5)*2.0f,-10.0f,0.0f);
glColor3f(1.0f, 0.0f, 1.0f);
glVertex3f((i-5)*2.0f,10.0f,0.0f);
}
for(int j=0;j<11;j++)
{
glVertex3f(-10.0f,(j-5)*2.0f,0.0f);
glVertex3f(10.0f,(j-5)*2.0f,0.0f);
}
glEnd();
*/
glTranslatef(0.0f, 0.0f, -m_fRadius);
glRotatef(wAngleX, 1.0f, 0.0f, 0.0f);
glRotatef(wAngleY, 0.0f, 1.0f, 0.0f);
glRotatef(wAngleZ, 0.0f, 0.0f, 1.0f);

wAngleX += 1.0f;
wAngleY += 10.0f;
wAngleZ += 5.0f;


glBegin(GL_QUAD_STRIP);
glColor3f(1.0f, 0.0f, 1.0f);
glVertex3f(-0.5f, 0.5f, 0.5f);

glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-0.5f, -0.5f, 0.5f);

glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(0.5f, 0.5f, 0.5f);

glColor3f(1.0f, 1.0f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.5f);

glColor3f(0.0f, 1.0f, 1.0f);
glVertex3f(0.5f, 0.5f, -0.5f);

glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(0.5f, -0.5f, -0.5f);

glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(-0.5f, 0.5f, -0.5f);

glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-0.5f, -0.5f, -0.5f);

glColor3f(1.0f, 0.0f, 1.0f);
glVertex3f(-0.5f, 0.5f, 0.5f);

glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-0.5f, -0.5f, 0.5f);

glEnd();

glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 1.0f);
glVertex3f(-0.5f, 0.5f, 0.5f);

glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(0.5f, 0.5f, 0.5f);

glColor3f(0.0f, 1.0f, 1.0f);
glVertex3f(0.5f, 0.5f, -0.5f);

glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glEnd();

glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-0.5f, -0.5f, 0.5f);

glColor3f(1.0f, 1.0f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.5f);

glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(0.5f, -0.5f, -0.5f);

glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glEnd();

glPopMatrix();

glFinish();
SwapBuffers(wglGetCurrentDC());

bBusy = FALSE;
}


NewROmancer

TB-Rex
08-21-2000, 03:12 AM
Thanks! I need no more code I tried it and it is working.