Hello gents, I require some assistance. For some reason, my win32 program refuses to display a triangle. I've tried to find ways to fix it, but my attempts seem to result in failures.
Here is the code to my program.
My window class.
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "EditorLink.h"
const char g_szClassName[] = "Window";
BOOL quit = FALSE;
void EnableOpenGL(HDC hDc,HGLRC hRc);
void DisableOpenGL(HDC hDc,HGLRC hRc);
Editor Edit;
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
quit = TRUE;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,msg,wParam,lParam);
}
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR CmdLine,int nCmdShow)
{
WNDCLASS wc;
HWND hWnd;
HGLRC hRc;
HDC hDc;
MSG msg;
wc.lpszClassName = g_szClassName;
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.hInstance = hInstance;
wc.style = CS_OWNDC;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.lpfnWndProc = WndProc;
wc.lpszMenuName = NULL;
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hIcon = LoadIcon(NULL,NULL);
RegisterClass(&wc);
hWnd = CreateWindow(
g_szClassName,
"OPENGL PRACTICE",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,700,700,
NULL,NULL,hInstance,NULL
);
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
EnableOpenGL(hDc,hRc);
Edit.init();
while(!quit)
{
if(GetMessage(&msg,NULL,0,0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
Edit.display();
SwapBuffers(hDc);
}
}
DisableOpenGL(hDc,hRc);
DestroyWindow(hWnd);
return msg.wParam;
}
void EnableOpenGL(HDC hDc,HGLRC hRc)
{
int nFormat;
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
0,0,0,0,0,0,0,0,0,0,0,0,0,
24,
8,
0,
PFD_MAIN_PLANE,
0,0,0,0
};
nFormat = ChoosePixelFormat(hDc,&pfd);
SetPixelFormat(hDc,nFormat,&pfd);
hRc = wglCreateContext(hDc);
wglMakeCurrent(hDc,hRc);
}
void DisableOpenGL(HDC hDc,HGLRC hRc)
{
wglMakeCurrent(NULL,NULL);
wglDeleteContext(hRc);
}
And my class where I entered the display data.
#include <gl/gl.h>
#include <gl/glu.h>
#include "EditorLink.h"
void Editor::init()
{
glClearColor(0.0,0.0,0.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,640.0/480.0,1.0,500.0);
glMatrixMode(GL_MODELVIEW);
}
void Editor::display()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex3f(0.0,2.0,-5.0);
glVertex3f(-2.0,-2.0,-5.0);
glVertex3f(2.0,-2.0,-5.0);
glEnd();
}
I don't know what is wrong. So some help would be nice.
Thank you and have a nice day.






