1.Code::Blocks (potem go nie używałem, bo nie kompilował, ale może to ważne, że go mam)
2.sudo apt-get install libgl1-mesa-dev
3.sudo apt-get install freeglut3
4.sudo apt-get install freeglut3-dev
Mam przykładowy kod, znaleziony gdzieś w sieci, bo OpenGL jeszcze;) nie umiem:
Kod: Zaznacz cały
#include <GL/freeglut.h>
#define window_width 640
#define window_height 480
// Main loop
void main_loop_function()
{
// Z angle
static float angle;
// Clear color (screen)
// And depth (used internally to block obstructed objects)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Load identity matrix
glLoadIdentity();
// Multiply in translation matrix
glTranslatef(0,0, -10);
// Multiply in rotation matrix
glRotatef(angle, 0, 0, 1);
// Render colored quad
glBegin(GL_QUADS);
glColor3ub(255, 000, 000); glVertex2f(-1, 1);
glColor3ub(000, 255, 000); glVertex2f( 1, 1);
glColor3ub(000, 000, 255); glVertex2f( 1, -1);
glColor3ub(255, 255, 000); glVertex2f(-1, -1);
glEnd();
// Swap buffers (color buffers, makes previous render visible)
glutSwapBuffers();
// Increase angle to rotate
angle+=0.25;
}
// Initialze OpenGL perspective matrix
void GL_Setup(int width, int height)
{
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glEnable( GL_DEPTH_TEST );
gluPerspective( 45, (float)width/height, .1, 100 );
glMatrixMode( GL_MODELVIEW );
}
// Initialize GLUT and start main loop
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitWindowSize(window_width, window_height);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("GLUT Example!!!");
glutIdleFunc(main_loop_function);
GL_Setup(window_width, window_height);
glutMainLoop();
}
Kod: Zaznacz cały
mazix@komputer:~/Pulpit$ g++ glut_file.cpp -lglut
/tmp/cc1Tjtuh.o: In function `GL_Setup(int, int)':
glut_file.cpp:(.text+0x1bc): undefined reference to `gluPerspective'
collect2: ld returned 1 exit status
mazix@komputer:~/Pulpit$ g++ glut_file.cpp -lglu
/usr/bin/ld: cannot find -lglu
collect2: ld returned 1 exit status
mazix@komputer:~/Pulpit$ g++ glut_file.cpp -lgl
/usr/bin/ld: cannot find -lgl
collect2: ld returned 1 exit status
mazix@komputer:~/Pulpit$ g++ glut_file.cpp -lfreeglut
/usr/bin/ld: cannot find -lfreeglut
collect2: ld returned 1 exit status
mazix@komputer:~/Pulpit$ g++ glut_file.cpp -lfreeglut -lGLU -lGL
/usr/bin/ld: cannot find -lfreeglut
collect2: ld returned 1 exit status
mazix@komputer:~/Pulpit$ g++ glut_file.cpp -lGLU -lGL
/tmp/cctkri3t.o: In function `main_loop_function()':
glut_file.cpp:(.text+0x138): undefined reference to `glutSwapBuffers'
/tmp/cctkri3t.o: In function `main':
glut_file.cpp:(.text+0x1e5): undefined reference to `glutInit'
glut_file.cpp:(.text+0x1f9): undefined reference to `glutInitWindowSize'
glut_file.cpp:(.text+0x205): undefined reference to `glutInitDisplayMode'
glut_file.cpp:(.text+0x211): undefined reference to `glutCreateWindow'
glut_file.cpp:(.text+0x21d): undefined reference to `glutIdleFunc'
glut_file.cpp:(.text+0x236): undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status
