#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.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, NULL);
wglDeleteContext(hRC);
PostQuitMessage(0);
return 0;
break;
case WM_SIZE:
height = HIWORD(lParam);
width = LOWORD(wParam);
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;
default:
break;
}
return (DefWindowProc(hwnd, message, wParam, lParam));
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX windowClass;
HWND hwnd;
MSG msg;
bool done;
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = hInstance;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground = NULL;
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = "MyClass";
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
if (!RegisterClassEx(&windowClass))
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;
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
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.0f)
angle = 0.0f;
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;
}
|
🔒 Locked
First OpenGL problem
Advertisement
Original Post
I copied this program straight from the book "OpenGL Game Programming" and I get Linker errors heres the program:
and these are the linker errors:
--------------------Configuration: OpenGLWA1 - Win32 Debug--------------------
Linking...
OpenGLWA1.obj : error LNK2005: _WinMain@16 already defined in bah.obj
bah.obj : error LNK2001: unresolved external symbol _gluPerspective@32
bah.obj : error LNK2001: unresolved external symbol __imp__glLoadIdentity@0
bah.obj : error LNK2001: unresolved external symbol __imp__glMatrixMode@4
bah.obj : error LNK2001: unresolved external symbol __imp__glViewport@16
bah.obj : error LNK2001: unresolved external symbol __imp__wglDeleteContext@4
bah.obj : error LNK2001: unresolved external symbol __imp__wglMakeCurrent@8
bah.obj : error LNK2001: unresolved external symbol __imp__wglCreateContext@4
bah.obj : error LNK2001: unresolved external symbol __imp__glEnd@0
bah.obj : error LNK2001: unresolved external symbol __imp__glVertex3f@12
bah.obj : error LNK2001: unresolved external symbol __imp__glBegin@4
bah.obj : error LNK2001: unresolved external symbol __imp__glColor3f@12
bah.obj : error LNK2001: unresolved external symbol __imp__glRotatef@16
bah.obj : error LNK2001: unresolved external symbol __imp__glTranslatef@12
bah.obj : error LNK2001: unresolved external symbol __imp__glClear@4
Debug/OpenGLWA1.exe : fatal error LNK1120: 14 unresolved externals
Error executing link.exe.
OpenGLWA1.exe - 16 error(s), 0 warning(s)
I almost possitive I am making it a WIN32 Application
But you guys are the OpenGL experts
Thx,
Jeff Desrosiers
Project->Add Files-> GLAUX.LIB, and all the other OpenGL Libs need to be included.. it says it somewhere int the book.
No problem.. I did the same thing. I skimmed the first few chapters because I thought I knew it all... and then in chapter one I didn''t know what it wouldn''t work.
Good luck with the rest.
Good luck with the rest.
I got most of the linker problems down but now I still got these 2:
--------------------Configuration: OpenGLWA1 - Win32 Debug--------------------
Linking...
OpenGLWA1.obj : error LNK2005: _WinMain@16 already defined in bah.obj
Debug/OpenGLWA1.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
OpenGLWA1.exe - 2 error(s), 0 warning(s)
Thx Drizzt
--------------------Configuration: OpenGLWA1 - Win32 Debug--------------------
Linking...
OpenGLWA1.obj : error LNK2005: _WinMain@16 already defined in bah.obj
Debug/OpenGLWA1.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
OpenGLWA1.exe - 2 error(s), 0 warning(s)
Thx Drizzt
Don''t you need to include stdlib?
I don''t think so. I''m not good with debugging.
I don''t think so. I''m not good with debugging.
You have a function called WinMain in both "bah.cpp" and and "OpenGLWA1.cpp" (or *.c). You must either remove or rename one of them.
BTW, there is no need for you to include "glaux.h" or link to "glaux.lib" in your program, since you use no functionality from glaux. In general you should avoid using glaux. If you don''t know what glaux is, then never mind, you don''t need to
Drizzt: Linker errors can almost never be solved by including a header.
BTW, there is no need for you to include "glaux.h" or link to "glaux.lib" in your program, since you use no functionality from glaux. In general you should avoid using glaux. If you don''t know what glaux is, then never mind, you don''t need to
Drizzt: Linker errors can almost never be solved by including a header.
Yeah... I''m not very good with debugging.
Now that I look at it.. I think Dactylos is right about the double declaration. You have to watch out for that.
Good luck, once again.
Now that I look at it.. I think Dactylos is right about the double declaration. You have to watch out for that.
Good luck, once again.
quote:
Original post by phueppl1
You have to create a normal Win32 Console Application, not the Dos Console thingy.... (unless you''re working with glut, which you''re obviously not..)
The code Jeff D posted should reside in a "Win32 Application", *not* a "Win32 Console Application" (and MSVC++ can not compile DOS apps, so there is no way to create a ''Dos Console thingy'' (unless it''s a really old version of MSVC++).
Besides, had the project type been the problem the error would more likely have been something like:
"OpenGLWA1.obj : error LNK2001: unresolved external symbol _main"
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement