The Setup :
void init ()
{
glClearColor(1.0,0.0,0.0,1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90,SCREEN_HEIGHT/SCREEN_WIDTH,0.0,1500.0);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING); //we enable lighting, to make the 3D object to 3D
glEnable(GL_LIGHT0);
float col[]={1.0,1.0,1.0,1.0}; //light color is white
glLightfv(GL_LIGHT0,GL_DIFFUSE,col);
}
Drawing The Line :
case WM_LBUTTONDOWN: glBegin( GL_LINES ); glColor3f( 1.0f, 0.0f, 0.0f ); glVertex3f(posX, posY, 0.0f); glVertex3f(posX, posY, posZ ); glEnd(); cout << "Test" << endl; break;
Displaying the graphics:
void display()
{
glLoadIdentity();
float pos[]={-1.0,1.0,-2.0,1.0}; //set the position
glLightfv(GL_LIGHT0,GL_POSITION,pos);
//glRotatef(angle,angle,0.0,2.0);
cout << name << endl;
// glCallList(cube);
for(std::vector<GLuint>::iterator I = cube.begin(); I != cube.end(); ++I) {
glCallList(*I);
}
glGetIntegerv(GL_VIEWPORT, viewport);
glGetDoublev(GL_PROJECTION_MATRIX, projection);
GetCursorPos(&mouse);
ScreenToClient(hwnd, &mouse);
winX = (float)mouse.x;
winY = (float)mouse.y;
winY = (float)viewport[3] - winY;
glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ );
cout << mouse.x << endl;
cout << mouse.y << endl;
SwapBuffers(hDC);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
}
And theres not much to see accept a black background with a red line that shows on the frustum only if I left click many times
Hope that helps