I was having some issues using a rendering worker thread in my application and created a stripped down application to troubleshoot, but stumbled onto a problem that is probably so obvious I am just completely overlooking it. The pertinent code is as follows:

BOOL GameDlg::OnInitDialog()
{
	CDialog::OnInitDialog();


	pDC = GetDC();
	g_hDC = ::GetDC(this->GetSafeHwnd());

	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);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void GameDlg::OnSize(UINT nType, int cx, int cy)
{
	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();
}

void GameDlg::OnPaint() 
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

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

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

	SwapBuffers(g_hDC);
	Invalidate(FALSE);
}

The key problem is that the camera is not where I expect, the glTranslatef() calls in OnPaint() do not do what I expect, or the viewing volume is incorrect. As is, the program displays nothing but a black screen. This is unexpected considering my call to glTranslate() before rendering that should move the line away 5 units, leaving me with a relatively short line but easily visible horizontal line. Even stranger, when I change the glTranslate call to glTranslatef(0.0f, 0.0f, -1.0f) I see a horizontal line centered vertically on the screen that is exactly half the width of the screen (it is as if x = -1 and x = 1 are at the left and right sides of the screen. But, if I change it to glTranslatef(0.0f, 0.0f, -2.0f) or any greater translation along the negative z-axis, the line disappears completely. I don't understand because I think I have set up my viewing volume to show a distance up to 1000 from the view, but it is acting like my viewing volume is only 1 unit deep. What is up with that?

>>glTranslatef(0.0f, 0.0f, -5.0f);
[-5.0,5.0] is the limit of ACS-triad axis, which is mapped to your screen. For Z [0.0f,-3.0f] should be plausible.

I'm sorry, but I don't know what you are trying to say. When you say that Z[0.0f, -3.0f] should be plausible what do you mean exactly?

The coordinates are mapped -5.0 to 5.0. Thus +(-)5.0 are the extremes. Avoid using them but use an intermediate.

Is what you are saying based on the 45 degree FOV? Are you saying that the z-translation of -5.0 would result in viewable y-extends of +(-) 5.0? If so I understand that, but why would a line from -0.5 to +0.5 not be visible? I really don't understand what you are trying to say (perhaps my misunderstanding of transformations). And, what do you mean by "use an intermediate" in reference to the code fragments I provided? I have no idea what you mean by that. Do you mean use values between -5.0 and +5.0 for my glVertex calls? Why would I be limited to that? Shouldn't I still see the parts of the line that are between -5.0 and +5.0 even if I drew a line from -6.0 to +6.0?

I'm only referring to the Z-axis here. Of course you will see the part of line from 6 to 6 but if your view is say, +5(ahead of screen) or -5(at infinity) you won't be seeing any of it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.