Monday, March 24, 2008

Was trying my hands at openGL...

I was trying my hands at openGL and came across a very good jumpstart tutorials at http://www.cprogramming.com/tutorial/opengl_first_opengl_program.html.
After going through the basics, couldn't wait to get some action going on. Created a new project in visual C++ 2008 Express Edition. Copy pasted the code in the above link ;-). On compilation was the following errors
1>------ Build started: Project: FirstOpenGL, Configuration: Debug Win32 ------
1>Compiling...
1>Main.cpp
1>e:\installations\visualstudioprojects\firstopengl\firstopengl\main.cpp(31) : fatal error C1083: Cannot open include file: 'gl/glaux.h': No such file or directory
1>Build log was saved at "file://e:\installations\VisualStudioProjects\FirstOpenGL\FirstOpenGL\Debug\BuildLog.htm"
1>FirstOpenGL - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


On googling found out that "glaux.h" has been deprecated. So removed the header file and F7.

1>------ Build started: Project: FirstOpenGL, Configuration: Debug Win32 ------
1>Compiling...
1>Main.cpp
1>e:\installations\visualstudioprojects\firstopengl\firstopengl\main.cpp(565) : error C2440: '=' : cannot convert from 'const char [8]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>e:\installations\visualstudioprojects\firstopengl\firstopengl\main.cpp(589) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [20]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>e:\installations\visualstudioprojects\firstopengl\firstopengl\main.cpp(622) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [8]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://e:\installations\VisualStudioProjects\FirstOpenGL\FirstOpenGL\Debug\BuildLog.htm"
1>FirstOpenGL - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



The above error usually occurs when unicode character set is used. There were different solutions available on different forums. The easiest one I found was to change the Properties->General->Character Set to Use Multi-Byte Character Set.



F7 again......

1>------ Build started: Project: FirstOpenGL, Configuration: Debug Win32 ------
1>Compiling...
1>Main.cpp
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Linking...
1>Main.obj : error LNK2019: unresolved external symbol __imp__glPopMatrix@0 referenced in function "void __cdecl DrawCube(float,float,float)" (?DrawCube@@YAXMMM@Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function "void __cdecl DrawCube(float,float,float)" (?DrawCube@@YAXMMM@Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__glVertex3f@12 referenced in function "void __cdecl DrawCube(float,float,float)" (?DrawCube@@YAXMMM@Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function "void __cdecl DrawCube(float,float,float)" (?DrawCube@@YAXMMM@Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__glPushMatrix@0 referenced in function "void __cdecl DrawCube(float,float,float)" (?DrawCube@@YAXMMM@Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__glScalef@12 referenced in function "void __cdecl DrawArm(float,float,float)" (?DrawArm@@YAXMMM@Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__glTranslatef@12 referenced in function "void __cdecl DrawArm(float,float,float)" (?DrawArm@@YAXMMM@Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__glColor3f@12 referenced in function "void __cdecl DrawArm(float,float,float)" (?DrawArm@@YAXMMM@Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__glRotatef@16 referenced in function "void __cdecl DrawRobot(float,float,float)" (?DrawRobot@@YAXMMM@Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__glFlush@0 referenced in function "void __cdecl Render(void)" (?Render@@YAXXZ)
1>Main.obj : error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function "void __cdecl Render(void)" (?Render@@YAXXZ)
1>Main.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function "void __cdecl Render(void)" (?Render@@YAXXZ)
1>Main.obj : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function "void __cdecl Render(void)" (?Render@@YAXXZ)
1>Main.obj : error LNK2019: unresolved external symbol __imp__glEnable@4 referenced in function "void __cdecl Render(void)" (?Render@@YAXXZ)
1>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)
1>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)
1>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)
1>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)
1>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)
1>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)
1>E:\installations\VisualStudioProjects\FirstOpenGL\Debug\FirstOpenGL.exe : fatal error LNK1120: 20 unresolved externals
1>Build log was saved at "file://e:\installations\VisualStudioProjects\FirstOpenGL\FirstOpenGL\Debug\BuildLog.htm"
1>FirstOpenGL - 21 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



All linking errors probably due to missing openGL libraries.
Added openGL32.lib in Properties->Linker->Input.




F7 again...
1>------ Build started: Project: FirstOpenGL, Configuration: Debug Win32 ------
1>Linking...
1>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)
1>E:\installations\VisualStudioProjects\FirstOpenGL\Debug\FirstOpenGL.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://e:\installations\VisualStudioProjects\FirstOpenGL\FirstOpenGL\Debug\BuildLog.htm"
1>FirstOpenGL - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



One more linking error a different library missing. It seems that "gluPerspective" function definition is found in "glu32.lib". Added that to the properties as above.



F7 again... and whooah successful :-)

1>------ Build started: Project: FirstOpenGL, Configuration: Debug Win32 ------
1>Linking...
1>Embedding manifest...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Build log was saved at "file://e:\installations\VisualStudioProjects\FirstOpenGL\FirstOpenGL\Debug\BuildLog.htm"
1>FirstOpenGL - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========


Ctrl+F5 and there was this dancing robot.



Hmm... I wish I had got the code working before doing some googling for solutions in different forums. ;-) Hehe. Anyways just thought will document at one place :-)

1 comments:

klingo said...

Thanx for help, man. I went through all these steps, too. I wasn't able to find out any solution for the last problem. How did you find out what libraries to add to the linker option ? like glu32.lib ?