Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Weird Problem with Translatef...or something else..

jadrianjadrian Posts: 5Member
I have this really strange and frustrating problem. I am writing a game with MFC and openGL and tried using multi-threading to control the timing of the physics engine and the rendering, but the rendering thread always only created a black screen (even though the same code worked in OnPaint(). To try to solve the problem, I made a really stripped down program to try to reproduce the problem, but instead have found a problem that I simply cannot explain. Here is the pertinent code:

In "OnInit"
[code]
pDC = GetDC();
g_hDC = ::GetDC(this->GetSafeHwnd());//pDC->GetSafeHdc();

int nPixelFormat;

PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0};

nPixelFormat = ChoosePixelFormat(g_hDC, &pfd);
SetPixelFormat(g_hDC, nPixelFormat, &pfd);

hRC = wglCreateContext(g_hDC);
wglMakeCurrent(g_hDC, hRC);
[/code]

In "OnSize"

[code]
CRect clientRect;
GetClientRect(clientRect);
glViewport(0, 0, clientRect.Width(), clientRect.Height());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)clientRect.Width() / (GLfloat) clientRect.Height(), 1.0f, 1000.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
[/code]

In "OnPaint"

[code]
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glTranslatef(0.0f, 0.0f, -1.0f);

glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_LINES);
glVertex3f(-5.0f, 0.0f, 0.0f);
glVertex3f(5.0f, 0.0f, 0.0f);
glEnd();

SwapBuffers(g_hDC);
Invalidate(FALSE);
[/code]

This is so simple it is ridiculous. Running as shown above, I see a horizontal white line as expected. But, if I change the glTranslatef call in "OnPaint" to glTranslatef(0.0f, 0.0f, -2.0f) or anything smaller than a -1 shift in the z-direction the line disappears. What gives? This is really stumping me...so any help would be greatly appreciated.
Sign In or Register to comment.