I'm trying to learn OpenGL and am using a couple of books and the NeHe tuts. I'm trying to draw a triangle in the scene, tt displays but only when the z position of the vertex is -1.0f, anything else and nothing is drawn. Can anyone see why that is?
I'm not using glut at the moment as I wanted to learn how to setup an OpenGL window myself :)
InitOpenGL:
GLvoid InitOpenGL(HWND hWnd, int iWidth, int iHeight, int iDepth)
{
hDC = GetDC(hWnd);
PIXELFORMATDESCRIPTOR pfd;
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_TYPE_RGBA;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = iDepth;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
int iFormat;
iFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC, iFormat, &pfd);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
ResizeOpenGL:
GLvoid ResizeOpenGL(GLsizei iWidth, GLsizei iHeight)
{
glViewport(0, 0, iWidth, iHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0f, (GLfloat) iWidth / (GLfloat) iHeight, 0.1f, 100.f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
Drawing Code:
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 0.5f, -1.0f);
glVertex3f(-0.5f,-0.5f, -1.0f);
glVertex3f( 0.5f,-0.5f, -1.0f);
glEnd();
SwapBuffers(hDC);