BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
{
hInst = hInstance; // Instanzzugriffsnummer in unserer globalen Variable speichern
hWnd = CreateWindow((char*)WinClass, "lp", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if( !hWnd )
{
return FALSE;
}
SetWindowPos(hWnd,NULL,0,0,640,480,0);
// -------------------- set up OpenGL -------------------------
WinDC=GetDC(hWnd);
memset(&Pfd,0,sizeof(Pfd));
Pfd.nSize=sizeof(Pfd); Pfd.nVersion=1; Pfd.dwFlags=PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
Pfd.iPixelType=PFD_TYPE_RGBA; Pfd.cColorBits=16; Pfd.cDepthBits=16; Pfd.iLayerType=PFD_MAIN_PLANE;
PixelFormat = ChoosePixelFormat(WinDC, &Pfd);
SetPixelFormat(WinDC, PixelFormat, &Pfd);
RC = wglCreateContext(WinDC);
wglMakeCurrent(WinDC,RC);
glClearColor(0.f,0.f,0.f,1.f);
glDepthFunc(GL_LEQUAL);
glDepthMask(true);
glViewport(0,0,640,480);
glEnable(GL_DEPTH_TEST);
// --------------------------------------------------------------
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch( message )
{
case WM_PAINT:
{
wglMakeCurrent(WinDC,RC);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
float mfFrTop,mfFrRight,mfFrBottom,mfFrLeft;
#define pi 3.141592653f
//calculate and set the viewcone
mfFrTop = 10/*nearclip*/*(float)tan((60/*v. viewa.*//2.f)*(pi/180.f));
mfFrRight = mfFrTop*(90/*h. viewa.*//60/*v. viewa.*/);
mfFrBottom = -mfFrTop;
mfFrLeft = -mfFrRight;
glFrustum(mfFrLeft,mfFrRight,mfFrBottom,mfFrTop,10/*nearclip*/,1000/*farclip*/);
glEnable(GL_LIGHTING); //enable lighting
glEnable(GL_LIGHT0); //enable light 0
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_FALSE); //local viewer shall not matter
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); //two sided lighting plz
//setup infinite directional light
float lightpos[4] = {0.f,0.f,1.f,0.f};
glLightfv(GL_LIGHT0,GL_POSITION,lightpos);
glColor3f(1,1,1); //shared color for all vertices
glNormal3f(0,0,1); //shared normal for all vertices
glBegin(GL_QUADS);
glVertex3f(-20,-20,-100);
glVertex3f(20,-20,-100);
glVertex3f(20,20,-100);
glVertex3f(-20,20,-100);
glEnd();
SwapBuffers(WinDC);
}
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hWnd, message, wParam, lParam );
}
return 0;
}