Recently I downloaded Code::Blocks 8.02 and yesterday I've decided to learn something about OpenGL. I got a link to a tutorial from my friend so I just went for it.
First thing I decided to do was to compile the example program from that tutorial and run it .Here's it's code (original comments only in polish, sorry):
/*
(c) Janusz Ganczarski (Power)
http://www.januszg.hg.pl
JanuszG@enter.net.pl
*/
#include <GL/glut.h>
#include <stdlib.h>
// funkcja generująca scenę 3D
void Display ()
{
// kolor tła - zawartość bufora koloru
glClearColor (1.0,1.0,1.0,1.0);
// czyszczenie bufora koloru
glClear (GL_COLOR_BUFFER_BIT);
// kolor kwadratu
glColor3f (1.0,0.0,0.0);
// początek definicji wielokąta
glBegin (GL_POLYGON);
// kolejne wierzchołki wielokąta
glVertex3f (0.0, 0.0, 0.0);
glVertex3f (0.0, 1.0, 0.0);
glVertex3f (1.0, 1.0, 0.0);
glVertex3f (1.0, 0.0, 0.0);
// koniec definicji prymitywu
glEnd ();
// skierowanie poleceń do wykonania
glFlush ();
// zamiana buforów koloru
glutSwapBuffers();
}
// zmiana wielkości okna
void Reshape (int width, int height)
{
// generowanie sceny 3D
Display ();
}
// stałe do obsługi menu podręcznego
enum
{
EXIT // wyjście
};
// obsługa menu podręcznego
void Menu (int value)
{
switch (value)
{
// wyjście
case EXIT:
exit (0);
}
}
int main (int argc, char *argv[])
{
// inicjalizacja biblioteki GLUT
glutInit (&argc,argv);
// inicjalizacja bufora ramki
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
// rozmiary głównego okna programu
glutInitWindowSize (400,400);
// utworzenie głównego okna programu
glutCreateWindow ("Kwadrat 1");
// dołączenie funkcji generującej scenę 3D
glutDisplayFunc (Display);
// dołączenie funkcji wywoływanej przy zmianie rozmiaru okna
glutReshapeFunc (Reshape);
// utworzenie menu podręcznego
glutCreateMenu (Menu);
// dodadnie pozycji do menu podręcznego
#ifdef WIN32
glutAddMenuEntry ("Wyjście",EXIT);
#else
glutAddMenuEntry ("Wyjscie",EXIT);
#endif
// określenie przycisku myszki obsługującej menu podręczne
glutAttachMenu (GLUT_RIGHT_BUTTON);
// wprowadzenie programu do obsługi pętli komunikatów
glutMainLoop ();
return 0;
}
I downloaded GLUT from OpenGL page and extracted both .dll's to windows/system and windows/system32 (wasn't sure where it's supposed to go), extracted .h to MinGW/include/GL and .lib's to MinGW/lib and also Extracted all 5 files to a separate folder. Then I created new GLUT project in C::B, and I was asked about the folder to which GLUT was unpacked - I responded with MinGW's folder. I pasted the example program's source into newly created main.cpp, then I linked both glut.lib and glut32.lib to the project (in project\build options\linker settings) and tried to compile and received an error (and some warnings about ignoring pragma content as well)
D:\IT\CodeBlocks\MinGW\include\GL\glut.h|43|error: redeclaration of C++ built-in type `short'
in header file in lines:
# ifndef _WCHAR_T_DEFINED
typedef unsigned short wchar_t;
# define _WCHAR_T_DEFINED
Uncle Google told me that stdio.h should be included before glut.h so I tried that one and got:
D:\IT\CodeBlocks\MinGW\include\GL\glut.h|48|warning: ignoring #pragma comment |
D:\IT\CodeBlocks\MinGW\include\GL\glut.h|49|warning: ignoring #pragma comment |
D:\IT\CodeBlocks\MinGW\include\GL\glut.h|50|warning: ignoring #pragma comment |
D:\IT\CodeBlocks\MinGW\include\GL\glut.h|51|warning: ignoring #pragma comment |
D:\IT\CodeBlocks\MinGW\include\GL\glut.h|53|warning: ignoring #pragma warning |
D:\IT\CodeBlocks\MinGW\include\GL\glut.h|54|warning: ignoring #pragma warning |
obj\Debug\main.o||In function `_Z7Displayv':|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|15|undefined reference to `__imp__glClearColor'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|18|undefined reference to `__imp__glClear'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|21|undefined reference to `__imp__glColor3f'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|24|undefined reference to `__imp__glBegin'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|27|undefined reference to `__imp__glVertex3f|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|28|undefined reference to `__imp__glVertex3f'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|29|undefined reference to `__imp__glVertex3f'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|30|undefined reference to `__imp__glVertex3f'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|33|undefined reference to `__imp__glEnd'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|36|undefined reference to `__imp__glFlush'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|39|undefined reference to `_glutSwapBuffers'|
obj\Debug\main.o||In function `main':|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|72|undefined reference to `_glutInit'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|75|undefined reference to `_glutInitDisplayMode'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|78|undefined reference to `_glutInitWindowSize'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|81|undefined reference to `_glutCreateWindow'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|84|undefined reference to `_glutDisplayFunc'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|87|undefined reference to `_glutReshapeFunc'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|90|undefined reference to `_glutCreateMenu'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|95|undefined reference to `_glutAddMenuEntry'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|102|undefined reference to `_glutAttachMenu'|
C:\Documents and Settings\User\Moje dokumenty\fun\3dfun3\main.cpp|105|undefined reference to `_glutMainLoop|
||=== Build finished: 21 errors, 6 warnings ===|
I created new GLUT project, linked both .lib's and tried to compile the code that is in every new GLUT project by default, included stdlib.h before glut.h and tried to compile. This time I got 50 "undefined reference" errors, more followed but weren't displayed.
If even the default code in an example program doesn't work then I guess it's not compiler/OpenGL issue, I guess I screwed something up (with GLUT). Any idea how to make these two programs work/what have I done wrong?
I described all the things I've done as detailed as possible. I'm using on WinXP sp2.