I was hoping some kind soul could help me out here if you have a min to look through my code and tell me what I am doing wrong.
Here is the code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
float angle = 0.0f;
HDC g_hDC;
void SetupPixelFormat(HDC hDC)
{
int nPixelFormat;
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0,0,0,0,0,0,
0,
0,
0,
0,0,0,0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0};
nPixelFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC,nPixelFormat,&pfd);
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static HGLRC hRC;
static HDC hDC;
char string[] = "Hello, World";
int width,height;
switch(message)
{
case WM_CREATE:
hDC = GetDC(hwnd);
g_hDC = hDC;
SetupPixelFormat(hDC);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC,hRC);
return 0;
break;
case WM_CLOSE:
wglMakeCurrent(hDC,hRC);
wglDeleteContext(hRC);
PostQuitMessage(0);
return 0;
break;
case WM_SIZE:
height = HIWORD(lParam);
width = LOWORD(lParam);
if (height == 0)
height = 1;
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
return 0;
break;
}
return (DefWindowProc(hwnd,message,wParam,lParam));
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX wc;
HWND hwnd;
MSG msg;
bool done;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "MyClass";
wc.hIconSm = LoadIcon(NULL,IDI_WINLOGO);
if(!RegisterClassEx(&wc))
return 0;
hwnd = CreateWindowEx(NULL,
"MyClass",
"The OpenGL Window Application",
WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
100, 100,
400, 400,
NULL,
NULL,
hInstance,
NULL);
if(!hwnd)
return 0;
done = false;
while(!done)
{
PeekMessage(&msg,hwnd,NULL,NULL,PM_REMOVE);
if(msg.message == WM_QUIT)
{
done = true;
}
else
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
angle = angle + 0.1f;
if (angle > 360)
angle = 0;
glTranslatef(0.0f,0.0f,-5.0f);
glRotatef(angle,0.0f,0.0f,1.0f);
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_TRIANGLES);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(1.0f,0.0f,0.0f);
glVertex3f(1.0f,1.0f,0.0f);
glEnd();
SwapBuffers(g_hDC);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
Here are the errors I am recieving:
------ Build started: Project: Starting OpenGL, Configuration: Debug Win32 ------
Compiling...
main.cpp
Linking...
main.obj : error LNK2019: unresolved external symbol _gluPerspective@32 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
main.obj : error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
main.obj : error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
main.obj : error LNK2019: unresolved external symbol __imp__glViewport@16 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
main.obj : error LNK2019: unresolved external symbol __imp__wglDeleteContext@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
main.obj : error LNK2019: unresolved external symbol __imp__wglMakeCurrent@8 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
main.obj : error LNK2019: unresolved external symbol __imp__wglCreateContext@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
main.obj : error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol __imp__glVertex3f@12 referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol __imp__glColor3f@12 referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol __imp__glRotatef@16 referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol __imp__glTranslatef@12 referenced in function _WinMain@16
main.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function _WinMain@16
G:\C++\Starting OpenGL\Debug\Starting OpenGL.exe : fatal error LNK1120: 14 unresolved externals
Build log was saved at "file://g:\C++\Starting OpenGL\Starting OpenGL\Debug\BuildLog.htm"
Starting OpenGL - 15 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Thanks in advance this is always a very kind forum