Hello,

I've tried a lot but i still can't handle it. In one moment after opening windows, i get another windows which tells: "program has stopped working". I am programming in CodeBlocks. Here is code:

Code :
#include <stdio.h>
#include <math.h>
#include <GL/gl.h>
#define GLUT_DISABLE_ATEXIT_HACK
#include <GL/glu.h>
#include <GL/glut.h>
struct punkt {
                 float x, y, z;
};
 
struct brylaOtaczajaca {
                 punkt max;
                 punkt min;
};
typedef float wSkalar;
class Wektor {
                 /*private:
                                 wSkalar x;
                                 wSkalar y;
                                 wSkalar z;
                                 */
                 public:
                                 wSkalar x;
                                 wSkalar y;
                                 wSkalar z;
                                 //konstruktory
                                 Wektor ();
                                 Wektor (wSkalar _x, wSkalar _y, wSkalar _z);
                                 Wektor (const Wektor &v);
                                 wSkalar X();
                                 wSkalar Y();
                                 wSkalar Z();
                                 //realizacja podstawowych działań na wektorach:
                                 //podstawienie wektora
                                 const Wektor &operator=(const Wektor &v);
                                 //równość wektorów
                                 const bool operator==(const Wektor &v) const;
                                 //nierówność wektorów
                                 const bool operator!=(const Wektor &v) const;
                                 //dodawanie wektorów
                                 const Wektor operator+(const Wektor &v) const;
                                 //dodawanie wektorów ncch einmal
                                 const Wektor operator+() const;
                                 //i jeszcze jeden sposób na dodanie
                                 const Wektor& operator+=(const Wektor &v);
                                 //odejmowanie
                                 const Wektor operator-() const;
                                 const Wektor operator-(const Wektor &v) const;
                                 const Wektor& operator-=(const Wektor &v);
                                 //mnożenie przez skalar
                                 const Wektor& operator*=(const wSkalar &s);
                                 const Wektor operator*(const wSkalar &s) const;
                                 //dzielenie przez skalar
                                 const Wektor &operator/=(const wSkalar &s);
                                 const Wektor operator/(const wSkalar &s) const;
                                 //iloczyn wektorowy
                                 const Wektor IlWektorow (const Wektor &v) const;
                                 const Wektor operator^(const Wektor &v) const;
                                 //iloczyn skalarny
                                 const wSkalar IlSklarny (const Wektor &v) const;
                                 const wSkalar operator%(const Wektor &v) const;
                                 //długość wektora
                                 const wSkalar Dlugosc() const;
                                 //wektor jednostkowy
                                 const Wektor jednostWektor() const;
                                 //normalizacja wektora
                                 void Normalizacja();
                                 //operator modułu (długości) wektora - przyda mi sie to?
                                 const wSkalar operator!() const;
                                 //zmienia długość wektora
                                 const Wektor operator | (const wSkalar dl) const;
                                 const Wektor& operator |= (const float dl);
                                 //zwraca kąt, który tworzą wektory
                                 const float inline Kat(const Wektor &v) const;
                                 //tworzy odbicie wektora względem powierzchni zdefiniowanej przez normalną
                                 const Wektor inline Odbicie(const Wektor &N) const;
 
};
class obiektWalec {
                 public:
                                 float masa;
                                 Wektor predkosc;
                                 Wektor przyspieszenie;
                                 Wektor polozenie;
                                 brylaOtaczajaca Bryla;
};
class Rownia {
                 public:
                                 float w[6][3];
                                 float nachylenie;
                                 Rownia();
                                 void Rysuj(GLfloat rx, GLfloat ry);
                                 void Laduj();
};
class Okno {
                 private:
                                 int k_wysokosc;
                                 int k_szerokosc;
                                 int k_poz_x;
                                 int k_poz_y;
                 public:
                                 Okno (int u_wys, int u_szer, int u_x, int u_y);
                                 void petla (int argc, char *argv[]);
};
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
GLuint listaW;
Rownia::Rownia() : nachylenie(45.0) {}
void Rownia::Laduj() {
         GLfloat w[6][3];
/*GLfloat tmp[6][3] = {{0.0, 0.0, 0.0},
                 {1.0, 0.0, 0.0},
                 {0.0, 1.0, 0.0},
                 {0.0, 1.0, 1.0},
                 {1.0, 0.0, 1.0},
                 {0.0, 0.0, 1.0}
                 };
                 w = tmp;*/
                 printf("Laduje wierzcholki walca\n");
                 w[0][0] = 0.0;
                 w[0][1] = 0.0;
                 w[0][2] = 0.0;
                 w[1][0] = 1.0;
                 w[1][1] = 0.0;
                 w[1][2] = 0.0;
                 w[2][0] = 0.0;
                 w[2][1] = 1.0;
                 w[2][2] = 0.0;
                 w[3][0] = 0.0;
                 w[3][1] = 1.0;
                 w[3][2] = 1.0;
                 w[4][0] = 1.0;
                 w[4][1] = 0.0;
                 w[4][2] = 1.0;
                 w[5][0] = 0.0;
                 w[5][1] = 0.0;
                 w[5][2] = 1.0;
                 printf("I zaladowane\n");
}
void Rownia::Rysuj(GLfloat rx, GLfloat ry) {
                 glPushMatrix();
                                 glTranslatef(0.0, 0.0, 0.0);
                                 glRotatef (rx,1.0,0.0,0.0);
                                 glRotatef (ry,0.0,1.0,0.0);
                                 glScalef(6.0, 6.0, 6.0);
                                 glBegin(GL_TRIANGLES);
                                                 glColor3f(1.0f, 0.0f, 0.0f);
                                                 glVertex3f(w[0][0], w[0][1], w[0][2]);
                                                 glVertex3f(w[1][0], w[1][1], w[1][2]);
                                                 glVertex3f(w[2][0], w[2][1], w[2][2]);
                                                 /*//lewa strona
                                                 glVertex3f(0.0, 0.0, 0.0);
                                                 glVertex3f(1.0, 0.0, 0.0);
                                                 glVertex3f(0.0, 1.0, 0.0);*/
                                                 glColor3f(0.0f, 1.0f, 0.0f);
                                                 //trójkąty tworzące spad
                                                 glVertex3f(0.0, 1.0, 0.0);
                                                 glVertex3f(1.0, 0.0, 0.0);
                                                 glVertex3f(0.0, 1.0, 1.0);
                                                 glVertex3f(0.0, 1.0, 1.0);
                                                 glVertex3f(1.0, 0.0, 0.0);
                                                 glVertex3f(1.0, 0.0, 1.0);
                                                 glColor3f(1.0f, 0.0f, 0.0f);
                                                 //prawa strona
                                                 glVertex3f(0.0, 1.0, 1.0);
                                                 glVertex3f(1.0, 0.0, 1.0);
                                                 glVertex3f(0.0, 0.0, 1.0);
                                                 glColor3f(0.0f, 0.0f, 1.0f);
                                                 //tył
                                                 glVertex3f(0.0, 1.0, 0.0);
                                                 glVertex3f(0.0, 1.0, 1.0);
                                                 glVertex3f(0.0, 0.0, 1.0);
                                                 glVertex3f(0.0, 1.0, 0.0);
                                                 glVertex3f(0.0, 0.0, 1.0);
                                                 glVertex3f(0.0, 0.0, 0.0);
                                 glEnd();
                 glPopMatrix();
}
Wektor::Wektor() : x(0.0), y(0.0), z(0.0) {}
Wektor::Wektor(wSkalar _x, wSkalar _y, wSkalar _z) : x(_x), y(_y), z(_z){}
Wektor::Wektor(const Wektor &v) : x(v.x), y(v.y), z(v.z) {}
wSkalar Wektor::X() { return x; }
wSkalar Wektor::Y() { return y; }
wSkalar Wektor::Z() { return z; }
const Wektor& Wektor::operator=(const Wektor &v) {
                 x = v.x;
                 y = v.y;
                 z = v.z;
                 return *this;
}
const bool Wektor::operator==(const Wektor &v) const{
                 return ((x == v.x) && (y == v.y) && (z == v.z));
}
const bool Wektor::operator!=(const Wektor &v) const {
                 return !(*this == v);
}
const Wektor Wektor::operator+(const Wektor &v) const {
                 return Wektor(x + v.x, y + v.y, z + v.z);
}
const Wektor Wektor::operator+() const {
                 return Wektor(*this);
}
const Wektor& Wektor::operator+=(const Wektor& v) {
                 x += v.x;
                 y += v.y;
                 z += v.z;
                 return *this;
}
const Wektor Wektor::operator-(const Wektor &v) const {
                 return Wektor (x - v.x, y - v.y, z - v.z);
}
const Wektor Wektor::operator-() const {
                 return Wektor(-x, -y, -z);
}
const Wektor& Wektor::operator-=(const Wektor &v) {
                 x -= v.x;
                 y -= v.y;
                 z -= v.z;
                 return *this;
}
const Wektor& Wektor::operator*=(const wSkalar &s) {
                 x *= s;
                 y *= s;
                 z *= s;
                 return *this;
}
const Wektor& Wektor::operator/=(const wSkalar &s) {
                 //dla efektywności - tak radzą w książce
                 const float odwr = 1/s;
                 x *= odwr;
                 y *= odwr;
                 z *= odwr;
                 return *this;
}
 
const Wektor Wektor::operator*(const wSkalar &s) const {
                 return Wektor (x*s, y*s, z*s);
}
const Wektor Wektor::operator/(const wSkalar &s) const {
                 wSkalar w = 1/s;
                 return Wektor(x*w, y*w, z*w);
}
//zakręcona funkcyjka
const Wektor Wektor::IlWektorow(const Wektor &v) const {
                 return Wektor(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x);
}
 
const wSkalar Wektor::IlSklarny(const Wektor &v) const {
                 return x*v.x + y*v.y + z*v.z;
}
const wSkalar Wektor::operator%(const Wektor &v) const {
                 return x*v.x + y*v.y + z*v.z;
}
const wSkalar Wektor::Dlugosc() const {
                 return (wSkalar)sqrt((double)(x*x + y*y + z*z));
}
const Wektor Wektor::jednostWektor() const {
                 return (*this) / Dlugosc();
}
void Wektor::Normalizacja() {
                 (*this) /= Dlugosc();
}
const wSkalar Wektor::operator!() const {
                 return sqrtf(x*x + y*y + z*z);
}
const Wektor Wektor::operator | (const wSkalar dl) const{
                 return *this * (dl / !(*this));
}
const Wektor& Wektor::operator |= (const float dl) {
                 return *this = *this | dl;
}
const float inline Wektor::Kat(const Wektor &v) const {
                 return acosf(*this % v);
}
 
//stanowczo zakręcone!
const Wektor inline Wektor::Odbicie(const Wektor &N) const {
                 const Wektor wek(*this | 1); //normalizuje wektor
                 return (wek - N * 2.0 * (wek % N)) * !*this;
}
bool wek = true;
GLint k_szerokosc = 640;
GLint k_wysokosc = 480;
Rownia *r;
// kąty obrotu
GLfloat rx = 0.0;
GLfloat ry = 0.0;
//zmienne globalne do manipulacji myszą
int przycisk_myszy = GLUT_UP;
int mysz_x, mysz_y;
Okno::Okno(int u_wys, int u_szer, int u_x, int u_y) {
                 k_wysokosc = u_wys;
                 k_szerokosc = u_szer;
                 k_poz_x = u_x;
                 k_poz_y = u_y;
                 Rownia *r = new Rownia();
}
void TestWektorow() {
                 Wektor a(1.0, 2.0, 3.0);
                 Wektor b(2.0, 2.0, 2.0);
                 Wektor c(0.0, 0.0, 0.0);
                 printf("Oto wektor a: [ %f , %f , %f ]\n", a.x, a.y, a.z);
                 printf("Oto wektor b: [ %f , %f , %f ]\n", b.x, b.y, b.z);
                 c = a + b;
                 printf("a + b = [ %f , %f , %f ]\n", c.x, c.y, c.z);
}
void init(void) {
                 glClearColor(0.0, 0.0, 0.0, 0.0);
                 glShadeModel(GL_SMOOTH);
 
                 glViewport(0,0,k_szerokosc,k_wysokosc);
 
                 glMatrixMode(GL_PROJECTION);
                 glLoadIdentity();
                 gluPerspective(45.0f,(GLfloat)k_szerokosc/(GLfloat)k_wysokosc,10.0f,10000.0f);
                 glEnable(GL_DEPTH_TEST);
                 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
                 glShadeModel(GL_SMOOTH);
                 glEnable(GL_TEXTURE_2D);
                 glEnable(GL_CULL_FACE);
                 glEnable(GL_DEPTH_TEST);
                 r->Laduj();
}
// obsługa przycisków myszki
void MouseButton (int button, int state, int x, int y)
{
         if (button == GLUT_LEFT_BUTTON)
         {
                 // zapamiętanie stanu lewego przycisku myszki
                 przycisk_myszy = state;
                 // zapamiętanie położenia kursora myszki
                 if (state == GLUT_DOWN)
                 {
                         mysz_x = x;
                         mysz_y = y;
                 }
         }
}
// obsługa ruchu kursora myszki
void MouseMotion (int x, int y) {
         if (przycisk_myszy == GLUT_DOWN){
                                 rx += 0.001*(x-mysz_x);
                                 ry += 0.001*(y-mysz_y);
                 }
}
 
// obsługa klawiszy funkcyjnych i klawiszy kursora
void SpecialKeys (int klawisz, int x, int y)
{
         switch (klawisz)
         {
                 //klawisz
                 case GLUT_KEY_LEFT:
                 ry -= 1;
                 break;
                 // kursor w górę
                 case GLUT_KEY_UP:
                 rx -= 1;
                 break;
                 // kursor w prawo
                 case GLUT_KEY_RIGHT:
                 ry += 1;
                 break;
                 // kursor w dół
                 case GLUT_KEY_DOWN:
                 rx += 1;
                 break;
         }
         //Reshape (glutGet (GLUT_WINDOW_WIDTH),glutGet (GLUT_WINDOW_HEIGHT));
}
void DisplayScene () {
                 /*const double t = glutGet(GLUT_ELAPSED_TIME) / 10000.0;
                 const double a = t*90.0;
                 */
                 glClearColor(1, 1, 1, 0);
                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                 glMatrixMode(GL_MODELVIEW);
                 glLoadIdentity();
                 glPushMatrix();
                                 glTranslatef(0.0f, 0.0f, -15.0f);
                                 if (wek){
                                                TestWektorow();
                                                wek = false;
                                 }
                                 r->Rysuj(rx, ry);
                 glPopMatrix();
                 glFlush();
                 glutSwapBuffers();
 
}
void Reshape (int width, int height) {
                 k_szerokosc=width;
                 k_wysokosc=height;
                 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                 glViewport(0,0,k_szerokosc,k_wysokosc);
                 glMatrixMode(GL_PROJECTION);
                 glLoadIdentity();
                 int szer = width;
                 int wys = height;
                 //co ja z tym pokręciłam?
                 gluPerspective(45.0f,(GLfloat)k_szerokosc/(GLfloat)k_wysokosc,10.0f,10000.0f);
                 glutPostRedisplay ();
}
 
void Okno::petla (int argc, char *argv[])
{
                 //inicjalizacja biblioteki GLUT
                 glutInit(&argc, argv);
                 //rozmiary głównego okna programu
                 glutInitWindowSize(k_wysokosc, k_szerokosc);
                 //jego pozycja
                 glutInitWindowPosition(k_poz_x, k_poz_y);
                 //inicjalizacja bufora ramki
                 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
                 //utworzenie głównego okna
                 glutCreateWindow("Fizyka");
                 //dołączenie funkcji generującej scenę
                 glutDisplayFunc (DisplayScene);
                 glutIdleFunc(DisplayScene);
                 glutReshapeFunc (Reshape);
                 // dołączenie funkcji obsługi klawiszy funkcyjnych i klawiszy kursora
                 glutSpecialFunc (SpecialKeys);
                 //obsługa przycisków myszki
                 glutMouseFunc (MouseButton);
                 //obsługa ruchu kursora myszki
                 glutMotionFunc (MouseMotion);
                 init();
                 printf("uruchomienie okna\n");
                 glutMainLoop();
}
//////////
int main (int argc, char *argv[]) {
                 Okno *okno = new Okno (640, 480, 10, 10);
                 okno->petla(argc, argv);
                 return 0;
}