   Problem with lights
  Hi!I''m starting programming games(in OpenGL) and i''ve got a problem with lights. This source code comes from "OpenGL games programming" book. When I run this simple program whole screen is black and it crashes {it isn''t whole code:} {please don''t mention about polish commments}case WM_CREATE:{hDC = GetDC(hwnd);g_HDC = hDC;SetupPixelFormat(hDC);glEnable(GL_POINT_SMOOTH);  glEnable(GL_LINE_SMOOTH);glEnable(GL_POLYGON_SMOOTH);glEnable(GL_BLEND);glClearColor(0.0f, 0.0f, 0.0f, 0.0f);//black colorglShadeModel(GL_SMOOTH);glEnable(GL_DEPTH_TEST);//usuwa ukryte powierzchnieglEnable(GL_CULL_FACE);//ukrywa tylna strone wielokatowglFrontFace(GL_CCW);//tylna = tworzone w kierunku przeciwnym do ruchu wskazowek zegaraglEnable(GL_LIGHTING);//aktywuje oswietlnie//okresla wlasciwosci materialuglMaterialfv(GL_FRONT, GL_AMBIENT, matAmbient);glMaterialfv(GL_FRONT, GL_DIFFUSE, matDiff);//okresla wlasciwosci oswietleniaglLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);//swiatlo otocznieglLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);//swiatlo rozproszoneglLightfv(GL_LIGHT0, GL_POSITION, lightPosition);//polazenie zrodla swiatla//wlacza oswietlentieglEnable(GL_LIGHT0);hRC = wglCreateContext(hDC);wglMakeCurrent(hDC, hRC);return 0;break;}and in main loop:glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();glTranslatef(0.0f, 0.0f, -5.0f);glColor3f(1.0f, 0.0f, 0.0f);glBegin(GL_TRIANGLES);glNormal3f(0.0f, 1.0f, 0.0f);glVertex3f(0.0f, 5.0f, 0.0f);glVertex3f(4.0f, 5.0f, 0.0f);glVertex3f(0.0f, 5.0f, 4.0f);glEnd();SwapBuffers(g_HDC);TranslateMessage(&msg;DispatchMessage(&msg;Please help me! 
  Can you send me whole sources?I will look at it.   ;  You have to set the hRC and make it current before you make any OpenGL commands! ;  Okay,  I’m working out of  “OpenGL Game Programming” book. I’m trying to understand this whole Norm, and normals thing. They give you a couple of example equations, but  most of them dont make any sense. How in the world do normals work? Please help!   [edited by - h_Ryan on September 27, 2003 6:53:04 PM];quote:Original post by H_ryan  Okay,  I’m working out of  “OpenGL Game Programming” book. I’m trying to understand this whole Norm, and normals thing. They give you a couple of example equations, but  most of them dont make any sense. How in the world do normals work? Please help!   Unlike in the real world, where light travels from a source and hits an object and bounces to your eyes, this is not possible to emulate in realtime with today''s hardware. I believe that it can be done via raytracing, but it is not suitable for realtime graphics. (I am not very sure about the explanation above, so pls correct me if i am wrong).  The solution is to use normals. Normals tell the renderer which direction a polygon is facing. So the lighting properties for that polygon can be calculated easily based on the direction it is facing.   Mystique Legacy : Rise of the Forgotten World ;  Normals are just a direction. (0,1,0) will make it go 1 unit in the y direction for every length of the normal. (12.224,-234.1,1.234) will make it moves you move 12.224 in the x direction, -234.1 in the y direction, and 1.234 in the z direction for each length of the normal. You can calculate its length by squaring each of the elements, adding them up, and then taking the square root (basically the distance formula using (0,0,0) as the second point). ;  This should be clarified. Raloth's explaination isn't quite right. A lighting normal (surface, face, vertex, whichever you choose) is a UNIT VECTOR from its point of origin. This means it always a length of 1. So for instance if you have a flat plane resting on the x and z axes, it would have a normal of (0, 1, 0). This allows for the surface to be lit properly. You can use a single normal for each vertex, or for an entire face(quad or triangle.. or even an n-sided polygon provided it's planar)   [edited by - Schmedly on September 27, 2003 12:31:04 AM]